Skip to content

Commit 3973644

Browse files
DaanHooglandDaan Hoogland
authored andcommitted
set displayName to name by default (apache#9719)
* set `desplayName` to `name` by default * list by displayname instead of name * back to using name * Update api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java --------- Co-authored-by: Daan Hoogland <dahn@apache.org>
1 parent 7223a54 commit 3973644

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import org.apache.cloudstack.api.response.UserVmResponse;
3434
import org.apache.cloudstack.api.response.VolumeResponse;
3535
import org.apache.cloudstack.context.CallContext;
36+
import org.apache.commons.collections.CollectionUtils;
37+
import org.apache.commons.collections.MapUtils;
38+
import org.apache.commons.lang3.BooleanUtils;
3639

3740
import com.cloud.exception.ConcurrentOperationException;
3841
import com.cloud.exception.InsufficientCapacityException;
@@ -41,6 +44,9 @@
4144
import com.cloud.exception.ResourceUnavailableException;
4245
import com.cloud.uservm.UserVm;
4346
import com.cloud.utils.exception.CloudRuntimeException;
47+
import com.cloud.utils.net.Dhcp;
48+
import com.cloud.utils.net.NetUtils;
49+
import com.cloud.utils.StringUtils;
4450
import com.cloud.vm.VirtualMachine;
4551

4652
@APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts an Instance based on a service offering, disk offering, and Template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
@@ -69,6 +75,138 @@ public class DeployVMCmd extends BaseDeployVMCmd {
6975
/////////////////// Accessors ///////////////////////
7076
/////////////////////////////////////////////////////
7177

78+
public String getAccountName() {
79+
if (accountName == null) {
80+
return CallContext.current().getCallingAccount().getAccountName();
81+
}
82+
return accountName;
83+
}
84+
85+
public Long getDiskOfferingId() {
86+
return diskOfferingId;
87+
}
88+
89+
public String getDeploymentPlanner() {
90+
return deploymentPlanner;
91+
}
92+
93+
public String getDisplayName() {
94+
if (StringUtils.isEmpty(displayName)) {
95+
displayName = name;
96+
}
97+
return displayName;
98+
}
99+
100+
public Long getDomainId() {
101+
if (domainId == null) {
102+
return CallContext.current().getCallingAccount().getDomainId();
103+
}
104+
return domainId;
105+
}
106+
107+
public ApiConstants.BootType getBootType() {
108+
if (StringUtils.isNotBlank(bootType)) {
109+
try {
110+
String type = bootType.trim().toUpperCase();
111+
return ApiConstants.BootType.valueOf(type);
112+
} catch (IllegalArgumentException e) {
113+
String errMesg = "Invalid bootType " + bootType + "Specified for Instance " + getName()
114+
+ " Valid values are: " + Arrays.toString(ApiConstants.BootType.values());
115+
logger.warn(errMesg);
116+
throw new InvalidParameterValueException(errMesg);
117+
}
118+
}
119+
return null;
120+
}
121+
122+
public ApiConstants.BootMode getBootMode() {
123+
if (StringUtils.isNotBlank(bootMode)) {
124+
try {
125+
String mode = bootMode.trim().toUpperCase();
126+
return ApiConstants.BootMode.valueOf(mode);
127+
} catch (IllegalArgumentException e) {
128+
String msg = String.format("Invalid %s: %s specified for Instance: %s. Valid values are: %s",
129+
ApiConstants.BOOT_MODE, bootMode, getName(), Arrays.toString(ApiConstants.BootMode.values()));
130+
logger.error(msg);
131+
throw new InvalidParameterValueException(msg);
132+
}
133+
}
134+
if (ApiConstants.BootType.UEFI.equals(getBootType())) {
135+
String msg = String.format("%s must be specified for the Instance with boot type: %s. Valid values are: %s",
136+
ApiConstants.BOOT_MODE, getBootType(), Arrays.toString(ApiConstants.BootMode.values()));
137+
logger.error(msg);
138+
throw new InvalidParameterValueException(msg);
139+
}
140+
return null;
141+
}
142+
143+
public Map<String, String> getVmProperties() {
144+
Map<String, String> map = new HashMap<>();
145+
if (MapUtils.isNotEmpty(vAppProperties)) {
146+
Collection parameterCollection = vAppProperties.values();
147+
Iterator iterator = parameterCollection.iterator();
148+
while (iterator.hasNext()) {
149+
HashMap<String, String> entry = (HashMap<String, String>)iterator.next();
150+
map.put(entry.get("key"), entry.get("value"));
151+
}
152+
}
153+
return map;
154+
}
155+
156+
public Map<Integer, Long> getVmNetworkMap() {
157+
Map<Integer, Long> map = new HashMap<>();
158+
if (MapUtils.isNotEmpty(vAppNetworks)) {
159+
Collection parameterCollection = vAppNetworks.values();
160+
Iterator iterator = parameterCollection.iterator();
161+
while (iterator.hasNext()) {
162+
HashMap<String, String> entry = (HashMap<String, String>) iterator.next();
163+
Integer nic;
164+
try {
165+
nic = Integer.valueOf(entry.get(VmDetailConstants.NIC));
166+
} catch (NumberFormatException nfe) {
167+
nic = null;
168+
}
169+
String networkUuid = entry.get(VmDetailConstants.NETWORK);
170+
if (logger.isTraceEnabled()) {
171+
logger.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid));
172+
}
173+
if (nic == null || StringUtils.isEmpty(networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) {
174+
throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic));
175+
}
176+
map.put(nic, _entityMgr.findByUuid(Network.class, networkUuid).getId());
177+
}
178+
}
179+
return map;
180+
}
181+
182+
public String getGroup() {
183+
return group;
184+
}
185+
186+
public HypervisorType getHypervisor() {
187+
return HypervisorType.getType(hypervisor);
188+
}
189+
190+
public Boolean isDisplayVm() {
191+
return displayVm;
192+
}
193+
194+
@Override
195+
public boolean isDisplay() {
196+
if(displayVm == null)
197+
return true;
198+
else
199+
return displayVm;
200+
}
201+
202+
public List<String> getSecurityGroupNameList() {
203+
return securityGroupNameList;
204+
}
205+
206+
public List<Long> getSecurityGroupIdList() {
207+
return securityGroupIdList;
208+
}
209+
72210
public Long getServiceOfferingId() {
73211
return serviceOfferingId;
74212
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
import com.cloud.exception.ResourceUnavailableException;
2222
import com.cloud.user.Account;
2323
import com.cloud.uservm.UserVm;
24+
import java.util.Collection;
25+
import java.util.HashMap;
26+
import java.util.List;
27+
import java.util.Map;
28+
29+
import com.cloud.utils.StringUtils;
2430
import com.cloud.utils.exception.CloudRuntimeException;
2531
import com.cloud.utils.net.Dhcp;
2632
import com.cloud.vm.VirtualMachine;
@@ -168,6 +174,9 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction,
168174
/////////////////////////////////////////////////////
169175

170176
public String getDisplayName() {
177+
if (StringUtils.isBlank(displayName)) {
178+
displayName = name;
179+
}
171180
return displayName;
172181
}
173182

0 commit comments

Comments
 (0)