Search in sources :

Example 1 with DeallocateVmVspCommand

use of com.cloud.agent.api.guru.DeallocateVmVspCommand 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 2 with DeallocateVmVspCommand

use of com.cloud.agent.api.guru.DeallocateVmVspCommand in project cloudstack by apache.

the class NuageVspResourceTest method testDeallocateVmVspCommand.

@Test
public void testDeallocateVmVspCommand() throws Exception {
    _resource.configure("NuageVspResource", _hostDetails);
    VspNetwork vspNetwork = buildVspNetwork();
    VspVm vspVm = buildVspVm();
    VspNic vspNic = buildVspNic();
    DeallocateVmVspCommand cmd = new DeallocateVmVspCommand(vspNetwork, vspVm, vspNic);
    Answer dellocateVmAns = _resource.executeRequest(cmd);
    assertTrue(dellocateVmAns.getResult());
}
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) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Aggregations

Answer (com.cloud.agent.api.Answer)2 DeallocateVmVspCommand (com.cloud.agent.api.guru.DeallocateVmVspCommand)2 VspNetwork (net.nuage.vsp.acs.client.api.model.VspNetwork)2 VspNic (net.nuage.vsp.acs.client.api.model.VspNic)2 VspVm (net.nuage.vsp.acs.client.api.model.VspVm)2 NuageTest (com.cloud.NuageTest)1 HostVO (com.cloud.host.HostVO)1 DB (com.cloud.utils.db.DB)1 NicVO (com.cloud.vm.NicVO)1 Test (org.junit.Test)1