Search in sources :

Example 1 with VspDomain

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();
}
Also used : VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) VspAddressRange(net.nuage.vsp.acs.client.api.model.VspAddressRange) AccountVO(com.cloud.user.AccountVO) DomainVO(com.cloud.domain.DomainVO) VpcVO(com.cloud.network.vpc.VpcVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) VlanVO(com.cloud.dc.VlanVO) Nullable(javax.annotation.Nullable) Pair(net.nuage.vsp.acs.client.common.model.Pair)

Example 2 with VspDomain

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());
        }
    }
}
Also used : VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) VMInstanceVO(com.cloud.vm.VMInstanceVO) UpdateDhcpOptionVspCommand(com.cloud.agent.api.guru.UpdateDhcpOptionVspCommand) Answer(com.cloud.agent.api.Answer) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) NicVO(com.cloud.vm.NicVO) VspDhcpVMOption(net.nuage.vsp.acs.client.api.model.VspDhcpVMOption)

Example 3 with VspDomain

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);
}
Also used : VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 4 with 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;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) DomainVO(com.cloud.domain.DomainVO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) CleanUpDomainCommand(com.cloud.agent.api.manager.CleanUpDomainCommand) VspDomainCleanUp(net.nuage.vsp.acs.client.api.model.VspDomainCleanUp) SyncDomainCommand(com.cloud.agent.api.sync.SyncDomainCommand)

Example 5 with VspDomain

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);
            }
        }
    });
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) MessageSubscriber(org.apache.cloudstack.framework.messagebus.MessageSubscriber) SyncDomainCommand(com.cloud.agent.api.sync.SyncDomainCommand) DomainVO(com.cloud.domain.DomainVO) CleanUpDomainCommand(com.cloud.agent.api.manager.CleanUpDomainCommand) VspDomainCleanUp(net.nuage.vsp.acs.client.api.model.VspDomainCleanUp) ArrayList(java.util.ArrayList) List(java.util.List) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) Domain(com.cloud.domain.Domain) DB(com.cloud.utils.db.DB)

Aggregations

VspDomain (net.nuage.vsp.acs.client.api.model.VspDomain)5 DomainVO (com.cloud.domain.DomainVO)3 Answer (com.cloud.agent.api.Answer)2 CleanUpDomainCommand (com.cloud.agent.api.manager.CleanUpDomainCommand)2 SyncDomainCommand (com.cloud.agent.api.sync.SyncDomainCommand)2 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)2 NuageVspDeviceVO (com.cloud.network.NuageVspDeviceVO)2 VspDomainCleanUp (net.nuage.vsp.acs.client.api.model.VspDomainCleanUp)2 VspNetwork (net.nuage.vsp.acs.client.api.model.VspNetwork)2 NuageTest (com.cloud.NuageTest)1 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 UpdateDhcpOptionVspCommand (com.cloud.agent.api.guru.UpdateDhcpOptionVspCommand)1 GetApiDefaultsAnswer (com.cloud.agent.api.manager.GetApiDefaultsAnswer)1 SyncNuageVspCmsIdAnswer (com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer)1 VlanVO (com.cloud.dc.VlanVO)1 Domain (com.cloud.domain.Domain)1 VpcVO (com.cloud.network.vpc.VpcVO)1 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)1 AccountVO (com.cloud.user.AccountVO)1 DB (com.cloud.utils.db.DB)1