Skip to content

Commit d6d4442

Browse files
committed
Merge remote-tracking branch 'upstream/main' into instance
2 parents 091c21a + 41b4f0a commit d6d4442

File tree

48 files changed

+2551
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2551
-157
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ jobs:
164164
component/test_cpu_limits
165165
component/test_cpu_max_limits
166166
component/test_cpu_project_limits
167-
component/test_deploy_vm_userdata_multi_nic",
167+
component/test_deploy_vm_userdata_multi_nic
168+
component/test_deploy_vm_lease",
168169
"component/test_egress_fw_rules
169170
component/test_invalid_gw_nm
170171
component/test_ip_reservation",

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,11 @@ public class EventTypes {
798798
// Resource Limit
799799
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
800800

801+
public static final String VM_LEASE_EXPIRED = "VM.LEASE.EXPIRED";
802+
public static final String VM_LEASE_DISABLED = "VM.LEASE.DISABLED";
803+
public static final String VM_LEASE_CANCELLED = "VM.LEASE.CANCELLED";
804+
public static final String VM_LEASE_EXPIRING = "VM.LEASE.EXPIRING";
805+
801806
static {
802807

803808
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -1292,6 +1297,12 @@ public class EventTypes {
12921297
entityEventDetails.put(EVENT_SHAREDFS_DESTROY, SharedFS.class);
12931298
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
12941299
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
1300+
1301+
// VM Lease
1302+
entityEventDetails.put(VM_LEASE_EXPIRED, VirtualMachine.class);
1303+
entityEventDetails.put(VM_LEASE_EXPIRING, VirtualMachine.class);
1304+
entityEventDetails.put(VM_LEASE_DISABLED, VirtualMachine.class);
1305+
entityEventDetails.put(VM_LEASE_CANCELLED, VirtualMachine.class);
12951306
}
12961307

12971308
public static boolean isNetworkEvent(String eventType) {

api/src/main/java/com/cloud/vm/VmDetailConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,8 @@ public interface VmDetailConstants {
110110
// CPU mode and model, ADMIN only
111111
String GUEST_CPU_MODE = "guest.cpu.mode";
112112
String GUEST_CPU_MODEL = "guest.cpu.model";
113+
114+
String INSTANCE_LEASE_EXPIRY_DATE = "leaseexpirydate";
115+
String INSTANCE_LEASE_EXPIRY_ACTION = "leaseexpiryaction";
116+
String INSTANCE_LEASE_EXECUTION = "leaseactionexecution";
113117
}

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ public class ApiConstants {
273273
public static final String INTERNAL_DNS2 = "internaldns2";
274274
public static final String INTERNET_PROTOCOL = "internetprotocol";
275275
public static final String INTERVAL_TYPE = "intervaltype";
276-
public static final String LOCATION_TYPE = "locationtype";
276+
public static final String INSTANCE_LEASE_DURATION = "leaseduration";
277+
public static final String INSTANCE_LEASE_ENABLED = "instanceleaseenabled";
278+
public static final String INSTANCE_LEASE_EXPIRY_ACTION = "leaseexpiryaction";
279+
public static final String INSTANCE_LEASE_EXPIRY_DATE= "leaseexpirydate";
277280
public static final String IOPS_READ_RATE = "iopsreadrate";
278281
public static final String IOPS_READ_RATE_MAX = "iopsreadratemax";
279282
public static final String IOPS_READ_RATE_MAX_LENGTH = "iopsreadratemaxlength";
@@ -322,11 +325,13 @@ public class ApiConstants {
322325
public static final String LAST_BOOT = "lastboottime";
323326
public static final String LAST_SERVER_START = "lastserverstart";
324327
public static final String LAST_SERVER_STOP = "lastserverstop";
328+
public static final String LEASED = "leased";
325329
public static final String LEVEL = "level";
326330
public static final String LENGTH = "length";
327331
public static final String LIMIT = "limit";
328332
public static final String LIMIT_CPU_USE = "limitcpuuse";
329333
public static final String LIST_HOSTS = "listhosts";
334+
public static final String LOCATION_TYPE = "locationtype";
330335
public static final String LOCK = "lock";
331336
public static final String LUN = "lun";
332337
public static final String LBID = "lbruleid";

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import org.apache.cloudstack.api.response.VsphereStoragePoliciesResponse;
3535
import org.apache.cloudstack.api.response.ZoneResponse;
3636
import org.apache.cloudstack.api.response.DiskOfferingResponse;
37+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
3738
import org.apache.commons.collections.MapUtils;
39+
import org.apache.commons.lang3.EnumUtils;
3840
import org.apache.commons.lang3.StringUtils;
3941
import org.apache.commons.collections.CollectionUtils;
4042

@@ -251,7 +253,15 @@ public class CreateServiceOfferingCmd extends BaseCmd {
251253
since="4.20")
252254
private Boolean purgeResources;
253255

256+
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION,
257+
type = CommandType.INTEGER,
258+
description = "Number of days instance is leased for.",
259+
since = "4.21.0")
260+
private Integer leaseDuration;
254261

262+
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
263+
description = "Lease expiry action, valid values are STOP and DESTROY")
264+
private String leaseExpiryAction;
255265

256266
/////////////////////////////////////////////////////
257267
/////////////////// Accessors ///////////////////////
@@ -487,6 +497,22 @@ public boolean getEncryptRoot() {
487497
return false;
488498
}
489499

500+
public VMLeaseManager.ExpiryAction getLeaseExpiryAction() {
501+
if (StringUtils.isBlank(leaseExpiryAction)) {
502+
return null;
503+
}
504+
VMLeaseManager.ExpiryAction action = EnumUtils.getEnumIgnoreCase(VMLeaseManager.ExpiryAction.class, leaseExpiryAction);
505+
if (action == null) {
506+
throw new InvalidParameterValueException("Invalid value configured for leaseexpiryaction, valid values are: " +
507+
com.cloud.utils.EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
508+
}
509+
return action;
510+
}
511+
512+
public Integer getLeaseDuration() {
513+
return leaseDuration;
514+
}
515+
490516
public boolean isPurgeResources() {
491517
return Boolean.TRUE.equals(purgeResources);
492518
}

api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void execute() {
7272
response.setInstancesDisksStatsRetentionTime((Integer) capabilities.get(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_TIME));
7373
response.setSharedFsVmMinCpuCount((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_CPU_COUNT));
7474
response.setSharedFsVmMinRamSize((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_RAM_SIZE));
75+
response.setInstanceLeaseEnabled((Boolean) capabilities.get(ApiConstants.INSTANCE_LEASE_ENABLED));
7576
response.setObjectName("capability");
7677
response.setResponseName(getCommandName());
7778
this.setResponseObject(response);

api/src/main/java/org/apache/cloudstack/api/command/user/vm/BaseDeployVMCmd.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@
4646
import org.apache.cloudstack.api.response.UserDataResponse;
4747
import org.apache.cloudstack.api.response.ZoneResponse;
4848
import org.apache.cloudstack.context.CallContext;
49+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
4950
import org.apache.commons.collections.CollectionUtils;
5051
import org.apache.commons.collections.MapUtils;
5152
import org.apache.commons.lang3.BooleanUtils;
53+
import org.apache.commons.lang3.EnumUtils;
5254
import org.apache.commons.lang3.StringUtils;
5355

5456
import com.cloud.agent.api.LogLevel;
@@ -60,9 +62,9 @@
6062
import com.cloud.offering.DiskOffering;
6163
import com.cloud.offering.DiskOfferingInfo;
6264
import com.cloud.template.VirtualMachineTemplate;
63-
import com.cloud.utils.net.Dhcp;
6465
import com.cloud.utils.net.NetUtils;
6566
import com.cloud.vm.VmDetailConstants;
67+
import com.cloud.utils.net.Dhcp;
6668

6769
public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd {
6870

@@ -262,6 +264,14 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
262264
description = "Enable packed virtqueues or not.")
263265
private Boolean nicPackedVirtQueues;
264266

267+
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION, type = CommandType.INTEGER, since = "4.21.0",
268+
description = "Number of days instance is leased for.")
269+
private Integer leaseDuration;
270+
271+
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
272+
description = "Lease expiry action, valid values are STOP and DESTROY")
273+
private String leaseExpiryAction;
274+
265275
private List<DiskOfferingInfo> dataDiskOfferingsInfo;
266276

267277
/////////////////////////////////////////////////////
@@ -458,6 +468,22 @@ public String getPassword() {
458468
return password;
459469
}
460470

471+
public Integer getLeaseDuration() {
472+
return leaseDuration;
473+
}
474+
475+
public VMLeaseManager.ExpiryAction getLeaseExpiryAction() {
476+
if (StringUtils.isBlank(leaseExpiryAction)) {
477+
return null;
478+
}
479+
VMLeaseManager.ExpiryAction action = EnumUtils.getEnumIgnoreCase(VMLeaseManager.ExpiryAction.class, leaseExpiryAction);
480+
if (action == null) {
481+
throw new InvalidParameterValueException("Invalid value configured for leaseexpiryaction, valid values are: " +
482+
com.cloud.utils.EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
483+
}
484+
return action;
485+
}
486+
461487
public List<Long> getNetworkIds() {
462488
if (MapUtils.isNotEmpty(vAppNetworks)) {
463489
if (CollectionUtils.isNotEmpty(networkIds) || ipAddress != null || getIp6Address() != null || MapUtils.isNotEmpty(ipToNetworkList)) {

api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
160160
since = "4.20.1")
161161
private String arch;
162162

163+
@Parameter(name = ApiConstants.LEASED, type = CommandType.BOOLEAN,
164+
description = "Whether to return only leased instances",
165+
since = "4.21.0")
166+
private Boolean onlyLeasedInstances = false;
167+
163168
/////////////////////////////////////////////////////
164169
/////////////////// Accessors ///////////////////////
165170
/////////////////////////////////////////////////////
@@ -303,6 +308,10 @@ public CPU.CPUArch getArch() {
303308
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
304309
}
305310

311+
public boolean getOnlyLeasedInstances() {
312+
return BooleanUtils.toBoolean(onlyLeasedInstances);
313+
}
314+
306315
/////////////////////////////////////////////////////
307316
/////////////// API Implementation///////////////////
308317
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19-
import java.util.Collection;
20-
import java.util.HashMap;
21-
import java.util.List;
22-
import java.util.Map;
23-
19+
import com.cloud.exception.InsufficientCapacityException;
20+
import com.cloud.exception.InvalidParameterValueException;
21+
import com.cloud.exception.ResourceUnavailableException;
22+
import com.cloud.user.Account;
23+
import com.cloud.uservm.UserVm;
2424
import com.cloud.utils.exception.CloudRuntimeException;
25-
26-
import org.apache.cloudstack.api.ApiArgValidator;
27-
import org.apache.cloudstack.api.response.UserDataResponse;
28-
25+
import com.cloud.utils.net.Dhcp;
26+
import com.cloud.vm.VirtualMachine;
2927
import org.apache.cloudstack.acl.RoleType;
3028
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
3129
import org.apache.cloudstack.api.ACL;
3230
import org.apache.cloudstack.api.APICommand;
31+
import org.apache.cloudstack.api.ApiArgValidator;
3332
import org.apache.cloudstack.api.ApiCommandResourceType;
3433
import org.apache.cloudstack.api.ApiConstants;
3534
import org.apache.cloudstack.api.ApiErrorCode;
@@ -40,15 +39,17 @@
4039
import org.apache.cloudstack.api.command.user.UserCmd;
4140
import org.apache.cloudstack.api.response.GuestOSResponse;
4241
import org.apache.cloudstack.api.response.SecurityGroupResponse;
42+
import org.apache.cloudstack.api.response.UserDataResponse;
4343
import org.apache.cloudstack.api.response.UserVmResponse;
4444
import org.apache.cloudstack.context.CallContext;
45+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
46+
import org.apache.commons.lang3.EnumUtils;
47+
import org.apache.commons.lang3.StringUtils;
4548

46-
import com.cloud.exception.InsufficientCapacityException;
47-
import com.cloud.exception.ResourceUnavailableException;
48-
import com.cloud.user.Account;
49-
import com.cloud.uservm.UserVm;
50-
import com.cloud.utils.net.Dhcp;
51-
import com.cloud.vm.VirtualMachine;
49+
import java.util.Collection;
50+
import java.util.HashMap;
51+
import java.util.List;
52+
import java.util.Map;
5253

5354
@APICommand(name = "updateVirtualMachine", description="Updates properties of a virtual machine. The VM has to be stopped and restarted for the " +
5455
"new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. " +
@@ -154,6 +155,14 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction,
154155
" autoscaling groups or CKS, delete protection will be ignored.")
155156
private Boolean deleteProtection;
156157

158+
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION, type = CommandType.INTEGER, since = "4.21.0",
159+
description = "Number of days to lease the instance from now onward. Use -1 to remove the existing lease")
160+
private Integer leaseDuration;
161+
162+
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
163+
description = "Lease expiry action, valid values are STOP and DESTROY")
164+
private String leaseExpiryAction;
165+
157166
/////////////////////////////////////////////////////
158167
/////////////////// Accessors ///////////////////////
159168
/////////////////////////////////////////////////////
@@ -324,4 +333,21 @@ public Long getApiResourceId() {
324333
public ApiCommandResourceType getApiResourceType() {
325334
return ApiCommandResourceType.VirtualMachine;
326335
}
336+
337+
public Integer getLeaseDuration() {
338+
return leaseDuration;
339+
}
340+
341+
public VMLeaseManager.ExpiryAction getLeaseExpiryAction() {
342+
if (StringUtils.isBlank(leaseExpiryAction)) {
343+
return null;
344+
}
345+
VMLeaseManager.ExpiryAction action = EnumUtils.getEnumIgnoreCase(VMLeaseManager.ExpiryAction.class, leaseExpiryAction);
346+
if (action == null) {
347+
throw new InvalidParameterValueException("Invalid value configured for leaseexpiryaction, valid values are: " +
348+
com.cloud.utils.EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
349+
}
350+
return action;
351+
}
352+
327353
}

api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public class CapabilitiesResponse extends BaseResponse {
136136
@Param(description = "the min Ram size for the service offering used by the shared filesystem instance", since = "4.20.0")
137137
private Integer sharedFsVmMinRamSize;
138138

139+
@SerializedName(ApiConstants.INSTANCE_LEASE_ENABLED)
140+
@Param(description = "true if instance lease feature is enabled", since = "4.21.0")
141+
private Boolean instanceLeaseEnabled;
142+
139143
public void setSecurityGroupsEnabled(boolean securityGroupsEnabled) {
140144
this.securityGroupsEnabled = securityGroupsEnabled;
141145
}
@@ -247,4 +251,8 @@ public void setSharedFsVmMinCpuCount(Integer sharedFsVmMinCpuCount) {
247251
public void setSharedFsVmMinRamSize(Integer sharedFsVmMinRamSize) {
248252
this.sharedFsVmMinRamSize = sharedFsVmMinRamSize;
249253
}
254+
255+
public void setInstanceLeaseEnabled(Boolean instanceLeaseEnabled) {
256+
this.instanceLeaseEnabled = instanceLeaseEnabled;
257+
}
250258
}

0 commit comments

Comments
 (0)