diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java index b437305134b..09836424658 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java @@ -87,6 +87,9 @@ public class UpdateVMCmd extends BaseCustomIdCmd { @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "new host name of the vm. The VM has to be stopped/started for this update to take affect", since = "4.4") private String name; + @Parameter(name = ApiConstants.INSTANCE_NAME, type = CommandType.STRING, description = "instance name of the user vm", since = "4.4", authorized = {RoleType.Admin}) + private String instanceName; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -123,7 +126,10 @@ public class UpdateVMCmd extends BaseCustomIdCmd { return name; } - ///////////////////////////////////////////////////// + public String getInstanceName() { + return instanceName; + } +///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/engine/schema/src/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/com/cloud/vm/VMInstanceVO.java index 3d4337f374d..d1f358d71f5 100644 --- a/engine/schema/src/com/cloud/vm/VMInstanceVO.java +++ b/engine/schema/src/com/cloud/vm/VMInstanceVO.java @@ -281,6 +281,11 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject { * @param displayVm updates the displayvm attribute signifying whether it has to be displayed to the end user or not. * @param customId * @param hostName TODO + * @param instanceName */ - void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData, boolean displayVm, boolean isDynamicallyScalable, String customId, String hostName); + void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData, boolean displayVm, boolean isDynamicallyScalable, String customId, String hostName, String instanceName); List findDestroyedVms(Date date); diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java index 7a05be8f604..c49aeca7034 100755 --- a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java +++ b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java @@ -216,7 +216,8 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } @Override - public void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData, boolean displayVm, boolean isDynamicallyScalable, String customId, String hostName) { + public void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData, boolean displayVm, + boolean isDynamicallyScalable, String customId, String hostName, String instanceName) { UserVmVO vo = createForUpdate(); vo.setDisplayName(displayName); vo.setHaEnabled(enable); @@ -230,6 +231,9 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use if (customId != null) { vo.setUuid(customId); } + if(instanceName != null){ + vo.setInstanceName(instanceName); + } update(id, vo); } diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index da204f39740..57787254837 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1442,7 +1442,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } private void validateRootVolumeDetachAttach(VolumeVO volume, UserVmVO vm) { - if (!(vm.getHypervisorType() == HypervisorType.XenServer)) { + if (!(vm.getHypervisorType() == HypervisorType.XenServer || vm.getHypervisorType() == HypervisorType.VMware)) { throw new InvalidParameterValueException("Root volume detach is allowed for hypervisor type " + HypervisorType.XenServer + " only"); } if (!(vm.getState() == State.Stopped) || (vm.getState() == State.Destroyed)) { diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java index 61e28d81bdf..324547f47ea 100755 --- a/server/src/com/cloud/vm/UserVmManager.java +++ b/server/src/com/cloud/vm/UserVmManager.java @@ -100,7 +100,7 @@ public interface UserVmManager extends UserVmService { void collectVmDiskStatistics(UserVmVO userVm); UserVm updateVirtualMachine(long id, String displayName, String group, Boolean ha, Boolean isDisplayVmEnabled, Long osTypeId, String userData, - Boolean isDynamicallyScalable, HTTPMethod httpMethod, String customId, String hostName) throws ResourceUnavailableException, InsufficientCapacityException; + Boolean isDynamicallyScalable, HTTPMethod httpMethod, String customId, String hostName, String instanceName) throws ResourceUnavailableException, InsufficientCapacityException; //the validateCustomParameters, save and remove CustomOfferingDetils functions can be removed from the interface once we can //find a common place for all the scaling and upgrading code of both user and systemvms. diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index fac56359957..20306fd8ac3 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1860,7 +1860,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } - return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName); + return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, + cmd.getHttpMethod(), cmd.getCustomId(), hostName, cmd.getInstanceName()); } private void saveUsageEvent(UserVmVO vm) { @@ -1910,12 +1911,19 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir @Override public UserVm updateVirtualMachine(long id, String displayName, String group, Boolean ha, Boolean isDisplayVmEnabled, Long osTypeId, String userData, - Boolean isDynamicallyScalable, HTTPMethod httpMethod, String customId, String hostName) throws ResourceUnavailableException, InsufficientCapacityException { + Boolean isDynamicallyScalable, HTTPMethod httpMethod, String customId, String hostName, String instanceName) throws ResourceUnavailableException, InsufficientCapacityException { UserVmVO vm = _vmDao.findById(id); if (vm == null) { throw new CloudRuntimeException("Unable to find virual machine with id " + id); } + if(instanceName != null){ + VMInstanceVO vmInstance = _vmInstanceDao.findVMByInstanceName(instanceName); + if(vmInstance != null && vmInstance.getId() != id){ + throw new CloudRuntimeException("Instance name : " + instanceName + " is not unique"); + } + } + if (vm.getState() == State.Error || vm.getState() == State.Expunging) { s_logger.error("vm is not in the right state: " + id); throw new InvalidParameterValueException("Vm with id " + id + " is not in the right state"); @@ -1983,7 +1991,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir checkIfHostNameUniqueInNtwkDomain(hostName, vmNtwks); } - _vmDao.updateVM(id, displayName, ha, osTypeId, userData, isDisplayVmEnabled, isDynamicallyScalable, customId, hostName); + _vmDao.updateVM(id, displayName, ha, osTypeId, userData, isDisplayVmEnabled, isDynamicallyScalable, customId, hostName, instanceName); if (updateUserdata) { boolean result = updateUserDataInternal(_vmDao.findById(id));