Skip to content

Commit 37d4a44

Browse files
committed
Use enums as source for allowedValues
1 parent 7f2df4c commit 37d4a44

15 files changed

Lines changed: 89 additions & 90 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/Parameter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@
5353
ApiArgValidator[] validations() default {};
5454

5555
String[] allowedValues() default {};
56+
57+
Class<? extends Enum> allowedValueType() default Enum.class;
58+
5659
boolean acceptedOnAdminPort() default true;
5760
}

api/src/main/java/org/apache/cloudstack/api/command/admin/network/NetworkOfferingBaseCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public abstract class NetworkOfferingBaseCmd extends BaseCmd {
156156
@Parameter(name = ApiConstants.NETWORK_MODE,
157157
type = CommandType.STRING,
158158
description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED",
159-
since = "4.20.0")
159+
since = "4.20.0",
160+
allowedValueType = NetworkOffering.NetworkMode.class)
160161
private String networkMode;
161162

162163
@Parameter(name = ApiConstants.FOR_TUNGSTEN,

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import com.cloud.offering.DiskOffering;
4242
import com.cloud.offering.ServiceOffering;
43+
import com.cloud.storage.Storage;
4344
import com.cloud.storage.Storage.ProvisioningType;
4445
import com.cloud.user.Account;
4546

@@ -86,14 +87,10 @@ public class CreateDiskOfferingCmd extends BaseCmd {
8687
private String storageType = ServiceOffering.StorageType.shared.toString();
8788

8889
@Parameter(
89-
name = ApiConstants.PROVISIONINGTYPE,
90-
type = CommandType.STRING,
91-
description = "Provisioning type used to create volumes. Valid values are thin, sparse, fat.",
92-
allowedValues = {
93-
"thin",
94-
"sparse",
95-
"fat"
96-
})
90+
name = ApiConstants.PROVISIONINGTYPE,
91+
type = CommandType.STRING,
92+
description = "Provisioning type used to create volumes. Valid values are thin, sparse, fat.",
93+
allowedValueType = Storage.ProvisioningType.class)
9794
private String provisioningType = ProvisioningType.THIN.toString();
9895

9996
@Parameter(name = ApiConstants.DISPLAY_OFFERING,

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,12 @@ public class CreateServiceOfferingCmd extends BaseCmd {
6868
private String displayText;
6969

7070
@Parameter(
71-
name = ApiConstants.PROVISIONINGTYPE,
72-
type = CommandType.STRING,
73-
description = "Provisioning type used to create volumes. Valid values are thin, sparse, fat.",
74-
allowedValues = {
75-
"thin",
76-
"sparse",
77-
"fat"
78-
})
71+
name = ApiConstants.PROVISIONINGTYPE,
72+
type = CommandType.STRING,
73+
description = "Provisioning type used to create volumes. Valid values are thin, sparse, fat.",
74+
allowedValueType = Storage.ProvisioningType.class)
7975
private String provisioningType = Storage.ProvisioningType.THIN.toString();
76+
8077
@Parameter(name = ApiConstants.MEMORY, type = CommandType.INTEGER, required = false, description = "The total memory of the service offering in MB")
8178
private Integer memory;
8279

api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
154154
type = CommandType.STRING,
155155
description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED",
156156
since = "4.20.0",
157-
allowedValues = {
158-
"NATTED",
159-
"ROUTED"
160-
})
157+
allowedValueType = NetworkOffering.NetworkMode.class)
161158
private String networkMode;
162159

163160
@Parameter(name = ApiConstants.SPECIFY_AS_NUMBER, type = CommandType.BOOLEAN, since = "4.20.0",
@@ -167,7 +164,8 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
167164
@Parameter(name = ApiConstants.ROUTING_MODE,
168165
type = CommandType.STRING,
169166
since = "4.20.0",
170-
description = "the routing mode for the VPC offering. Supported types are: Static or Dynamic.")
167+
description = "the routing mode for the VPC offering. Supported types are: Static or Dynamic.",
168+
allowedValueType = NetworkOffering.RoutingMode.class)
171169
private String routingMode;
172170

173171
@Parameter(name = ApiConstants.CONSERVE_MODE, type = CommandType.BOOLEAN,

api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd {
5252
type = CommandType.STRING,
5353
required = true,
5454
description = "Relational Operator to be used with threshold. Valid values are EQ, GT, LT, GE, LE.",
55-
allowedValues = {
56-
"EQ",
57-
"GT",
58-
"LT",
59-
"GE",
60-
"LE"
61-
})
55+
allowedValueType = Condition.Operator.class)
6256
private String relationalOperator;
6357

6458
@Parameter(name = ApiConstants.THRESHOLD, type = CommandType.LONG, required = true, description = "Value for which the Counter will be evaluated with the Operator selected.")

api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ public class UpdateConditionCmd extends BaseAsyncCmd {
5454
type = CommandType.STRING,
5555
required = true,
5656
description = "Relational Operator to be used with threshold. Valid values are EQ, GT, LT, GE, LE.",
57-
allowedValues = {
58-
"EQ",
59-
"GT",
60-
"LT",
61-
"GE",
62-
"LE"
63-
})
57+
allowedValueType = Condition.Operator.class)
6458
private String relationalOperator;
6559

6660
@Parameter(name = ApiConstants.THRESHOLD, type = CommandType.LONG, required = true, description = "Value for which the Counter will be evaluated with the Operator selected.")

api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupScheduleCmd.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ public class CreateBackupScheduleCmd extends BaseCmd {
5959
type = CommandType.STRING,
6060
required = true,
6161
description = "Valid values are HOURLY, DAILY, WEEKLY, and MONTHLY",
62-
allowedValues = {
63-
"HOURLY",
64-
"DAILY",
65-
"WEEKLY",
66-
"MONTHLY"
67-
})
62+
allowedValueType = DateUtil.IntervalType.class)
6863
private String intervalType;
6964

7065
@Parameter(name = ApiConstants.SCHEDULE,

api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ public class CreateIpv6FirewallRuleCmd extends BaseAsyncCreateCmd {
8383
name = ApiConstants.TRAFFIC_TYPE,
8484
type = CommandType.STRING,
8585
description = "The traffic type for the Ipv6 firewall rule, can be ingress or egress, defaulted to ingress if not specified",
86-
allowedValues = {
87-
"Ingress",
88-
"Egress"
89-
})
86+
allowedValueType = FirewallRule.TrafficType.class)
9087
private String trafficType;
9188

9289
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "An optional field, whether to the display the rule to the end User or not", authorized = {RoleType.Admin})

api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd implements UserCmd {
7070
+ "* executable : Templates that are owned by the calling User, or public Templates, that can be used to deploy an Instance. "
7171
+ "* community : Templates that have been marked as public but not featured. "
7272
+ "* all : all Templates (only usable by admins).",
73-
allowedValues = {
74-
"featured",
75-
"self",
76-
"selfexecutable",
77-
"sharedexecutable",
78-
"executable",
79-
"community",
80-
"all"
81-
})
73+
allowedValueType = TemplateFilter.class)
8274
private String isoFilter = TemplateFilter.selfexecutable.toString();
8375

8476
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "List all ISOs by name")
@@ -100,11 +92,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd implements UserCmd {
10092
type = CommandType.STRING,
10193
description = "the CPU arch of the ISO. Valid options are: x86_64, aarch64, s390x",
10294
since = "4.20",
103-
allowedValues = {
104-
"x86_64",
105-
"aarch64",
106-
"s390x"
107-
})
95+
allowedValueType = CPU.CPUArch.class)
10896
private String arch;
10997

11098
@Parameter(name = ApiConstants.OS_CATEGORY_ID, type = CommandType.UUID, entityType= GuestOSCategoryResponse.class,

0 commit comments

Comments
 (0)