diff --git a/api/src/com/cloud/api/commands/SetVMOSTypeCmd.java b/api/src/com/cloud/api/commands/SetVMOSTypeCmd.java new file mode 100644 index 00000000000..bb1971e9fc9 --- /dev/null +++ b/api/src/com/cloud/api/commands/SetVMOSTypeCmd.java @@ -0,0 +1,89 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.UserVmResponse; +import com.cloud.event.EventTypes; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; +import com.cloud.uservm.UserVm; + +@Implementation(description="Set VM OS Type.", responseObject=UserVmResponse.class) +public class SetVMOSTypeCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(SetVMOSTypeCmd.class.getName()); + + private static final String s_name = "SetVMOSTypeResponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="the ID of the virtual machine") + private Long virtualMachineId; + + @Parameter(name=ApiConstants.OS_TYPE_ID, type=CommandType.LONG, required=true, description="the ID of the OS Type that best represents the OS of this template.") + private Long osTypeId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getOsTypeId() { + return osTypeId; + } + + public Long getVirtualMachineId() { + return virtualMachineId; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getName() { + return s_name; + } + + + @Override + public void execute(){ + boolean result = _userVmService.setVMOSType(this); + if (result) { + UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId); + if (userVm != null) { + UserVmResponse response = _responseGenerator.createUserVmResponse(userVm); + response.setResponseName(DeployVMCmd.getResultObjectName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to set VM OS type"); + } + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to set VM OS type"); + } + } +} diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index bc73f6a4d3f..836d784e45e 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -28,6 +28,7 @@ import com.cloud.api.commands.DetachVolumeCmd; import com.cloud.api.commands.RebootVMCmd; import com.cloud.api.commands.RecoverVMCmd; import com.cloud.api.commands.ResetVMPasswordCmd; +import com.cloud.api.commands.SetVMOSTypeCmd; import com.cloud.api.commands.StartVMCmd; import com.cloud.api.commands.StopVMCmd; import com.cloud.api.commands.UpdateVMCmd; @@ -63,6 +64,13 @@ public interface UserVmService { */ UserVm destroyVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException; + /** + * Destroys one virtual machine + * @param VMId the id of virtual machine + * @param OSTypeId the id of guest OS type + */ + boolean setVMOSType(SetVMOSTypeCmd cmd); + /** * Resets the password of a virtual machine. * @param cmd - the command specifying vmId, password diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 9ba071ca1ef..a8f1371a9db 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -34,6 +34,7 @@ listResourceLimits=com.cloud.api.commands.ListResourceLimitsCmd;15 #### VM commands deployVirtualMachine=com.cloud.api.commands.DeployVMCmd;11 +setVMOSType=com.cloud.api.commands.SetVMOSTypeCmd;15 destroyVirtualMachine=com.cloud.api.commands.DestroyVMCmd;15 rebootVirtualMachine=com.cloud.api.commands.RebootVMCmd;15 startVirtualMachine=com.cloud.api.commands.StartVMCmd;15 @@ -239,4 +240,4 @@ listNetworkOfferings=com.cloud.api.commands.ListNetworkOfferingsCmd;15 #### network commands createNetwork=com.cloud.api.commands.CreateNetworkCmd;15 deleteNetwork=com.cloud.api.commands.DeleteNetworkCmd;15 -listNetworks=com.cloud.api.commands.ListNetworksCmd;15 \ No newline at end of file +listNetworks=com.cloud.api.commands.ListNetworksCmd;15 diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 2f7d5525991..665ae2fe234 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -75,6 +75,7 @@ import com.cloud.api.commands.DetachVolumeCmd; import com.cloud.api.commands.RebootVMCmd; import com.cloud.api.commands.RecoverVMCmd; import com.cloud.api.commands.ResetVMPasswordCmd; +import com.cloud.api.commands.SetVMOSTypeCmd; import com.cloud.api.commands.StartVMCmd; import com.cloud.api.commands.StopVMCmd; import com.cloud.api.commands.UpdateVMCmd; @@ -3270,6 +3271,18 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM } return _vmDao.findById(id); } + + @Override + public boolean setVMOSType(SetVMOSTypeCmd cmd) { + long id = cmd.getVirtualMachineId(); + UserVmVO vmInstance = _vmDao.findById(id); + if (vmInstance == null) { + throw new CloudRuntimeException("Unable to find virtual machine with id " + id + ", internal error."); + } + vmInstance.setGuestOSId(cmd.getOsTypeId()); + _vmDao.update(id, vmInstance); + return true; + } @Override public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {