@Override public NetworkVO getNetworkWithSecurityGroupEnabled(Long zoneId) { List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId); if (networks == null || networks.isEmpty()) { return null; } if (networks.size() > 1) { s_logger.debug("There are multiple network with security group enabled? select one of them..."); } return networks.get(0); }
@Override public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) { List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId); if (networks == null || networks.isEmpty()) { return null; } NetworkVO ret_network = null; for (NetworkVO nw : networks) { List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(nw.getId()); for (VlanVO vlan : vlans) { if (_ipAddressDao.countFreeIpsInVlan(vlan.getId()) > 0) { ret_network = nw; break; } } if (ret_network != null) { break; } } if (ret_network == null) { s_logger.debug("Can not find network with security group enabled with free IPs"); } return ret_network; }
/** * Get default network for a console proxy VM starting up in an advanced zone. If the zone * is security group-enabled, the first network found that supports SG services is returned. * If the zone is not SG-enabled, the Public network is returned. * @param dc - The zone. * @return The selected default network. * @throws CloudRuntimeException - If the zone is not a valid choice or a network couldn't be found. */ protected NetworkVO getDefaultNetworkForAdvancedZone(DataCenter dc) { if (dc.getNetworkType() != NetworkType.Advanced) { throw new CloudRuntimeException("Zone " + dc + " is not advanced."); } if (dc.isSecurityGroupEnabled()) { List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dc.getId()); if (CollectionUtils.isEmpty(networks)) { throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc); } return networks.get(0); } else { TrafficType defaultTrafficType = TrafficType.Public; List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dc.getId(), defaultTrafficType); // api should never allow this situation to happen if (defaultNetworks.size() != 1) { throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1"); } return defaultNetworks.get(0); } }
NetworkVO defaultPublicNetwork = null; if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) { List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId); if (networks == null || networks.size() == 0) { throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);