use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class NuageVspEntityBuilder method buildVspNetwork.
public VspNetwork buildVspNetwork(long domainId, Network network) {
VspNetwork.Builder vspNetworkBuilder = new VspNetwork.Builder().id(network.getId()).uuid(network.getUuid()).name(network.getName()).cidr(network.getCidr()).gateway(network.getGateway());
DomainVO domain = _domainDao.findById(domainId);
VspDomain vspDomain = buildVspDomain(domain);
vspNetworkBuilder.domain(vspDomain);
AccountVO account = _accountDao.findById(network.getAccountId());
if (account != null) {
vspNetworkBuilder.accountUuid(account.getUuid()).accountName(account.getAccountName());
}
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
vspNetworkBuilder.egressDefaultPolicy(networkOffering.getEgressDefaultPolicy()).publicAccess(networkOffering.getSupportsPublicAccess());
if (network.getVpcId() != null) {
VpcVO vpc = _vpcDao.findById(network.getVpcId());
vspNetworkBuilder.vpcUuid(vpc.getUuid()).vpcName(vpc.getName()).networkType(VspNetwork.NetworkType.Vpc);
} else {
if (networkOffering.getGuestType() == Network.GuestType.Shared) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkIdIncludingRemoved(network.getId());
List<VspAddressRange> vspAddressRanges = Lists.transform(vlans, new Function<VlanVO, VspAddressRange>() {
@Nullable
@Override
public VspAddressRange apply(VlanVO vlanVO) {
return new VspAddressRange.Builder().gateway(vlanVO.getVlanGateway()).netmask(vlanVO.getVlanNetmask()).build();
}
});
vspNetworkBuilder.networkType(VspNetwork.NetworkType.Shared).addressRanges(vspAddressRanges);
} else if (_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.SourceNat) || _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.StaticNat)) {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L3);
} else {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L2);
}
}
boolean firewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.Firewall);
vspNetworkBuilder.firewallServiceSupported(firewallServiceSupported);
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configurationDao, _networkDetailsDao, network, networkOffering);
vspNetworkBuilder.domainTemplateName(preConfiguredDomainTemplateName);
if (usesVirtualRouter(networkOffering.getId())) {
try {
List<Pair<String, String>> ipAddressRanges = networkOffering.getGuestType() == Network.GuestType.Shared ? getSharedIpAddressRanges(network.getId()) : getIpAddressRanges(network);
String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
vspNetworkBuilder.virtualRouterIp(virtualRouterIp);
} catch (InsufficientVirtualNetworkCapacityException ex) {
s_logger.error("There is an insufficient network capacity in network " + network.getId(), ex);
throw new CloudRuntimeException("There is an insufficient network capacity in network " + network.getId(), ex);
}
}
return vspNetworkBuilder.build();
}
use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class NuageVspEntityBuilder method updateVspNetworkByPublicIp.
public VspNetwork updateVspNetworkByPublicIp(VspNetwork vspNetwork, Network network, String publicIp) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
final long ip = NetUtils.ip2Long(publicIp);
VlanVO matchingVlan = Iterables.find(vlans, new Predicate<VlanVO>() {
@Override
public boolean apply(@Nullable VlanVO vlan) {
Pair<String, String> ipAddressRange = getIpAddressRange(vlan);
long startIp = NetUtils.ip2Long(ipAddressRange.getLeft());
long endIp = NetUtils.ip2Long(ipAddressRange.getRight());
return startIp <= ip && ip <= endIp;
}
});
return new VspNetwork.Builder().fromObject(vspNetwork).gateway(matchingVlan.getVlanGateway()).cidr(NetUtils.getCidrFromGatewayAndNetmask(matchingVlan.getVlanGateway(), matchingVlan.getVlanNetmask())).build();
}
use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class NuageVspElement method applyStaticNats.
@Override
public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
List<VspStaticNat> vspStaticNatDetails = new ArrayList<VspStaticNat>();
for (StaticNat staticNat : rules) {
IPAddressVO sourceNatIp = _ipAddressDao.findById(staticNat.getSourceIpAddressId());
VlanVO sourceNatVlan = _vlanDao.findById(sourceNatIp.getVlanId());
checkVlanUnderlayCompatibility(sourceNatVlan);
NicVO nicVO = _nicDao.findByIp4AddressAndNetworkId(staticNat.getDestIpAddress(), staticNat.getNetworkId());
VspStaticNat vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(staticNat.isForRevoke(), sourceNatIp, sourceNatVlan, nicVO);
vspStaticNatDetails.add(vspStaticNat);
}
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(config);
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(config.getPhysicalNetworkId());
ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(vspNetwork, vspStaticNatDetails);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
}
}
return true;
}
use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class NuageVspEntityBuilder method getSharedIpAddressRanges.
private List<Pair<String, String>> getSharedIpAddressRanges(long networkId) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
List<Pair<String, String>> ipAddressRanges = Lists.newArrayList();
for (VlanVO vlan : vlans) {
Pair<String, String> ipAddressRange = getIpAddressRange(vlan);
if (ipAddressRange != null) {
ipAddressRanges.add(ipAddressRange);
}
}
return ipAddressRanges;
}
use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class NetworkModelImpl method isIP6AddressAvailableInNetwork.
@Override
public boolean isIP6AddressAvailableInNetwork(long networkId) {
Network network = _networksDao.findById(networkId);
if (network == null) {
return false;
}
if (network.getIp6Gateway() == null) {
return false;
}
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
for (Vlan vlan : vlans) {
if (isIP6AddressAvailableInVlan(vlan.getId())) {
return true;
}
}
return false;
}
Aggregations