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 updates entries in vm_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>
This commit is contained in:
parent
9a4e79990a
commit
c8929dfd10
|
|
@ -21,6 +21,9 @@ import org.apache.cloudstack.api.response.GuestOSResponse;
|
|||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
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());
|
||||
|
||||
|
|
@ -60,6 +63,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 ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -103,4 +109,14 @@ 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];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import com.cloud.exception.ResourceUnavailableException;
|
|||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
||||
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. " +
|
||||
|
|
@ -71,6 +73,9 @@ public class UpdateVMCmd extends BaseCmd{
|
|||
@Parameter(name = ApiConstants.IS_DYNAMICALLY_SCALABLE, type = CommandType.BOOLEAN, description = "true if VM contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory")
|
||||
protected Boolean isDynamicallyScalable;
|
||||
|
||||
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs.")
|
||||
protected Map details;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -103,6 +108,15 @@ public class UpdateVMCmd extends BaseCmd{
|
|||
return isDynamicallyScalable;
|
||||
}
|
||||
|
||||
public Map getDetails() {
|
||||
if (this.details == null || this.details.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collection paramsCollection = this.details.values();
|
||||
return (Map) (paramsCollection.toArray())[0];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1825,6 +1825,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
|
||||
|
|
@ -1851,7 +1852,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);
|
||||
&& bootable == null && sortKey == null && isDynamicallyScalable == null && isRoutingTemplate == null && details == null);
|
||||
if (!updateNeeded) {
|
||||
return template;
|
||||
}
|
||||
|
|
@ -1912,6 +1913,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);
|
||||
|
|
|
|||
|
|
@ -1904,6 +1904,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
Long osTypeId = cmd.getOsTypeId();
|
||||
String userData = cmd.getUserData();
|
||||
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
|
||||
Map details = cmd.getDetails();
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
|
||||
// Input validation and permission checks
|
||||
|
|
@ -1922,6 +1923,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, isDisplayVmEnabled, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue