Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5302010EE2 for ; Thu, 13 Mar 2014 00:06:45 +0000 (UTC) Received: (qmail 8697 invoked by uid 500); 13 Mar 2014 00:06:44 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 8664 invoked by uid 500); 13 Mar 2014 00:06:44 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 8657 invoked by uid 99); 13 Mar 2014 00:06:44 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Mar 2014 00:06:44 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F01679433C2; Thu, 13 Mar 2014 00:06:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nitin@apache.org To: commits@cloudstack.apache.org Message-Id: <9f3b85f51d0f40b8a89e3512ae32efd3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/master to 3ee1fc2 Date: Thu, 13 Mar 2014 00:06:43 +0000 (UTC) Repository: cloudstack Updated Branches: refs/heads/master cd8af6a3e -> 3ee1fc28d 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 Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3ee1fc28 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3ee1fc28 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3ee1fc28 Branch: refs/heads/master Commit: 3ee1fc28deafc575dedd655bc6af37c274142275 Parents: cd8af6a Author: amogh.vasekar Authored: Wed Mar 12 15:15:18 2014 -0700 Committer: Nitin Mehta Committed: Wed Mar 12 17:03:38 2014 -0700 ---------------------------------------------------------------------- api/src/com/cloud/event/EventTypes.java | 18 ++ api/src/com/cloud/server/ManagementService.java | 73 ++++++ api/src/com/cloud/storage/GuestOS.java | 6 + .../com/cloud/storage/GuestOSHypervisor.java | 10 + .../cloudstack/api/ApiCommandJobType.java | 6 +- .../org/apache/cloudstack/api/ApiConstants.java | 2 + .../cloudstack/api/ResponseGenerator.java | 4 + .../api/command/admin/guest/AddGuestOsCmd.java | 136 +++++++++++ .../admin/guest/AddGuestOsMappingCmd.java | 146 +++++++++++ .../admin/guest/ListGuestOsMappingCmd.java | 101 ++++++++ .../command/admin/guest/RemoveGuestOsCmd.java | 98 ++++++++ .../admin/guest/RemoveGuestOsMappingCmd.java | 98 ++++++++ .../command/admin/guest/UpdateGuestOsCmd.java | 104 ++++++++ .../admin/guest/UpdateGuestOsMappingCmd.java | 102 ++++++++ .../api/response/GuestOsMappingResponse.java | 102 ++++++++ client/tomcatconf/commands.properties.in | 9 + .../com/cloud/storage/GuestOSHypervisorVO.java | 62 ++++- .../schema/src/com/cloud/storage/GuestOSVO.java | 25 +- .../cloud/storage/dao/GuestOSHypervisorDao.java | 3 + .../storage/dao/GuestOSHypervisorDaoImpl.java | 27 +++ server/src/com/cloud/api/ApiResponseHelper.java | 23 +- .../src/com/cloud/server/ManagementServer.java | 3 + .../com/cloud/server/ManagementServerImpl.java | 240 ++++++++++++++++++- setup/db/db/schema-430to440.sql | 10 + 24 files changed, 1401 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/com/cloud/event/EventTypes.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index a5fc0f0..39ef710 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -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) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/com/cloud/server/ManagementService.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 5fcf0b5..abe6e2c 100755 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -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, Integer> listGuestOSCategoriesByCriteria(ListGuestOsCategoriesCmd cmd); + /** + * Obtains a list of all guest OS mappings + * + * @return list of GuestOSHypervisor + */ + Pair, 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(); + + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/com/cloud/storage/GuestOS.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/storage/GuestOS.java b/api/src/com/cloud/storage/GuestOS.java index 437cd37..767a60e 100644 --- a/api/src/com/cloud/storage/GuestOS.java +++ b/api/src/com/cloud/storage/GuestOS.java @@ -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(); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/com/cloud/storage/GuestOSHypervisor.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/storage/GuestOSHypervisor.java b/api/src/com/cloud/storage/GuestOSHypervisor.java index f022722..1cfc3a1 100644 --- a/api/src/com/cloud/storage/GuestOSHypervisor.java +++ b/api/src/com/cloud/storage/GuestOSHypervisor.java @@ -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(); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/ApiCommandJobType.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/ApiCommandJobType.java b/api/src/org/apache/cloudstack/api/ApiCommandJobType.java index f27f001..227fb30 100644 --- a/api/src/org/apache/cloudstack/api/ApiCommandJobType.java +++ b/api/src/org/apache/cloudstack/api/ApiCommandJobType.java @@ -51,5 +51,7 @@ public enum ApiCommandJobType { InternalLbVm, DedicatedGuestVlanRange, IAMPolicy, - IAMGroup -} \ No newline at end of file + IAMGroup, + GuestOs, + GuestOsMapping +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/ApiConstants.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 0a3fafd..089affb 100755 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -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"; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/ResponseGenerator.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java index 1cb5388..b846d3f 100644 --- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java @@ -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); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java new file mode 100644 index 0000000..3ba9669 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java @@ -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"; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java new file mode 100644 index 0000000..8af50a1 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java @@ -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"; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java new file mode 100644 index 0000000..a7fc9e0 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java @@ -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, Integer> result = _mgr.listGuestOSMappingByCriteria(this); + ListResponse response = new ListResponse(); + List osMappingResponses = new ArrayList(); + for (GuestOSHypervisor guestOSHypervisor : result.first()) { + GuestOsMappingResponse guestOsMappingResponse = _responseGenerator.createGuestOSMappingResponse(guestOSHypervisor); + osMappingResponses.add(guestOsMappingResponse); + } + + response.setResponses(osMappingResponses, result.second()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java new file mode 100644 index 0000000..3de7f7a --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java @@ -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; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java new file mode 100644 index 0000000..ddd4539 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java @@ -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; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java new file mode 100644 index 0000000..e4b1ecd --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java @@ -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; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java new file mode 100644 index 0000000..d760d53 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java @@ -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; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java b/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java new file mode 100644 index 0000000..a0f7d1d --- /dev/null +++ b/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java @@ -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; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 879c58d..0a06c4d 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -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 http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/engine/schema/src/com/cloud/storage/GuestOSHypervisorVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/GuestOSHypervisorVO.java b/engine/schema/src/com/cloud/storage/GuestOSHypervisorVO.java index 8210abf..1fbc9d7 100644 --- a/engine/schema/src/com/cloud/storage/GuestOSHypervisorVO.java +++ b/engine/schema/src/com/cloud/storage/GuestOSHypervisorVO.java @@ -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,12 +45,29 @@ 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; + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/engine/schema/src/com/cloud/storage/GuestOSVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/GuestOSVO.java b/engine/schema/src/com/cloud/storage/GuestOSVO.java index 57b8529..a0040be 100644 --- a/engine/schema/src/com/cloud/storage/GuestOSVO.java +++ b/engine/schema/src/com/cloud/storage/GuestOSVO.java @@ -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; + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java b/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java index 651cfb5..5b6e719 100644 --- a/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java +++ b/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java @@ -24,4 +24,7 @@ public interface GuestOSHypervisorDao extends GenericDao implements GuestOSHypervisorDao { protected final SearchBuilder guestOsSearch; + protected final SearchBuilder 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 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); + } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/server/src/com/cloud/api/ApiResponseHelper.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 2deaa50..a2cc352 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -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; @@ -3137,6 +3140,23 @@ public class ApiResponseHelper implements ResponseGenerator { } @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(); response.setId(snapshotSchedule.getUuid()); @@ -3698,4 +3718,5 @@ public class ApiResponseHelper implements ResponseGenerator { response.setResponses(responses); return response; } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/server/src/com/cloud/server/ManagementServer.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 3b5f5ff..4e58a4f 100755 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -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. * http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/server/src/com/cloud/server/ManagementServerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 663d4e5..cb73519 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -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, Integer>(result.first(), result.second()); } + @Override + public Pair, 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 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, Integer> result = _guestOSHypervisorDao.searchAndCount(sc, searchFilter); + return new Pair, 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); @@ -3272,6 +3502,11 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } @Override + public GuestOSHypervisorVO getGuestOsHypervisor(Long guestOsHypervisorId) { + return _guestOSHypervisorDao.findById(guestOsHypervisorId); + } + + @Override public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) { Account caller = CallContext.current().getCallingAccount(); Long groupId = cmd.getId(); @@ -3789,4 +4024,5 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe public void setLockMasterListener(LockMasterListener lockMasterListener) { _lockMasterListener = lockMasterListener; } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ee1fc28/setup/db/db/schema-430to440.sql ---------------------------------------------------------------------- diff --git a/setup/db/db/schema-430to440.sql b/setup/db/db/schema-430to440.sql index ee4cf21..ab6bc98 100644 --- a/setup/db/db/schema-430to440.sql +++ b/setup/db/db/schema-430to440.sql @@ -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();