Search in sources :

Example 76 with VirtualMachine

use of com.cloud.vm.VirtualMachine 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");
    }
}
Also used : SystemVmResponse(com.cloud.api.response.SystemVmResponse) ServerApiException(com.cloud.api.ServerApiException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 77 with VirtualMachine

use of com.cloud.vm.VirtualMachine 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");
    }
}
Also used : SystemVmResponse(com.cloud.api.response.SystemVmResponse) ServerApiException(com.cloud.api.ServerApiException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 78 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testDeallocate.

@Test
public void testDeallocate() throws Exception {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
    final NetworkOfferingVO offering = mock(NetworkOfferingVO.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(offering);
    final DomainVO domain = mock(DomainVO.class);
    when(domain.getUuid()).thenReturn("aaaaaa");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(domain);
    final NicVO nic = mock(NicVO.class);
    when(nic.getId()).thenReturn(NETWORK_ID);
    when(nic.getIPv4Address()).thenReturn("10.10.10.10");
    when(nic.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
    when(_nicDao.findById(NETWORK_ID)).thenReturn(nic);
    final NicProfile nicProfile = mock(NicProfile.class);
    when(nicProfile.getId()).thenReturn(NETWORK_ID);
    when(nicProfile.getIPv4Address()).thenReturn("10.10.10.10");
    when(nicProfile.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
    final VirtualMachine vm = mock(VirtualMachine.class);
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(vm.getState()).thenReturn(VirtualMachine.State.Expunging);
    final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
    when(vmProfile.getUuid()).thenReturn("aaaaaa");
    when(vmProfile.getInstanceName()).thenReturn("Test-VM");
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    _nuageVspGuestNetworkGuru.deallocate(network, nicProfile, vmProfile);
}
Also used : DomainVO(com.cloud.domain.DomainVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) NicProfile(com.cloud.vm.NicProfile) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualMachine(com.cloud.vm.VirtualMachine) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 79 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class ListLoadBalancerRuleInstancesCmdByAdmin method execute.

@Override
public void execute() {
    Pair<List<? extends UserVm>, List<String>> vmServiceMap = _lbService.listLoadBalancerInstances(this);
    List<? extends UserVm> result = vmServiceMap.first();
    List<String> serviceStates = vmServiceMap.second();
    if (!isListLbVmip()) {
        // list lb instances
        ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            for (int i = 0; i < result.size(); i++) {
                vmResponses.get(i).setServiceState(serviceStates.get(i));
            }
        }
        response.setResponses(vmResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<LoadBalancerRuleVmMapResponse>();
        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
        List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            List<String> ipaddr = null;
            for (int i = 0; i < result.size(); i++) {
                LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
                vmResponses.get(i).setServiceState(serviceStates.get(i));
                lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
                //get vm id from the uuid
                VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
                lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
                lbRuleVmIpResponse.setObjectName("lbrulevmidip");
                listlbVmRes.add(lbRuleVmIpResponse);
            }
        }
        lbRes.setResponseName(getCommandName());
        lbRes.setResponses(listlbVmRes);
        setResponseObject(lbRes);
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancerRuleVmMapResponse(org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) UserVm(com.cloud.uservm.UserVm) List(java.util.List) ArrayList(java.util.ArrayList) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 80 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method finalizeStop.

@Override
public void finalizeStop(final VirtualMachineProfile profile, final Answer answer) {
    if (answer != null) {
        final VirtualMachine vm = profile.getVirtualMachine();
        final DomainRouterVO domR = _routerDao.findById(vm.getId());
        processStopOrRebootAnswer(domR, answer);
        final List<DomainRouterVO> routers = _routerDao.listByVpcId(domR.getVpcId());
        for (final DomainRouterVO domainRouterVO : routers) {
            s_logger.info("Updating the redundant state of router " + domainRouterVO);
            updateRoutersRedundantState(domainRouterVO);
        }
    }
}
Also used : DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

VirtualMachine (com.cloud.vm.VirtualMachine)141 HostVO (com.cloud.host.HostVO)38 ArrayList (java.util.ArrayList)35 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 HashMap (java.util.HashMap)25 List (java.util.List)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 VMInstanceVO (com.cloud.vm.VMInstanceVO)20 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)19 DataCenter (com.cloud.dc.DataCenter)17 Host (com.cloud.host.Host)17 ServiceOffering (com.cloud.offering.ServiceOffering)17 Test (org.junit.Test)17 ServerApiException (com.cloud.api.ServerApiException)16 SystemVmResponse (com.cloud.api.response.SystemVmResponse)14 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)14 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)13 Account (com.cloud.user.Account)13 UserVm (com.cloud.uservm.UserVm)13