use of net.nuage.vsp.acs.client.api.model.VspDomain 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 net.nuage.vsp.acs.client.api.model.VspDomain in project cloudstack by apache.
the class NuageVspGuestNetworkGuru method updateDhcpOptionsForExistingVms.
private void updateDhcpOptionsForExistingVms(Network network, HostVO nuageVspHost, VspNetwork vspNetwork, boolean networkHasDns, Map<Long, Boolean> networkHasDnsCache) throws InsufficientVirtualNetworkCapacityException {
// Update dhcp options if a VR is added when we are not initiating the network
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("DomainRouter is added to an existing network: %s in state: %s", network.getName(), network.getState()));
}
List<NicVO> userNics = _nicDao.listByNetworkId(network.getId());
LinkedListMultimap<Long, VspDhcpVMOption> dhcpOptionsPerDomain = LinkedListMultimap.create();
for (NicVO userNic : userNics) {
if (userNic.getVmType() == VirtualMachine.Type.DomainRouter) {
continue;
}
VMInstanceVO userVm = _vmInstanceDao.findById(userNic.getInstanceId());
boolean defaultHasDns = getDefaultHasDns(networkHasDnsCache, userNic);
VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(userNic, defaultHasDns, networkHasDns);
dhcpOptionsPerDomain.put(userVm.getDomainId(), dhcpOption);
}
for (Long domainId : dhcpOptionsPerDomain.keySet()) {
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(_domainDao.findById(domainId));
VspNetwork vspNetworkForDomain = new VspNetwork.Builder().fromObject(vspNetwork).domain(vspDomain).build();
List<VspDhcpVMOption> dhcpOptions = dhcpOptionsPerDomain.get(domainId);
UpdateDhcpOptionVspCommand cmd = new UpdateDhcpOptionVspCommand(dhcpOptions, vspNetworkForDomain);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("UpdateDhcpOptionVspCommand failed at \"reserve\" for network " + vspNetwork.getName() + " under domain " + vspNetwork.getVspDomain().getName());
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
}
}
}
use of net.nuage.vsp.acs.client.api.model.VspDomain in project cloudstack by apache.
the class NuageVspEntityBuilderTest method testBuildVspDomain.
@Test
public void testBuildVspDomain() {
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(_mockedDomain);
validateVspDomain(vspDomain);
}
use of net.nuage.vsp.acs.client.api.model.VspDomain in project cloudstack by apache.
the class NuageVspManagerImpl method auditDomainsOnVsp.
private boolean auditDomainsOnVsp(HostVO host, boolean add) {
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
if (CollectionUtils.isEmpty(nuageVspDevices)) {
return true;
}
final SyncDomainCommand.Type action = add ? SyncDomainCommand.Type.ADD : SyncDomainCommand.Type.REMOVE;
_hostDao.loadDetails(host);
List<DomainVO> allDomains = _domainDao.listAll();
for (DomainVO domain : allDomains) {
if (action == SyncDomainCommand.Type.REMOVE) {
VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
Answer answer = _agentMgr.easySend(host.getId(), cmd);
if (!answer.getResult()) {
return false;
}
}
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, action);
Answer answer = _agentMgr.easySend(host.getId(), cmd);
if (!answer.getResult()) {
return false;
}
}
return true;
}
use of net.nuage.vsp.acs.client.api.model.VspDomain in project cloudstack by apache.
the class NuageVspManagerImpl method initMessageBusListeners.
@DB
private void initMessageBusListeners() {
// Create corresponding enterprise and profile in VSP when creating a CS Domain
_messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, new MessageSubscriber() {
@Override
public void onPublishMessage(String senderAddress, String subject, Object args) {
Long domainId = (Long) args;
Domain domain = _domainDao.findById(domainId);
try {
_domainDao.acquireInLockTable(domain.getId());
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.ADD);
_agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
}
} finally {
_domainDao.releaseFromLockTable(domain.getId());
}
}
});
// Clean up corresponding resources in VSP when deleting a CS Domain
_messageBus.subscribe(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {
@Override
public void onPublishMessage(String senderAddress, String subject, Object args) {
DomainVO domain = (DomainVO) args;
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
_agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
}
}
});
// Delete corresponding enterprise and profile in VSP when deleting a CS Domain
_messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {
@Override
public void onPublishMessage(String senderAddress, String subject, Object args) {
DomainVO domain = (DomainVO) args;
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
SyncDomainCommand syncCmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.REMOVE);
_agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
}
}
});
}
Aggregations