From 150d684e055cbb708abac6710be3c89bd5f6649a Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 3 Dec 2010 18:38:50 -0800 Subject: [PATCH] 1) isShared attribute belongs to Network now, not NetworkOffering 2) Added list by networkId support to listVirtualMachines command. 3) Implemented search by zoneId in listNetworks command --- api/src/com/cloud/api/ApiConstants.java | 1 + .../CancelPrimaryStorageMaintenanceCmd.java | 9 ++++++ .../cloud/api/commands/CreateNetworkCmd.java | 7 ++++ .../commands/CreateNetworkOfferingCmd.java | 7 ---- .../com/cloud/api/commands/DeployVMCmd.java | 21 +++++++----- .../cloud/api/commands/ListNetworksCmd.java | 9 ++++++ .../api/commands/ListStoragePoolsCmd.java | 5 +++ .../com/cloud/api/commands/ListVMsCmd.java | 7 ++++ ...reparePrimaryStorageForMaintenanceCmd.java | 9 ++++++ .../api/response/NetworkOfferingResponse.java | 13 +------- api/src/com/cloud/network/Network.java | 2 ++ .../com/cloud/offering/NetworkOffering.java | 2 -- .../src/com/cloud/api/ApiResponseHelper.java | 4 +-- .../configuration/ConfigurationManager.java | 16 +++++----- .../ConfigurationManagerImpl.java | 11 ++----- .../consoleproxy/ConsoleProxyManagerImpl.java | 4 +-- .../src/com/cloud/network/NetworkManager.java | 4 +-- .../com/cloud/network/NetworkManagerImpl.java | 32 ++++++++++--------- server/src/com/cloud/network/NetworkVO.java | 22 +++++++++++-- .../src/com/cloud/network/dao/NetworkDao.java | 6 ++-- .../com/cloud/network/dao/NetworkDaoImpl.java | 18 +++++++++++ .../router/DomainRouterManagerImpl.java | 4 +-- .../cloud/offerings/NetworkOfferingVO.java | 21 +++--------- server/src/com/cloud/server/Criteria.java | 1 + .../cloud/server/ManagementServerImpl.java | 28 +++++++++++++++- .../SecondaryStorageManagerImpl.java | 4 +-- .../src/com/cloud/vm/UserVmManagerImpl.java | 9 ++++-- setup/db/create-schema.sql | 2 +- 28 files changed, 181 insertions(+), 97 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index f132b53fb07..0d6b2f039bd 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -170,6 +170,7 @@ public class ApiConstants { public static final String MAX_CONNECTIONS = "maxconnections"; public static final String NETWORK_OFFERING_ID = "networkofferingid"; public static final String NETWORK_IDS = "networkids"; + public static final String NETWORK_ID = "networkid"; public static final String SPECIFY_VLAN = "specifyvlan"; public static final String IS_DEFAULT = "isdefault"; } diff --git a/api/src/com/cloud/api/commands/CancelPrimaryStorageMaintenanceCmd.java b/api/src/com/cloud/api/commands/CancelPrimaryStorageMaintenanceCmd.java index d7e62720f39..8f6fa8ba033 100644 --- a/api/src/com/cloud/api/commands/CancelPrimaryStorageMaintenanceCmd.java +++ b/api/src/com/cloud/api/commands/CancelPrimaryStorageMaintenanceCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.StoragePoolResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.storage.StoragePool; import com.cloud.user.Account; @@ -67,6 +68,14 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd { public static String getResultObjectName() { return "primarystorage"; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Host; + } + + public Long getInstanceId() { + return getId(); + } @Override public long getEntityOwnerId() { diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java index 161605aea57..67842c99533 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkCmd.java @@ -76,6 +76,9 @@ public class CreateNetworkCmd extends BaseCmd { @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN") private Long domainId; + + @Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans") + private Boolean isShared; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -131,6 +134,10 @@ public class CreateNetworkCmd extends BaseCmd { public String getDisplayText() { return displayText; } + + public Boolean getIsShared() { + return isShared; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java index 64f9d59276b..9c30aff5c06 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java @@ -57,9 +57,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="true is network offering supports vlans") private Boolean specifyVlan; - - @Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans") - private Boolean isShared; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -92,10 +89,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd { public Boolean getSpecifyVlan() { return specifyVlan; } - - public Boolean getIsShared() { - return isShared; - } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/com/cloud/api/commands/DeployVMCmd.java b/api/src/com/cloud/api/commands/DeployVMCmd.java index 7ccd75d3db7..0e3c9a5e9b3 100644 --- a/api/src/com/cloud/api/commands/DeployVMCmd.java +++ b/api/src/com/cloud/api/commands/DeployVMCmd.java @@ -31,13 +31,15 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.UserVmResponse; import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; -import com.cloud.exception.InsufficientStorageCapacityException; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceAllocationException; -import com.cloud.exception.StorageUnavailableException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; import com.cloud.user.UserContext; import com.cloud.uservm.UserVm; +import com.cloud.utils.exception.ExecutionException; @Implementation(description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject=UserVmResponse.class) public class DeployVMCmd extends BaseAsyncCmd { @@ -227,17 +229,20 @@ public class DeployVMCmd extends BaseAsyncCmd { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm"); } } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + s_logger.info(ex); throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); - } catch (InsufficientStorageCapacityException ex) { - s_logger.warn("Exception: ", ex); + } catch (InsufficientCapacityException ex) { + s_logger.info(ex); throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); - } catch (StorageUnavailableException ex) { + } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); - } catch (Exception ex) { + } catch (ExecutionException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); - } + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + } } } diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java index 4cb95e9516f..26d6927158b 100644 --- a/api/src/com/cloud/api/commands/ListNetworksCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.ApiConstants; import com.cloud.api.BaseListCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; +import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.ListResponse; import com.cloud.api.response.NetworkResponse; import com.cloud.network.Network; @@ -48,6 +49,9 @@ public class ListNetworksCmd extends BaseListCmd { @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN") private Long domainId; + + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the Zone ID of the network") + private Long zoneId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -64,6 +68,11 @@ public class ListNetworksCmd extends BaseListCmd { public Long getDomainId() { return domainId; } + + public Long getZoneId() { + return zoneId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/ListStoragePoolsCmd.java b/api/src/com/cloud/api/commands/ListStoragePoolsCmd.java index fc2375b8ac6..d52b1569a15 100644 --- a/api/src/com/cloud/api/commands/ListStoragePoolsCmd.java +++ b/api/src/com/cloud/api/commands/ListStoragePoolsCmd.java @@ -29,6 +29,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.StoragePoolResponse; +import com.cloud.async.AsyncJob; import com.cloud.storage.StoragePool; @Implementation(description="Lists storage pools.", responseObject=StoragePoolResponse.class) @@ -94,6 +95,10 @@ public class ListStoragePoolsCmd extends BaseListCmd { @Override public String getName() { return s_name; + } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Host; } @Override diff --git a/api/src/com/cloud/api/commands/ListVMsCmd.java b/api/src/com/cloud/api/commands/ListVMsCmd.java index fcfab3b0f46..a40bf3802a1 100644 --- a/api/src/com/cloud/api/commands/ListVMsCmd.java +++ b/api/src/com/cloud/api/commands/ListVMsCmd.java @@ -70,6 +70,9 @@ public class ListVMsCmd extends BaseListCmd { @Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="list by network type; true if need to list vms using Virtual Network, false otherwise") private Boolean forVirtualNetwork; + + @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list by network id") + private Long networkId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -118,6 +121,10 @@ public class ListVMsCmd extends BaseListCmd { public void setForVirtualNetwork(Boolean forVirtualNetwork) { this.forVirtualNetwork = forVirtualNetwork; } + + public Long getNetworkId() { + return networkId; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/com/cloud/api/commands/PreparePrimaryStorageForMaintenanceCmd.java b/api/src/com/cloud/api/commands/PreparePrimaryStorageForMaintenanceCmd.java index 08321e7d502..50c832aba13 100644 --- a/api/src/com/cloud/api/commands/PreparePrimaryStorageForMaintenanceCmd.java +++ b/api/src/com/cloud/api/commands/PreparePrimaryStorageForMaintenanceCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.StoragePoolResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.storage.StoragePool; import com.cloud.user.Account; @@ -63,6 +64,14 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd { public static String getResultObjectName() { return "primarystorage"; } + + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Host; + } + + public Long getInstanceId() { + return getId(); + } @Override public long getEntityOwnerId() { diff --git a/api/src/com/cloud/api/response/NetworkOfferingResponse.java b/api/src/com/cloud/api/response/NetworkOfferingResponse.java index ded3bc6775f..05eef83820d 100644 --- a/api/src/com/cloud/api/response/NetworkOfferingResponse.java +++ b/api/src/com/cloud/api/response/NetworkOfferingResponse.java @@ -32,10 +32,7 @@ public class NetworkOfferingResponse extends BaseResponse{ @SerializedName("isdefault") @Param(description="true if network offering is default, false otherwise") private Boolean isDefault; - - @SerializedName("isshared") @Param(description="true if network offering is shared, false otherwise") - private Boolean isShared; - + @SerializedName("specifyvlan") @Param(description="true if network offering supports vlans, false otherwise") private Boolean specifyVlan; @@ -126,12 +123,4 @@ public class NetworkOfferingResponse extends BaseResponse{ public void setSpecifyVlan(Boolean specifyVlan) { this.specifyVlan = specifyVlan; } - - public Boolean getIsShared() { - return isShared; - } - - public void setIsShared(Boolean isShared) { - this.isShared = isShared; - } } diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index d00f4d616d3..a27843358a2 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -110,4 +110,6 @@ public interface Network extends ControlledEntity { GuestIpType getGuestType(); String getDisplayText(); + + boolean isShared(); } diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 10ce22ad873..0a4e7c7e504 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -73,7 +73,5 @@ public interface NetworkOffering { String getTags(); - boolean isShared(); - boolean isDefault(); } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 1a44de10514..f3d4ef814f1 100644 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -2305,7 +2305,6 @@ public class ApiResponseHelper implements ResponseGenerator { response.setMaxconnections(offering.getConcurrentConnections()); response.setIsDefault(offering.isDefault()); response.setSpecifyVlan(offering.getSpecifyVlan()); - response.setIsShared(offering.isShared()); response.setObjectName("networkoffering"); return response; } @@ -2340,8 +2339,9 @@ public class ApiResponseHelper implements ResponseGenerator { response.setNetworkOfferingId(networkOffering.getId()); response.setNetworkOfferingName(networkOffering.getName()); response.setNetworkOfferingDisplayText(networkOffering.getDisplayText()); - response.setIsShared(networkOffering.isShared()); } + + response.setIsShared(network.isShared()); response.setState(network.getState().toString()); response.setRelated(network.getRelated()); response.setDns1(network.getDns1()); diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 7af2974a5fc..53a87936bde 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -170,17 +170,17 @@ public interface ConfigurationManager extends Manager { /** * Creates a new network offering - * @param id - * @param name - * @param displayText - * @param type - * @param trafficType - * @param tags - * @param maxConnections + * @param name + * @param displayText + * @param type + * @param trafficType + * @param tags + * @param maxConnections + * @param id * @param specifyVlan; * @return network offering object */ - NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, boolean isShared); + NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan); 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 3ae68fee580..e6a4d14f9b1 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2391,7 +2391,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String typeString = cmd.getType(); String trafficTypeString = cmd.getTraffictype(); Boolean specifyVlan = cmd.getSpecifyVlan(); - Boolean isShared = cmd.getIsShared(); TrafficType trafficType = null; GuestIpType type = null; @@ -2418,23 +2417,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (specifyVlan == null) { specifyVlan = false; } - - if (isShared == null) { - isShared = false; - } Integer maxConnections = cmd.getMaxconnections(); - return createNetworkOffering(userId, name, displayText, type, trafficType, tags, maxConnections, specifyVlan, isShared); + return createNetworkOffering(userId, name, displayText, type, trafficType, tags, maxConnections, specifyVlan); } @Override - public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, boolean isShared) { + public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan) { String networkRateStr = _configDao.getValue("network.throttling.rate"); String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); tags = cleanupTags(tags); - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, type, false, specifyVlan, networkRate, multicastRate, maxConnections, isShared, false); + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, type, false, specifyVlan, networkRate, multicastRate, maxConnections, false); if ((offering = _networkOfferingDao.persist(offering)) != null) { saveConfigurationEvent(userId, null, EventTypes.EVENT_NETWORK_OFFERING_CREATE, "Successfully created new network offering with name: " + name + ".", "noId=" + offering.getId(), "name=" + name, diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 6e299080619..63c67256e70 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1071,9 +1071,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null).get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null, false).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null).get(0), null)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null, false).get(0), null)); } ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0); try { diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 3b2822647b0..07ec43cf517 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -198,8 +198,8 @@ public interface NetworkManager extends NetworkService { */ List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat); - List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText); - List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText); + List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isShared); + List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isShared); List getSystemAccountNetworkOfferings(String... offeringNames); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 9dff381e3a5..0c739c2b3c9 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -71,7 +71,6 @@ import com.cloud.dc.dao.VlanDao; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; -import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; @@ -1003,9 +1002,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemVmStorageNetwork, storageNetworkOffering); - NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtualized, false, false, rateMbps, multicastRateMbps, null, false, true); + NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtualized, false, false, rateMbps, multicastRateMbps, null, true); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering); - NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, GuestIpType.DirectSingle, false, false, rateMbps, multicastRateMbps, null, false, true); + NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, GuestIpType.DirectSingle, false, false, rateMbps, multicastRateMbps, null, true); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering); AccountsUsingNetworkConfigurationSearch = _accountDao.createSearchBuilder(); @@ -1085,12 +1084,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText) { - return setupNetworkConfiguration(owner, offering, null, plan, name, displayText); + public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isShared) { + return setupNetworkConfiguration(owner, offering, null, plan, name, displayText, isShared); } @Override - public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText) { + public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isShared) { List configs = _networkConfigDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); if (configs.size() > 0) { if (s_logger.isDebugEnabled()) { @@ -1123,7 +1122,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag related = id; } - NetworkVO vo = new NetworkVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText); + NetworkVO vo = new NetworkVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, isShared); configs.add(_networkConfigDao.persist(vo)); } @@ -1532,7 +1531,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public List setupNetworkConfiguration(Account owner, ServiceOfferingVO offering, DeploymentPlan plan) { NetworkOfferingVO networkOffering = _networkOfferingDao.findByServiceOffering(offering); - return setupNetworkConfiguration(owner, networkOffering, plan, null, null); + return setupNetworkConfiguration(owner, networkOffering, plan, null, null, false); } private String [] getGuestIpRange() { @@ -1895,6 +1894,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String vlanId = cmd.getVlan(); String name = cmd.getNetworkName(); String displayText = cmd.getDisplayText(); + Boolean isShared = cmd.getIsShared(); Account owner = null; //Check if network offering exists @@ -1926,10 +1926,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { owner = ctxAccount; } - - if (owner.getId() == Account.ACCOUNT_ID_SYSTEM && !networkOffering.isShared()) { - throw new InvalidParameterValueException("Non-system account is required when create a network from Dedicated network offering with id=" + networkOfferingId); - } //VlanId can be specified only when network offering supports it if (vlanId != null && !networkOffering.getSpecifyVlan()) { @@ -1957,7 +1953,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - List networks = setupNetworkConfiguration(owner, networkOffering, userNetwork, plan, name, displayText); + List networks = setupNetworkConfiguration(owner, networkOffering, userNetwork, plan, name, displayText, isShared); Long networkId = null; if (networks == null || networks.isEmpty()) { @@ -1967,8 +1963,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag networkId = networks.get(0).getId(); } - //If network offering is shared, don't pass owner account and networkOfferingId for vlan - if (networkOffering.isShared()) { + //Don't pass owner to create vlan when network offering is of type Direct + if (networkOffering.getGuestIpType() == GuestIpType.DirectSingle) { owner = null; } @@ -1995,10 +1991,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public List searchForNetworks(ListNetworksCmd cmd) { Object id = cmd.getId(); Object keyword = cmd.getKeyword(); + Long zoneId= cmd.getZoneId(); Account account = UserContext.current().getAccount(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); Long accountId = null; + if (isAdmin(account.getType())) { if (domainId != null) { if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) { @@ -2041,6 +2039,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sc.addAnd("id", SearchCriteria.Op.EQ, id); } + if (zoneId != null) { + sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); + } + SearchCriteria ssc = _networkConfigDao.createSearchCriteria(); ssc.addOr("accountId", SearchCriteria.Op.EQ, accountId); if (accountName == null && domainId == null) { diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index d99d06369e4..a83d54816c1 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -115,6 +115,9 @@ public class NetworkVO implements Network { @Column(name="dns2") String dns2; + @Column(name="shared") + boolean isShared; + public NetworkVO() { } @@ -137,8 +140,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) { - this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText); + public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText, Boolean isShared) { + this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText, isShared); this.gateway = that.getGateway(); this.dns1 = that.getDns1(); this.dns2 = that.getDns2(); @@ -162,8 +165,9 @@ public class NetworkVO implements Network { * @param accountId * @param name * @param displayText + * @param isShared TODO */ - 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) { + 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 isShared) { this(trafficType, guestType, mode, broadcastDomainType, networkOfferingId, dataCenterId); this.domainId = domainId; this.accountId = accountId; @@ -171,6 +175,7 @@ public class NetworkVO implements Network { this.id = id; this.name = name; this.displayText = displayText; + this.isShared = isShared; } @Override @@ -327,6 +332,15 @@ public class NetworkVO implements Network { public void setDisplayText(String displayText) { this.displayText = displayText; } + + @Override + public boolean isShared() { + return isShared; + } + + public void setShared(boolean isShared) { + this.isShared = isShared; + } @Override public boolean equals(Object obj) { @@ -359,4 +373,6 @@ public class NetworkVO implements Network { buf.append(id).append("|").append(trafficType.toString()).append("|").append(networkOfferingId).append("]"); return buf.toString(); } + + } diff --git a/server/src/com/cloud/network/dao/NetworkDao.java b/server/src/com/cloud/network/dao/NetworkDao.java index a6f92858ed3..eba82e475b6 100644 --- a/server/src/com/cloud/network/dao/NetworkDao.java +++ b/server/src/com/cloud/network/dao/NetworkDao.java @@ -28,8 +28,8 @@ public interface NetworkDao extends GenericDao { List listBy(long accountId); List listBy(long accountId, long offeringId, long dataCenterId); @Override - NetworkVO persist(NetworkVO config); - void addAccountToNetworkConfiguration(long configId, long accountId); + NetworkVO persist(NetworkVO network); + void addAccountToNetworkConfiguration(long networkId, long accountId); SearchBuilder createSearchBuilderForAccount(); List getNetworkConfigurationsForOffering(long offeringId, long dataCenterId, long accountId); List getRelatedNetworkConfigurations(long related); @@ -40,4 +40,6 @@ public interface NetworkDao extends GenericDao { * @return mac address if there is one. null if not. */ String getNextAvailableMacAddress(long networkConfigId); + + List listBy(long accountId, long networkId); } diff --git a/server/src/com/cloud/network/dao/NetworkDaoImpl.java b/server/src/com/cloud/network/dao/NetworkDaoImpl.java index 1373629b5e4..fdb6214dc29 100644 --- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java @@ -25,6 +25,7 @@ import java.util.Random; import javax.ejb.Local; import javax.persistence.TableGenerator; +import com.cloud.domain.DomainVO; import com.cloud.network.NetworkAccountDaoImpl; import com.cloud.network.NetworkAccountVO; import com.cloud.network.NetworkVO; @@ -49,6 +50,7 @@ public class NetworkDaoImpl extends GenericDaoBase implements N final SearchBuilder OfferingSearch; final SearchBuilder RelatedConfigSearch; final SearchBuilder RelatedConfigsSearch; + final SearchBuilder AccountNetworkSearch; NetworkAccountDaoImpl _accountsDao = new NetworkAccountDaoImpl(); final TableGenerator _tgMacAddress; @@ -90,6 +92,14 @@ public class NetworkDaoImpl extends GenericDaoBase implements N RelatedConfigsSearch.and("related", RelatedConfigsSearch.entity().getRelated(), SearchCriteria.Op.EQ); RelatedConfigsSearch.done(); + + AccountNetworkSearch = createSearchBuilder(); + AccountNetworkSearch.and("networkId", AccountNetworkSearch.entity().getId(), SearchCriteria.Op.EQ); + SearchBuilder mapJoin = _accountsDao.createSearchBuilder(); + mapJoin.and("accountId", mapJoin.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountNetworkSearch.join("networkSearch", mapJoin, AccountNetworkSearch.entity().getId(), mapJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER); + AccountNetworkSearch.done(); + _tgMacAddress = _tgs.get("macAddress"); } @@ -178,4 +188,12 @@ public class NetworkDaoImpl extends GenericDaoBase implements N seq = seq | _prefix | ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l); return NetUtils.long2Mac(seq); } + + @Override + public List listBy(long accountId, long networkId) { + SearchCriteria sc = AccountNetworkSearch.create(); + sc.setParameters("networkId", networkId); + sc.setJoinParameters("networkSearch", "accountId", accountId); + return listBy(sc); + } } diff --git a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java index 432877708c6..19f42905e8e 100644 --- a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java +++ b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java @@ -2086,11 +2086,11 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork); NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan, null, null).get(0); + NetworkVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan, null, null, false).get(0); List> networks = new ArrayList>(3); NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmPublicNetwork).get(0); - List publicConfigs = _networkMgr.setupNetworkConfiguration(_systemAcct, publicOffering, plan, null, null); + List publicConfigs = _networkMgr.setupNetworkConfiguration(_systemAcct, publicOffering, plan, null, null, false); NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); //defaultNic.setIp4Address(sourceNatIp); diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index f758a66d658..11b35cbe854 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -80,10 +80,7 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name="tags") String tags; - - @Column(name="shared") - boolean isShared; - + @Column(name="default") boolean isDefault; @@ -201,15 +198,6 @@ public class NetworkOfferingVO implements NetworkOffering { this.serviceOfferingId = serviceOfferingId; } - @Override - public boolean isShared() { - return isShared; - } - - public void setShared(boolean isShared) { - this.isShared = isShared; - } - @Override public boolean isDefault() { return isDefault; @@ -224,7 +212,7 @@ public class NetworkOfferingVO implements NetworkOffering { this.created = created; } - public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isShared, boolean isDefault) { + public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault) { this.name = name; this.displayText = displayText; this.guestIpType = type; @@ -235,11 +223,10 @@ public class NetworkOfferingVO implements NetworkOffering { this.systemOnly = systemOnly; this.specifyVlan = specifyVlan; this.isDefault = isDefault; - this.isShared = isShared; } public NetworkOfferingVO(ServiceOfferingVO offering) { - this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, offering.getGuestIpType(), false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null, false, false); + this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, offering.getGuestIpType(), false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null, false); this.serviceOfferingId = offering.getId(); } @@ -251,7 +238,7 @@ public class NetworkOfferingVO implements NetworkOffering { * @param type */ public NetworkOfferingVO(String name, TrafficType trafficType, GuestIpType type) { - this(name, "System Offering for " + name, trafficType, type, true, false, null, null, null, false, false); + this(name, "System Offering for " + name, trafficType, type, true, false, null, null, null, false); } @Override diff --git a/server/src/com/cloud/server/Criteria.java b/server/src/com/cloud/server/Criteria.java index 6d41b967be9..74bc4e54b84 100644 --- a/server/src/com/cloud/server/Criteria.java +++ b/server/src/com/cloud/server/Criteria.java @@ -78,6 +78,7 @@ public class Criteria { public static final String NETWORKGROUP = "networkGroup"; public static final String GROUP = "group"; public static final String EMPTY_GROUP = "emptyGroup"; + public static final String NETWORKID = "networkId"; public Criteria(String orderBy, Boolean ascending, Long offset, Long limit) { this.offset = offset; diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index e56d60214a8..57897e8ab18 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -190,9 +190,11 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.info.ConsoleProxyInfo; import com.cloud.network.IPAddressVO; import com.cloud.network.NetworkManager; +import com.cloud.network.NetworkVO; import com.cloud.network.RemoteAccessVpnVO; import com.cloud.network.VpnUserVO; import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.RemoteAccessVpnDao; import com.cloud.network.dao.VpnUserDao; import com.cloud.network.security.NetworkGroupManager; @@ -274,6 +276,7 @@ import com.cloud.vm.ConsoleProxyVO; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.InstanceGroupVMMapVO; import com.cloud.vm.InstanceGroupVO; +import com.cloud.vm.NicVO; import com.cloud.vm.SecondaryStorageVmVO; import com.cloud.vm.State; import com.cloud.vm.UserVmManager; @@ -285,6 +288,7 @@ import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.InstanceGroupDao; import com.cloud.vm.dao.InstanceGroupVMMapDao; +import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.SecondaryStorageVmDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; @@ -331,6 +335,8 @@ public class ManagementServerImpl implements ManagementServer { private final StoragePoolHostDao _poolHostDao; private final StorageManager _storageMgr; private final UserVmDao _vmDao; + private final NetworkDao _networkDao; + private final NicDao _nicDao; private final Adapters _userAuthenticators; private final HostPodDao _hostPodDao; @@ -353,6 +359,7 @@ public class ManagementServerImpl implements ManagementServer { private final RemoteAccessVpnDao _remoteAccessVpnDao; private final VpnUserDao _vpnUsersDao; @Inject private UserVmService _userVmService; + private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker")); private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker")); @@ -391,6 +398,8 @@ public class ManagementServerImpl implements ManagementServer { _hostPodDao = locator.getDao(HostPodDao.class); _jobDao = locator.getDao(AsyncJobDao.class); _clusterDao = locator.getDao(ClusterDao.class); + _networkDao = locator.getDao(NetworkDao.class); + _nicDao = locator.getDao(NicDao.class); _accountMgr = locator.getManager(AccountManager.class); _agentMgr = locator.getManager(AgentManager.class); @@ -436,7 +445,7 @@ public class ManagementServerImpl implements ManagementServer { _asyncMgr = locator.getManager(AsyncJobManager.class); _tmpltMgr = locator.getManager(TemplateManager.class); _networkGroupMgr = locator.getManager(NetworkGroupManager.class); - _uploadMonitor = locator.getManager(UploadMonitor.class); + _uploadMonitor = locator.getManager(UploadMonitor.class); _userAuthenticators = locator.getAdapters(UserAuthenticator.class); if (_userAuthenticators == null || !_userAuthenticators.isSet()) { @@ -2589,6 +2598,7 @@ public class ManagementServerImpl implements ManagementServer { c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId()); c.addCriteria(Criteria.GROUPID, cmd.getGroupId()); c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork()); + c.addCriteria(Criteria.NETWORKID, cmd.getNetworkId()); if (path != null) { c.addCriteria(Criteria.PATH, path); @@ -2634,6 +2644,7 @@ public class ManagementServerImpl implements ManagementServer { Object groupId = c.getCriteria(Criteria.GROUPID); Object useVirtualNetwork = c.getCriteria(Criteria.FOR_VIRTUAL_NETWORK); Object path = c.getCriteria(Criteria.PATH); + Object networkId = c.getCriteria(Criteria.NETWORKID); sb.and("displayName", sb.entity().getDisplayName(), SearchCriteria.Op.LIKE); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); @@ -2667,6 +2678,17 @@ public class ManagementServerImpl implements ManagementServer { sb.join("groupSearch", groupSearch, sb.entity().getId(), groupSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); } + if (networkId != null) { + SearchBuilder nicSearch = _nicDao.createSearchBuilder(); + nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + + SearchBuilder networkSearch = _networkDao.createSearchBuilder(); + networkSearch.and("networkId", networkSearch.entity().getId(), SearchCriteria.Op.EQ); + nicSearch.join("networkSearch", networkSearch, nicSearch.entity().getNetworkId(), networkSearch.entity().getId(), JoinBuilder.JoinType.INNER); + + sb.join("nicSearch", nicSearch, sb.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + } + if (useVirtualNetwork != null) { SearchBuilder serviceSearch = _offeringsDao.createSearchBuilder(); if ((Boolean)useVirtualNetwork){ @@ -2718,6 +2740,10 @@ public class ManagementServerImpl implements ManagementServer { if (path != null) { sc.setJoinParameters("domainSearch", "path", path + "%"); } + + if (networkId != null) { + sc.setJoinParameters("nicSearch", "networkId", networkId); + } if (name != null) { sc.setParameters("name", "%" + name + "%"); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index b93bf3c15dd..991d22daa80 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -741,9 +741,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null).get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null, false).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null).get(0), null)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null, false).get(0), null)); } SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId()); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 6b456504978..35491499e0f 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -143,7 +143,6 @@ import com.cloud.network.security.NetworkGroupManager; import com.cloud.network.security.NetworkGroupVO; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; -import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; @@ -3701,8 +3700,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM if (network == null) { throw new InvalidParameterValueException("Unable to find network by id " + networkId); } else { - if (network.getAccountId() != Account.ACCOUNT_ID_SYSTEM && network.getAccountId() != accountId) { - throw new PermissionDeniedException("Unable to create a vm using network with id " + networkId + ", permission denied"); + if (!network.isShared()) { + //Iterate through account/network map + List networkMap = _networkDao.listBy(accountId, networkId); + if (networkMap == null || networkMap.isEmpty()) { + throw new PermissionDeniedException("Unable to create a vm using network with id " + networkId + ", permission denied"); + } } else if (network.getTrafficType() != TrafficType.Guest) { throw new InvalidParameterValueException("Unable to create a vm using network which traffic type is " + network.getTrafficType() + ". " + "Only Guest traffic type is acceptes"); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index eda390a0c11..a35dfbd71b3 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -137,6 +137,7 @@ CREATE TABLE `cloud`.`networks` ( `guru_data` varchar(1024) COMMENT 'data stored by the network guru that setup this network', `set_fields` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'which fields are set already', `guest_type` char(32) COMMENT 'type of guest network', + `shared` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '0 if network is shared, 1 if network dedicated', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -197,7 +198,6 @@ CREATE TABLE `cloud`.`network_offerings` ( `service_offering_id` bigint unsigned UNIQUE COMMENT 'service offering id that this network offering is tied to', `created` datetime NOT NULL COMMENT 'time the entry was created', `removed` datetime DEFAULT NULL COMMENT 'time the entry was removed', - `shared` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '0 if network is shared, 1 if network dedicated', `default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if network is default', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;