Search in sources :

Example 6 with SystemVmResponse

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

the class DestroySystemVmCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    VirtualMachine instance = _mgr.destroySystemVM(this);
    if (instance != null) {
        SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to destroy system vm");
    }
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 7 with SystemVmResponse

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

the class ListSystemVMsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends VirtualMachine>, Integer> systemVMs = _mgr.searchForSystemVm(this);
    ListResponse<SystemVmResponse> response = new ListResponse<SystemVmResponse>();
    List<SystemVmResponse> vmResponses = new ArrayList<SystemVmResponse>();
    for (VirtualMachine systemVM : systemVMs.first()) {
        SystemVmResponse vmResponse = _responseGenerator.createSystemVmResponse(systemVM);
        vmResponse.setObjectName("systemvm");
        vmResponses.add(vmResponse);
    }
    response.setResponses(vmResponses, systemVMs.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 8 with SystemVmResponse

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

the class MigrateSystemVMCmd method execute.

@Override
public void execute() {
    Host destinationHost = _resourceService.getHost(getHostId());
    if (destinationHost == null) {
        throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
    }
    try {
        CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
        //FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
        VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
        if (migratedVm != null) {
            // return the generic system VM instance response
            SystemVmResponse response = _responseGenerator.createSystemVmResponse(migratedVm);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate the system vm");
        }
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    } catch (ManagementServerException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    } catch (VirtualMachineMigrationException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ManagementServerException(com.cloud.exception.ManagementServerException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Host(com.cloud.host.Host) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 9 with SystemVmResponse

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

the class ApiResponseHelper method createSystemVmResponse.

@Override
public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
    SystemVmResponse vmResponse = new SystemVmResponse();
    if (vm.getType() == Type.SecondaryStorageVm || vm.getType() == Type.ConsoleProxy || vm.getType() == Type.DomainRouter) {
        // SystemVm vm = (SystemVm) systemVM;
        vmResponse.setId(vm.getUuid());
        // vmResponse.setObjectId(vm.getId());
        vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
        vmResponse.setName(vm.getHostName());
        if (vm.getPodIdToDeployIn() != null) {
            HostPodVO pod = ApiDBUtils.findPodById(vm.getPodIdToDeployIn());
            if (pod != null) {
                vmResponse.setPodId(pod.getUuid());
            }
        }
        VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
        if (template != null) {
            vmResponse.setTemplateId(template.getUuid());
        }
        vmResponse.setCreated(vm.getCreated());
        if (vm.getHostId() != null) {
            Host host = ApiDBUtils.findHostById(vm.getHostId());
            if (host != null) {
                vmResponse.setHostId(host.getUuid());
                vmResponse.setHostName(host.getName());
                vmResponse.setHypervisor(host.getHypervisorType().toString());
            }
        }
        if (vm.getState() != null) {
            vmResponse.setState(vm.getState().toString());
        }
        // for console proxies, add the active sessions
        if (vm.getType() == Type.ConsoleProxy) {
            ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
            // proxy can be already destroyed
            if (proxy != null) {
                vmResponse.setActiveViewerSessions(proxy.getActiveSession());
            }
        }
        DataCenter zone = ApiDBUtils.findZoneById(vm.getDataCenterId());
        if (zone != null) {
            vmResponse.setZoneId(zone.getUuid());
            vmResponse.setZoneName(zone.getName());
            vmResponse.setDns1(zone.getDns1());
            vmResponse.setDns2(zone.getDns2());
        }
        List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
        for (NicProfile singleNicProfile : nicProfiles) {
            Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
            if (network != null) {
                if (network.getTrafficType() == TrafficType.Management) {
                    vmResponse.setPrivateIp(singleNicProfile.getIPv4Address());
                    vmResponse.setPrivateMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setPrivateNetmask(singleNicProfile.getIPv4Netmask());
                } else if (network.getTrafficType() == TrafficType.Control) {
                    vmResponse.setLinkLocalIp(singleNicProfile.getIPv4Address());
                    vmResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setLinkLocalNetmask(singleNicProfile.getIPv4Netmask());
                } else if (network.getTrafficType() == TrafficType.Public) {
                    vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
                    vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
                    vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
                } else if (network.getTrafficType() == TrafficType.Guest) {
                    /*
                          * In basic zone, public ip has TrafficType.Guest in case EIP service is not enabled.
                          * When EIP service is enabled in the basic zone, system VM by default get the public
                          * IP allocated for EIP. So return the guest/public IP accordingly.
                          * */
                    NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
                    if (networkOffering.getElasticIp()) {
                        IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(vm.getId());
                        if (ip != null) {
                            Vlan vlan = ApiDBUtils.findVlanById(ip.getVlanId());
                            vmResponse.setPublicIp(ip.getAddress().addr());
                            vmResponse.setPublicNetmask(vlan.getVlanNetmask());
                            vmResponse.setGateway(vlan.getVlanGateway());
                        }
                    } else {
                        vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
                        vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
                        vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
                        vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
                    }
                }
            }
        }
    }
    vmResponse.setObjectName("systemvm");
    return vmResponse;
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VMTemplateVO(com.cloud.storage.VMTemplateVO) Host(com.cloud.host.Host) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) IpAddress(com.cloud.network.IpAddress) Vlan(com.cloud.dc.Vlan) GuestVlan(com.cloud.network.GuestVlan) NicProfile(com.cloud.vm.NicProfile) HostPodVO(com.cloud.dc.HostPodVO)

Aggregations

SystemVmResponse (org.apache.cloudstack.api.response.SystemVmResponse)9 VirtualMachine (com.cloud.vm.VirtualMachine)8 ServerApiException (org.apache.cloudstack.api.ServerApiException)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 ManagementServerException (com.cloud.exception.ManagementServerException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)2 Host (com.cloud.host.Host)2 ServiceOffering (com.cloud.offering.ServiceOffering)2 DataCenter (com.cloud.dc.DataCenter)1 HostPodVO (com.cloud.dc.HostPodVO)1 Vlan (com.cloud.dc.Vlan)1 GuestVlan (com.cloud.network.GuestVlan)1 IpAddress (com.cloud.network.IpAddress)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 NetworkOffering (com.cloud.offering.NetworkOffering)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 ConsoleProxyVO (com.cloud.vm.ConsoleProxyVO)1