Skip to content

Commit dd4ab6a

Browse files
committed
Use enums for remaining API allowed values
1 parent caf4eb1 commit dd4ab6a

7 files changed

Lines changed: 37 additions & 9 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.template;
19+
20+
public enum TemplateApiType {
21+
USER,
22+
VNF,
23+
SYSTEM,
24+
ROUTING,
25+
BUILTIN
26+
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.cloud.exception.ResourceAllocationException;
5151
import com.cloud.network.vpc.VpcOffering;
5252
import com.cloud.user.Account;
53+
import com.cloud.utils.net.NetUtils;
5354

5455
import static com.cloud.network.Network.Service.Dhcp;
5556
import static com.cloud.network.Network.Service.Dns;
@@ -97,10 +98,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
9798
type = CommandType.STRING,
9899
description = "The internet protocol of the offering. Options are IPv4 and dualstack. Default is IPv4. dualstack will create an offering that supports both IPv4 and IPv6",
99100
since = "4.17.0",
100-
allowedValues = {
101-
"IPv4",
102-
"DualStack"
103-
})
101+
allowedValueType = NetUtils.InternetProtocol.class)
104102
private String internetProtocol;
105103

106104
@Parameter(name = ApiConstants.SERVICE_OFFERING_ID,

api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class ListNetworksCmd extends BaseListRetrieveOnlyResourceCountCmd implem
111111

112112
@Parameter(name = ApiConstants.NETWORK_FILTER,
113113
type = CommandType.STRING,
114-
allowedValues = {"account", "domain", "accountdomain", "shared", "all"},
114+
allowedValueType = Network.NetworkFilter.class,
115115
since = "4.17.0",
116116
description = "Possible values are \"account\", \"domain\", \"accountdomain\",\"shared\", and \"all\". Default value is \"all\"."
117117
+ "* account : account networks that have been registered for or created by the calling User. "

api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.cloudstack.api.response.ZoneResponse;
3131

3232
import com.cloud.storage.Snapshot;
33+
import com.cloud.utils.DateUtil;
3334

3435
@APICommand(name = "listSnapshots", description = "Lists all available Snapshots for the Account.", responseObject = SnapshotResponse.class, entityType = {
3536
Snapshot.class }, responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)

api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.lang3.StringUtils;
3838

3939
import com.cloud.exception.ResourceAllocationException;
40+
import com.cloud.template.TemplateApiType;
4041

4142
@APICommand(name = "getUploadParamsForTemplate", description = "Upload an existing Template into the CloudStack cloud. ",
4243
responseObject = GetUploadParamsResponse.class, since = "4.6.0",
@@ -108,7 +109,7 @@ public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd {
108109

109110
@Parameter(name = ApiConstants.TEMPLATE_TYPE,
110111
type = CommandType.STRING,
111-
allowedValues = {"USER", "VNF", "SYSTEM", "ROUTING", "BUILTIN"},
112+
allowedValueType = TemplateApiType.class,
112113
description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).",
113114
since = "4.22.0")
114115
private String templateType;

api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.cloud.exception.ResourceAllocationException;
4646
import com.cloud.hypervisor.Hypervisor;
4747
import com.cloud.hypervisor.HypervisorGuru;
48+
import com.cloud.template.TemplateApiType;
4849
import com.cloud.template.VirtualMachineTemplate;
4950

5051
@APICommand(name = "registerTemplate", description = "Registers an existing Template into the CloudStack cloud. ", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
@@ -182,7 +183,7 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
182183

183184
@Parameter(name = ApiConstants.TEMPLATE_TYPE,
184185
type = CommandType.STRING,
185-
allowedValues = {"USER", "VNF", "SYSTEM", "ROUTING", "BUILTIN"},
186+
allowedValueType = TemplateApiType.class,
186187
description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).",
187188
since = "4.19.0")
188189
private String templateType;

api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import org.apache.cloudstack.api.command.user.UserCmd;
2828
import org.apache.cloudstack.api.response.TemplateResponse;
2929

30-
import com.cloud.template.VirtualMachineTemplate;
30+
import com.cloud.template.TemplateApiType;
3131
import com.cloud.user.Account;
32+
import com.cloud.template.VirtualMachineTemplate;
3233

3334
@APICommand(name = "updateTemplate", description = "Updates attributes of a Template.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
3435
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -41,7 +42,7 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements Use
4142

4243
@Parameter(name = ApiConstants.TEMPLATE_TYPE,
4344
type = CommandType.STRING,
44-
allowedValues = {"USER", "VNF", "SYSTEM", "ROUTING", "BUILTIN"},
45+
allowedValueType = TemplateApiType.class,
4546
description = "The type of the Template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).")
4647
private String templateType;
4748

0 commit comments

Comments
 (0)