Search in sources :

Example 1 with DomainRouterResponse

use of org.apache.cloudstack.api.response.DomainRouterResponse in project cloudstack by apache.

the class StopNetScalerVMCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails("NetScaler vm Id: " + getId());
    VirtualRouter result = null;
    VirtualRouter vm = _routerService.findRouter(getId());
    if (vm == null || vm.getRole() != Role.NETSCALER_VM) {
        throw new InvalidParameterValueException("Can't find NetScaler lb vm by id");
    } else {
        result = _netsclarLbService.stopNetscalerServiceVm(getId(), isForced(), CallContext.current().getCallingAccount(), CallContext.current().getCallingUserId());
    }
    if (result != null) {
        DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop Netscaler vm");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 2 with DomainRouterResponse

use of org.apache.cloudstack.api.response.DomainRouterResponse in project cloudstack by apache.

the class StartInternalLBVMCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Internal Lb Vm Id: " + getId());
    VirtualRouter result = null;
    VirtualRouter router = _routerService.findRouter(getId());
    if (router == null || router.getRole() != Role.INTERNAL_LB_VM) {
        throw new InvalidParameterValueException("Can't find internal lb vm by id");
    } else {
        result = _internalLbSvc.startInternalLbVm(getId(), CallContext.current().getCallingAccount(), CallContext.current().getCallingUserId());
    }
    if (result != null) {
        DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(result);
        routerResponse.setResponseName(getCommandName());
        setResponseObject(routerResponse);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start internal lb vm");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 3 with DomainRouterResponse

use of org.apache.cloudstack.api.response.DomainRouterResponse in project cloudstack by apache.

the class DomainRouterJoinDaoImpl method newDomainRouterResponse.

@Override
public DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO router, Account caller) {
    DomainRouterResponse routerResponse = new DomainRouterResponse();
    routerResponse.setId(router.getUuid());
    routerResponse.setZoneId(router.getDataCenterUuid());
    routerResponse.setName(router.getName());
    routerResponse.setTemplateId(router.getTemplateUuid());
    VMTemplateVO template = ApiDBUtils.findTemplateById(router.getTemplateId());
    if (template != null) {
        routerResponse.setTemplateName(template.getName());
    }
    routerResponse.setCreated(router.getCreated());
    routerResponse.setState(router.getState());
    routerResponse.setIsRedundantRouter(router.isRedundantRouter());
    routerResponse.setScriptsVersion(router.getScriptsVersion());
    if (router.getRedundantState() != null) {
        routerResponse.setRedundantState(router.getRedundantState().toString());
    }
    if (router.getTemplateVersion() != null) {
        String routerVersion = CloudStackVersion.trimRouterVersion(router.getTemplateVersion());
        routerResponse.setVersion(routerVersion);
        routerResponse.setRequiresUpgrade((CloudStackVersion.compare(routerVersion, NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId())) < 0));
    } else {
        routerResponse.setVersion("UNKNOWN");
        routerResponse.setRequiresUpgrade(true);
    }
    routerResponse.setHasAnnotation(annotationDao.hasAnnotations(router.getUuid(), AnnotationService.EntityType.VR.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    if (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || _accountMgr.isRootAdmin(caller.getId())) {
        if (router.getHostId() != null) {
            routerResponse.setHostId(router.getHostUuid());
            routerResponse.setHostName(router.getHostName());
            routerResponse.setHypervisor(router.getHypervisorType().toString());
        }
        routerResponse.setPodId(router.getPodUuid());
        HostPodVO pod = ApiDBUtils.findPodById(router.getPodId());
        if (pod != null) {
            routerResponse.setPodName(pod.getName());
        }
        long nic_id = router.getNicId();
        if (nic_id > 0) {
            TrafficType ty = router.getTrafficType();
            if (ty != null) {
                // nics response object
                if (ty == TrafficType.Public) {
                    routerResponse.setPublicIp(router.getIpAddress());
                    routerResponse.setPublicMacAddress(router.getMacAddress());
                    routerResponse.setPublicNetmask(router.getNetmask());
                    routerResponse.setGateway(router.getGateway());
                    routerResponse.setPublicNetworkId(router.getNetworkUuid());
                } else if (ty == TrafficType.Control) {
                    routerResponse.setLinkLocalIp(router.getIpAddress());
                    routerResponse.setLinkLocalMacAddress(router.getMacAddress());
                    routerResponse.setLinkLocalNetmask(router.getNetmask());
                    routerResponse.setLinkLocalNetworkId(router.getNetworkUuid());
                } else if (ty == TrafficType.Guest) {
                    routerResponse.setGuestIpAddress(router.getIpAddress());
                    routerResponse.setGuestMacAddress(router.getMacAddress());
                    routerResponse.setGuestNetmask(router.getNetmask());
                    routerResponse.setGuestNetworkId(router.getNetworkUuid());
                    routerResponse.setGuestNetworkName(router.getNetworkName());
                    routerResponse.setNetworkDomain(router.getNetworkDomain());
                }
            }
            NicResponse nicResponse = new NicResponse();
            nicResponse.setId(router.getNicUuid());
            nicResponse.setIpaddress(router.getIpAddress());
            nicResponse.setGateway(router.getGateway());
            nicResponse.setNetmask(router.getNetmask());
            nicResponse.setNetworkid(router.getNetworkUuid());
            nicResponse.setNetworkName(router.getNetworkName());
            nicResponse.setMacAddress(router.getMacAddress());
            nicResponse.setIp6Address(router.getIp6Address());
            nicResponse.setIp6Gateway(router.getIp6Gateway());
            nicResponse.setIp6Cidr(router.getIp6Cidr());
            if (router.getBroadcastUri() != null) {
                nicResponse.setBroadcastUri(router.getBroadcastUri().toString());
            }
            if (router.getIsolationUri() != null) {
                nicResponse.setIsolationUri(router.getIsolationUri().toString());
            }
            if (router.getTrafficType() != null) {
                nicResponse.setTrafficType(router.getTrafficType().toString());
            }
            if (router.getGuestType() != null) {
                nicResponse.setType(router.getGuestType().toString());
            }
            nicResponse.setIsDefault(router.isDefaultNic());
            nicResponse.setObjectName("nic");
            routerResponse.addNic(nicResponse);
        }
    }
    routerResponse.setServiceOfferingId(router.getServiceOfferingUuid());
    routerResponse.setServiceOfferingName(router.getServiceOfferingName());
    // populate owner.
    ApiResponseHelper.populateOwner(routerResponse, router);
    routerResponse.setDomainId(router.getDomainUuid());
    routerResponse.setDomainName(router.getDomainName());
    routerResponse.setZoneName(router.getDataCenterName());
    routerResponse.setDns1(router.getDns1());
    routerResponse.setDns2(router.getDns2());
    routerResponse.setIp6Dns1(router.getIp6Dns1());
    routerResponse.setIp6Dns2(router.getIp6Dns2());
    routerResponse.setVpcId(router.getVpcUuid());
    routerResponse.setVpcName(router.getVpcName());
    routerResponse.setRole(router.getRole().toString());
    // set async job
    if (router.getJobId() != null) {
        routerResponse.setJobId(router.getJobUuid());
        routerResponse.setJobStatus(router.getJobStatus());
    }
    if (router.getRole() == Role.INTERNAL_LB_VM) {
        routerResponse.setObjectName("internalloadbalancervm");
    } else {
        routerResponse.setObjectName("router");
    }
    return routerResponse;
}
Also used : VMTemplateVO(com.cloud.storage.VMTemplateVO) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) HostPodVO(com.cloud.dc.HostPodVO) TrafficType(com.cloud.network.Networks.TrafficType) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 4 with DomainRouterResponse

use of org.apache.cloudstack.api.response.DomainRouterResponse in project cloudstack by apache.

the class ViewResponseHelper method createDomainRouterResponse.

public static List<DomainRouterResponse> createDomainRouterResponse(DomainRouterJoinVO... routers) {
    Account caller = CallContext.current().getCallingAccount();
    Hashtable<Long, DomainRouterResponse> vrDataList = new Hashtable<Long, DomainRouterResponse>();
    // Initialise the vrdatalist with the input data
    for (DomainRouterJoinVO vr : routers) {
        DomainRouterResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newDomainRouterResponse(vr, caller);
        } else {
            // update nics for 1 to many mapping fields
            vrData = ApiDBUtils.fillRouterDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<DomainRouterResponse>(vrDataList.values());
}
Also used : Account(com.cloud.user.Account) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO)

Example 5 with DomainRouterResponse

use of org.apache.cloudstack.api.response.DomainRouterResponse in project cloudstack by apache.

the class DestroyRouterCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext ctx = CallContext.current();
    ctx.setEventDetails("Router Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
    VirtualRouter result = _routerService.destroyRouter(getId(), ctx.getCallingAccount(), ctx.getCallingUserId());
    if (result != null) {
        DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy router");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) CallContext(org.apache.cloudstack.context.CallContext) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) VirtualRouter(com.cloud.network.router.VirtualRouter)

Aggregations

DomainRouterResponse (org.apache.cloudstack.api.response.DomainRouterResponse)12 VirtualRouter (com.cloud.network.router.VirtualRouter)8 ServerApiException (org.apache.cloudstack.api.ServerApiException)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 DomainRouterJoinVO (com.cloud.api.query.vo.DomainRouterJoinVO)3 ArrayList (java.util.ArrayList)3 DomainRouterVO (com.cloud.vm.DomainRouterVO)2 List (java.util.List)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 HostPodVO (com.cloud.dc.HostPodVO)1 TrafficType (com.cloud.network.Networks.TrafficType)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 Account (com.cloud.user.Account)1 Hashtable (java.util.Hashtable)1 NicResponse (org.apache.cloudstack.api.response.NicResponse)1 CallContext (org.apache.cloudstack.context.CallContext)1