Search in sources :

Example 1 with HostVO

use of com.cloud.host.HostVO 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 2 with HostVO

use of com.cloud.host.HostVO 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 3 with HostVO

use of com.cloud.host.HostVO 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;
}
Also used : Answer(com.cloud.agent.api.Answer) ApplyStaticNatVspCommand(com.cloud.agent.api.element.ApplyStaticNatVspCommand) ArrayList(java.util.ArrayList) VspStaticNat(net.nuage.vsp.acs.client.api.model.VspStaticNat) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO) VspStaticNat(net.nuage.vsp.acs.client.api.model.VspStaticNat) StaticNat(com.cloud.network.rules.StaticNat)

Example 4 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class NuageVspElement method applyACLRules.

protected boolean applyACLRules(final Network network, List<? extends InternalIdentity> rules, boolean isNetworkAcl, boolean networkReset) throws ResourceUnavailableException {
    VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
    List<VspAclRule> vspAclRules = Lists.transform(rules, new Function<InternalIdentity, VspAclRule>() {

        @Nullable
        @Override
        public VspAclRule apply(@Nullable InternalIdentity input) {
            if (input instanceof FirewallRule) {
                return _nuageVspEntityBuilder.buildVspAclRule((FirewallRule) input, network);
            }
            return _nuageVspEntityBuilder.buildVspAclRule((NetworkACLItem) input);
        }
    });
    HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
    VspAclRule.ACLType vspAclType = isNetworkAcl ? VspAclRule.ACLType.NetworkACL : VspAclRule.ACLType.Firewall;
    ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(vspAclType, vspNetwork, vspAclRules, networkReset);
    Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
        if ((null != answer) && (null != answer.getDetails())) {
            throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
        }
    }
    return true;
}
Also used : HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ApplyAclRuleVspCommand(com.cloud.agent.api.element.ApplyAclRuleVspCommand) VspAclRule(net.nuage.vsp.acs.client.api.model.VspAclRule) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) InternalIdentity(org.apache.cloudstack.api.InternalIdentity) FirewallRule(com.cloud.network.rules.FirewallRule) Nullable(javax.annotation.Nullable)

Example 5 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class NuageVspElement method implement.

@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Entering NuageElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
    }
    if (network.getVpcId() != null) {
        return applyACLRulesForVpc(network, offering);
    }
    if (!canHandle(network, offering, Service.Connectivity)) {
        return false;
    }
    if (network.getBroadcastUri() == null) {
        s_logger.error("Nic has no broadcast Uri with the virtual router IP");
        return false;
    }
    VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
    List<VspAclRule> ingressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Ingress);
    List<VspAclRule> egressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Egress);
    List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
    List<String> floatingIpUuids = new ArrayList<String>();
    for (IPAddressVO ip : ips) {
        floatingIpUuids.add(ip.getUuid());
    }
    VspDhcpDomainOption vspDhcpOptions = _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering);
    HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
    ImplementVspCommand cmd = new ImplementVspCommand(vspNetwork, ingressFirewallRules, egressFirewallRules, floatingIpUuids, vspDhcpOptions);
    Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
        if ((null != answer) && (null != answer.getDetails())) {
            throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) VspDhcpDomainOption(net.nuage.vsp.acs.client.api.model.VspDhcpDomainOption) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) VspAclRule(net.nuage.vsp.acs.client.api.model.VspAclRule) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) ImplementVspCommand(com.cloud.agent.api.element.ImplementVspCommand) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46