Search in sources :

Example 76 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class F5ExternalLoadBalancerElement method listExternalLoadBalancers.

@Override
@Deprecated
public List<Host> listExternalLoadBalancers(ListExternalLoadBalancersCmd cmd) {
    Long zoneId = cmd.getZoneId();
    DataCenterVO zone = null;
    PhysicalNetworkVO pNetwork = null;
    if (zoneId != null) {
        zone = _dcDao.findById(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
        }
        List<PhysicalNetworkVO> physicalNetworks = _physicalNetworkDao.listByZone(zoneId);
        if ((physicalNetworks == null) || (physicalNetworks.size() > 1)) {
            throw new InvalidParameterValueException("There are no physical networks or multiple physical networks configured in zone with ID: " + zoneId + " to add this device.");
        }
        pNetwork = physicalNetworks.get(0);
        return listExternalLoadBalancers(pNetwork.getId(), NetworkDevice.F5BigIpLoadBalancer.getName());
    } else {
        throw new InvalidParameterValueException("Zone Id must be specified to list the external load balancers");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 77 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class JuniperSRXExternalFirewallElement method listExternalFirewalls.

@Override
@Deprecated
public List<Host> listExternalFirewalls(ListExternalFirewallsCmd cmd) {
    List<Host> firewallHosts = new ArrayList<Host>();
    Long zoneId = cmd.getZoneId();
    DataCenterVO zone = null;
    PhysicalNetworkVO pNetwork = null;
    if (zoneId != null) {
        zone = _dcDao.findById(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
        }
        List<PhysicalNetworkVO> physicalNetworks = _physicalNetworkDao.listByZone(zoneId);
        if ((physicalNetworks == null) || (physicalNetworks.size() > 1)) {
            throw new InvalidParameterValueException("There are no physical networks or multiple physical networks configured in zone with ID: " + zoneId + " to add this device.");
        }
        pNetwork = physicalNetworks.get(0);
    }
    firewallHosts.addAll(listExternalFirewalls(pNetwork.getId(), NetworkDevice.JuniperSRXFirewall.getName()));
    return firewallHosts;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Host(com.cloud.host.Host)

Example 78 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class VxlanGuestNetworkGuruTest method setUp.

@Before
public void setUp() {
    guru = spy(new VxlanGuestNetworkGuru());
    ((GuestNetworkGuru) guru)._physicalNetworkDao = physnetdao;
    guru._physicalNetworkDao = physnetdao;
    guru._dcDao = dcdao;
    guru._networkModel = netmodel;
    guru._networkDao = netdao;
    ((GuestNetworkGuru) guru)._configServer = confsvr;
    DataCenterVO dc = mock(DataCenterVO.class);
    when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(dc.getGuestNetworkCidr()).thenReturn("10.1.1.1/24");
    when(dcdao.findById(anyLong())).thenReturn(dc);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Before(org.junit.Before)

Example 79 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class ConfigurationManagerImpl method createZone.

@Override
@DB
public DataCenterVO createZone(final long userId, final String zoneName, final String dns1, final String dns2, final String internalDns1, final String internalDns2, final String guestCidr, final String domain, final Long domainId, final NetworkType zoneType, final String allocationStateStr, final String networkDomain, final boolean isSecurityGroupEnabled, final boolean isLocalStorageEnabled, final String ip6Dns1, final String ip6Dns2) {
    // hence the method below is generic to check for common params
    if (guestCidr != null && !NetUtils.validateGuestCidr(guestCidr)) {
        throw new InvalidParameterValueException("Please enter a valid guest cidr");
    }
    // Validate network domain
    if (networkDomain != null) {
        if (!NetUtils.verifyDomainName(networkDomain)) {
            throw new InvalidParameterValueException("Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + "and the hyphen ('-'); can't start or end with \"-\"");
        }
    }
    checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr, ip6Dns1, ip6Dns2);
    final byte[] bytes = (zoneName + System.currentTimeMillis()).getBytes();
    final String zoneToken = UUID.nameUUIDFromBytes(bytes).toString();
    // Create the new zone in the database
    final DataCenterVO zoneFinal = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, domain, domainId, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2);
    if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
        final Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
        zoneFinal.setAllocationState(allocationState);
    } else {
        // Zone will be disabled since 3.0. Admin should enable it after
        // physical network and providers setup.
        zoneFinal.setAllocationState(Grouping.AllocationState.Disabled);
    }
    return Transaction.execute(new TransactionCallback<DataCenterVO>() {

        @Override
        public DataCenterVO doInTransaction(final TransactionStatus status) {
            final DataCenterVO zone = _zoneDao.persist(zoneFinal);
            CallContext.current().putContextParameter(DataCenter.class, zone.getUuid());
            if (domainId != null) {
                // zone is explicitly dedicated to this domain
                // create affinity group associated and dedicate the zone.
                final AffinityGroup group = createDedicatedAffinityGroup(null, domainId, null);
                final DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null, group.getId());
                _dedicatedDao.persist(dedicatedResource);
            }
            // Create default system networks
            createDefaultSystemNetworks(zone.getId());
            return zone;
        }
    });
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AllocationState(com.cloud.org.Grouping.AllocationState) TransactionStatus(com.cloud.utils.db.TransactionStatus) Grouping(com.cloud.org.Grouping) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup) DB(com.cloud.utils.db.DB)

Example 80 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class ConfigurationManagerImpl method createVlanAndPublicIpRange.

@Override
@DB
public Vlan createVlanAndPublicIpRange(final long zoneId, final long networkId, final long physicalNetworkId, final boolean forVirtualNetwork, final Long podId, final String startIP, final String endIP, final String vlanGateway, final String vlanNetmask, String vlanId, Domain domain, final Account vlanOwner, final String startIPv6, final String endIPv6, final String vlanIp6Gateway, final String vlanIp6Cidr) {
    final Network network = _networkModel.getNetwork(networkId);
    boolean ipv4 = false, ipv6 = false;
    if (startIP != null) {
        ipv4 = true;
    }
    if (startIPv6 != null) {
        ipv6 = true;
    }
    if (!ipv4 && !ipv6) {
        throw new InvalidParameterValueException("Please specify IPv4 or IPv6 address.");
    }
    // Validate the zone
    final DataCenterVO zone = _zoneDao.findById(zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Please specify a valid zone.");
    }
    // ACL check
    checkZoneAccess(CallContext.current().getCallingAccount(), zone);
    // Validate the physical network
    if (_physicalNetworkDao.findById(physicalNetworkId) == null) {
        throw new InvalidParameterValueException("Please specify a valid physical network id");
    }
    // Validate the pod
    if (podId != null) {
        final Pod pod = _podDao.findById(podId);
        if (pod == null) {
            throw new InvalidParameterValueException("Please specify a valid pod.");
        }
        if (pod.getDataCenterId() != zoneId) {
            throw new InvalidParameterValueException("Pod id=" + podId + " doesn't belong to zone id=" + zoneId);
        }
        // pod vlans can be created in basic zone only
        if (zone.getNetworkType() != NetworkType.Basic || network.getTrafficType() != TrafficType.Guest) {
            throw new InvalidParameterValueException("Pod id can be specified only for the networks of type " + TrafficType.Guest + " in zone of type " + NetworkType.Basic);
        }
    }
    // 2) if vlan is missing, default it to the guest network's vlan
    if (network.getTrafficType() == TrafficType.Guest) {
        String networkVlanId = null;
        boolean connectivityWithoutVlan = false;
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Connectivity)) {
            Map<Capability, String> connectivityCapabilities = _networkModel.getNetworkServiceCapabilities(network.getId(), Service.Connectivity);
            connectivityWithoutVlan = MapUtils.isNotEmpty(connectivityCapabilities) && connectivityCapabilities.containsKey(Capability.NoVlan);
        }
        final URI uri = network.getBroadcastUri();
        if (connectivityWithoutVlan) {
            networkVlanId = network.getBroadcastDomainType().toUri(network.getUuid()).toString();
        } else if (uri != null) {
            // Do not search for the VLAN tag when the network doesn't support VLAN
            if (uri.toString().startsWith("vlan")) {
                final String[] vlan = uri.toString().split("vlan:\\/\\/");
                networkVlanId = vlan[1];
                // For pvlan
                networkVlanId = networkVlanId.split("-")[0];
            }
        }
        if (vlanId != null && !connectivityWithoutVlan) {
            // network's vlanId
            if (networkVlanId != null && !NetUtils.isSameIsolationId(networkVlanId, vlanId)) {
                throw new InvalidParameterValueException("Vlan doesn't match vlan of the network");
            }
        } else {
            vlanId = networkVlanId;
        }
    } else if (network.getTrafficType() == TrafficType.Public && vlanId == null) {
        throw new InvalidParameterValueException("Unable to determine vlan id or untagged vlan for public network");
    }
    if (vlanId == null) {
        vlanId = Vlan.UNTAGGED;
    }
    final VlanType vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached;
    if ((domain != null || vlanOwner != null) && zone.getNetworkType() != NetworkType.Advanced) {
        throw new InvalidParameterValueException("Vlan owner can be defined only in the zone of type " + NetworkType.Advanced);
    }
    if (ipv4) {
        // Make sure the gateway is valid
        if (!NetUtils.isValidIp(vlanGateway)) {
            throw new InvalidParameterValueException("Please specify a valid gateway");
        }
        // Make sure the netmask is valid
        if (!NetUtils.isValidNetmask(vlanNetmask)) {
            throw new InvalidParameterValueException("Please specify a valid netmask");
        }
    }
    if (ipv6) {
        if (!NetUtils.isValidIpv6(vlanIp6Gateway)) {
            throw new InvalidParameterValueException("Please specify a valid IPv6 gateway");
        }
        if (!NetUtils.isValidIp6Cidr(vlanIp6Cidr)) {
            throw new InvalidParameterValueException("Please specify a valid IPv6 CIDR");
        }
    }
    if (ipv4) {
        final String newCidr = NetUtils.getCidrFromGatewayAndNetmask(vlanGateway, vlanNetmask);
        //Make sure start and end ips are with in the range of cidr calculated for this gateway and netmask {
        if (!NetUtils.isIpWithtInCidrRange(vlanGateway, newCidr) || !NetUtils.isIpWithtInCidrRange(startIP, newCidr) || !NetUtils.isIpWithtInCidrRange(endIP, newCidr)) {
            throw new InvalidParameterValueException("Please specify a valid IP range or valid netmask or valid gateway");
        }
        // Check if the new VLAN's subnet conflicts with the guest network
        // in
        // the specified zone (guestCidr is null for basic zone)
        // when adding shared network with same cidr of zone guest cidr,
        // if the specified vlan is not present in zone, physical network, allow to create the network as the isolation is based on VLAN.
        final String guestNetworkCidr = zone.getGuestNetworkCidr();
        if (guestNetworkCidr != null && NetUtils.isNetworksOverlap(newCidr, guestNetworkCidr) && _zoneDao.findVnet(zoneId, physicalNetworkId, vlanId).isEmpty() != true) {
            throw new InvalidParameterValueException("The new IP range you have specified has  overlapped with the guest network in zone: " + zone.getName() + "along with existing Vlan also. Please specify a different gateway/netmask");
        }
        // Check if there are any errors with the IP range
        checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP);
        checkConflictsWithPortableIpRange(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP);
        // Throw an exception if this subnet overlaps with subnet on other VLAN,
        // if this is ip range extension, gateway, network mask should be same and ip range should not overlap
        final List<VlanVO> vlans = _vlanDao.listByZone(zone.getId());
        for (final VlanVO vlan : vlans) {
            final String otherVlanGateway = vlan.getVlanGateway();
            final String otherVlanNetmask = vlan.getVlanNetmask();
            // Continue if it's not IPv4
            if (otherVlanGateway == null || otherVlanNetmask == null) {
                continue;
            }
            if (vlan.getNetworkId() == null) {
                continue;
            }
            final String otherCidr = NetUtils.getCidrFromGatewayAndNetmask(otherVlanGateway, otherVlanNetmask);
            if (!NetUtils.isNetworksOverlap(newCidr, otherCidr)) {
                continue;
            }
            // from here, subnet overlaps
            if (!vlanId.equals(vlan.getVlanTag())) {
                boolean overlapped = false;
                if (network.getTrafficType() == TrafficType.Public) {
                    overlapped = true;
                } else {
                    final Long nwId = vlan.getNetworkId();
                    if (nwId != null) {
                        final Network nw = _networkModel.getNetwork(nwId);
                        if (nw != null && nw.getTrafficType() == TrafficType.Public) {
                            overlapped = true;
                        }
                    }
                }
                if (overlapped) {
                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() + " has overlapped with the subnet. Please specify a different gateway/netmask.");
                }
            } else {
                final String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
                final String otherVlanStartIP = otherVlanIpRange[0];
                String otherVlanEndIP = null;
                if (otherVlanIpRange.length > 1) {
                    otherVlanEndIP = otherVlanIpRange[1];
                }
                // extend IP range
                if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) {
                    throw new InvalidParameterValueException("The IP range has already been added with gateway " + otherVlanGateway + " ,and netmask " + otherVlanNetmask + ", Please specify the gateway/netmask if you want to extend ip range");
                }
                if (!NetUtils.is31PrefixCidr(newCidr)) {
                    if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
                        throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + " Please specify a different start IP/end IP.");
                    }
                }
            }
        }
    }
    String ipv6Range = null;
    if (ipv6) {
        ipv6Range = startIPv6;
        if (endIPv6 != null) {
            ipv6Range += "-" + endIPv6;
        }
        final List<VlanVO> vlans = _vlanDao.listByZone(zone.getId());
        for (final VlanVO vlan : vlans) {
            if (vlan.getIp6Gateway() == null) {
                continue;
            }
            if (NetUtils.isSameIsolationId(vlanId, vlan.getVlanTag())) {
                if (NetUtils.isIp6RangeOverlap(ipv6Range, vlan.getIp6Range())) {
                    throw new InvalidParameterValueException("The IPv6 range with tag: " + vlan.getVlanTag() + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
                }
                if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) {
                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + vlan.getIp6Gateway() + ". Please specify a different tag.");
                }
            }
        }
    }
    // Check if the vlan is being used
    if (_zoneDao.findVnet(zoneId, physicalNetworkId, vlanId).size() > 0) {
        throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone " + zone.getName());
    }
    String ipRange = null;
    if (ipv4) {
        ipRange = startIP;
        if (endIP != null) {
            ipRange += "-" + endIP;
        }
    }
    // Everything was fine, so persist the VLAN
    final VlanVO vlan = commitVlanAndIpRange(zoneId, networkId, physicalNetworkId, podId, startIP, endIP, vlanGateway, vlanNetmask, vlanId, domain, vlanOwner, vlanIp6Gateway, vlanIp6Cidr, ipv4, zone, vlanType, ipv6Range, ipRange);
    return vlan;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Pod(com.cloud.dc.Pod) Capability(com.cloud.network.Network.Capability) URI(java.net.URI) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VlanVO(com.cloud.dc.VlanVO) VlanType(com.cloud.dc.Vlan.VlanType) DB(com.cloud.utils.db.DB)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)214 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)53 HostVO (com.cloud.host.HostVO)42 Account (com.cloud.user.Account)37 NetworkVO (com.cloud.network.dao.NetworkVO)35 DomainRouterVO (com.cloud.vm.DomainRouterVO)33 HostPodVO (com.cloud.dc.HostPodVO)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 ClusterVO (com.cloud.dc.ClusterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 DB (com.cloud.utils.db.DB)26 Network (com.cloud.network.Network)25 HashMap (java.util.HashMap)25 ConfigurationException (javax.naming.ConfigurationException)25 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)20 Test (org.junit.Test)20 NicProfile (com.cloud.vm.NicProfile)19 ActionEvent (com.cloud.event.ActionEvent)18