Skip to content

Commit 728635a

Browse files
committed
CLOUDSTACK-8721: Fixed Setting details of VM through API results in removal of all other details except the one passed in API
1 parent cd02a59 commit 728635a

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class UpdateVMCmd extends BaseCustomIdCmd {
9494
private String instanceName;
9595

9696
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs.")
97-
protected Map details;
97+
protected Map<String, String> details;
9898

9999
/////////////////////////////////////////////////////
100100
/////////////////// Accessors ///////////////////////
@@ -136,13 +136,13 @@ public String getInstanceName() {
136136
return instanceName;
137137
}
138138

139-
public Map getDetails() {
139+
public Map<String, String> getDetails() {
140140
if (this.details == null || this.details.isEmpty()) {
141141
return null;
142142
}
143143

144-
Collection paramsCollection = this.details.values();
145-
return (Map) (paramsCollection.toArray())[0];
144+
Collection<String> paramsCollection = this.details.values();
145+
return (Map<String, String>) (paramsCollection.toArray())[0];
146146
}
147147

148148
/////////////////////////////////////////////////////

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
21472147
String userData = cmd.getUserData();
21482148
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
21492149
String hostName = cmd.getHostName();
2150-
Map details = cmd.getDetails();
2150+
Map<String,String> details = cmd.getDetails();
21512151
Account caller = CallContext.current().getCallingAccount();
21522152

21532153
// Input validation and permission checks
@@ -2188,7 +2188,13 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
21882188
}
21892189

21902190
if (details != null && !details.isEmpty()) {
2191-
vmInstance.setDetails(details);
2191+
_vmDao.loadDetails(vmInstance);
2192+
2193+
for(Map.Entry<String,String> entry : details.entrySet()) {
2194+
if(entry instanceof Map.Entry) {
2195+
vmInstance.setDetail(entry.getKey(), entry.getValue());
2196+
}
2197+
}
21922198
_vmDao.saveDetails(vmInstance);
21932199
}
21942200

0 commit comments

Comments
 (0)