Skip to content

Instance lease: Allow deployment of instances with lease duration and leaseexpiry action #10560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

sudo87
Copy link
Collaborator

@sudo87 sudo87 commented Mar 13, 2025

Description

This PR enables Administrator to provide capability for end user to provision Lease based instances, which will self destroyed or stopped once lease expires. This will improve efficient utilization of cloud infrastructure and reduce unused VMs in the cloud infrastructure.

Doc PR: apache/cloudstack-documentation#492

Feature can be enabled by updating value for following key to true:
instance.lease.enabled: true
default: false

There are additional configuration keys:

instance.lease.scheduler.interval: when scheduler will run to execute expiryaction, default value: 3600 (seconds)
instance.lease.alertscheduler.interval: alert scheduler interval, sends alerts for any instance which are about to expire in next 7 days (default: 86400)

Feature introduces new parameters in following APIs:
leaseduration: duration in days for which instance is provisioned
leaseexpiryaction: action will be executed once expiry is over

  1. DeployVMCmd
deploy virtualmachine name=test-vm templateid=e6962fb7-fa6f-11ef-86b8-50eb71576f75 serviceofferingid=8fcc7ba4-298c-4c21-b5f6-c3c4e1d2afe7 leaseduration=10 leaseexpiryaction=STOP zoneid=988db21e-ffc9-4708-9546-797cb7592cb9
  1. CreateServiceOfferingCmd
create serviceoffering name=cmd-lease leaseduration=10 leaseexpiryaction=STOP
  1. UpdateVMCmd
update virtualmachine id=e22a2b2b-66c0-4566-9648-ec3219dbcb96 leaseduration=-1

Valid values for
leaseduration: positive number, negative value to removing lease from instance (-1)
leaseexpiryaction: STOP | DESTROY

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

Screenshot from 2025-03-28 09-43-07
Screenshot from 2025-03-28 09-44-48
Screenshot from 2025-03-28 09-45-04
Screenshot from 2025-03-28 09-46-46
Screenshot from 2025-03-28 09-46-23
Screenshot from 2025-03-28 09-46-18
Screenshot from 2025-03-28 09-45-48
Screenshot from 2025-03-28 09-42-18

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@sudo87
Copy link
Collaborator Author

sudo87 commented Mar 13, 2025

@blueorangutan package

@blueorangutan
Copy link

@sudo87 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 12761


@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
description = "Lease expiry action")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add posible choices in the description.

Copy link

codecov bot commented Mar 13, 2025

Codecov Report

Attention: Patch coverage is 43.43891% with 250 lines in your changes missing coverage. Please review.

Project coverage is 16.33%. Comparing base (fd3d605) to head (89db8a2).

Files with missing lines Patch % Lines
...apache/cloudstack/vm/lease/VMLeaseManagerImpl.java 43.54% 95 Missing and 10 partials ⚠️
...ava/com/cloud/api/query/dao/UserVmJoinDaoImpl.java 37.50% 28 Missing and 2 partials ⚠️
.../cloud/configuration/ConfigurationManagerImpl.java 0.00% 25 Missing ⚠️
...apache/cloudstack/api/response/UserVmResponse.java 0.00% 18 Missing ⚠️
...main/java/com/cloud/api/query/vo/UserVmJoinVO.java 0.00% 13 Missing ⚠️
...oudstack/api/response/ServiceOfferingResponse.java 0.00% 12 Missing ⚠️
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 87.80% 4 Missing and 6 partials ⚠️
...ain/java/com/cloud/api/query/QueryManagerImpl.java 0.00% 8 Missing ⚠️
...he/cloudstack/api/command/user/vm/UpdateVMCmd.java 0.00% 6 Missing ⚠️
.../com/cloud/api/query/vo/ServiceOfferingJoinVO.java 0.00% 6 Missing ⚠️
... and 6 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10560      +/-   ##
============================================
+ Coverage     16.30%   16.33%   +0.02%     
- Complexity    13449    13485      +36     
============================================
  Files          5675     5677       +2     
  Lines        499249   499762     +513     
  Branches      60377    60458      +81     
============================================
+ Hits          81422    81637     +215     
- Misses       408756   409035     +279     
- Partials       9071     9090      +19     
Flag Coverage Δ
uitests 3.98% <ø> (-0.01%) ⬇️
unittests 17.19% <43.43%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sudo87 build failing with unit tests failure. Please check

}

@Test
public void testAlert() {
Copy link
Contributor

@shwstppr shwstppr Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have to mock global config to true for this case?

@sudo87
Copy link
Collaborator Author

sudo87 commented Mar 17, 2025

@blueorangutan package

@blueorangutan
Copy link

@sudo87 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 12802

is_config_suitable)


class TestDeployVMLease(cloudstackTestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sudo87
can you add this test to .github/workflows/ci.yml so it will be tested by Simulator CI ?


public static ConfigKey<Boolean> InstanceLeaseEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class,
"instance.lease.enabled", "false", "Indicates whether to enable the Instance Lease feature",
true, List.of(ConfigKey.Scope.Global));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sudo87
please double check if the global setting is dynamic or not. (and other global settings as well)

dynamic: not need to restart mamagement server
non-dynamic: it is required to restart management server

1. Execute lease action once on the instance
2. Cancel lease on instance when feature is disabled
3. Relevant events when lease gets disabled, cancelled, executed
4. Disable associating lease after deployment
5. UI elements and flow changes
6. Changes based on feedback from demo
@sudo87
Copy link
Collaborator Author

sudo87 commented Mar 27, 2025

@blueorangutan package

@blueorangutan
Copy link

@sudo87 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 12903

@sudo87
Copy link
Collaborator Author

sudo87 commented Mar 28, 2025

@blueorangutan test

@blueorangutan
Copy link

@sudo87 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@sudo87 sudo87 marked this pull request as ready for review March 28, 2025 04:36
@blueorangutan
Copy link

[SF] Trillian test result (tid-12838)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 57986 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10560-t12838-kvm-ol8.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

Copy link

github-actions bot commented Apr 2, 2025

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@sudo87
Copy link
Collaborator Author

sudo87 commented Apr 7, 2025

@blueorangutan package

@blueorangutan
Copy link

@sudo87 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 12969

@sudo87
Copy link
Collaborator Author

sudo87 commented Apr 8, 2025

@blueorangutan test

@blueorangutan
Copy link

@sudo87 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian Build Failed (tid-12899)

@sudo87
Copy link
Collaborator Author

sudo87 commented Apr 8, 2025

@blueorangutan test

@blueorangutan
Copy link

@sudo87 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian test result (tid-12900)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 97286 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10560-t12900-kvm-ol8.zip
Smoke tests completed. 131 look OK, 10 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_CRUD_operations_userdata Error 1522.32 test_register_userdata.py
test_deploy_vm_with_registered_userdata Error 7.69 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_override_policy_allow Error 7.63 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_override_policy_append Error 7.45 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_override_policy_deny Error 7.62 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_params Error 7.42 test_register_userdata.py
test_link_and_unlink_userdata_to_template Error 7.93 test_register_userdata.py
test_user_userdata_crud Error 7.73 test_register_userdata.py
ContextSuite context=TestRAMCPUResourceAccounting>:setup Error 0.00 test_resource_accounting.py
test_01_create_template Error 1.14 test_templates.py
test_CreateTemplateWithDuplicateName Error 1.15 test_templates.py
test_02_create_template_with_checksum_sha1 Error 65.59 test_templates.py
test_03_create_template_with_checksum_sha256 Error 65.60 test_templates.py
test_04_create_template_with_checksum_md5 Error 65.60 test_templates.py
test_05_create_template_with_no_checksum Error 65.60 test_templates.py
test_09_list_templates_download_details Failure 0.07 test_templates.py
ContextSuite context=TestISOUsage>:setup Error 0.00 test_usage.py
test_10_attachAndDetach_iso Failure 1512.90 test_vm_life_cycle.py
ContextSuite context=TestMigrateVMStrictTags>:setup Error 0.00 test_vm_strict_host_tags.py
ContextSuite context=TestRestoreVMStrictTags>:setup Error 0.00 test_vm_strict_host_tags.py
ContextSuite context=TestScaleVMStrictTags>:setup Error 0.00 test_vm_strict_host_tags.py
ContextSuite context=TestVMDeploymentPlannerStrictTags>:setup Error 0.00 test_vm_strict_host_tags.py
test_04_deploy_vnf_appliance Error 311.91 test_vnf_templates.py
test_06_download_detached_volume Error 302.18 test_volumes.py
test_13_migrate_volume_and_change_offering Error 124.16 test_volumes.py
ContextSuite context=TestIpv6Vpc>:setup Error 0.00 test_vpc_ipv6.py
ContextSuite context=TestVPCRedundancy>:setup Error 0.00 test_vpc_redundant.py

@winterhazel winterhazel self-requested a review April 17, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants