diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index 1f3ae284a30..0ba0cf666cf 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -1,4 +1,8 @@ #new labels (begin) ********************************************************************************************** +label.action.enable.physical.network=Enable physical network +label.action.disable.physical.network=Disable physical network +message.action.enable.physical.network=Please confirm that you want to enable this physical network. +message.action.disable.physical.network=Please confirm that you want to disable this physical network. label.ipaddress=IP Address label.vcdcname=vCenter DC name label.vcipaddress=vCenter IP Address diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index b97ce9fac56..ba178efb717 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -139,6 +139,7 @@ import com.cloud.storage.swift.SwiftManager; import com.cloud.test.IPRangeConfig; import com.cloud.user.Account; import com.cloud.user.AccountManager; +import com.cloud.user.AccountVO; import com.cloud.user.ResourceLimitService; import com.cloud.user.User; import com.cloud.user.UserContext; @@ -2178,23 +2179,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (forVirtualNetwork) { if (vlanOwner != null) { - // verify resource limits - //long ipResourceLimit = _resourceLimitMgr.findCorrectResourceLimitForAccount(vlanOwner, ResourceType.public_ip); - + long accountIpRange = NetUtils.ip2Long(endIP) - NetUtils.ip2Long(startIP) + 1; //check resource limits _resourceLimitMgr.checkResourceLimit(vlanOwner, ResourceType.public_ip, accountIpRange); -// if (s_logger.isDebugEnabled()) { -// s_logger.debug(" IPResourceLimit " + ipResourceLimit + " accountIpRange " + accountIpRange); -// } -// if (ipResourceLimit != -1 && accountIpRange > ipResourceLimit) { // -1 -// // means -// // infinite -// throw new InvalidParameterValueException(" Public IP Resource Limit is set to " + ipResourceLimit + -// " which is less than the IP range of " + accountIpRange + " provided"); -// } associateIpRangeToAccount = true; } } @@ -2204,7 +2194,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Transaction txn = Transaction.currentTxn(); txn.start(); - Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner); + Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, + endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner); if (associateIpRangeToAccount) { _networkMgr.associateIpAddressListToAccount(userId, vlanOwner.getId(), zoneId, vlan.getId(), null); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index fca654eb57c..8a39778ae7b 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -3095,6 +3095,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return false; } } + + //In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network + DataCenter zone = _configMgr.getZone(network.getDataCenterId()); + if (zone.getNetworkType() == NetworkType.Basic) { + List systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), + Type.ConsoleProxy, Type.SecondaryStorageVm); + if (systemVms != null && !systemVms.isEmpty()) { + s_logger.warn("Can't delete the network, not all consoleProxy/secondaryStorage vms are expunged"); + return false; + } + } // Shutdown network first shutdownNetwork(networkId, context, false); diff --git a/server/src/com/cloud/vm/dao/VMInstanceDao.java b/server/src/com/cloud/vm/dao/VMInstanceDao.java index 27c568d9ba7..e9a6daeb4e2 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDao.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDao.java @@ -92,5 +92,8 @@ public interface VMInstanceDao extends GenericDao, StateDao< List listHostIdsByVmCount(long dcId, Long podId, Long clusterId, long accountId); - Long countRunningByAccount(long accountId); + Long countRunningByAccount(long accountId); + + List listNonRemovedVmsByTypeAndNetwork(long networkId, VirtualMachine.Type... types); + } diff --git a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java index ea890061e17..5d4be394573 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -33,6 +33,7 @@ import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.db.Attribute; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; @@ -41,6 +42,8 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.Transaction; import com.cloud.utils.db.UpdateBuilder; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NicVO; +import com.cloud.vm.UserVmVO; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Event; @@ -68,16 +71,20 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem protected final GenericSearchBuilder CountVirtualRoutersByAccount; protected GenericSearchBuilder CountRunningByHost; protected GenericSearchBuilder CountRunningByAccount; + protected SearchBuilder NetworkTypeSearch; protected final Attribute _updateTimeAttr; - private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1 = "SELECT host.cluster_id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE "; - private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2 = " AND host.type = 'Routing' GROUP BY host.cluster_id ORDER BY 2 ASC "; + private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1 = + "SELECT host.cluster_id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE "; + private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2 = + " AND host.type = 'Routing' GROUP BY host.cluster_id ORDER BY 2 ASC "; private static final String ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT = "SELECT pod.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host_pod_ref` pod LEFT JOIN `cloud`.`vm_instance` vm ON pod.id = vm.pod_id WHERE pod.data_center_id = ? " + " GROUP BY pod.id ORDER BY 2 ASC "; - private static final String ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT = "SELECT host.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE host.data_center_id = ? " + + private static final String ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT = + "SELECT host.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE host.data_center_id = ? " + " AND host.pod_id = ? AND host.cluster_id = ? AND host.type = 'Routing' " + " GROUP BY host.id ORDER BY 2 ASC "; @@ -514,5 +521,30 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem sc.setParameters("account", accountId); sc.setParameters("state", State.Running); return customSearch(sc, null).get(0); - } + } + + @Override + public List listNonRemovedVmsByTypeAndNetwork(long networkId, VirtualMachine.Type... types) { + if (NetworkTypeSearch == null) { + NicDao _nicDao = ComponentLocator.getLocator("management-server").getDao(NicDao.class); + SearchBuilder nicSearch = _nicDao.createSearchBuilder(); + nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + nicSearch.and("ip4Address", nicSearch.entity().getIp4Address(), SearchCriteria.Op.NNULL); + + NetworkTypeSearch = createSearchBuilder(); + NetworkTypeSearch.and("types", NetworkTypeSearch.entity().getType(), SearchCriteria.Op.IN); + NetworkTypeSearch.and("removed", NetworkTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL); + NetworkTypeSearch.join("nicSearch", nicSearch, NetworkTypeSearch.entity().getId(), + nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + NetworkTypeSearch.done(); + } + + SearchCriteria sc = NetworkTypeSearch.create(); + if (types != null && types.length != 0) { + sc.setParameters("types", (Object[]) types); + } + sc.setJoinParameters("nicSearch", "networkId", networkId); + + return listBy(sc); + } } diff --git a/ui/index.jsp b/ui/index.jsp index f8fc4615cc6..89f39cd75a2 100644 --- a/ui/index.jsp +++ b/ui/index.jsp @@ -1652,6 +1652,10 @@