diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java index d3df5426941..273b23f0979 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkCmd.java @@ -85,6 +85,9 @@ public class CreateNetworkCmd extends BaseCmd { @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain") private String networkDomain; + @Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network is shared across accounts in the Zone") + private Boolean isShared; + @Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="Tag the network") private List tags; @@ -151,10 +154,13 @@ public class CreateNetworkCmd extends BaseCmd { return projectId; } + public Boolean getIsShared() { + return isShared == null ? false : isShared; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// - @Override public String getCommandName() { return s_name; diff --git a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java index 4636b9d0c27..5ff1018f685 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java @@ -33,6 +33,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.NetworkOfferingResponse; +import com.cloud.network.Network.GuestIpType; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; import com.cloud.user.Account; @@ -55,7 +56,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the traffic type for the network offering, supported types are Public, Management, Control, Guest, Vlan or Storage.") private String traffictype; - @Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, required=true, description="the guest ip type for the network offering, supported types are Direct and Virtual.") + @Deprecated + //this parameter is deprecated, we have to use "type" parameter instead + @Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, description="the guest ip type for the network offering, supported types are Direct and Virtual.") private String guestIpType; @Parameter(name=ApiConstants.MAX_CONNECTIONS, type=CommandType.INTEGER, description="maximum number of concurrent connections supported by the network offering") @@ -142,10 +145,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd { return networkRate; } - public String getGuestIpType() { - return guestIpType; - } - public static String getName() { return _name; } @@ -187,7 +186,19 @@ public class CreateNetworkOfferingCmd extends BaseCmd { } public String getType() { - return type; + if (type != null) { + return type; + } + + if (guestIpType != null) { + // Verify guest ip type + for (GuestIpType gType : GuestIpType.values()) { + if (gType.name().equalsIgnoreCase(guestIpType)) { + return guestIpType; + } + } + } + return null; } public Map> getServiceProviders() { diff --git a/api/src/com/cloud/api/response/NetworkResponse.java b/api/src/com/cloud/api/response/NetworkResponse.java index f4f4a272551..f998cfc706b 100644 --- a/api/src/com/cloud/api/response/NetworkResponse.java +++ b/api/src/com/cloud/api/response/NetworkResponse.java @@ -69,7 +69,6 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes @SerializedName("networkofferingavailability") @Param(description="availability of the network offering the network is created from") private String networkOfferingAvailability; - @Deprecated @SerializedName(ApiConstants.IS_SHARED) @Param(description="true if network is shared, false otherwise") private Boolean isShared; diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index b13c8683744..14d333dd7a5 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -263,5 +263,6 @@ public interface Network extends ControlledEntity { List getTags(); Type getType(); - + + boolean getIsShared(); } diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkProfile.java index c03435f1472..2360058801c 100644 --- a/api/src/com/cloud/network/NetworkProfile.java +++ b/api/src/com/cloud/network/NetworkProfile.java @@ -51,6 +51,7 @@ public class NetworkProfile implements Network { private List tags; private Network.Type type; private GuestIpType guestIpType; + private boolean isShared; public NetworkProfile(Network network) { this.id = network.getId(); @@ -74,6 +75,7 @@ public class NetworkProfile implements Network { this.isSecurityGroupEnabled = network.isSecurityGroupEnabled(); this.type = network.getType(); this.guestIpType = network.getGuestType(); + this.isShared = network.getIsShared(); } @Override @@ -205,4 +207,9 @@ public class NetworkProfile implements Network { public Network.Type getType(){ return type; } + + @Override + public boolean getIsShared() { + return isShared; + } } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index e49dabaa923..58818fb0b53 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -2189,9 +2189,8 @@ public class ApiResponseHelper implements ResponseGenerator { response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString()); } - if (network.getType() != null && network.getType() == Network.Type.Shared) { - response.setIsShared(true); - } + response.setIsShared(network.getIsShared()); + response.setIsDefault(network.isDefault()); response.setState(network.getState().toString()); response.setRelated(network.getRelated()); diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index add65a754bb..4627f4eed20 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -33,7 +33,6 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.network.Network; -import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.Networks.TrafficType; @@ -176,7 +175,6 @@ public interface ConfigurationManager extends ConfigurationService, Manager { * @param trafficType * @param tags * @param maxConnections - * @param guestIpType TODO * @param networkRate TODO * @param serviceProviderMap TODO * @param isDefault TODO @@ -187,7 +185,7 @@ public interface ConfigurationManager extends ConfigurationService, Manager { * @return network offering object */ - NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, GuestIpType guestIpType, Integer networkRate, Map> serviceProviderMap, boolean isDefault, boolean isSecurityGroupEnabled, Network.Type type); + NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, Integer networkRate, Map> serviceProviderMap, boolean isDefault, boolean isSecurityGroupEnabled, Network.Type type); Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index c26c4a5e5b1..379c5e643ee 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1525,7 +1525,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } userNetwork.setBroadcastDomainType(broadcastDomainType); userNetwork.setNetworkDomain(networkDomain); - _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, null, null); + _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, null, null, true); } } } @@ -2846,13 +2846,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String trafficTypeString = cmd.getTraffictype(); Boolean specifyVlan = cmd.getSpecifyVlan(); String availabilityStr = cmd.getAvailability(); - String guestIpTypeString = cmd.getGuestIpType(); Boolean isSecurityGroupEnabled = cmd.getSecurityGroupEnabled(); Integer networkRate = cmd.getNetworkRate(); TrafficType trafficType = null; - GuestIpType guestIpType = null; Availability availability = null; Network.Type type = null; @@ -2867,17 +2865,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage"); } - // Verify guest ip type - for (GuestIpType gType : GuestIpType.values()) { - if (gType.name().equalsIgnoreCase(guestIpTypeString)) { - guestIpType = gType; - break; - } - } - - if (guestIpType == null) { - throw new InvalidParameterValueException("Invalid guest IP type; can have Direct or Virtual value"); - } //Verify offering type for (Network.Type offType : Network.Type.values()) { @@ -2888,7 +2875,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } if (type == null) { - throw new InvalidParameterValueException("Invalid type is given; can have Shared and Isolated values"); + throw new InvalidParameterValueException("Invalid \"type\" parameter is given; can have Shared and Isolated values"); } // Verify availability @@ -2965,19 +2952,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } - return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, guestIpType, networkRate, serviceProviderMap, false, isSecurityGroupEnabled, type); + return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false, isSecurityGroupEnabled, type); } @Override @DB public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, - Availability availability, GuestIpType guestIpType, Integer networkRate, Map> serviceProviderMap, boolean isDefault, boolean isSecurityGroupEnabled, Network.Type type) { + Availability availability, Integer networkRate, Map> serviceProviderMap, boolean isDefault, boolean isSecurityGroupEnabled, Network.Type type) { String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); tags = cleanupTags(tags); - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability,guestIpType, tags, isSecurityGroupEnabled, type); + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, isSecurityGroupEnabled, type); Transaction txn = Transaction.currentTxn(); txn.start(); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 2d9285fc4ad..b155abf42b3 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -558,9 +558,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); - networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false).get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false, false).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null)); + networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null)); } VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId, desiredHyp); diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index d9438c3de08..13e1add9adb 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -108,11 +108,11 @@ public interface NetworkManager extends NetworkService { */ List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId); - List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) + List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean isShared) throws ConcurrentOperationException; List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup, - Long domainId, List tags) throws ConcurrentOperationException; + Long domainId, List tags, boolean isShared) throws ConcurrentOperationException; List getSystemAccountNetworkOfferings(String... offeringNames); @@ -161,7 +161,7 @@ public interface NetworkManager extends NetworkService { boolean destroyNetwork(long networkId, ReservationContext context); Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isDefault, Long zoneId, String gateway, String cidr, String vlanId, String networkDomain, Account owner, - boolean isSecurityGroupEnabled, Long domainId, List tags) throws ConcurrentOperationException, InsufficientCapacityException; + boolean isSecurityGroupEnabled, Long domainId, List tags, Boolean isShared) throws ConcurrentOperationException, InsufficientCapacityException; /** * @throws InsufficientCapacityException diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index d7e003502f2..210c159e114 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -806,19 +806,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag //check that offering already exists NetworkOfferingVO offering = null; if (_networkOfferingDao.findByUniqueName(NetworkOffering.SystemGuestNetwork) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.SystemGuestNetwork, "System Offering for System-Guest-Network", TrafficType.Guest, null, null, false, Availability.Optional, GuestIpType.Direct, null, defaultDirectNetworkOfferingProviders, true, true, Network.Type.Shared); + offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.SystemGuestNetwork, "System Offering for System-Guest-Network", TrafficType.Guest, null, null, false, Availability.Optional, null, defaultDirectNetworkOfferingProviders, true, true, Network.Type.Shared); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultVirtualizedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM,NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, null, null, false, Availability.Required, GuestIpType.Virtual, null, defaultVirtualNetworkOfferingProviders, true, false, Network.Type.Isolated); + offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM,NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, null, null, false, Availability.Required, null, defaultVirtualNetworkOfferingProviders, true, false, Network.Type.Isolated); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultDirectNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, null, null, true, Availability.Optional, GuestIpType.Direct, null, defaultDirectNetworkOfferingProviders, true, false, Network.Type.Shared); + offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, null, null, true, Availability.Optional, null, defaultDirectNetworkOfferingProviders, true, false, Network.Type.Shared); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } @@ -916,15 +916,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) + public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean isShared) throws ConcurrentOperationException { - return setupNetwork(owner, offering, null, plan, name, displayText, isDefault, false, null, null); + return setupNetwork(owner, offering, null, plan, name, displayText, isDefault, false, null, null, isShared); } @Override @DB public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup, - Long domainId, List tags) throws ConcurrentOperationException { + Long domainId, List tags, boolean isShared) throws ConcurrentOperationException { Account locked = _accountDao.acquireInLockTable(owner.getId()); if (locked == null) { throw new ConcurrentOperationException("Unable to acquire lock on " + owner); @@ -984,7 +984,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } NetworkVO vo = new NetworkVO(id, network, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, isDefault, - predefined.isSecurityGroupEnabled(), (domainId != null), predefined.getNetworkDomain(), offering.getType()); + predefined.isSecurityGroupEnabled(), (domainId != null), predefined.getNetworkDomain(), offering.getType(), isShared); vo.setTags(tags); networks.add(_networksDao.persist(vo, vo.getGuestType() != null)); @@ -1564,6 +1564,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Account caller = UserContext.current().getCaller(); List tags = cmd.getTags(); boolean isDomainSpecific = false; + Boolean isShared = cmd.getIsShared(); if (tags != null && tags.size() > 1) { throw new InvalidParameterException("Only one tag can be specified for a network at this time"); @@ -1580,17 +1581,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (networkOffering.getState() != NetworkOffering.State.Enabled) { throw new InvalidParameterValueException("Can't use network offering id=" + networkOfferingId + " as its state is not " + NetworkOffering.State.Enabled); } - - boolean isShared = false; - if (networkOffering.getType() == Network.Type.Shared) { - isShared = true; - } // Check if the network is domain specific if (cmd.getDomainId() != null && cmd.getAccountName() == null) { if (networkOffering.getTrafficType() != TrafficType.Guest || networkOffering.getType() != Network.Type.Shared) { - throw new InvalidParameterValueException("Domain level networks are supported just for traffic type " + TrafficType.Guest + " and only for type " + Network.Type.Shared); - } else if (!isShared) { + throw new InvalidParameterValueException("Domain level networks are supported just for traffic type " + TrafficType.Guest + " and type " + Network.Type.Shared); + } else if (isShared == null || !isShared) { throw new InvalidParameterValueException("Network dedicated to domain should be shared"); } else { DomainVO domain = _domainDao.findById(cmd.getDomainId()); @@ -1690,7 +1686,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag domainId = cmd.getDomainId(); } - Network network = createNetwork(networkOfferingId, name, displayText, isDefault, zoneId, gateway, cidr, vlanId, networkDomain, owner, false, domainId, tags); + Network network = createNetwork(networkOfferingId, name, displayText, isDefault, zoneId, gateway, cidr, vlanId, networkDomain, owner, false, domainId, tags, isShared); // Don't pass owner to create vlan when network offering is of type Shared - done to prevent accountVlanMap entry // creation when vlan is mapped to network @@ -1711,7 +1707,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB public Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isDefault, Long zoneId, String gateway, String cidr, String vlanId, String networkDomain, - Account owner, boolean isSecurityGroupEnabled, Long domainId, List tags) throws ConcurrentOperationException, InsufficientCapacityException { + Account owner, boolean isSecurityGroupEnabled, Long domainId, List tags, Boolean isShared) throws ConcurrentOperationException, InsufficientCapacityException { NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId); DataCenterVO zone = _dcDao.findById(zoneId); @@ -1719,21 +1715,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // allow isDefault to be set only for Shared network if (networkOffering.getType() == Network.Type.Isolated) { if (isDefault != null && !isDefault) { - throw new InvalidParameterValueException("Can specify isDefault parameter only for Direct network."); + throw new InvalidParameterValueException("Can specify isDefault parameter only for network of type " + Network.Type.Shared); } else { isDefault = true; } + if (isShared != null && isShared) { + throw new InvalidParameterValueException("Can specify isShared parameter for Direct networks only"); + } } else { if (isDefault == null) { isDefault = false; } } - - // if network is shared, default its owner to be system - boolean isShared = false; - if (networkOffering.getType() == Network.Type.Shared) { - isShared = true; - } + if (isShared) { owner = _accountMgr.getSystemAccount(); } @@ -1827,7 +1821,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - List networks = setupNetwork(owner, networkOffering, userNetwork, plan, name, displayText, isDefault, true, domainId, tags); + List networks = setupNetwork(owner, networkOffering, userNetwork, plan, name, displayText, isDefault, true, domainId, tags, isShared); Network network = null; if (networks == null || networks.isEmpty()) { @@ -2748,7 +2742,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // create new Virtual network for the user if it doesn't exist if (createNetwork) { List offerings = _configMgr.listNetworkOfferings(TrafficType.Guest, false); - network = createNetwork(offerings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, zoneId, null, null, null, null, owner, false, null, null); + network = createNetwork(offerings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, zoneId, null, null, null, null, owner, false, null, null, false); if (network == null) { s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId); diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 4a67c19a43b..3a749471403 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -182,8 +182,8 @@ public class NetworkVO implements Network { this.guestType = guestType; } - public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText, boolean isDefault, boolean isSecurityGroupEnabled, boolean isDomainSpecific, String networkDomain, Type type) { - this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText,isDefault, isDomainSpecific, networkDomain, type); + public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText, boolean isDefault, boolean isSecurityGroupEnabled, boolean isDomainSpecific, String networkDomain, Type type, boolean isShared) { + this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText,isDefault, isDomainSpecific, networkDomain, type, isShared); this.gateway = that.getGateway(); this.cidr = that.getCidr(); this.broadcastUri = that.getBroadcastUri(); @@ -207,13 +207,14 @@ public class NetworkVO implements Network { * @param accountId * @param name * @param displayText - * @param isShared * @param isDefault * @param isDomainSpecific * @param networkDomain * @param type TODO + * @param isShared TODO + * @param isShared */ - public NetworkVO(long id, TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related, String name, String displayText, boolean isDefault, boolean isDomainSpecific, String networkDomain, Type type) { + public NetworkVO(long id, TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related, String name, String displayText, boolean isDefault, boolean isDomainSpecific, String networkDomain, Type type, boolean isShared) { this(trafficType, guestType, mode, broadcastDomainType, networkOfferingId, dataCenterId, State.Allocated); this.domainId = domainId; this.accountId = accountId; @@ -221,15 +222,11 @@ public class NetworkVO implements Network { this.id = id; this.name = name; this.displayText = displayText; - if (type == Network.Type.Shared) { - this.isShared = true; - } else if (type == Network.Type.Isolated) { - this.isShared = false; - } this.isDefault = isDefault; this.isDomainSpecific = isDomainSpecific; this.networkDomain = networkDomain; this.type = type; + this.isShared = isShared; } @Override @@ -493,4 +490,9 @@ public class NetworkVO implements Network { buf.append(id).append("|").append(trafficType.toString()).append("|").append(networkOfferingId).append("]"); return buf.toString(); } + + @Override + public boolean getIsShared() { + return isShared; + } } diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index cd0a385e2a7..790bf05bd24 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -486,7 +486,7 @@ public class ElasticLoadBalancerManagerImpl implements List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false, false).get(0); List> networks = new ArrayList>(2); NicProfile guestNic = new NicProfile(); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index c1a70f1c911..d56ad569fe5 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1063,11 +1063,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false, false).get(0); List> networks = new ArrayList>(3); NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); - List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); + List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false, false); networks.add(new Pair(publicNetworks.get(0), defaultNic)); NicProfile gatewayNic = new NicProfile(); if (isRedundant) { @@ -1253,7 +1253,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false, false).get(0); List> networks = new ArrayList>(3); diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index 27823837b3f..ff6b75111f2 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -232,7 +232,7 @@ public class NetworkOfferingVO implements NetworkOffering { return type; } - public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, GuestIpType guestIpType, String tags, boolean isSecurityGroupEnabled, Network.Type type) { + public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, String tags, boolean isSecurityGroupEnabled, Network.Type type) { this.name = name; this.displayText = displayText; this.rateMbps = rateMbps; @@ -245,9 +245,13 @@ public class NetworkOfferingVO implements NetworkOffering { this.availability = availability; this.uniqueName = name; this.tags = tags; - this.guestType = guestIpType; this.securityGroupEnabled = isSecurityGroupEnabled; this.type = type; + if (type == Type.Isolated) { + this.guestType = GuestIpType.Virtual; + } else if (type == Type.Shared){ + this.guestType = GuestIpType.Direct; + } } public NetworkOfferingVO() { @@ -259,7 +263,7 @@ public class NetworkOfferingVO implements NetworkOffering { * @param trafficType */ public NetworkOfferingVO(String name, TrafficType trafficType) { - this(name, "System Offering for " + name, trafficType, true, false, 0, 0, null, true, Availability.Required, null, null, false, null); + this(name, "System Offering for " + name, trafficType, true, false, 0, 0, null, true, Availability.Required, null, false, null); this.state = State.Enabled; this.type = Type.Shared; } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index e32158e7ce9..01cc278697d 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -67,7 +67,6 @@ import com.cloud.domain.dao.DomainDao; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; -import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.Network.State; @@ -852,7 +851,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { "System-Guest-Network", TrafficType.Guest, false, false, null, null, null, true, - Availability.Optional, GuestIpType.Direct, null, true, Network.Type.Shared); + Availability.Optional, null, true, Network.Type.Shared); guestNetworkOffering.setState(NetworkOffering.State.Enabled); @@ -869,7 +868,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { "Virtual Vlan", TrafficType.Guest, false, false, null, null, null, true, - Availability.Required, GuestIpType.Virtual, null, false, Network.Type.Isolated); + Availability.Required, null, false, Network.Type.Isolated); defaultGuestNetworkOffering.setState(NetworkOffering.State.Enabled); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering); @@ -886,7 +885,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { "Direct", TrafficType.Guest, false, true, null, null, null, true, - Availability.Optional, GuestIpType.Direct, null, false, Network.Type.Shared); + Availability.Optional, null, false, Network.Type.Shared); defaultGuestDirectNetworkOffering.setState(NetworkOffering.State.Enabled); defaultGuestDirectNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering); @@ -953,7 +952,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, isNetworkDefault, false, networkDomain, Network.Type.Shared); + NetworkVO network = new NetworkVO(id, trafficType, null, mode, broadcastDomainType, networkOfferingId, zoneId, domainId, accountId, related, null, null, isNetworkDefault, false, networkDomain, Network.Type.Shared, true); network.setGuruName(guruNames.get(network.getTrafficType())); network.setDns1(zone.getDns1()); network.setDns2(zone.getDns2()); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index b042e574533..d18aecf8c28 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -504,9 +504,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); try { - networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false).get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false, false).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null)); + networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null)); } } catch (ConcurrentOperationException e) { s_logger.info("Unable to setup due to concurrent operation. " + e); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f30c8f97377..0da715ac0ff 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2178,7 +2178,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (virtualNetworks.isEmpty()) { s_logger.debug("Creating default Virtual network for account " + owner + " as a part of deployVM process"); Network newNetwork = _networkMgr.createNetwork(defaultVirtualOffering.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, zone.getId(), - null, null, null, null, owner, false, null, null); + null, null, null, null, owner, false, null, null, false); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { throw new InvalidParameterValueException("More than 1 default Virtaul networks are found for account " + owner + "; please specify networkIds"); @@ -2191,7 +2191,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (defaultVirtualOffering.get(0).getAvailability() == Availability.Optional) { s_logger.debug("Creating default Virtual network for account " + owner + " as a part of deployVM process"); Network newNetwork = _networkMgr.createNetwork(defaultVirtualOffering.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, zone.getId(), - null, null, null, null, owner, false, null, null); + null, null, null, null, owner, false, null, null, false); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else { throw new InvalidParameterValueException("Unable to find default networks for account " + owner); @@ -3336,7 +3336,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager List virtualNetworks = _networkMgr.listNetworksForAccount(newAccount.getId(), zone.getId(), GuestIpType.Virtual, true); if (virtualNetworks.isEmpty()) { Network newNetwork = _networkMgr.createNetwork(networkOffering, newAccount.getAccountName() + "-network", newAccount.getAccountName() + "-network", null, vm.getDataCenterIdToDeployIn(), - null, null, null, null, newAccount, false, null, null); + null, null, null, null, newAccount, false, null, null, false); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { throw new InvalidParameterValueException("More than 1 default Virtaul networks are found for account " + newAccount + "; please specify networkIds"); diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 5e1f5bb6a0e..a9127b6ab20 100644 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -2,6 +2,7 @@ package com.cloud.network; import java.util.List; import java.util.Map; +import java.util.Set; import javax.ejb.Local; import javax.naming.ConfigurationException; @@ -9,6 +10,7 @@ import javax.naming.ConfigurationException; import com.cloud.api.commands.AssociateIPAddrCmd; import com.cloud.api.commands.CreateNetworkCmd; import com.cloud.api.commands.ListNetworksCmd; +import com.cloud.api.commands.RestartNetworkCmd; import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; import com.cloud.deploy.DeployDestination; @@ -20,9 +22,12 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network.Capability; import com.cloud.network.Network.GuestIpType; +import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; +import com.cloud.network.element.PasswordServiceProvider; +import com.cloud.network.element.RemoteAccessVPNServiceProvider; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.StaticNat; @@ -193,7 +198,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) + public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean isShared) throws ConcurrentOperationException { // TODO Auto-generated method stub return null; @@ -201,7 +206,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup, - Long domainId, List tags) throws ConcurrentOperationException { + Long domainId, List tags, boolean isShared) throws ConcurrentOperationException { // TODO Auto-generated method stub return null; } @@ -336,7 +341,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isDefault, Long zoneId, String gateway, String cidr, String vlanId, String networkDomain, - Account owner, boolean isSecurityGroupEnabled, Long domainId, List tags) throws ConcurrentOperationException, InsufficientCapacityException { + Account owner, boolean isSecurityGroupEnabled, Long domainId, List tags, Boolean isShared) throws ConcurrentOperationException, InsufficientCapacityException { // TODO Auto-generated method stub return null; } @@ -479,5 +484,37 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS // TODO Auto-generated method stub return null; } + + @Override + public Map> listNetworkOfferingServices(long networkOfferingId) { + return null; + } + + @Override + public boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + return false; + } + + @Override + public List getRemoteAccessVpnElements() { + return null; + } + @Override + public List getPasswordResetElements() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Long getPodIdForVlan(long vlanDbId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isProviderSupported(long networkOfferingId, Service service, Provider provider) { + // TODO Auto-generated method stub + return false; + } }