Skip to content

Commit 12c077d

Browse files
authored
api,ui: multi arch improvements (#10289)
1 parent 1adfaf9 commit 12c077d

File tree

90 files changed

+2804
-723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2804
-723
lines changed

api/src/main/java/com/cloud/cpu/CPU.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,55 @@
1616
// under the License.
1717
package com.cloud.cpu;
1818

19-
import com.cloud.utils.exception.CloudRuntimeException;
2019
import org.apache.commons.lang3.StringUtils;
2120

22-
import java.util.LinkedHashMap;
23-
import java.util.Map;
24-
2521
public class CPU {
22+
public enum CPUArch {
23+
x86("i686", 32),
24+
amd64("x86_64", 64),
25+
arm64("aarch64", 64);
2626

27-
public static final String archX86Identifier = "i686";
28-
public static final String archX86_64Identifier = "x86_64";
29-
public static final String archARM64Identifier = "aarch64";
30-
31-
public static class CPUArch {
32-
private static final Map<String, CPUArch> cpuArchMap = new LinkedHashMap<>();
33-
34-
public static final CPUArch archX86 = new CPUArch(archX86Identifier, 32);
35-
public static final CPUArch amd64 = new CPUArch(archX86_64Identifier, 64);
36-
public static final CPUArch arm64 = new CPUArch(archARM64Identifier, 64);
27+
private final String type;
28+
private final int bits;
3729

38-
private String type;
39-
private int bits;
40-
41-
public CPUArch(String type, int bits) {
30+
CPUArch(String type, int bits) {
4231
this.type = type;
4332
this.bits = bits;
44-
cpuArchMap.put(type, this);
33+
}
34+
35+
public static CPUArch getDefault() {
36+
return amd64;
4537
}
4638

4739
public String getType() {
48-
return this.type;
40+
return type;
4941
}
5042

5143
public int getBits() {
52-
return this.bits;
44+
return bits;
5345
}
5446

5547
public static CPUArch fromType(String type) {
5648
if (StringUtils.isBlank(type)) {
57-
return amd64;
49+
return getDefault();
50+
}
51+
for (CPUArch arch : values()) {
52+
if (arch.type.equals(type)) {
53+
return arch;
54+
}
55+
}
56+
throw new IllegalArgumentException("Unsupported arch type: " + type);
57+
}
58+
59+
public static String getTypesAsCSV() {
60+
StringBuilder sb = new StringBuilder();
61+
for (CPUArch arch : values()) {
62+
sb.append(arch.getType()).append(",");
5863
}
59-
switch (type) {
60-
case archX86Identifier: return archX86;
61-
case archX86_64Identifier: return amd64;
62-
case archARM64Identifier: return arm64;
63-
default: throw new CloudRuntimeException(String.format("Unsupported arch type: %s", type));
64+
if (sb.length() > 0) {
65+
sb.setLength(sb.length() - 1);
6466
}
67+
return sb.toString();
6568
}
6669
}
6770
}

api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
2322
import org.apache.cloudstack.api.APICommand;
2423
import org.apache.cloudstack.api.ApiConstants;
2524
import org.apache.cloudstack.api.BaseListCmd;
@@ -28,7 +27,9 @@
2827
import org.apache.cloudstack.api.response.ListResponse;
2928
import org.apache.cloudstack.api.response.PodResponse;
3029
import org.apache.cloudstack.api.response.ZoneResponse;
30+
import org.apache.commons.lang3.StringUtils;
3131

32+
import com.cloud.cpu.CPU;
3233
import com.cloud.org.Cluster;
3334
import com.cloud.utils.Pair;
3435

@@ -68,6 +69,11 @@ public class ListClustersCmd extends BaseListCmd {
6869
@Parameter(name = ApiConstants.SHOW_CAPACITIES, type = CommandType.BOOLEAN, description = "flag to display the capacity of the clusters")
6970
private Boolean showCapacities;
7071

72+
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING,
73+
description = "CPU arch of the clusters",
74+
since = "4.20.1")
75+
private String arch;
76+
7177
/////////////////////////////////////////////////////
7278
/////////////////// Accessors ///////////////////////
7379
/////////////////////////////////////////////////////
@@ -112,6 +118,10 @@ public Boolean getShowCapacities() {
112118
return showCapacities;
113119
}
114120

121+
public CPU.CPUArch getArch() {
122+
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
123+
}
124+
115125
/////////////////////////////////////////////////////
116126
/////////////// API Implementation///////////////////
117127
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
2524
import org.apache.cloudstack.api.APICommand;
2625
import org.apache.cloudstack.api.ApiCommandResourceType;
2726
import org.apache.cloudstack.api.ApiConstants;
@@ -34,7 +33,9 @@
3433
import org.apache.cloudstack.api.response.PodResponse;
3534
import org.apache.cloudstack.api.response.UserVmResponse;
3635
import org.apache.cloudstack.api.response.ZoneResponse;
36+
import org.apache.commons.lang3.StringUtils;
3737

38+
import com.cloud.cpu.CPU;
3839
import com.cloud.exception.InvalidParameterValueException;
3940
import com.cloud.host.Host;
4041
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -105,6 +106,9 @@ public class ListHostsCmd extends BaseListCmd {
105106
@Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, description = "hypervisor type of host: XenServer,KVM,VMware,Hyperv,BareMetal,Simulator")
106107
private String hypervisor;
107108

109+
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, description = "CPU Arch of the host", since = "4.20.1")
110+
private String arch;
111+
108112
/////////////////////////////////////////////////////
109113
/////////////////// Accessors ///////////////////////
110114
/////////////////////////////////////////////////////
@@ -189,6 +193,10 @@ public String getHostOutOfBandManagementPowerState() {
189193
return outOfBandManagementPowerState;
190194
}
191195

196+
public CPU.CPUArch getArch() {
197+
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
198+
}
199+
192200
/////////////////////////////////////////////////////
193201
/////////////// API Implementation///////////////////
194202
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.router;
1818

19-
import org.apache.commons.lang.BooleanUtils;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiCommandResourceType;
2321
import org.apache.cloudstack.api.ApiConstants;
@@ -32,7 +30,10 @@
3230
import org.apache.cloudstack.api.response.UserVmResponse;
3331
import org.apache.cloudstack.api.response.VpcResponse;
3432
import org.apache.cloudstack.api.response.ZoneResponse;
33+
import org.apache.commons.lang.BooleanUtils;
34+
import org.apache.commons.lang3.StringUtils;
3535

36+
import com.cloud.cpu.CPU;
3637
import com.cloud.network.router.VirtualRouter.Role;
3738
import com.cloud.vm.VirtualMachine;
3839

@@ -86,6 +87,11 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
8687
description = "if true is passed for this parameter, also fetch last executed health check results for the router. Default is false")
8788
private Boolean fetchHealthCheckResults;
8889

90+
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING,
91+
description = "CPU arch of the router",
92+
since = "4.20.1")
93+
private String arch;
94+
8995
/////////////////////////////////////////////////////
9096
/////////////////// Accessors ///////////////////////
9197
/////////////////////////////////////////////////////
@@ -146,6 +152,10 @@ public boolean shouldFetchHealthCheckResults() {
146152
return BooleanUtils.isTrue(fetchHealthCheckResults);
147153
}
148154

155+
public CPU.CPUArch getArch() {
156+
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
157+
}
158+
149159

150160
/////////////////////////////////////////////////////
151161
/////////////// API Implementation///////////////////

api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
2322
import org.apache.cloudstack.api.APICommand;
2423
import org.apache.cloudstack.api.ApiCommandResourceType;
2524
import org.apache.cloudstack.api.ApiConstants;
@@ -31,7 +30,9 @@
3130
import org.apache.cloudstack.api.response.StoragePoolResponse;
3231
import org.apache.cloudstack.api.response.SystemVmResponse;
3332
import org.apache.cloudstack.api.response.ZoneResponse;
33+
import org.apache.commons.lang3.StringUtils;
3434

35+
import com.cloud.cpu.CPU;
3536
import com.cloud.utils.Pair;
3637
import com.cloud.vm.VirtualMachine;
3738

@@ -74,6 +75,11 @@ public class ListSystemVMsCmd extends BaseListCmd {
7475
since = "3.0.1")
7576
private Long storageId;
7677

78+
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING,
79+
description = "CPU arch of the system VM",
80+
since = "4.20.1")
81+
private String arch;
82+
7783
/////////////////////////////////////////////////////
7884
/////////////////// Accessors ///////////////////////
7985
/////////////////////////////////////////////////////
@@ -110,6 +116,10 @@ public Long getStorageId() {
110116
return storageId;
111117
}
112118

119+
public CPU.CPUArch getArch() {
120+
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
121+
}
122+
113123
/////////////////////////////////////////////////////
114124
/////////////// API Implementation///////////////////
115125
/////////////////////////////////////////////////////

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@
4646
import org.apache.cloudstack.api.response.UserVmResponse;
4747
import org.apache.cloudstack.api.response.VpcResponse;
4848
import org.apache.cloudstack.api.response.ZoneResponse;
49-
import org.apache.commons.lang3.BooleanUtils;
5049
import org.apache.commons.collections.CollectionUtils;
50+
import org.apache.commons.lang3.BooleanUtils;
51+
import org.apache.commons.lang3.StringUtils;
5152

53+
import com.cloud.cpu.CPU;
5254
import com.cloud.exception.InvalidParameterValueException;
5355
import com.cloud.server.ResourceIcon;
5456
import com.cloud.server.ResourceTag;
@@ -153,6 +155,11 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
153155
@Parameter(name = ApiConstants.USER_DATA_ID, type = CommandType.UUID, entityType = UserDataResponse.class, required = false, description = "the instances by userdata", since = "4.20.1")
154156
private Long userdataId;
155157

158+
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING,
159+
description = "CPU arch of the VM",
160+
since = "4.20.1")
161+
private String arch;
162+
156163
/////////////////////////////////////////////////////
157164
/////////////////// Accessors ///////////////////////
158165
/////////////////////////////////////////////////////
@@ -292,6 +299,10 @@ public Boolean getVnf() {
292299
return isVnf;
293300
}
294301

302+
public CPU.CPUArch getArch() {
303+
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
304+
}
305+
295306
/////////////////////////////////////////////////////
296307
/////////////// API Implementation///////////////////
297308
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/DomainRouterResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ public class DomainRouterResponse extends BaseResponseWithAnnotations implements
245245
@Param(description = "the version of the code / software in the router")
246246
private String softwareVersion;
247247

248+
@SerializedName(ApiConstants.ARCH)
249+
@Param(description = "CPU arch of the router", since = "4.20.1")
250+
private String arch;
251+
248252
public DomainRouterResponse() {
249253
nics = new LinkedHashSet<NicResponse>();
250254
}
@@ -518,4 +522,8 @@ public String getSoftwareVersion() {
518522
public void setSoftwareVersion(String softwareVersion) {
519523
this.softwareVersion = softwareVersion;
520524
}
525+
526+
public void setArch(String arch) {
527+
this.arch = arch;
528+
}
521529
}

api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public class SystemVmResponse extends BaseResponseWithAnnotations {
186186
@Param(description = "the name of the service offering of the system virtual machine.")
187187
private String serviceOfferingName;
188188

189+
@SerializedName(ApiConstants.ARCH)
190+
@Param(description = "CPU arch of the system VM", since = "4.20.1")
191+
private String arch;
192+
189193
@Override
190194
public String getObjectId() {
191195
return this.getId();
@@ -490,4 +494,8 @@ public String getServiceOfferingName() {
490494
public void setServiceOfferingName(String serviceOfferingName) {
491495
this.serviceOfferingName = serviceOfferingName;
492496
}
497+
498+
public void setArch(String arch) {
499+
this.arch = arch;
500+
}
493501
}

api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
import org.apache.cloudstack.api.ApiConstants;
3232
import org.apache.cloudstack.api.BaseResponseWithTagInformation;
3333
import org.apache.cloudstack.api.EntityReference;
34+
import org.apache.commons.collections.CollectionUtils;
3435

3536
import com.cloud.network.router.VirtualRouter;
3637
import com.cloud.serializer.Param;
3738
import com.cloud.uservm.UserVm;
3839
import com.cloud.vm.VirtualMachine;
3940
import com.google.gson.annotations.SerializedName;
40-
import org.apache.commons.collections.CollectionUtils;
4141

4242
@SuppressWarnings("unused")
4343
@EntityReference(value = {VirtualMachine.class, UserVm.class, VirtualRouter.class})
@@ -396,6 +396,10 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
396396
@Param(description = "User VM type", since = "4.20.0")
397397
private String vmType;
398398

399+
@SerializedName(ApiConstants.ARCH)
400+
@Param(description = "CPU arch of the VM", since = "4.20.1")
401+
private String arch;
402+
399403
public UserVmResponse() {
400404
securityGroupList = new LinkedHashSet<>();
401405
nics = new TreeSet<>(Comparator.comparingInt(x -> Integer.parseInt(x.getDeviceId())));
@@ -1169,4 +1173,12 @@ public String getVmType() {
11691173
public void setIpAddress(String ipAddress) {
11701174
this.ipAddress = ipAddress;
11711175
}
1176+
1177+
public String getArch() {
1178+
return arch;
1179+
}
1180+
1181+
public void setArch(String arch) {
1182+
this.arch = arch;
1183+
}
11721184
}

0 commit comments

Comments
 (0)