mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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>
This commit is contained in:
parent
cd8af6a3e2
commit
3ee1fc28de
@ -50,6 +50,8 @@ import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
@ -479,6 +481,14 @@ public class EventTypes {
|
||||
public static final String EVENT_EXTERNAL_OPENDAYLIGHT_DELETE_CONTROLLER = "PHYSICAL.ODLCONTROLLER.DELETE";
|
||||
public static final String EVENT_EXTERNAL_OPENDAYLIGHT_CONFIGURE_CONTROLLER = "PHYSICAL.ODLCONTROLLER.CONFIGURE";
|
||||
|
||||
//Guest OS related events
|
||||
public static final String EVENT_GUEST_OS_ADD = "GUEST.OS.ADD";
|
||||
public static final String EVENT_GUEST_OS_REMOVE = "GUEST.OS.REMOVE";
|
||||
public static final String EVENT_GUEST_OS_UPDATE = "GUEST.OS.UPDATE";
|
||||
public static final String EVENT_GUEST_OS_MAPPING_ADD = "GUEST.OS.MAPPING.ADD";
|
||||
public static final String EVENT_GUEST_OS_MAPPING_REMOVE = "GUEST.OS.MAPPING.REMOVE";
|
||||
public static final String EVENT_GUEST_OS_MAPPING_UPDATE = "GUEST.OS.MAPPING.UPDATE";
|
||||
|
||||
static {
|
||||
|
||||
// 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 {
|
||||
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_ADD_CONTROLLER, "OpenDaylightController");
|
||||
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_DELETE_CONTROLLER, "OpenDaylightController");
|
||||
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_CONFIGURE_CONTROLLER, "OpenDaylightController");
|
||||
|
||||
//Guest OS
|
||||
entityEventDetails.put(EVENT_GUEST_OS_ADD, GuestOS.class.getName());
|
||||
entityEventDetails.put(EVENT_GUEST_OS_REMOVE, GuestOS.class.getName());
|
||||
entityEventDetails.put(EVENT_GUEST_OS_UPDATE, GuestOS.class.getName());
|
||||
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_ADD, GuestOSHypervisor.class.getName());
|
||||
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_REMOVE, GuestOSHypervisor.class.getName());
|
||||
entityEventDetails.put(EVENT_GUEST_OS_MAPPING_UPDATE, GuestOSHypervisor.class.getName());
|
||||
}
|
||||
|
||||
public static String getEntityForEvent(String eventName) {
|
||||
|
||||
@ -23,6 +23,13 @@ import java.util.Map;
|
||||
import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
|
||||
import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
|
||||
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.ListGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.RemoveGuestOsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.RemoveGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
|
||||
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
|
||||
@ -67,6 +74,7 @@ import com.cloud.hypervisor.HypervisorCapabilities;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.org.Cluster;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.storage.GuestOsCategory;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.user.SSHKeyPair;
|
||||
@ -146,6 +154,69 @@ public interface ManagementService {
|
||||
*/
|
||||
Pair<List<? extends GuestOsCategory>, Integer> listGuestOSCategoriesByCriteria(ListGuestOsCategoriesCmd cmd);
|
||||
|
||||
/**
|
||||
* Obtains a list of all guest OS mappings
|
||||
*
|
||||
* @return list of GuestOSHypervisor
|
||||
*/
|
||||
Pair<List<? extends GuestOSHypervisor>, Integer> listGuestOSMappingByCriteria(ListGuestOsMappingCmd cmd);
|
||||
|
||||
/**
|
||||
* Adds a new guest OS mapping
|
||||
*
|
||||
* @return A VO containing the new mapping, with its hypervisor, hypervisor type, guest OS name, and the name of guest OS specific to hypervisor
|
||||
*/
|
||||
GuestOSHypervisor addGuestOsMapping(AddGuestOsMappingCmd addGuestOsMappingCmd);
|
||||
|
||||
/**
|
||||
* Find newly added guest OS mapping by ID
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
GuestOSHypervisor getAddedGuestOsMapping(Long guestOsHypervisorId);
|
||||
|
||||
/**
|
||||
* Adds a new guest OS
|
||||
*
|
||||
* @return A VO containing the new guest OS, with its category ID, name and display name
|
||||
*/
|
||||
GuestOS addGuestOs(AddGuestOsCmd addGuestOsCmd);
|
||||
|
||||
/**
|
||||
* Find newly added guest OS by ID
|
||||
*
|
||||
* @return A VO containing the guest OS specified by ID, with its category ID, name and display name
|
||||
*/
|
||||
GuestOS getAddedGuestOs(Long guestOsId);
|
||||
|
||||
/**
|
||||
* Updates an existing guest OS
|
||||
*
|
||||
* @return A VO containing the updated display name
|
||||
*/
|
||||
GuestOS updateGuestOs(UpdateGuestOsCmd updateGuestOsCmd);
|
||||
|
||||
/**
|
||||
* Updates an existing guest OS mapping
|
||||
*
|
||||
* @return A VO containing the updated OS name for hypervisor
|
||||
*/
|
||||
GuestOSHypervisor updateGuestOsMapping(UpdateGuestOsMappingCmd updateGuestOsMappingCmd);
|
||||
|
||||
/**
|
||||
* Removes an existing guest OS
|
||||
*
|
||||
* @return True is successfully marked for delete, false otherwise
|
||||
*/
|
||||
boolean removeGuestOs(RemoveGuestOsCmd removeGuestOsCmd);
|
||||
|
||||
/**
|
||||
* Removes an existing guest OS mapping
|
||||
*
|
||||
* @return True is successfully marked for delete, false otherwise
|
||||
*/
|
||||
boolean removeGuestOsMapping(RemoveGuestOsMappingCmd removeGuestOsMappingCmd);
|
||||
|
||||
VirtualMachine stopSystemVM(StopSystemVmCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
VirtualMachine startSystemVM(long vmId);
|
||||
@ -361,4 +432,6 @@ public interface ManagementService {
|
||||
ConcurrentOperationException;
|
||||
|
||||
void cleanupVMReservations();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
// under the License.
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
@ -26,4 +28,8 @@ public interface GuestOS extends InternalIdentity, Identity {
|
||||
String getDisplayName();
|
||||
|
||||
long getCategoryId();
|
||||
|
||||
Date getCreated();
|
||||
|
||||
Date getRemoved();
|
||||
}
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
// under the License.
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
public interface GuestOSHypervisor extends InternalIdentity {
|
||||
@ -25,4 +27,12 @@ public interface GuestOSHypervisor extends InternalIdentity {
|
||||
String getGuestOsName();
|
||||
|
||||
long getGuestOsId();
|
||||
|
||||
String getHypervisorVersion();
|
||||
|
||||
String getUuid();
|
||||
|
||||
Date getRemoved();
|
||||
|
||||
Date getCreated();
|
||||
}
|
||||
|
||||
@ -51,5 +51,7 @@ public enum ApiCommandJobType {
|
||||
InternalLbVm,
|
||||
DedicatedGuestVlanRange,
|
||||
IAMPolicy,
|
||||
IAMGroup
|
||||
}
|
||||
IAMGroup,
|
||||
GuestOs,
|
||||
GuestOsMapping
|
||||
}
|
||||
|
||||
@ -171,6 +171,8 @@ public class ApiConstants {
|
||||
public static final String OP = "op";
|
||||
public static final String OS_CATEGORY_ID = "oscategoryid";
|
||||
public static final String OS_TYPE_ID = "ostypeid";
|
||||
public static final String OS_DISPLAY_NAME = "osdisplayname";
|
||||
public static final String OS_NAME_FOR_HYPERVISOR = "osnameforhypervisor";
|
||||
public static final String PARAMS = "params";
|
||||
public static final String PARENT_DOMAIN_ID = "parentdomainid";
|
||||
public static final String PASSWORD = "password";
|
||||
|
||||
@ -47,6 +47,7 @@ import org.apache.cloudstack.api.response.FirewallResponse;
|
||||
import org.apache.cloudstack.api.response.FirewallRuleResponse;
|
||||
import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
|
||||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
import org.apache.cloudstack.api.response.GuestOsMappingResponse;
|
||||
import org.apache.cloudstack.api.response.GuestVlanRangeResponse;
|
||||
import org.apache.cloudstack.api.response.HostForMigrationResponse;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
@ -175,6 +176,7 @@ import com.cloud.projects.ProjectInvitation;
|
||||
import com.cloud.region.ha.GlobalLoadBalancerRule;
|
||||
import com.cloud.server.ResourceTag;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.storage.ImageStore;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.StoragePool;
|
||||
@ -424,6 +426,8 @@ public interface ResponseGenerator {
|
||||
|
||||
GuestOSResponse createGuestOSResponse(GuestOS os);
|
||||
|
||||
GuestOsMappingResponse createGuestOSMappingResponse(GuestOSHypervisor osHypervisor);
|
||||
|
||||
SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule sched);
|
||||
|
||||
UsageRecordResponse createUsageResponse(Usage usageRecord);
|
||||
|
||||
@ -0,0 +1,136 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.guest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.GuestOSCategoryResponse;
|
||||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "addGuestOs", description = "Add a new guest OS type", responseObject = GuestOSResponse.class,
|
||||
since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class AddGuestOsCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AddGuestOsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "addguestosresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.OS_CATEGORY_ID, type = CommandType.UUID, entityType = GuestOSCategoryResponse.class, required = true, description = "ID of Guest OS category")
|
||||
private Long osCategoryId;
|
||||
|
||||
@Parameter(name = ApiConstants.OS_DISPLAY_NAME, type = CommandType.STRING, required = true, description = "Unique display name for Guest OS")
|
||||
private String osDisplayName;
|
||||
|
||||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = false, description = "Optional name for Guest OS")
|
||||
private String osName;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getOsCategoryId() {
|
||||
return osCategoryId;
|
||||
}
|
||||
|
||||
public String getOsDisplayName() {
|
||||
return osDisplayName;
|
||||
}
|
||||
|
||||
public String getOsName() {
|
||||
return osName;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
GuestOS guestOs = _mgr.addGuestOs(this);
|
||||
if (guestOs != null) {
|
||||
setEntityId(guestOs.getId());
|
||||
setEntityUuid(guestOs.getUuid());
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add new guest OS type entity");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
CallContext.current().setEventDetails("Guest OS Id: " + getEntityId());
|
||||
GuestOS guestOs = _mgr.getAddedGuestOs(getEntityId());
|
||||
if (guestOs != null) {
|
||||
GuestOSResponse response = _responseGenerator.createGuestOSResponse(guestOs);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add new guest OS type");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "adding a new guest OS type Id: " + getEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.GuestOs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCreateEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCreateEventDescription() {
|
||||
return "adding new guest OS type";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,146 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.guest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
import org.apache.cloudstack.api.response.GuestOsMappingResponse;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "addGuestOsMapping", description = "Adds a guest OS name to hypervisor OS name mapping", responseObject = GuestOsMappingResponse.class,
|
||||
since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class AddGuestOsMappingCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AddGuestOsMappingCmd.class.getName());
|
||||
|
||||
private static final String s_name = "addguestosmappingresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.OS_TYPE_ID, type = CommandType.UUID, required = false, entityType = GuestOSResponse.class, description = "UUID of Guest OS type. Either the UUID or Display Name must be passed")
|
||||
private Long osTypeId;
|
||||
|
||||
@Parameter(name = ApiConstants.OS_DISPLAY_NAME, type = CommandType.STRING, required = false, description = "Display Name of Guest OS standard type. Either Display Name or UUID must be passed")
|
||||
private String osStdName;
|
||||
|
||||
@Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, required = true, description = "Hypervisor type. One of : XenServer, KVM, VMWare")
|
||||
private String hypervisor;
|
||||
|
||||
@Parameter(name = ApiConstants.HYPERVISOR_VERSION, type = CommandType.STRING, required = true, description = "Hypervisor version to create the mapping for. Use 'default' for default versions")
|
||||
private String hypervisorVersion;
|
||||
|
||||
@Parameter(name = ApiConstants.OS_NAME_FOR_HYPERVISOR, type = CommandType.STRING, required = true, description = "OS name specific to the hypervisor")
|
||||
private String osNameForHypervisor;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getOsTypeId() {
|
||||
return osTypeId;
|
||||
}
|
||||
|
||||
public String getOsStdName() {
|
||||
return osStdName;
|
||||
}
|
||||
|
||||
public String getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
public String getHypervisorVersion() {
|
||||
return hypervisorVersion;
|
||||
}
|
||||
|
||||
public String getOsNameForHypervisor() {
|
||||
return osNameForHypervisor;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
GuestOSHypervisor guestOsMapping = _mgr.addGuestOsMapping(this);
|
||||
if (guestOsMapping != null) {
|
||||
setEntityId(guestOsMapping.getId());
|
||||
setEntityUuid(guestOsMapping.getUuid());
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add guest OS mapping entity");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
GuestOSHypervisor guestOsMapping = _mgr.getAddedGuestOsMapping(getEntityId());
|
||||
if (guestOsMapping != null) {
|
||||
GuestOsMappingResponse response = _responseGenerator.createGuestOSMappingResponse(guestOsMapping);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add guest OS mapping");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_MAPPING_ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "adding a new guest OS mapping Id: " + getEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.GuestOsMapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCreateEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_MAPPING_ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCreateEventDescription() {
|
||||
return "adding new guest OS mapping";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.guest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
import org.apache.cloudstack.api.response.GuestOsMappingResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@APICommand(name = "listGuestOsMapping", description = "Lists all available OS mappings for given hypervisor", responseObject = GuestOsMappingResponse.class,
|
||||
since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class ListGuestOsMappingCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListGuestOsMappingCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listguestosmappingresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GuestOsMappingResponse.class, required = false, description = "list mapping by its UUID")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name = ApiConstants.OS_TYPE_ID, type = CommandType.UUID, entityType = GuestOSResponse.class, required = false, description = "list mapping by Guest OS Type UUID")
|
||||
private Long osTypeId;
|
||||
|
||||
@Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, required = false, description = "list Guest OS mapping by hypervisor")
|
||||
private String hypervisor;
|
||||
|
||||
@Parameter(name = ApiConstants.HYPERVISOR_VERSION, type = CommandType.STRING, required = false, description = "list Guest OS mapping by hypervisor version. Must be used with hypervisor parameter")
|
||||
private String hypervisorVersion;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Long getOsTypeId() {
|
||||
return osTypeId;
|
||||
}
|
||||
|
||||
public String getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
public String getHypervisorVersion() {
|
||||
return hypervisorVersion;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
Pair<List<? extends GuestOSHypervisor>, Integer> result = _mgr.listGuestOSMappingByCriteria(this);
|
||||
ListResponse<GuestOsMappingResponse> response = new ListResponse<GuestOsMappingResponse>();
|
||||
List<GuestOsMappingResponse> osMappingResponses = new ArrayList<GuestOsMappingResponse>();
|
||||
for (GuestOSHypervisor guestOSHypervisor : result.first()) {
|
||||
GuestOsMappingResponse guestOsMappingResponse = _responseGenerator.createGuestOSMappingResponse(guestOSHypervisor);
|
||||
osMappingResponses.add(guestOsMappingResponse);
|
||||
}
|
||||
|
||||
response.setResponses(osMappingResponses, result.second());
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.guest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "removeGuestOs", description = "Removes a Guest OS from listing.", responseObject = SuccessResponse.class, since = "4.4.0",
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class RemoveGuestOsCmd extends BaseAsyncCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(RemoveGuestOsCmd.class.getName());
|
||||
private static final String s_name = "removeguestosresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GuestOSResponse.class, required = true, description = "ID of the guest OS")
|
||||
private Long id;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
CallContext.current().setEventDetails("Guest OS Id: " + id);
|
||||
boolean result = _mgr.removeGuestOs(this);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove guest OS");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Removing Guest OS: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.GuestOs;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.guest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.GuestOsMappingResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "removeGuestOsMapping", description = "Removes a Guest OS Mapping.", responseObject = SuccessResponse.class, since = "4.4.0",
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class RemoveGuestOsMappingCmd extends BaseAsyncCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(RemoveGuestOsMappingCmd.class.getName());
|
||||
private static final String s_name = "removeguestosmappingresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GuestOsMappingResponse.class, required = true, description = "ID of the guest OS mapping")
|
||||
private Long id;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
CallContext.current().setEventDetails("Guest OS Mapping Id: " + id);
|
||||
boolean result = _mgr.removeGuestOsMapping(this);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove guest OS mapping");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Removing Guest OS Mapping: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_MAPPING_REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.GuestOsMapping;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.guest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "updateGuestOs", description = "Updates the information about Guest OS", responseObject = GuestOSResponse.class,
|
||||
since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class UpdateGuestOsCmd extends BaseAsyncCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateGuestOsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "updateguestosresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GuestOSResponse.class, required = true, description = "UUID of the Guest OS")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name = ApiConstants.OS_DISPLAY_NAME, type = CommandType.STRING, required = true, description = "Unique display name for Guest OS")
|
||||
private String osDisplayName;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getOsDisplayName() {
|
||||
return osDisplayName;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
GuestOS guestOs = _mgr.updateGuestOs(this);
|
||||
if (guestOs != null) {
|
||||
GuestOSResponse response = _responseGenerator.createGuestOSResponse(guestOs);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update guest OS type");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Updating guest OS: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.GuestOs;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.guest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.GuestOsMappingResponse;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "updateGuestOsMapping", description = "Updates the information about Guest OS to Hypervisor specific name mapping", responseObject = GuestOsMappingResponse.class,
|
||||
since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class UpdateGuestOsMappingCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateGuestOsMappingCmd.class.getName());
|
||||
|
||||
private static final String s_name = "updateguestosmappingresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GuestOsMappingResponse.class, required = true, description = "UUID of the Guest OS to hypervisor name Mapping")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name = ApiConstants.OS_NAME_FOR_HYPERVISOR, type = CommandType.STRING, required = true, description = "Hypervisor specific name for this Guest OS")
|
||||
private String osNameForHypervisor;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getOsNameForHypervisor() {
|
||||
return osNameForHypervisor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
GuestOSHypervisor guestOsMapping = _mgr.updateGuestOsMapping(this);
|
||||
if (guestOsMapping != null) {
|
||||
GuestOsMappingResponse response = _responseGenerator.createGuestOSMappingResponse(guestOsMapping);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
}
|
||||
else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update guest OS mapping");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Updating Guest OS Mapping: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_GUEST_OS_MAPPING_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.GuestOsMapping;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.EntityReference;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
|
||||
@EntityReference(value = GuestOSHypervisor.class)
|
||||
public class GuestOsMappingResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.ID)
|
||||
@Param(description = "the ID of the Guest OS mapping")
|
||||
private String id;
|
||||
|
||||
@SerializedName(ApiConstants.HYPERVISOR)
|
||||
@Param(description = "the hypervisor")
|
||||
private String hypervisor;
|
||||
|
||||
@SerializedName(ApiConstants.HYPERVISOR_VERSION)
|
||||
@Param(description = "version of the hypervisor for mapping")
|
||||
private String hypervisorVersion;
|
||||
|
||||
@SerializedName(ApiConstants.OS_TYPE_ID)
|
||||
@Param(description = "the ID of the Guest OS type")
|
||||
private String osTypeId;
|
||||
|
||||
@SerializedName(ApiConstants.OS_DISPLAY_NAME)
|
||||
@Param(description = "standard display name for the Guest OS")
|
||||
private String osStdName;
|
||||
|
||||
@SerializedName(ApiConstants.OS_NAME_FOR_HYPERVISOR)
|
||||
@Param(description = "hypervisor specific name for the Guest OS")
|
||||
private String osNameForHypervisor;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
public void setHypervisor(String hypervisor) {
|
||||
this.hypervisor = hypervisor;
|
||||
}
|
||||
|
||||
public String getHypervisorVersion() {
|
||||
return hypervisorVersion;
|
||||
}
|
||||
|
||||
public void setHypervisorVersion(String hypervisorVersion) {
|
||||
this.hypervisorVersion = hypervisorVersion;
|
||||
}
|
||||
|
||||
public String getOsTypeId() {
|
||||
return osTypeId;
|
||||
}
|
||||
|
||||
public void setOsTypeId(String osTypeId) {
|
||||
this.osTypeId = osTypeId;
|
||||
}
|
||||
|
||||
public String getOsStdName() {
|
||||
return osStdName;
|
||||
}
|
||||
|
||||
public void setOsStdName(String osStdName) {
|
||||
this.osStdName = osStdName;
|
||||
}
|
||||
|
||||
public String getOsNameForHypervisor() {
|
||||
return osNameForHypervisor;
|
||||
}
|
||||
|
||||
public void setOsNameForHypervisor(String osNameForHypervisor) {
|
||||
this.osNameForHypervisor = osNameForHypervisor;
|
||||
}
|
||||
}
|
||||
@ -110,6 +110,15 @@ extractIso=15
|
||||
#### guest OS commands
|
||||
listOsTypes=15
|
||||
listOsCategories=15
|
||||
addGuestOs=1
|
||||
updateGuestOs=1
|
||||
removeGuestOs=1
|
||||
|
||||
#### guest OS mapping commands
|
||||
listGuestOsMapping=1
|
||||
addGuestOsMapping=1
|
||||
updateGuestOsMapping=1
|
||||
removeGuestOsMapping=1
|
||||
|
||||
#### service offering commands
|
||||
createServiceOffering=1
|
||||
|
||||
@ -16,6 +16,9 @@
|
||||
// under the License.
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
@ -23,6 +26,8 @@ import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@Entity
|
||||
@Table(name = "guest_os_hypervisor")
|
||||
public class GuestOSHypervisorVO implements GuestOSHypervisor {
|
||||
@ -32,7 +37,7 @@ public class GuestOSHypervisorVO implements GuestOSHypervisor {
|
||||
long id;
|
||||
|
||||
@Column(name = "guest_os_id")
|
||||
private long guestOsId;
|
||||
long guestOsId;
|
||||
|
||||
@Column(name = "guest_os_name")
|
||||
String guestOsName;
|
||||
@ -40,11 +45,28 @@ public class GuestOSHypervisorVO implements GuestOSHypervisor {
|
||||
@Column(name = "hypervisor_type")
|
||||
String hypervisorType;
|
||||
|
||||
@Column(name = "hypervisor_version")
|
||||
String hypervisorVersion;
|
||||
|
||||
@Column(name = "uuid")
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
@Column(name = GenericDao.REMOVED_COLUMN)
|
||||
Date removed;
|
||||
|
||||
@Column(name = GenericDao.CREATED_COLUMN)
|
||||
Date created;
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHypervisorVersion() {
|
||||
return hypervisorVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHypervisorType() {
|
||||
return hypervisorType;
|
||||
@ -60,4 +82,42 @@ public class GuestOSHypervisorVO implements GuestOSHypervisor {
|
||||
return guestOsId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getRemoved() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setGuestOsId(long guestOsId) {
|
||||
this.guestOsId = guestOsId;
|
||||
}
|
||||
|
||||
public void setGuestOsName(String guestOsName) {
|
||||
this.guestOsName = guestOsName;
|
||||
}
|
||||
|
||||
public void setHypervisorType(String hypervisorType) {
|
||||
this.hypervisorType = hypervisorType;
|
||||
}
|
||||
|
||||
public void setHypervisorVersion(String hypervisorVersion) {
|
||||
this.hypervisorVersion = hypervisorVersion;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public void setRemoved(Date removed) {
|
||||
this.removed = removed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@ -25,6 +26,8 @@ import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@Entity
|
||||
@Table(name = "guest_os")
|
||||
public class GuestOSVO implements GuestOS {
|
||||
@ -45,6 +48,12 @@ public class GuestOSVO implements GuestOS {
|
||||
@Column(name = "uuid")
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
@Column(name = GenericDao.REMOVED_COLUMN)
|
||||
private Date removed;
|
||||
|
||||
@Column(name = GenericDao.CREATED_COLUMN)
|
||||
private Date created;
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
@ -79,10 +88,24 @@ public class GuestOSVO implements GuestOS {
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setRemoved(Date removed) {
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getRemoved() {
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,4 +24,7 @@ public interface GuestOSHypervisorDao extends GenericDao<GuestOSHypervisorVO, Lo
|
||||
|
||||
HypervisorType findHypervisorTypeByGuestOsId(long guestOsId);
|
||||
|
||||
GuestOSHypervisorVO findByOsIdAndHypervisor(long guestOsId, String hypervisorType, String hypervisorVersion);
|
||||
|
||||
boolean removeGuestOsMapping(Long id);
|
||||
}
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
// under the License.
|
||||
package com.cloud.storage.dao;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -31,11 +33,18 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
public class GuestOSHypervisorDaoImpl extends GenericDaoBase<GuestOSHypervisorVO, Long> implements GuestOSHypervisorDao {
|
||||
|
||||
protected final SearchBuilder<GuestOSHypervisorVO> guestOsSearch;
|
||||
protected final SearchBuilder<GuestOSHypervisorVO> mappingSearch;
|
||||
|
||||
protected GuestOSHypervisorDaoImpl() {
|
||||
guestOsSearch = createSearchBuilder();
|
||||
guestOsSearch.and("guest_os_id", guestOsSearch.entity().getGuestOsId(), SearchCriteria.Op.EQ);
|
||||
guestOsSearch.done();
|
||||
|
||||
mappingSearch = createSearchBuilder();
|
||||
mappingSearch.and("guest_os_id", mappingSearch.entity().getGuestOsId(), SearchCriteria.Op.EQ);
|
||||
mappingSearch.and("hypervisor_type", mappingSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
|
||||
mappingSearch.and("hypervisor_version", mappingSearch.entity().getHypervisorVersion(), SearchCriteria.Op.EQ);
|
||||
mappingSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,4 +55,22 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase<GuestOSHypervisorVO
|
||||
return HypervisorType.getType(goh.getHypervisorType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuestOSHypervisorVO findByOsIdAndHypervisor(long guestOsId, String hypervisorType, String hypervisorVersion) {
|
||||
SearchCriteria<GuestOSHypervisorVO> sc = mappingSearch.create();
|
||||
sc.setParameters("guest_os_id", guestOsId);
|
||||
sc.setParameters("hypervisor_type", hypervisorType);
|
||||
sc.setParameters("hypervisor_version", hypervisorVersion);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeGuestOsMapping(Long id) {
|
||||
GuestOSHypervisorVO guestOsHypervisor = findById(id);
|
||||
createForUpdate(id);
|
||||
guestOsHypervisor.setRemoved(new Date());
|
||||
update(id, guestOsHypervisor);
|
||||
return super.remove(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -30,6 +30,8 @@ import java.util.TimeZone;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
import org.apache.cloudstack.affinity.AffinityGroup;
|
||||
@ -64,6 +66,7 @@ import org.apache.cloudstack.api.response.FirewallResponse;
|
||||
import org.apache.cloudstack.api.response.FirewallRuleResponse;
|
||||
import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
|
||||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
import org.apache.cloudstack.api.response.GuestOsMappingResponse;
|
||||
import org.apache.cloudstack.api.response.GuestVlanRangeResponse;
|
||||
import org.apache.cloudstack.api.response.HostForMigrationResponse;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
@ -145,7 +148,6 @@ import org.apache.cloudstack.region.Region;
|
||||
import org.apache.cloudstack.usage.Usage;
|
||||
import org.apache.cloudstack.usage.UsageService;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.query.ViewResponseHelper;
|
||||
import com.cloud.api.query.vo.AccountJoinVO;
|
||||
@ -263,6 +265,7 @@ import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.storage.ImageStore;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
@ -3136,6 +3139,23 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuestOsMappingResponse createGuestOSMappingResponse(GuestOSHypervisor guestOSHypervisor) {
|
||||
GuestOsMappingResponse response = new GuestOsMappingResponse();
|
||||
response.setId(guestOSHypervisor.getUuid());
|
||||
response.setHypervisor(guestOSHypervisor.getHypervisorType());
|
||||
response.setHypervisorVersion(guestOSHypervisor.getHypervisorVersion());
|
||||
response.setOsNameForHypervisor((guestOSHypervisor.getGuestOsName()));
|
||||
GuestOS guestOs = ApiDBUtils.findGuestOSById(guestOSHypervisor.getGuestOsId());
|
||||
if (guestOs != null) {
|
||||
response.setOsStdName(guestOs.getDisplayName());
|
||||
response.setOsTypeId(guestOs.getUuid());
|
||||
}
|
||||
|
||||
response.setObjectName("guestosmapping");
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule snapshotSchedule) {
|
||||
SnapshotScheduleResponse response = new SnapshotScheduleResponse();
|
||||
@ -3698,4 +3718,5 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setResponses(responses);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ package com.cloud.server;
|
||||
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.storage.GuestOSHypervisorVO;
|
||||
import com.cloud.storage.GuestOSVO;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
@ -54,6 +55,8 @@ public interface ManagementServer extends ManagementService, PluggableService {
|
||||
|
||||
GuestOSVO getGuestOs(Long guestOsId);
|
||||
|
||||
GuestOSHypervisorVO getGuestOsHypervisor(Long guestOsHypervisorId);
|
||||
|
||||
/**
|
||||
* Returns the vnc port of the vm.
|
||||
*
|
||||
|
||||
@ -40,6 +40,9 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
|
||||
@ -69,6 +72,13 @@ import org.apache.cloudstack.api.command.admin.domain.DeleteDomainCmd;
|
||||
import org.apache.cloudstack.api.command.admin.domain.ListDomainChildrenCmd;
|
||||
import org.apache.cloudstack.api.command.admin.domain.ListDomainsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.ListGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.RemoveGuestOsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.RemoveGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
|
||||
@ -455,8 +465,6 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.GetVncPortAnswer;
|
||||
@ -544,6 +552,8 @@ import com.cloud.service.dao.ServiceOfferingDetailsDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.storage.GuestOSHypervisor;
|
||||
import com.cloud.storage.GuestOSHypervisorVO;
|
||||
import com.cloud.storage.GuestOSVO;
|
||||
import com.cloud.storage.GuestOsCategory;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
@ -556,6 +566,7 @@ import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||
import com.cloud.storage.dao.GuestOSDao;
|
||||
import com.cloud.storage.dao.GuestOSHypervisorDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
@ -671,6 +682,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
@Inject
|
||||
private GuestOSCategoryDao _guestOSCategoryDao;
|
||||
@Inject
|
||||
private GuestOSHypervisorDao _guestOSHypervisorDao;
|
||||
@Inject
|
||||
private PrimaryDataStoreDao _poolDao;
|
||||
@Inject
|
||||
private NetworkDao _networkDao;
|
||||
@ -2109,6 +2122,216 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
return new Pair<List<? extends GuestOsCategory>, Integer>(result.first(), result.second());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<? extends GuestOSHypervisor>, Integer> listGuestOSMappingByCriteria(ListGuestOsMappingCmd cmd) {
|
||||
Filter searchFilter = new Filter(GuestOSHypervisorVO.class, "hypervisorType", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
Long id = cmd.getId();
|
||||
Long osTypeId = cmd.getOsTypeId();
|
||||
String hypervisor = cmd.getHypervisor();
|
||||
String hypervisorVersion = cmd.getHypervisorVersion();
|
||||
|
||||
//throw exception if hypervisor name is not passed, but version is
|
||||
if (hypervisorVersion != null && (hypervisor == null || hypervisor.isEmpty())) {
|
||||
throw new InvalidParameterValueException("Hypervisor version parameter cannot be used without specifying a hypervisor : XenServer, KVM or VMware");
|
||||
}
|
||||
|
||||
SearchCriteria<GuestOSHypervisorVO> sc = _guestOSHypervisorDao.createSearchCriteria();
|
||||
|
||||
if (id != null) {
|
||||
sc.addAnd("id", SearchCriteria.Op.EQ, id);
|
||||
}
|
||||
|
||||
if (osTypeId != null) {
|
||||
sc.addAnd("guestOsId", SearchCriteria.Op.EQ, osTypeId);
|
||||
}
|
||||
|
||||
if (hypervisor != null) {
|
||||
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisor);
|
||||
}
|
||||
|
||||
if (hypervisorVersion != null) {
|
||||
sc.addAnd("hypervisorVersion", SearchCriteria.Op.EQ, hypervisorVersion);
|
||||
}
|
||||
|
||||
Pair<List<GuestOSHypervisorVO>, Integer> result = _guestOSHypervisorDao.searchAndCount(sc, searchFilter);
|
||||
return new Pair<List<? extends GuestOSHypervisor>, Integer>(result.first(), result.second());
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_ADD, eventDescription = "Adding new guest OS to hypervisor name mapping", create = true)
|
||||
public GuestOSHypervisor addGuestOsMapping(AddGuestOsMappingCmd cmd) {
|
||||
Long osTypeId = cmd.getOsTypeId();
|
||||
String osStdName = cmd.getOsStdName();
|
||||
String hypervisor = cmd.getHypervisor();
|
||||
String hypervisorVersion = cmd.getHypervisorVersion();
|
||||
String osNameForHypervisor = cmd.getOsNameForHypervisor();
|
||||
GuestOS guestOs = null;
|
||||
|
||||
if ((osTypeId == null) && (osStdName == null || osStdName.isEmpty())) {
|
||||
throw new InvalidParameterValueException("Please specify either a guest OS name or UUID");
|
||||
}
|
||||
|
||||
HypervisorType hypervisorType = HypervisorType.getType(hypervisor);
|
||||
|
||||
if (!(hypervisorType == HypervisorType.KVM || hypervisorType == HypervisorType.XenServer || hypervisorType == HypervisorType.VMware)) {
|
||||
throw new InvalidParameterValueException("Please specify a valid hypervisor : XenServer, KVM or VMware");
|
||||
}
|
||||
|
||||
HypervisorCapabilitiesVO hypervisorCapabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(hypervisorType, hypervisorVersion);
|
||||
if (hypervisorCapabilities == null) {
|
||||
throw new InvalidParameterValueException("Please specify a valid hypervisor and supported version");
|
||||
}
|
||||
|
||||
//by this point either osTypeId or osStdType is non-empty. Find by either of them. ID takes preference if both are specified
|
||||
if (osTypeId != null) {
|
||||
guestOs = ApiDBUtils.findGuestOSById(osTypeId);
|
||||
}
|
||||
else if (osStdName != null) {
|
||||
guestOs = ApiDBUtils.findGuestOSByDisplayName(osStdName);
|
||||
}
|
||||
|
||||
if (guestOs == null) {
|
||||
throw new InvalidParameterValueException("Unable to find the guest OS by name or UUID");
|
||||
}
|
||||
//check for duplicates
|
||||
GuestOSHypervisorVO duplicate = _guestOSHypervisorDao.findByOsIdAndHypervisor(osTypeId.longValue(), hypervisorType.toString(), hypervisorVersion);
|
||||
|
||||
if (duplicate != null) {
|
||||
throw new InvalidParameterValueException("Mapping from hypervisor : " + hypervisorType.toString() + ", version : " + hypervisorVersion + " and guest OS : "
|
||||
+ guestOs.getDisplayName() + " already exists!");
|
||||
}
|
||||
GuestOSHypervisorVO guestOsMapping = new GuestOSHypervisorVO();
|
||||
guestOsMapping.setGuestOsId(guestOs.getId());
|
||||
guestOsMapping.setGuestOsName(osNameForHypervisor);
|
||||
guestOsMapping.setHypervisorType(hypervisorType.toString());
|
||||
guestOsMapping.setHypervisorVersion(hypervisorVersion);
|
||||
return _guestOSHypervisorDao.persist(guestOsMapping);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_ADD, eventDescription = "Adding a new guest OS to hypervisor name mapping", async = true)
|
||||
public GuestOSHypervisor getAddedGuestOsMapping(Long guestOsMappingId) {
|
||||
return getGuestOsHypervisor(guestOsMappingId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_ADD, eventDescription = "Adding new guest OS type", create = true)
|
||||
public GuestOS addGuestOs(AddGuestOsCmd cmd) {
|
||||
Long categoryId = cmd.getOsCategoryId();
|
||||
String displayName = cmd.getOsDisplayName();
|
||||
String name = cmd.getOsName();
|
||||
|
||||
GuestOSCategoryVO guestOsCategory = ApiDBUtils.findGuestOsCategoryById(categoryId);
|
||||
if (guestOsCategory == null) {
|
||||
throw new InvalidParameterValueException("Guest OS category not found. Please specify a valid Guest OS category");
|
||||
}
|
||||
|
||||
GuestOS guestOs = ApiDBUtils.findGuestOSByDisplayName(displayName);
|
||||
if (guestOs != null) {
|
||||
throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique name");
|
||||
}
|
||||
|
||||
GuestOSVO guestOsVo = new GuestOSVO();
|
||||
guestOsVo.setCategoryId(categoryId.longValue());
|
||||
guestOsVo.setDisplayName(displayName);
|
||||
guestOsVo.setName(name);
|
||||
return _guestOSDao.persist(guestOsVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_ADD, eventDescription = "Adding a new guest OS type", async = true)
|
||||
public GuestOS getAddedGuestOs(Long guestOsId) {
|
||||
return getGuestOs(guestOsId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_UPDATE, eventDescription = "updating guest OS type", async = true)
|
||||
public GuestOS updateGuestOs(UpdateGuestOsCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
String displayName = cmd.getOsDisplayName();
|
||||
|
||||
//check if guest OS exists
|
||||
GuestOS guestOsHandle = ApiDBUtils.findGuestOSById(id);
|
||||
if (guestOsHandle == null) {
|
||||
throw new InvalidParameterValueException("Guest OS not found. Please specify a valid ID for the Guest OS");
|
||||
}
|
||||
|
||||
//Check if update is needed
|
||||
if (displayName.equals(guestOsHandle.getDisplayName())) {
|
||||
return guestOsHandle;
|
||||
}
|
||||
|
||||
//Check if another Guest OS by same name exists
|
||||
GuestOS duplicate = ApiDBUtils.findGuestOSByDisplayName(displayName);
|
||||
if(duplicate != null) {
|
||||
throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique guest OS name");
|
||||
}
|
||||
GuestOSVO guestOs = _guestOSDao.createForUpdate(id);
|
||||
guestOs.setDisplayName(displayName);
|
||||
if (_guestOSDao.update(id, guestOs)) {
|
||||
return _guestOSDao.findById(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_REMOVE, eventDescription = "removing guest OS type", async = true)
|
||||
public boolean removeGuestOs(RemoveGuestOsCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
|
||||
//check if guest OS exists
|
||||
GuestOS guestOs = ApiDBUtils.findGuestOSById(id);
|
||||
if (guestOs == null) {
|
||||
throw new InvalidParameterValueException("Guest OS not found. Please specify a valid ID for the Guest OS");
|
||||
}
|
||||
|
||||
return _guestOSDao.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_UPDATE, eventDescription = "updating guest OS mapping", async = true)
|
||||
public GuestOSHypervisor updateGuestOsMapping(UpdateGuestOsMappingCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
String osNameForHypervisor = cmd.getOsNameForHypervisor();
|
||||
|
||||
//check if mapping exists
|
||||
GuestOSHypervisor guestOsHypervisorHandle = _guestOSHypervisorDao.findById(id);
|
||||
if (guestOsHypervisorHandle == null) {
|
||||
throw new InvalidParameterValueException("Guest OS Mapping not found. Please specify a valid ID for the Guest OS Mapping");
|
||||
}
|
||||
|
||||
GuestOSHypervisorVO guestOsHypervisor = _guestOSHypervisorDao.createForUpdate(id);
|
||||
guestOsHypervisor.setGuestOsName(osNameForHypervisor);
|
||||
if (_guestOSHypervisorDao.update(id, guestOsHypervisor)) {
|
||||
return _guestOSHypervisorDao.findById(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_REMOVE, eventDescription = "removing guest OS mapping", async = true)
|
||||
public boolean removeGuestOsMapping(RemoveGuestOsMappingCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
|
||||
//check if mapping exists
|
||||
GuestOSHypervisor guestOsHypervisorHandle = _guestOSHypervisorDao.findById(id);
|
||||
if (guestOsHypervisorHandle == null) {
|
||||
throw new InvalidParameterValueException("Guest OS Mapping not found. Please specify a valid ID for the Guest OS Mapping");
|
||||
}
|
||||
|
||||
return _guestOSHypervisorDao.removeGuestOsMapping(id);
|
||||
|
||||
}
|
||||
|
||||
protected ConsoleProxyInfo getConsoleProxyForVm(long dataCenterId, long userVmId) {
|
||||
return _consoleProxyMgr.assignProxy(dataCenterId, userVmId);
|
||||
}
|
||||
@ -2663,6 +2886,13 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
cmdList.add(UpdatePortForwardingRuleCmd.class);
|
||||
cmdList.add(ListGuestOsCategoriesCmd.class);
|
||||
cmdList.add(ListGuestOsCmd.class);
|
||||
cmdList.add(ListGuestOsMappingCmd.class);
|
||||
cmdList.add(AddGuestOsCmd.class);
|
||||
cmdList.add(AddGuestOsMappingCmd.class);
|
||||
cmdList.add(UpdateGuestOsCmd.class);
|
||||
cmdList.add(UpdateGuestOsMappingCmd.class);
|
||||
cmdList.add(RemoveGuestOsCmd.class);
|
||||
cmdList.add(RemoveGuestOsMappingCmd.class);
|
||||
cmdList.add(AttachIsoCmd.class);
|
||||
cmdList.add(CopyIsoCmd.class);
|
||||
cmdList.add(DeleteIsoCmd.class);
|
||||
@ -3271,6 +3501,11 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
return _guestOSDao.findById(guestOsId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuestOSHypervisorVO getGuestOsHypervisor(Long guestOsHypervisorId) {
|
||||
return _guestOSHypervisorDao.findById(guestOsHypervisorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
@ -3789,4 +4024,5 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
public void setLockMasterListener(LockMasterListener lockMasterListener) {
|
||||
_lockMasterListener = lockMasterListener;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -611,3 +611,13 @@ CREATE TABLE `cloud`.`vgpu_types` (
|
||||
CONSTRAINT `fk_vgpu_types__gpu_group_id` FOREIGN KEY (`gpu_group_id`) REFERENCES `host_gpu_groups` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB CHARSET=utf8;
|
||||
|
||||
ALTER TABLE `cloud`.`guest_os_hypervisor` ADD COLUMN `hypervisor_version` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Hypervisor version for this mapping';
|
||||
ALTER TABLE `cloud`.`guest_os_hypervisor` ADD COLUMN `uuid` varchar(40) COMMENT 'UUID of the mapping';
|
||||
ALTER TABLE `cloud`.`guest_os_hypervisor` ADD CONSTRAINT `uc_guest_os_hypervisor__uuid` UNIQUE (`uuid`);
|
||||
ALTER TABLE `cloud`.`guest_os_hypervisor` ADD COLUMN `created` datetime COMMENT 'Time when mapping was created';
|
||||
ALTER TABLE `cloud`.`guest_os_hypervisor` ADD COLUMN `removed` datetime COMMENT 'Time when mapping was removed if deleted, else NULL';
|
||||
UPDATE `cloud`.`guest_os_hypervisor` SET `uuid` = UUID();
|
||||
UPDATE `cloud`.`guest_os_hypervisor` SET `created` = now();
|
||||
ALTER TABLE `cloud`.`guest_os` ADD COLUMN `created` datetime COMMENT 'Time when Guest OS was created in system';
|
||||
ALTER TABLE `cloud`.`guest_os` ADD COLUMN `removed` datetime COMMENT 'Time when Guest OS was removed if deleted, else NULL';
|
||||
UPDATE `cloud`.`guest_os` SET `created` = now();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user