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);
}
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations