You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ni...@apache.org on 2014/05/07 23:34:21 UTC
git commit: updated refs/heads/master to 5388d34
Repository: cloudstack
Updated Branches:
refs/heads/master 0e975a773 -> 5388d349a
CLOUDSTACK-6597: Updatevm - root admin should be allowed to change instance name
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5388d349
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5388d349
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5388d349
Branch: refs/heads/master
Commit: 5388d349a46ae046b602fd92e4fa734ac6cad892
Parents: 0e975a7
Author: Nitin Mehta <ni...@citrix.com>
Authored: Wed May 7 14:34:01 2014 -0700
Committer: Nitin Mehta <ni...@citrix.com>
Committed: Wed May 7 14:34:01 2014 -0700
----------------------------------------------------------------------
.../cloudstack/api/command/user/vm/UpdateVMCmd.java | 8 +++++++-
engine/schema/src/com/cloud/vm/VMInstanceVO.java | 5 +++++
engine/schema/src/com/cloud/vm/dao/UserVmDao.java | 3 ++-
engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java | 6 +++++-
.../src/com/cloud/storage/VolumeApiServiceImpl.java | 2 +-
server/src/com/cloud/vm/UserVmManager.java | 2 +-
server/src/com/cloud/vm/UserVmManagerImpl.java | 14 +++++++++++---
7 files changed, 32 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5388d349/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
----------------------------------------------------------------------
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 b437305..0983642 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///////////////////
/////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5388d349/engine/schema/src/com/cloud/vm/VMInstanceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/com/cloud/vm/VMInstanceVO.java
index 3d4337f..d1f358d 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<State, Vi
return instanceName;
}
+ // Be very careful to use this. This has to be unique for the vm and if changed should be done by root admin only.
+ public void setInstanceName(String instanceName) {
+ this.instanceName = instanceName;
+ }
+
@Override
public State getState() {
return state;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5388d349/engine/schema/src/com/cloud/vm/dao/UserVmDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmDao.java b/engine/schema/src/com/cloud/vm/dao/UserVmDao.java
index 884d0a3..dfafdeb 100755
--- a/engine/schema/src/com/cloud/vm/dao/UserVmDao.java
+++ b/engine/schema/src/com/cloud/vm/dao/UserVmDao.java
@@ -44,8 +44,9 @@ public interface UserVmDao extends GenericDao<UserVmVO, Long> {
* @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<UserVmVO> findDestroyedVms(Date date);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5388d349/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java
index 7a05be8..c49aeca 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<UserVmVO, Long> 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<UserVmVO, Long> implements Use
if (customId != null) {
vo.setUuid(customId);
}
+ if(instanceName != null){
+ vo.setInstanceName(instanceName);
+ }
update(id, vo);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5388d349/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index da204f3..5778725 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)) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5388d349/server/src/com/cloud/vm/UserVmManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java
index 61e28d8..324547f 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.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5388d349/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index fac5635..20306fd 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));