Skip to content

Commit d9748b0

Browse files
committed
Merge branch 'main' into oauth-per-domain
2 parents c2ca9e6 + 82986f6 commit d9748b0

79 files changed

Lines changed: 5319 additions & 2065 deletions

File tree

Some content is hidden

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

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.apache.cloudstack.storage.object.ObjectStore;
4444
import org.apache.cloudstack.storage.sharedfs.SharedFS;
4545
import org.apache.cloudstack.usage.Usage;
46-
import org.apache.cloudstack.vm.schedule.VMSchedule;
46+
import org.apache.cloudstack.schedule.ResourceSchedule;
4747

4848
import com.cloud.dc.DataCenter;
4949
import com.cloud.dc.DataCenterGuestIpv6Prefix;
@@ -125,17 +125,18 @@ public class EventTypes {
125125
public static final String EVENT_VM_UNMANAGE = "VM.UNMANAGE";
126126
public static final String EVENT_VM_RECOVER = "VM.RECOVER";
127127

128-
// VM Schedule
129-
public static final String EVENT_VM_SCHEDULE_CREATE = "VM.SCHEDULE.CREATE";
130-
public static final String EVENT_VM_SCHEDULE_UPDATE = "VM.SCHEDULE.UPDATE";
131-
public static final String EVENT_VM_SCHEDULE_DELETE = "VM.SCHEDULE.DELETE";
132-
128+
// VM Schedule action-execution events (fired when a scheduled action runs).
133129
public static final String EVENT_VM_SCHEDULE_START = "VM.SCHEDULE.START";
134130
public static final String EVENT_VM_SCHEDULE_STOP = "VM.SCHEDULE.STOP";
135131
public static final String EVENT_VM_SCHEDULE_REBOOT = "VM.SCHEDULE.REBOOT";
136132
public static final String EVENT_VM_SCHEDULE_FORCE_STOP = "VM.SCHEDULE.FORCE.STOP";
137133
public static final String EVENT_VM_SCHEDULE_FORCE_REBOOT = "VM.SCHEDULE.FORCE.REBOOT";
138134

135+
// Generic Resource Schedule CRUD events (apply to all resource types).
136+
public static final String EVENT_SCHEDULE_CREATE = "SCHEDULE.CREATE";
137+
public static final String EVENT_SCHEDULE_UPDATE = "SCHEDULE.UPDATE";
138+
public static final String EVENT_SCHEDULE_DELETE = "SCHEDULE.DELETE";
139+
139140
// Domain Router
140141
public static final String EVENT_ROUTER_CREATE = "ROUTER.CREATE";
141142
public static final String EVENT_ROUTER_DESTROY = "ROUTER.DESTROY";
@@ -676,6 +677,7 @@ public class EventTypes {
676677
public static final String EVENT_AUTOSCALEVMGROUP_DISABLE = "AUTOSCALEVMGROUP.DISABLE";
677678
public static final String EVENT_AUTOSCALEVMGROUP_SCALEDOWN = "AUTOSCALEVMGROUP.SCALEDOWN";
678679
public static final String EVENT_AUTOSCALEVMGROUP_SCALEUP = "AUTOSCALEVMGROUP.SCALEUP";
680+
public static final String EVENT_AUTOSCALEVMGROUP_SCHEDULE_UPDATE = "AUTOSCALEVMGROUP.SCHEDULE.UPDATE";
679681

680682
public static final String EVENT_BAREMETAL_DHCP_SERVER_ADD = "PHYSICAL.DHCP.ADD";
681683
public static final String EVENT_BAREMETAL_DHCP_SERVER_DELETE = "PHYSICAL.DHCP.DELETE";
@@ -888,15 +890,18 @@ public class EventTypes {
888890
entityEventDetails.put(EVENT_VM_IMPORT, VirtualMachine.class);
889891
entityEventDetails.put(EVENT_VM_UNMANAGE, VirtualMachine.class);
890892

891-
// VMSchedule
892-
entityEventDetails.put(EVENT_VM_SCHEDULE_CREATE, VMSchedule.class);
893-
entityEventDetails.put(EVENT_VM_SCHEDULE_DELETE, VMSchedule.class);
894-
entityEventDetails.put(EVENT_VM_SCHEDULE_UPDATE, VMSchedule.class);
895-
entityEventDetails.put(EVENT_VM_SCHEDULE_START, VMSchedule.class);
896-
entityEventDetails.put(EVENT_VM_SCHEDULE_STOP, VMSchedule.class);
897-
entityEventDetails.put(EVENT_VM_SCHEDULE_REBOOT, VMSchedule.class);
898-
entityEventDetails.put(EVENT_VM_SCHEDULE_FORCE_STOP, VMSchedule.class);
899-
entityEventDetails.put(EVENT_VM_SCHEDULE_FORCE_REBOOT, VMSchedule.class);
893+
// VMSchedule action-execution events
894+
entityEventDetails.put(EVENT_VM_SCHEDULE_START, ResourceSchedule.class);
895+
entityEventDetails.put(EVENT_VM_SCHEDULE_STOP, ResourceSchedule.class);
896+
entityEventDetails.put(EVENT_VM_SCHEDULE_REBOOT, ResourceSchedule.class);
897+
entityEventDetails.put(EVENT_VM_SCHEDULE_FORCE_STOP, ResourceSchedule.class);
898+
entityEventDetails.put(EVENT_VM_SCHEDULE_FORCE_REBOOT, ResourceSchedule.class);
899+
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_SCHEDULE_UPDATE, ResourceSchedule.class);
900+
901+
// Generic Resource Schedule
902+
entityEventDetails.put(EVENT_SCHEDULE_CREATE, ResourceSchedule.class);
903+
entityEventDetails.put(EVENT_SCHEDULE_UPDATE, ResourceSchedule.class);
904+
entityEventDetails.put(EVENT_SCHEDULE_DELETE, ResourceSchedule.class);
900905

901906
entityEventDetails.put(EVENT_ROUTER_CREATE, VirtualRouter.class);
902907
entityEventDetails.put(EVENT_ROUTER_DESTROY, VirtualRouter.class);

api/src/main/java/com/cloud/host/Host.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static String[] toStrings(Host.Type... types) {
6363
String HOST_OVFTOOL_VERSION = "host.ovftool.version";
6464
String HOST_VIRTV2V_VERSION = "host.virtv2v.version";
6565
String HOST_SSH_PORT = "host.ssh.port";
66+
String HOST_CDROM_MAX_COUNT = "host.cdrom.max.count";
6667
String GUEST_OS_CATEGORY_ID = "guest.os.category.id";
6768
String GUEST_OS_RULE = "guest.os.rule";
6869

api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.command.user.UserCmd;
2929
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
30+
import org.apache.cloudstack.api.response.TemplateResponse;
3031
import org.apache.cloudstack.api.response.UserVmResponse;
3132

3233
import com.cloud.event.EventTypes;
@@ -51,6 +52,10 @@ public class DetachIsoCmd extends BaseAsyncCmd implements UserCmd {
5152
description = "If true, ejects the ISO before detaching on VMware. Default: false", since = "4.15.1")
5253
protected Boolean forced;
5354

55+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = TemplateResponse.class,
56+
description = "The ID of the ISO to detach. Required when the Instance has more than one ISO attached.", since = "4.23.0")
57+
protected Long id;
58+
5459
/////////////////////////////////////////////////////
5560
/////////////////// Accessors ///////////////////////
5661
/////////////////////////////////////////////////////
@@ -104,7 +109,7 @@ public ApiCommandResourceType getApiResourceType() {
104109

105110
@Override
106111
public void execute() {
107-
boolean result = _templateService.detachIso(virtualMachineId, null, isForced());
112+
boolean result = _templateService.detachIso(virtualMachineId, id, isForced());
108113
if (result) {
109114
UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
110115
UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", userVm).get(0);
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.schedule;
18+
19+
import com.cloud.exception.InvalidParameterValueException;
20+
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiCommandResourceType;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.BaseCmd;
25+
import org.apache.cloudstack.api.Parameter;
26+
import org.apache.cloudstack.api.response.ResourceScheduleResponse;
27+
import org.apache.cloudstack.context.CallContext;
28+
import org.apache.cloudstack.schedule.ResourceScheduleManager;
29+
import org.apache.commons.lang3.EnumUtils;
30+
31+
import javax.inject.Inject;
32+
import java.util.Date;
33+
import java.util.Map;
34+
35+
@APICommand(name = "createResourceSchedule", description = "Create Resource Schedule", responseObject = ResourceScheduleResponse.class,
36+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.23.0",
37+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
38+
public class CreateResourceScheduleCmd extends BaseCmd {
39+
40+
@Inject
41+
ResourceScheduleManager resourceScheduleManager;
42+
43+
@Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, required = true, description = "Type of the resource")
44+
private String resourceType;
45+
46+
@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, required = true, description = "ID of the resource for which schedule is to be defined")
47+
private String resourceId;
48+
49+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, required = false, description = "Description of the schedule")
50+
private String description;
51+
52+
@Parameter(name = ApiConstants.SCHEDULE, type = CommandType.STRING, required = true, description = "Schedule for action on resource in cron format. e.g. '0 15 10 * *' for 'at 15:00 on 10th day of every month'")
53+
private String schedule;
54+
55+
@Parameter(name = ApiConstants.TIMEZONE, type = CommandType.STRING, required = true, description = "Specifies a timezone for this command. For more information on the timezone parameter, see TimeZone Format.")
56+
private String timeZone;
57+
58+
@Parameter(name = ApiConstants.ACTION, type = CommandType.STRING, required = true, description = "Action to take on the resource.")
59+
private String action;
60+
61+
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = false, description = "Start date from which the schedule becomes active. Defaults to current date plus 1 minute. (Format \"yyyy-MM-dd hh:mm:ss\")")
62+
private Date startDate;
63+
64+
@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = false, description = "End date after which the schedule becomes inactive. (Format \"yyyy-MM-dd hh:mm:ss\")")
65+
private Date endDate;
66+
67+
@Parameter(name = ApiConstants.ENABLED, type = CommandType.BOOLEAN, required = false, description = "Enable schedule. Defaults to true")
68+
private Boolean enabled;
69+
70+
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, required = false, description = "Map of (key/value pairs) details for the schedule.")
71+
private Map details;
72+
73+
public ApiCommandResourceType getResourceType() {
74+
ApiCommandResourceType type = EnumUtils.getEnumIgnoreCase(ApiCommandResourceType.class, resourceType);
75+
if (type == null) {
76+
throw new InvalidParameterValueException("Unknown resource type: " + resourceType);
77+
}
78+
return type;
79+
}
80+
81+
public String getResourceId() {
82+
return resourceId;
83+
}
84+
85+
public String getDescription() {
86+
return description;
87+
}
88+
89+
public String getSchedule() {
90+
return schedule;
91+
}
92+
93+
public String getTimeZone() {
94+
return timeZone;
95+
}
96+
97+
public String getAction() {
98+
return action;
99+
}
100+
101+
public Date getStartDate() {
102+
return startDate;
103+
}
104+
105+
public Date getEndDate() {
106+
return endDate;
107+
}
108+
109+
public Boolean getEnabled() {
110+
if (enabled == null) {
111+
enabled = true;
112+
}
113+
return enabled;
114+
}
115+
116+
public Map<String, String> getDetails() {
117+
return convertDetailsToMap(details);
118+
}
119+
120+
@Override
121+
public void execute() {
122+
ResourceScheduleResponse response = resourceScheduleManager.createSchedule(getResourceType(), getResourceId(),
123+
getDescription(), getSchedule(), getTimeZone(), getAction(), getStartDate(), getEndDate(), getEnabled(), getDetails());
124+
response.setResponseName(getCommandName());
125+
setResponseObject(response);
126+
}
127+
128+
@Override
129+
public long getEntityOwnerId() {
130+
return CallContext.current().getCallingAccount().getAccountId();
131+
}
132+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.schedule;
18+
19+
import com.cloud.exception.InvalidParameterValueException;
20+
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiCommandResourceType;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.BaseCmd;
25+
import org.apache.cloudstack.api.Parameter;
26+
import org.apache.cloudstack.api.response.ResourceScheduleResponse;
27+
import org.apache.cloudstack.api.response.SuccessResponse;
28+
import org.apache.cloudstack.context.CallContext;
29+
import org.apache.cloudstack.schedule.ResourceScheduleManager;
30+
import org.apache.commons.lang3.EnumUtils;
31+
32+
import javax.inject.Inject;
33+
import java.util.List;
34+
35+
@APICommand(name = "deleteResourceSchedule", description = "Delete Resource Schedule", responseObject = SuccessResponse.class,
36+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.23.0",
37+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
38+
public class DeleteResourceScheduleCmd extends BaseCmd {
39+
40+
@Inject
41+
ResourceScheduleManager resourceScheduleManager;
42+
43+
@Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, required = true, description = "Type of the resource")
44+
private String resourceType;
45+
46+
@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, required = true, description = "ID of the resource for which schedules are to be deleted")
47+
private String resourceId;
48+
49+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ResourceScheduleResponse.class, required = false, description = "ID of the schedule to be deleted")
50+
private Long id;
51+
52+
@Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ResourceScheduleResponse.class, required = false, description = "comma separated list of schedule ids to be deleted")
53+
private List<Long> ids;
54+
55+
public ApiCommandResourceType getResourceType() {
56+
ApiCommandResourceType type = EnumUtils.getEnumIgnoreCase(ApiCommandResourceType.class, resourceType);
57+
if (type == null) {
58+
throw new InvalidParameterValueException("Unknown resource type: " + resourceType);
59+
}
60+
return type;
61+
}
62+
63+
public String getResourceId() {
64+
return resourceId;
65+
}
66+
67+
public Long getId() {
68+
return id;
69+
}
70+
71+
public List<Long> getIds() {
72+
return ids;
73+
}
74+
75+
@Override
76+
public void execute() {
77+
resourceScheduleManager.removeSchedule(getResourceType(), getResourceId(), getId(), getIds());
78+
SuccessResponse response = new SuccessResponse(getCommandName());
79+
setResponseObject(response);
80+
}
81+
82+
@Override
83+
public long getEntityOwnerId() {
84+
return CallContext.current().getCallingAccount().getAccountId();
85+
}
86+
}

0 commit comments

Comments
 (0)