You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2013/10/01 00:42:08 UTC
git commit: updated refs/heads/master to b253d95
Updated Branches:
refs/heads/master 1a23d6eba -> b253d95de
UpdateVirtualMachine: code cleanup - got rid of warnings and unused code from the method; extracted part of the code to its separate method.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b253d95d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b253d95d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b253d95d
Branch: refs/heads/master
Commit: b253d95de9719c83d8128fb4b24d997d55ff7c58
Parents: 1a23d6e
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Mon Sep 30 15:11:50 2013 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Mon Sep 30 15:34:56 2013 -0700
----------------------------------------------------------------------
server/src/com/cloud/vm/UserVmManager.java | 4 +
server/src/com/cloud/vm/UserVmManagerImpl.java | 83 +++++++++------------
2 files changed, 41 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b253d95d/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 e1bee8d..485e633 100755
--- a/server/src/com/cloud/vm/UserVmManager.java
+++ b/server/src/com/cloud/vm/UserVmManager.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.cloudstack.api.BaseCmd.HTTPMethod;
import org.apache.cloudstack.framework.config.ConfigKey;
import com.cloud.agent.api.VmDiskStatsEntry;
@@ -110,4 +111,7 @@ public interface UserVmManager extends UserVmService {
boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic);
void collectVmDiskStatistics (UserVmVO userVm);
+
+ UserVm updateVirtualMachine(long id, String displayName, String group, Boolean ha, Boolean isDisplayVmEnabled, Long osTypeId, String userData,
+ Boolean isDynamicallyScalable, HTTPMethod httpMethod)throws ResourceUnavailableException, InsufficientCapacityException;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b253d95d/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 9b694e1..55d166c 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -1768,43 +1768,29 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
Account caller = CallContext.current().getCallingAccount();
- // Input validation
- UserVmVO vmInstance = null;
-
- // Verify input parameters
- vmInstance = _vmDao.findById(id.longValue());
-
+ // Input validation and permission checks
+ UserVmVO vmInstance = _vmDao.findById(id.longValue());
if (vmInstance == null) {
throw new InvalidParameterValueException(
"unable to find virtual machine with id " + id);
}
- ServiceOffering offering = _serviceOfferingDao.findById(vmInstance
- .getServiceOfferingId());
- if (!offering.getOfferHA() && ha != null && ha) {
- throw new InvalidParameterValueException(
- "Can't enable ha for the vm as it's created from the Service offering having HA disabled");
- }
-
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true,
vmInstance);
-
- if (displayName == null) {
- displayName = vmInstance.getDisplayName();
- }
-
- if (ha == null) {
- ha = vmInstance.isHaEnabled();
- }
-
- if (isDisplayVmEnabled == null) {
- isDisplayVmEnabled = vmInstance.isDisplayVm();
- } else{
+
+ if (isDisplayVmEnabled != null) {
if(!_accountMgr.isRootAdmin(caller.getType())){
throw new PermissionDeniedException( "Cannot update parameter displayvm, only admin permitted ");
}
}
+ return updateVirtualMachine(id, displayName, group, ha, isDisplayVmEnabled, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod());
+ }
+
+ @Override
+ public UserVm updateVirtualMachine(long id, String displayName, String group, Boolean ha,
+ Boolean isDisplayVmEnabled, Long osTypeId, String userData, Boolean isDynamicallyScalable, HTTPMethod httpMethod)
+ throws ResourceUnavailableException, InsufficientCapacityException {
UserVmVO vm = _vmDao.findById(id);
if (vm == null) {
throw new CloudRuntimeException(
@@ -1816,45 +1802,50 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
throw new InvalidParameterValueException("Vm with id " + id
+ " is not in the right state");
}
+
+ if (displayName == null) {
+ displayName = vm.getDisplayName();
+ }
+
+ if (ha == null) {
+ ha = vm.isHaEnabled();
+ }
+
+ ServiceOffering offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
+ if (!offering.getOfferHA() && ha) {
+ throw new InvalidParameterValueException(
+ "Can't enable ha for the vm as it's created from the Service offering having HA disabled");
+ }
+
+ if (isDisplayVmEnabled == null) {
+ isDisplayVmEnabled = vm.isDisplayVm();
+ }
boolean updateUserdata = false;
if (userData != null) {
// check and replace newlines
userData = userData.replace("\\n", "");
- validateUserData(userData, cmd.getHttpMethod());
+ validateUserData(userData, httpMethod);
// update userData on domain router.
updateUserdata = true;
} else {
- userData = vmInstance.getUserData();
- }
-
- String description = "";
-
- if (displayName != null && !displayName.equals(vmInstance.getDisplayName())) {
- description += "New display name: " + displayName + ". ";
+ userData = vm.getUserData();
}
- if (ha != vmInstance.isHaEnabled()) {
- if (ha) {
- description += "Enabled HA. ";
- } else {
- description += "Disabled HA. ";
- }
+ if (isDynamicallyScalable == null) {
+ isDynamicallyScalable = vm.isDynamicallyScalable();
}
+
if (osTypeId == null) {
- osTypeId = vmInstance.getGuestOSId();
- } else {
- description += "Changed Guest OS Type to " + osTypeId + ". ";
+ osTypeId = vm.getGuestOSId();
}
if (group != null) {
- if (addInstanceToGroup(id, group)) {
- description += "Added to group: " + group + ".";
- }
+ addInstanceToGroup(id, group);
}
if (isDynamicallyScalable == null) {
- isDynamicallyScalable = vmInstance.isDynamicallyScalable();
+ isDynamicallyScalable = vm.isDynamicallyScalable();
}
_vmDao.updateVM(id, displayName, ha, osTypeId, userData, isDisplayVmEnabled, isDynamicallyScalable);