Search in sources :

Example 1 with ShutDownVpcVspCommand

use of com.cloud.agent.api.element.ShutDownVpcVspCommand in project cloudstack by apache.

the class NuageVspResourceTest method testShutDownVpcVspCommand.

@Test
public void testShutDownVpcVspCommand() throws Exception {
    _resource.configure("NuageVspResource", _hostDetails);
    ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand("domainUuid", "vpcUuid", "domainTemplateName", Lists.<String>newArrayList());
    Answer shutVpcAns = _resource.executeRequest(cmd);
    assertTrue(shutVpcAns.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) ShutDownVpcVspCommand(com.cloud.agent.api.element.ShutDownVpcVspCommand) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 2 with ShutDownVpcVspCommand

use of com.cloud.agent.api.element.ShutDownVpcVspCommand in project cloudstack by apache.

the class NuageVspElement method shutdownVpc.

@Override
public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
    if (vpc.getState().equals(Vpc.State.Inactive)) {
        List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
        if (CollectionUtils.isEmpty(routers)) {
            routers = _routerDao.listIncludingRemovedByVpcId(vpc.getId());
        }
        List<String> domainRouterUuids = Lists.transform(routers, new Function<DomainRouterVO, String>() {

            @Nullable
            @Override
            public String apply(@Nullable DomainRouterVO input) {
                return input != null ? input.getUuid() : null;
            }
        });
        Domain vpcDomain = _domainDao.findById(vpc.getDomainId());
        HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(getPhysicalNetworkId(vpc.getZoneId()));
        String preConfiguredDomainTemplateName;
        VpcDetailVO domainTemplateNameDetail = _vpcDetailsDao.findDetail(vpc.getId(), NuageVspManager.nuageDomainTemplateDetailName);
        if (domainTemplateNameDetail != null) {
            preConfiguredDomainTemplateName = domainTemplateNameDetail.getValue();
        } else {
            preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key());
        }
        ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand(vpcDomain.getUuid(), vpc.getUuid(), preConfiguredDomainTemplateName, domainRouterUuids);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("ShutDownVpcVspCommand for VPC " + vpc.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
            if ((null != answer) && (null != answer.getDetails())) {
                throw new ResourceUnavailableException(answer.getDetails(), Vpc.class, vpc.getId());
            }
        }
    }
    return true;
}
Also used : HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ShutDownVpcVspCommand(com.cloud.agent.api.element.ShutDownVpcVspCommand) Domain(com.cloud.domain.Domain) DomainRouterVO(com.cloud.vm.DomainRouterVO) Nullable(javax.annotation.Nullable) VpcDetailVO(org.apache.cloudstack.resourcedetail.VpcDetailVO)

Aggregations

Answer (com.cloud.agent.api.Answer)2 ShutDownVpcVspCommand (com.cloud.agent.api.element.ShutDownVpcVspCommand)2 NuageTest (com.cloud.NuageTest)1 Domain (com.cloud.domain.Domain)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 HostVO (com.cloud.host.HostVO)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1 Nullable (javax.annotation.Nullable)1 VpcDetailVO (org.apache.cloudstack.resourcedetail.VpcDetailVO)1 Test (org.junit.Test)1