Skip to content

Commit 3ee1fc2

Browse files
amoghvnitinmeh
authored andcommitted
CLOUDSTACK-6217:
Add APIs for ability to add new guest OS types, and their hypervisor specific mappings. The table guest_os_hypervisor is currently maintained but not used, and the APIs reuse the same Signed off by: Nitin Mehta <nitin.mehta@citrix.com>
1 parent cd8af6a commit 3ee1fc2

24 files changed

Lines changed: 1401 additions & 7 deletions

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import com.cloud.offering.NetworkOffering;
5151
import com.cloud.offering.ServiceOffering;
5252
import com.cloud.projects.Project;
53+
import com.cloud.storage.GuestOS;
54+
import com.cloud.storage.GuestOSHypervisor;
5355
import com.cloud.storage.Snapshot;
5456
import com.cloud.storage.Volume;
5557
import com.cloud.template.VirtualMachineTemplate;
@@ -479,6 +481,14 @@ public class EventTypes {
479481
public static final String EVENT_EXTERNAL_OPENDAYLIGHT_DELETE_CONTROLLER = "PHYSICAL.ODLCONTROLLER.DELETE";
480482
public static final String EVENT_EXTERNAL_OPENDAYLIGHT_CONFIGURE_CONTROLLER = "PHYSICAL.ODLCONTROLLER.CONFIGURE";
481483

484+
//Guest OS related events
485+
public static final String EVENT_GUEST_OS_ADD = "GUEST.OS.ADD";
486+
public static final String EVENT_GUEST_OS_REMOVE = "GUEST.OS.REMOVE";
487+
public static final String EVENT_GUEST_OS_UPDATE = "GUEST.OS.UPDATE";
488+
public static final String EVENT_GUEST_OS_MAPPING_ADD = "GUEST.OS.MAPPING.ADD";
489+
public static final String EVENT_GUEST_OS_MAPPING_REMOVE = "GUEST.OS.MAPPING.REMOVE";
490+
public static final String EVENT_GUEST_OS_MAPPING_UPDATE = "GUEST.OS.MAPPING.UPDATE";
491+
482492
static {
483493

484494
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -795,6 +805,14 @@ public class EventTypes {
795805
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_ADD_CONTROLLER, "OpenDaylightController");
796806
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_DELETE_CONTROLLER, "OpenDaylightController");
797807
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_CONFIGURE_CONTROLLER, "OpenDaylightController");
808+
809+
//Guest OS
810+
entityEventDetails.put(EVENT_GUEST_OS_ADD, GuestOS.class.getName());
811+
entityEventDetails.put(EVENT_GUEST_OS_REMOVE, GuestOS.class.getName());
812+
entityEventDetails.put(EVENT_GUEST_OS_UPDATE, GuestOS.class.getName());
813+
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_ADD, GuestOSHypervisor.class.getName());
814+
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_REMOVE, GuestOSHypervisor.class.getName());
815+
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_UPDATE, GuestOSHypervisor.class.getName());
798816
}
799817

800818
public static String getEntityForEvent(String eventName) {

api/src/com/cloud/server/ManagementService.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
2424
import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
2525
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
26+
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsCmd;
27+
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsMappingCmd;
28+
import org.apache.cloudstack.api.command.admin.guest.ListGuestOsMappingCmd;
29+
import org.apache.cloudstack.api.command.admin.guest.RemoveGuestOsCmd;
30+
import org.apache.cloudstack.api.command.admin.guest.RemoveGuestOsMappingCmd;
31+
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsCmd;
32+
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsMappingCmd;
2633
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
2734
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
2835
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
@@ -67,6 +74,7 @@
6774
import com.cloud.network.IpAddress;
6875
import com.cloud.org.Cluster;
6976
import com.cloud.storage.GuestOS;
77+
import com.cloud.storage.GuestOSHypervisor;
7078
import com.cloud.storage.GuestOsCategory;
7179
import com.cloud.storage.StoragePool;
7280
import com.cloud.user.SSHKeyPair;
@@ -146,6 +154,69 @@ public interface ManagementService {
146154
*/
147155
Pair<List<? extends GuestOsCategory>, Integer> listGuestOSCategoriesByCriteria(ListGuestOsCategoriesCmd cmd);
148156

157+
/**
158+
* Obtains a list of all guest OS mappings
159+
*
160+
* @return list of GuestOSHypervisor
161+
*/
162+
Pair<List<? extends GuestOSHypervisor>, Integer> listGuestOSMappingByCriteria(ListGuestOsMappingCmd cmd);
163+
164+
/**
165+
* Adds a new guest OS mapping
166+
*
167+
* @return A VO containing the new mapping, with its hypervisor, hypervisor type, guest OS name, and the name of guest OS specific to hypervisor
168+
*/
169+
GuestOSHypervisor addGuestOsMapping(AddGuestOsMappingCmd addGuestOsMappingCmd);
170+
171+
/**
172+
* Find newly added guest OS mapping by ID
173+
*
174+
* @return A VO containing the guest OS mapping specified by ID, with its hypervisor, hypervisor type, guest OS name, and the name of guest OS specific to hypervisor
175+
*/
176+
GuestOSHypervisor getAddedGuestOsMapping(Long guestOsHypervisorId);
177+
178+
/**
179+
* Adds a new guest OS
180+
*
181+
* @return A VO containing the new guest OS, with its category ID, name and display name
182+
*/
183+
GuestOS addGuestOs(AddGuestOsCmd addGuestOsCmd);
184+
185+
/**
186+
* Find newly added guest OS by ID
187+
*
188+
* @return A VO containing the guest OS specified by ID, with its category ID, name and display name
189+
*/
190+
GuestOS getAddedGuestOs(Long guestOsId);
191+
192+
/**
193+
* Updates an existing guest OS
194+
*
195+
* @return A VO containing the updated display name
196+
*/
197+
GuestOS updateGuestOs(UpdateGuestOsCmd updateGuestOsCmd);
198+
199+
/**
200+
* Updates an existing guest OS mapping
201+
*
202+
* @return A VO containing the updated OS name for hypervisor
203+
*/
204+
GuestOSHypervisor updateGuestOsMapping(UpdateGuestOsMappingCmd updateGuestOsMappingCmd);
205+
206+
/**
207+
* Removes an existing guest OS
208+
*
209+
* @return True is successfully marked for delete, false otherwise
210+
*/
211+
boolean removeGuestOs(RemoveGuestOsCmd removeGuestOsCmd);
212+
213+
/**
214+
* Removes an existing guest OS mapping
215+
*
216+
* @return True is successfully marked for delete, false otherwise
217+
*/
218+
boolean removeGuestOsMapping(RemoveGuestOsMappingCmd removeGuestOsMappingCmd);
219+
149220
VirtualMachine stopSystemVM(StopSystemVmCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException;
150221

151222
VirtualMachine startSystemVM(long vmId);
@@ -361,4 +432,6 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE
361432
ConcurrentOperationException;
362433

363434
void cleanupVMReservations();
435+
436+
364437
}

api/src/com/cloud/storage/GuestOS.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19+
import java.util.Date;
20+
1921
import org.apache.cloudstack.api.Identity;
2022
import org.apache.cloudstack.api.InternalIdentity;
2123

@@ -26,4 +28,8 @@ public interface GuestOS extends InternalIdentity, Identity {
2628
String getDisplayName();
2729

2830
long getCategoryId();
31+
32+
Date getCreated();
33+
34+
Date getRemoved();
2935
}

api/src/com/cloud/storage/GuestOSHypervisor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19+
import java.util.Date;
20+
1921
import org.apache.cloudstack.api.InternalIdentity;
2022

2123
public interface GuestOSHypervisor extends InternalIdentity {
@@ -25,4 +27,12 @@ public interface GuestOSHypervisor extends InternalIdentity {
2527
String getGuestOsName();
2628

2729
long getGuestOsId();
30+
31+
String getHypervisorVersion();
32+
33+
String getUuid();
34+
35+
Date getRemoved();
36+
37+
Date getCreated();
2838
}

api/src/org/apache/cloudstack/api/ApiCommandJobType.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ public enum ApiCommandJobType {
5151
InternalLbVm,
5252
DedicatedGuestVlanRange,
5353
IAMPolicy,
54-
IAMGroup
55-
}
54+
IAMGroup,
55+
GuestOs,
56+
GuestOsMapping
57+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ public class ApiConstants {
171171
public static final String OP = "op";
172172
public static final String OS_CATEGORY_ID = "oscategoryid";
173173
public static final String OS_TYPE_ID = "ostypeid";
174+
public static final String OS_DISPLAY_NAME = "osdisplayname";
175+
public static final String OS_NAME_FOR_HYPERVISOR = "osnameforhypervisor";
174176
public static final String PARAMS = "params";
175177
public static final String PARENT_DOMAIN_ID = "parentdomainid";
176178
public static final String PASSWORD = "password";

api/src/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.cloudstack.api.response.FirewallRuleResponse;
4848
import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
4949
import org.apache.cloudstack.api.response.GuestOSResponse;
50+
import org.apache.cloudstack.api.response.GuestOsMappingResponse;
5051
import org.apache.cloudstack.api.response.GuestVlanRangeResponse;
5152
import org.apache.cloudstack.api.response.HostForMigrationResponse;
5253
import org.apache.cloudstack.api.response.HostResponse;
@@ -175,6 +176,7 @@
175176
import com.cloud.region.ha.GlobalLoadBalancerRule;
176177
import com.cloud.server.ResourceTag;
177178
import com.cloud.storage.GuestOS;
179+
import com.cloud.storage.GuestOSHypervisor;
178180
import com.cloud.storage.ImageStore;
179181
import com.cloud.storage.Snapshot;
180182
import com.cloud.storage.StoragePool;
@@ -424,6 +426,8 @@ public interface ResponseGenerator {
424426

425427
GuestOSResponse createGuestOSResponse(GuestOS os);
426428

429+
GuestOsMappingResponse createGuestOSMappingResponse(GuestOSHypervisor osHypervisor);
430+
427431
SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule sched);
428432

429433
UsageRecordResponse createUsageResponse(Usage usageRecord);
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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.admin.guest;
18+
19+
import org.apache.log4j.Logger;
20+
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiCommandJobType;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.GuestOSCategoryResponse;
29+
import org.apache.cloudstack.api.response.GuestOSResponse;
30+
import org.apache.cloudstack.context.CallContext;
31+
32+
import com.cloud.event.EventTypes;
33+
import com.cloud.storage.GuestOS;
34+
import com.cloud.user.Account;
35+
36+
@APICommand(name = "addGuestOs", description = "Add a new guest OS type", responseObject = GuestOSResponse.class,
37+
since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
38+
public class AddGuestOsCmd extends BaseAsyncCreateCmd {
39+
public static final Logger s_logger = Logger.getLogger(AddGuestOsCmd.class.getName());
40+
41+
private static final String s_name = "addguestosresponse";
42+
43+
/////////////////////////////////////////////////////
44+
//////////////// API parameters /////////////////////
45+
/////////////////////////////////////////////////////
46+
47+
@Parameter(name = ApiConstants.OS_CATEGORY_ID, type = CommandType.UUID, entityType = GuestOSCategoryResponse.class, required = true, description = "ID of Guest OS category")
48+
private Long osCategoryId;
49+
50+
@Parameter(name = ApiConstants.OS_DISPLAY_NAME, type = CommandType.STRING, required = true, description = "Unique display name for Guest OS")
51+
private String osDisplayName;
52+
53+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = false, description = "Optional name for Guest OS")
54+
private String osName;
55+
56+
57+
/////////////////////////////////////////////////////
58+
/////////////////// Accessors ///////////////////////
59+
/////////////////////////////////////////////////////
60+
61+
public Long getOsCategoryId() {
62+
return osCategoryId;
63+
}
64+
65+
public String getOsDisplayName() {
66+
return osDisplayName;
67+
}
68+
69+
public String getOsName() {
70+
return osName;
71+
}
72+
73+
/////////////////////////////////////////////////////
74+
/////////////// API Implementation///////////////////
75+
/////////////////////////////////////////////////////
76+
77+
@Override
78+
public String getCommandName() {
79+
return s_name;
80+
}
81+
82+
@Override
83+
public long getEntityOwnerId() {
84+
return Account.ACCOUNT_ID_SYSTEM;
85+
}
86+
87+
@Override
88+
public void create() {
89+
GuestOS guestOs = _mgr.addGuestOs(this);
90+
if (guestOs != null) {
91+
setEntityId(guestOs.getId());
92+
setEntityUuid(guestOs.getUuid());
93+
} else {
94+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add new guest OS type entity");
95+
}
96+
}
97+
98+
@Override
99+
public void execute() {
100+
CallContext.current().setEventDetails("Guest OS Id: " + getEntityId());
101+
GuestOS guestOs = _mgr.getAddedGuestOs(getEntityId());
102+
if (guestOs != null) {
103+
GuestOSResponse response = _responseGenerator.createGuestOSResponse(guestOs);
104+
response.setResponseName(getCommandName());
105+
setResponseObject(response);
106+
} else {
107+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add new guest OS type");
108+
}
109+
}
110+
111+
@Override
112+
public String getEventType() {
113+
return EventTypes.EVENT_GUEST_OS_ADD;
114+
}
115+
116+
@Override
117+
public String getEventDescription() {
118+
return "adding a new guest OS type Id: " + getEntityId();
119+
}
120+
121+
@Override
122+
public ApiCommandJobType getInstanceType() {
123+
return ApiCommandJobType.GuestOs;
124+
}
125+
126+
@Override
127+
public String getCreateEventType() {
128+
return EventTypes.EVENT_GUEST_OS_ADD;
129+
}
130+
131+
@Override
132+
public String getCreateEventDescription() {
133+
return "adding new guest OS type";
134+
}
135+
136+
}

0 commit comments

Comments
 (0)