Search in sources :

Example 1 with VspNetwork

use of net.nuage.vsp.acs.client.api.model.VspNetwork 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 VspNetwork

use of net.nuage.vsp.acs.client.api.model.VspNetwork in project cloudstack by apache.

the class NuageVspGuestNetworkGuru method trash.

@Override
public boolean trash(Network network, NetworkOffering offering) {
    long networkId = network.getId();
    network = _networkDao.acquireInLockTable(networkId, 1200);
    if (network == null) {
        throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    }
    try {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
        }
        VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
        HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
        TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(vspNetwork);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
            if ((null != answer) && (null != answer.getDetails())) {
                s_logger.error(answer.getDetails());
            }
            return false;
        }
    } finally {
        _networkDao.releaseFromLockTable(network.getId());
    }
    return super.trash(network, offering);
}
Also used : TrashNetworkVspCommand(com.cloud.agent.api.guru.TrashNetworkVspCommand) Answer(com.cloud.agent.api.Answer) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HostVO(com.cloud.host.HostVO)

Example 3 with VspNetwork

use of net.nuage.vsp.acs.client.api.model.VspNetwork in project cloudstack by apache.

the class NuageVspGuestNetworkGuru method deallocate.

@Override
@DB
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
    boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    if (lockedNetwork && s_logger.isDebugEnabled()) {
        s_logger.debug("Locked network " + network.getId() + " for deallocation of user VM " + vm.getInstanceName());
    }
    try {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Handling deallocate() call back, which is called when a VM is destroyed or interface is removed, " + "to delete VM Interface with IP " + nic.getIPv4Address() + " from a VM " + vm.getInstanceName() + " with state " + vm.getVirtualMachine().getState());
        }
        NicVO nicFromDb = _nicDao.findById(nic.getId());
        VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(vm.getVirtualMachine().getDomainId(), network);
        VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
        VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
        HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
        DeallocateVmVspCommand cmd = new DeallocateVmVspCommand(vspNetwork, vspVm, vspNic);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("DeallocateVmNuageVspCommand for VM " + vm.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
            if ((null != answer) && (null != answer.getDetails())) {
                s_logger.error(answer.getDetails());
            }
        }
        // because it is still allocated for the VR.
        if (vspNetwork.isShared() && VirtualMachine.Type.User.equals(vm.getType()) && nic.getIPv4Address().equals(vspNetwork.getVirtualRouterIp())) {
            nic.deallocate();
        } else {
            super.deallocate(network, nic, vm);
        }
    } finally {
        if (network != null && lockedNetwork) {
            _networkDao.releaseFromLockTable(network.getId());
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Unlocked network " + network.getId() + " for deallocation of user VM " + vm.getInstanceName());
            }
        }
    }
}
Also used : Answer(com.cloud.agent.api.Answer) DeallocateVmVspCommand(com.cloud.agent.api.guru.DeallocateVmVspCommand) VspVm(net.nuage.vsp.acs.client.api.model.VspVm) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) VspNic(net.nuage.vsp.acs.client.api.model.VspNic) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO) DB(com.cloud.utils.db.DB)

Example 4 with VspNetwork

use of net.nuage.vsp.acs.client.api.model.VspNetwork in project cloudstack by apache.

the class NuageVspGuestNetworkGuru method allocate.

@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    if (vm.getType() != VirtualMachine.Type.DomainRouter && _nuageVspEntityBuilder.usesVirtualRouter(network.getNetworkOfferingId())) {
        VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
        if (nic != null && nic.getRequestedIPv4() != null && vspNetwork.getVirtualRouterIp().equals(nic.getRequestedIPv4())) {
            DataCenter dc = _dcDao.findById(network.getDataCenterId());
            s_logger.error("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved for the VR in network " + network);
            throw new InsufficientVirtualNetworkCapacityException("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved " + "for the VR in network " + network, DataCenter.class, dc.getId());
        }
    }
    return super.allocate(network, nic, vm);
}
Also used : DataCenter(com.cloud.dc.DataCenter) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork)

Example 5 with VspNetwork

use of net.nuage.vsp.acs.client.api.model.VspNetwork 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)

Aggregations

VspNetwork (net.nuage.vsp.acs.client.api.model.VspNetwork)19 Answer (com.cloud.agent.api.Answer)14 Test (org.junit.Test)8 NuageTest (com.cloud.NuageTest)7 HostVO (com.cloud.host.HostVO)7 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 NicVO (com.cloud.vm.NicVO)4 VspAclRule (net.nuage.vsp.acs.client.api.model.VspAclRule)4 VspNic (net.nuage.vsp.acs.client.api.model.VspNic)4 VspStaticNat (net.nuage.vsp.acs.client.api.model.VspStaticNat)4 VspVm (net.nuage.vsp.acs.client.api.model.VspVm)4 ApplyAclRuleVspCommand (com.cloud.agent.api.element.ApplyAclRuleVspCommand)3 VlanVO (com.cloud.dc.VlanVO)3 IPAddressVO (com.cloud.network.dao.IPAddressVO)3 AccountVO (com.cloud.user.AccountVO)3 VspDhcpDomainOption (net.nuage.vsp.acs.client.api.model.VspDhcpDomainOption)3 VspDhcpVMOption (net.nuage.vsp.acs.client.api.model.VspDhcpVMOption)3 ApplyStaticNatVspCommand (com.cloud.agent.api.element.ApplyStaticNatVspCommand)2 DeallocateVmVspCommand (com.cloud.agent.api.guru.DeallocateVmVspCommand)2