You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2020/10/21 07:48:32 UTC
[cloudstack] branch 4.14 updated: Validating type parameter and
including all types (#4412)
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch 4.14
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.14 by this push:
new 15954fe Validating type parameter and including all types (#4412)
15954fe is described below
commit 15954fefee7a98760c66294215f8b1410c412af1
Author: davidjumani <dj...@gmail.com>
AuthorDate: Wed Oct 21 13:18:05 2020 +0530
Validating type parameter and including all types (#4412)
---
api/src/main/java/com/cloud/network/Network.java | 16 +++++++++++++++-
.../api/command/user/network/ListNetworksCmd.java | 11 +++++++++--
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/api/src/main/java/com/cloud/network/Network.java b/api/src/main/java/com/cloud/network/Network.java
index 28528f1..599bfee 100644
--- a/api/src/main/java/com/cloud/network/Network.java
+++ b/api/src/main/java/com/cloud/network/Network.java
@@ -43,7 +43,21 @@ import com.cloud.utils.fsm.StateObject;
public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity, Serializable, Displayable {
enum GuestType {
- Shared, Isolated, L2
+ Shared, Isolated, L2;
+
+ public static GuestType fromValue(String type) {
+ if (StringUtils.isBlank(type)) {
+ return null;
+ } else if (type.equalsIgnoreCase("Shared")) {
+ return Shared;
+ } else if (type.equalsIgnoreCase("Isolated")) {
+ return Isolated;
+ } else if (type.equalsIgnoreCase("L2")) {
+ return L2;
+ } else {
+ throw new InvalidParameterValueException("Unexpected Guest type : " + type);
+ }
+ }
}
enum PVlanType {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java
index b737212..0127fac 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java
@@ -36,6 +36,7 @@ import org.apache.cloudstack.api.response.ZoneResponse;
import com.cloud.network.Network;
import com.cloud.utils.Pair;
+import com.google.common.base.Strings;
@APICommand(name = "listNetworks", description = "Lists all available networks.", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class},
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -52,7 +53,7 @@ public class ListNetworksCmd extends BaseListTaggedResourcesCmd implements UserC
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the zone ID of the network")
private Long zoneId;
- @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "the type of the network. Supported values are: isolated and shared")
+ @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "the type of the network. Supported values are: isolated, l2, shared and all")
private String guestIpType;
@Parameter(name = ApiConstants.IS_SYSTEM, type = CommandType.BOOLEAN, description = "true if network is system, false otherwise")
@@ -101,7 +102,13 @@ public class ListNetworksCmd extends BaseListTaggedResourcesCmd implements UserC
}
public String getGuestIpType() {
- return guestIpType;
+ if (!Strings.isNullOrEmpty(guestIpType)) {
+ if (guestIpType.equalsIgnoreCase("all")) {
+ return null;
+ }
+ return Network.GuestType.fromValue(guestIpType).toString();
+ }
+ return null;
}
public Boolean getIsSystem() {