use of com.cloud.api.response.SystemVmResponse in project CloudStack-archive by CloudStack-extras.
the class StartSystemVMCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Vm Id: " + getId());
VirtualMachine instance = _mgr.startSystemVM(getId());
if (instance != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to start system vm");
}
}
use of com.cloud.api.response.SystemVmResponse in project CloudStack-archive by CloudStack-extras.
the class StopSystemVmCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
UserContext.current().setEventDetails("Vm Id: " + getId());
VirtualMachine result = _mgr.stopSystemVM(this);
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to stop system vm");
}
}
use of com.cloud.api.response.SystemVmResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createSystemVmResponse.
@Override
public SystemVmResponse createSystemVmResponse(final VirtualMachine vm) {
final 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) {
final HostPodVO pod = ApiDBUtils.findPodById(vm.getPodIdToDeployIn());
if (pod != null) {
vmResponse.setPodId(pod.getUuid());
}
}
final VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
if (template != null) {
vmResponse.setTemplateId(template.getUuid());
}
vmResponse.setCreated(vm.getCreated());
if (vm.getHostId() != null) {
final 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) {
final ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
// proxy can be already destroyed
if (proxy != null) {
vmResponse.setActiveViewerSessions(proxy.getActiveSession());
}
}
final 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());
}
final List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
for (final NicProfile singleNicProfile : nicProfiles) {
final 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.
* */
final NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
if (networkOffering.getElasticIp()) {
final IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(vm.getId());
if (ip != null) {
final 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;
}
use of com.cloud.api.response.SystemVmResponse in project cosmic by MissionCriticalCloud.
the class UpgradeSystemVMCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Vm Id: " + getId());
final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
final VirtualMachine result = _mgr.upgradeSystemVM(this);
if (result != null) {
final SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to reboot system vm");
}
}
use of com.cloud.api.response.SystemVmResponse in project cosmic by MissionCriticalCloud.
the class ListSystemVMsCmd method execute.
@Override
public void execute() {
final Pair<List<? extends VirtualMachine>, Integer> systemVMs = _mgr.searchForSystemVm(this);
final ListResponse<SystemVmResponse> response = new ListResponse<>();
final List<SystemVmResponse> vmResponses = new ArrayList<>();
for (final VirtualMachine systemVM : systemVMs.first()) {
final SystemVmResponse vmResponse = _responseGenerator.createSystemVmResponse(systemVM);
vmResponse.setObjectName("systemvm");
vmResponses.add(vmResponse);
}
response.setResponses(vmResponses, systemVMs.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
Aggregations