Search in sources :

Example 1 with BroadcastDomainType

use of com.cloud.model.enumeration.BroadcastDomainType in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method createDefaultSystemNetworks.

@Override
public void createDefaultSystemNetworks(final long zoneId) throws ConcurrentOperationException {
    final DataCenterVO zone = _zoneDao.findById(zoneId);
    final String networkDomain = null;
    // the zone creation
    if (zone != null) {
        final List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
        for (final NetworkOfferingVO offering : ntwkOff) {
            final DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null, null);
            final NetworkVO userNetwork = new NetworkVO();
            final Account systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
            BroadcastDomainType broadcastDomainType = null;
            if (offering.getTrafficType() == TrafficType.Management) {
                broadcastDomainType = BroadcastDomainType.Native;
            } else if (offering.getTrafficType() == TrafficType.Control) {
                broadcastDomainType = BroadcastDomainType.LinkLocal;
            } else if (offering.getTrafficType() == TrafficType.Public) {
                if (zone.getNetworkType() == NetworkType.Advanced || zone.getNetworkType() == NetworkType.Basic) {
                    broadcastDomainType = BroadcastDomainType.Vlan;
                } else {
                    // so broadcastDomainType remains null! why have None/Undecided/UnKnown?
                    continue;
                }
            } else if (offering.getTrafficType() == TrafficType.Guest) {
                continue;
            }
            userNetwork.setBroadcastDomainType(broadcastDomainType);
            userNetwork.setNetworkDomain(networkDomain);
            _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, Domain.ROOT_DOMAIN, null, null, null, null, true, null, null, null, null, null);
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.legacymodel.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 2 with BroadcastDomainType

use of com.cloud.model.enumeration.BroadcastDomainType in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method createPrivateNetwork.

@Override
@DB
public Network createPrivateNetwork(final String networkName, final String displayText, final long physicalNetworkId, final String broadcastUriString, final String startIp, String endIp, final String gateway, final String netmask, final long networkOwnerId, final Long vpcId, final Boolean sourceNat, final Long networkOfferingId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    final Account owner = _accountMgr.getAccount(networkOwnerId);
    // Get system network offering
    NetworkOfferingVO ntwkOff = null;
    if (networkOfferingId != null) {
        ntwkOff = _networkOfferingDao.findById(networkOfferingId);
    }
    if (ntwkOff == null) {
        ntwkOff = findSystemNetworkOffering(NetworkOffering.DefaultPrivateGatewayNetworkOffering);
    }
    // Validate physical network
    final PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
    if (pNtwk == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a physical network" + " having the given id");
        ex.addProxyObject(String.valueOf(physicalNetworkId), "physicalNetworkId");
        throw ex;
    }
    // if end ip is not specified, default it to startIp
    if (!NetUtils.isValidIp4(startIp)) {
        throw new InvalidParameterValueException("Invalid format for the ip address parameter");
    }
    if (endIp == null) {
        endIp = startIp;
    } else if (!NetUtils.isValidIp4(endIp)) {
        throw new InvalidParameterValueException("Invalid format for the endIp address parameter");
    }
    if (!NetUtils.isValidIp4(gateway)) {
        throw new InvalidParameterValueException("Invalid gateway");
    }
    if (!NetUtils.isValidIp4Netmask(netmask)) {
        throw new InvalidParameterValueException("Invalid netmask");
    }
    final String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
    final URI uri = BroadcastDomainType.fromString(broadcastUriString);
    final String uriString = uri.toString();
    final BroadcastDomainType tiep = BroadcastDomainType.getSchemeValue(uri);
    // TODO make a test for any supported scheme
    if (!(tiep == BroadcastDomainType.Vlan || tiep == BroadcastDomainType.Lswitch)) {
        throw new InvalidParameterValueException("unsupported type of broadcastUri specified: " + broadcastUriString);
    }
    final NetworkOfferingVO ntwkOffFinal = ntwkOff;
    try {
        return Transaction.execute(new TransactionCallbackWithException<Network, Exception>() {

            @Override
            public Network doInTransaction(final TransactionStatus status) throws ResourceAllocationException, InsufficientCapacityException {
                // lock datacenter as we need to get mac address seq from there
                final DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true);
                // check if we need to create guest network
                Network privateNetwork = _networksDao.getPrivateNetwork(uriString, cidr, networkOwnerId, pNtwk.getDataCenterId(), networkOfferingId);
                if (privateNetwork == null) {
                    // create Guest network
                    privateNetwork = _networkMgr.createGuestNetwork(ntwkOffFinal.getId(), networkName, displayText, gateway, cidr, uriString, null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, vpcId, null, null, true, null, dc.getDns1(), dc.getDns2(), null, null, null);
                    if (privateNetwork != null) {
                        s_logger.debug("Successfully created guest network " + privateNetwork);
                    } else {
                        throw new CloudRuntimeException("Creating guest network failed");
                    }
                } else {
                    s_logger.debug("Private network already exists: " + privateNetwork);
                    // Do not allow multiple private gateways with same Vlan within a VPC
                    if (vpcId != null && vpcId.equals(privateNetwork.getVpcId())) {
                        throw new InvalidParameterValueException("Private network for the vlan: " + uriString + " and cidr  " + cidr + "  already exists " + "for Vpc " + vpcId + " in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
                    }
                }
                if (vpcId != null) {
                    // add entry to private_ip_address table
                    PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(), startIp, vpcId);
                    if (privateIp != null) {
                        throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" + " in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
                    }
                    final Long mac = dc.getMacAddress();
                    final Long nextMac = mac + 1;
                    dc.setMacAddress(nextMac);
                    privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac, vpcId, sourceNat);
                    _privateIpDao.persist(privateIp);
                    _dcDao.update(dc.getId(), dc);
                }
                s_logger.debug("Private network " + privateNetwork + " is created");
                return privateNetwork;
            }
        });
    } catch (final Exception e) {
        ExceptionUtil.rethrowRuntime(e);
        ExceptionUtil.rethrow(e, ResourceAllocationException.class);
        ExceptionUtil.rethrow(e, InsufficientCapacityException.class);
        throw new IllegalStateException(e);
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.legacymodel.user.Account) TransactionStatus(com.cloud.utils.db.TransactionStatus) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) URI(java.net.URI) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) SQLException(java.sql.SQLException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) UnknownHostException(java.net.UnknownHostException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Network(com.cloud.legacymodel.network.Network) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) DB(com.cloud.utils.db.DB)

Example 3 with BroadcastDomainType

use of com.cloud.model.enumeration.BroadcastDomainType in project cosmic by MissionCriticalCloud.

the class NetworksTest method vlanBroadcastDomainTypeTest.

@Test
public void vlanBroadcastDomainTypeTest() throws URISyntaxException {
    final String uri1 = "vlan://1";
    final Long value2 = 2L;
    final String uri2 = BroadcastDomainType.Vlan.toUri(value2).toString();
    final BroadcastDomainType type1 = BroadcastDomainType.getTypeOf(uri1);
    final String id1 = BroadcastDomainType.getValue(uri1);
    final String id2 = BroadcastDomainType.getValue(uri2);
    Assert.assertEquals("uri1 should be of broadcasttype vlan", BroadcastDomainType.Vlan, type1);
    Assert.assertEquals("id1 should be \"1\"", "1", id1);
    Assert.assertEquals("id2 should be \"2\"", "2", id2);
}
Also used : BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) Test(org.junit.Test)

Example 4 with BroadcastDomainType

use of com.cloud.model.enumeration.BroadcastDomainType in project cosmic by MissionCriticalCloud.

the class NetworksTest method otherTypesTest.

@Test
public void otherTypesTest() throws URISyntaxException {
    final String bogeyUri = "lswitch://0";
    final String uri1 = "lswitch:1";
    final String uri2 = "mido://2";
    BroadcastDomainType type = BroadcastDomainType.getTypeOf(bogeyUri);
    String id = BroadcastDomainType.getValue(bogeyUri);
    Assert.assertEquals("uri0 should be of broadcasttype vlan", BroadcastDomainType.Lswitch, type);
    Assert.assertEquals("id0 should be \"//0\"", "//0", id);
    type = BroadcastDomainType.getTypeOf(uri1);
    id = BroadcastDomainType.getValue(uri1);
    Assert.assertEquals("uri1 should be of broadcasttype vlan", BroadcastDomainType.Lswitch, type);
    Assert.assertEquals("id1 should be \"1\"", "1", id);
    type = BroadcastDomainType.getTypeOf(uri2);
    id = BroadcastDomainType.getValue(uri2);
    Assert.assertEquals("uri2 should be of broadcasttype vlan", BroadcastDomainType.Mido, type);
    Assert.assertEquals("id2 should be \"2\"", "2", id);
}
Also used : BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) Test(org.junit.Test)

Example 5 with BroadcastDomainType

use of com.cloud.model.enumeration.BroadcastDomainType in project cosmic by MissionCriticalCloud.

the class NetworksTest method vlanValueTest.

@Test
public void vlanValueTest() throws URISyntaxException {
    final String uri1 = "vlan://1";
    final String uri2 = "1";
    final String vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(uri1));
    Assert.assertEquals("vtag should be \"1\"", "1", vtag);
    final BroadcastDomainType tiep1 = BroadcastDomainType.getTypeOf(uri1);
    Assert.assertEquals("the type of uri1 should be 'Vlan'", BroadcastDomainType.Vlan, tiep1);
    final BroadcastDomainType tiep2 = BroadcastDomainType.getTypeOf(uri2);
    Assert.assertEquals("the type of uri1 should be 'Undecided'", BroadcastDomainType.UnDecided, tiep2);
    final BroadcastDomainType tiep3 = BroadcastDomainType.getTypeOf(Vlan.UNTAGGED);
    Assert.assertEquals("the type of uri1 should be 'vlan'", BroadcastDomainType.Native, tiep3);
}
Also used : BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) Test(org.junit.Test)

Aggregations

BroadcastDomainType (com.cloud.model.enumeration.BroadcastDomainType)11 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)5 Test (org.junit.Test)5 DataCenterVO (com.cloud.dc.DataCenterVO)3 Account (com.cloud.legacymodel.user.Account)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)3 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 URI (java.net.URI)2 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)1 HostVO (com.cloud.host.HostVO)1 CreateLogicalRouterAnswer (com.cloud.legacymodel.communication.answer.CreateLogicalRouterAnswer)1 CreateLogicalRouterCommand (com.cloud.legacymodel.communication.command.CreateLogicalRouterCommand)1 DataCenter (com.cloud.legacymodel.dc.DataCenter)1 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)1 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)1 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)1 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)1 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)1