From 620e7e0305d5753413ba2775ded811fdce632488 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 11 Jan 2011 16:06:27 -0800 Subject: [PATCH] Implemented list by trafficType in listNetworks command --- api/src/com/cloud/api/commands/ListNetworksCmd.java | 7 +++++++ .../com/cloud/configuration/ConfigurationManagerImpl.java | 4 +++- server/src/com/cloud/network/NetworkManagerImpl.java | 5 +++++ server/src/com/cloud/server/ConfigurationServerImpl.java | 6 ++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java index 17b062c06fc..b9400f9b444 100644 --- a/api/src/com/cloud/api/commands/ListNetworksCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java @@ -63,6 +63,9 @@ public class ListNetworksCmd extends BaseListCmd { @Parameter(name=ApiConstants.IS_DEFAULT, type=CommandType.BOOLEAN, description="true if network is default, false otherwise") private Boolean isDefault; + + @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="type of the traffic") + private String trafficType; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -100,6 +103,10 @@ public class ListNetworksCmd extends BaseListCmd { return isDefault; } + public String getTrafficType() { + return trafficType; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 8617edfdc31..b666a28da25 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1216,6 +1216,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Account systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM); BroadcastDomainType broadcastDomainType = null; + boolean isNetworkDefault = false; if (offering.getTrafficType() == TrafficType.Management) { broadcastDomainType = BroadcastDomainType.Native; } else if (offering.getTrafficType() == TrafficType.Control) { @@ -1228,13 +1229,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } else if (offering.getTrafficType() == TrafficType.Guest) { if (zone.getNetworkType() == NetworkType.Basic) { + isNetworkDefault = true; broadcastDomainType = BroadcastDomainType.Native; } else { continue; } } userNetwork.setBroadcastDomainType(broadcastDomainType); - _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, true, false); + _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, true, isNetworkDefault); } } } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 34844091da3..4100d407fcd 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1444,6 +1444,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); String type = cmd.getType(); + String trafficType = cmd.getTrafficType(); Boolean isSystem = cmd.getIsSystem(); Boolean isShared = cmd.getIsShared(); Boolean isDefault = cmd.isDefault(); @@ -1535,6 +1536,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault); } + if (trafficType != null) { + sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType); + } + List networks = _networksDao.search(sc, searchFilter); return networks; diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index a4fe04634b7..ea8c55a716d 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -752,7 +752,8 @@ public class ConfigurationServerImpl implements ConfigurationServer { BroadcastDomainType broadcastDomainType = null; TrafficType trafficType= offering.getTrafficType(); - + + boolean isNetworkDefault = false; if (trafficType == TrafficType.Management || trafficType == TrafficType.Storage) { broadcastDomainType = BroadcastDomainType.Native; } else if (trafficType == TrafficType.Control) { @@ -765,6 +766,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { } } else if (offering.getTrafficType() == TrafficType.Guest) { if (zone.getNetworkType() == NetworkType.Basic) { + isNetworkDefault = true; broadcastDomainType = BroadcastDomainType.Native; } else { continue; @@ -772,7 +774,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { } if (broadcastDomainType != null) { - NetworkVO network = new NetworkVO(id, trafficType, null, mode, broadcastDomainType, networkOfferingId, zoneId, domainId, accountId, related, null, null, true, false); + NetworkVO network = new NetworkVO(id, trafficType, null, mode, broadcastDomainType, networkOfferingId, zoneId, domainId, accountId, related, null, null, true, isNetworkDefault); network.setGuruName(guruNames.get(network.getTrafficType())); network.setDns1(zone.getDns1()); network.setDns2(zone.getDns2());