mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-7871: allow VM and template details update using update APIs
Allows updating details (key/value) pair which updatse entries
invm_template_details and user_vm_details tables using updateVM and updateTemplate
APIs. This allows sys admins to update nics, controllers etc without DB hacking.
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
(cherry picked from commit 97fa4a023e)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
Conflicts:
api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
server/src/com/cloud/vm/UserVmManagerImpl.java
This commit is contained in:
parent
1d92eebbe5
commit
5e57eeefd9
|
|
@ -22,6 +22,9 @@ import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
|
|||
import org.apache.cloudstack.api.response.GuestOSResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName());
|
||||
|
||||
|
|
@ -64,6 +67,9 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd {
|
|||
@Parameter(name = ApiConstants.ROUTING, type = CommandType.BOOLEAN, description = "true if the template type is routing i.e., if template is used to deploy router")
|
||||
protected Boolean isRoutingType;
|
||||
|
||||
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs.")
|
||||
protected Map details;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -107,4 +113,13 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd {
|
|||
public Boolean isRoutingType() {
|
||||
return isRoutingType;
|
||||
}
|
||||
}
|
||||
|
||||
public Map getDetails() {
|
||||
if (this.details == null || this.details.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collection paramsCollection = this.details.values();
|
||||
return (Map) (paramsCollection.toArray())[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,9 @@ import com.cloud.user.Account;
|
|||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@APICommand(name = "updateVirtualMachine", description="Updates properties of a virtual machine. The VM has to be stopped and restarted for the " +
|
||||
"new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. " +
|
||||
"Therefore, stop the VM manually before issuing this call.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
|
||||
|
|
@ -87,6 +90,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.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs.")
|
||||
protected Map details;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -123,6 +129,15 @@ public class UpdateVMCmd extends BaseCustomIdCmd {
|
|||
return name;
|
||||
}
|
||||
|
||||
public Map getDetails() {
|
||||
if (this.details == null || this.details.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collection paramsCollection = this.details.values();
|
||||
return (Map) (paramsCollection.toArray())[0];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1777,6 +1777,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
Boolean isRoutingTemplate = cmd.isRoutingType();
|
||||
Boolean bootable = cmd.isBootable();
|
||||
Integer sortKey = cmd.getSortKey();
|
||||
Map details = cmd.getDetails();
|
||||
Account account = CallContext.current().getCallingAccount();
|
||||
|
||||
// verify that template exists
|
||||
|
|
@ -1799,7 +1800,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
|
||||
boolean updateNeeded =
|
||||
!(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null && bootable == null && sortKey == null &&
|
||||
isDynamicallyScalable == null && isRoutingTemplate == null);
|
||||
isDynamicallyScalable == null && isRoutingTemplate == null && details == null);
|
||||
if (!updateNeeded) {
|
||||
return template;
|
||||
}
|
||||
|
|
@ -1859,6 +1860,11 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
}
|
||||
}
|
||||
|
||||
if (details != null && !details.isEmpty()) {
|
||||
template.setDetails(details);
|
||||
_tmpltDao.saveDetails(template);
|
||||
}
|
||||
|
||||
_tmpltDao.update(id, template);
|
||||
|
||||
return _tmpltDao.findById(id);
|
||||
|
|
|
|||
|
|
@ -1847,6 +1847,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
String userData = cmd.getUserData();
|
||||
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
|
||||
String hostName = cmd.getHostName();
|
||||
Map details = cmd.getDetails();
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
|
||||
// Input validation and permission checks
|
||||
|
|
@ -1886,6 +1887,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
|
||||
}
|
||||
|
||||
if (details != null && !details.isEmpty()) {
|
||||
vmInstance.setDetails(details);
|
||||
_vmDao.saveDetails(vmInstance);
|
||||
}
|
||||
|
||||
return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue