Search in sources :

Example 76 with UserVm

use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.

the class UpdateVmNicIpCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Nic Id: " + getNicId());
    final String ip;
    if ((ip = getIpaddress()) != null) {
        if (!NetUtils.isValidIp4(ip)) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid ip address " + ip);
        }
    }
    final UserVm vm = _userVmService.updateNicIpForVirtualMachine(this);
    final ArrayList<VMDetails> dc = new ArrayList<>();
    dc.add(VMDetails.valueOf("nics"));
    final EnumSet<VMDetails> details = EnumSet.copyOf(dc);
    if (vm != null) {
        final UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, vm).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update ip address on vm NIC. Refer to server logs for details.");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) VMDetails(com.cloud.api.ApiConstants.VMDetails) ServerApiException(com.cloud.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 77 with UserVm

use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.

the class UpgradeVMCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
    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 UserVm result = _userVmService.upgradeVirtualMachine(this);
    if (result != null) {
        final UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 78 with UserVm

use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.

the class UpdateVmNicIpTest method testSuccess.

@Test
public void testSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    final UserVmService userVmService = Mockito.mock(UserVmService.class);
    updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class);
    final UserVm userVm = Mockito.mock(UserVm.class);
    Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(userVm);
    updateVmNicIpCmd._userVmService = userVmService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    final List<UserVmResponse> list = new LinkedList<>();
    final UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
    list.add(userVmResponse);
    Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
    updateVmNicIpCmd._responseGenerator = responseGenerator;
    updateVmNicIpCmd.execute();
}
Also used : UserVm(com.cloud.uservm.UserVm) UserVmService(com.cloud.vm.UserVmService) ResponseGenerator(com.cloud.api.ResponseGenerator) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) UserVmResponse(com.cloud.api.response.UserVmResponse) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 79 with UserVm

use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createIpForwardingRuleResponse.

@Override
public IpForwardingRuleResponse createIpForwardingRuleResponse(final StaticNatRule fwRule) {
    final IpForwardingRuleResponse response = new IpForwardingRuleResponse();
    response.setId(fwRule.getUuid());
    response.setProtocol(fwRule.getProtocol());
    final IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
    if (ip != null) {
        response.setPublicIpAddressId(ip.getId());
        response.setPublicIpAddress(ip.getAddress().addr());
        if (fwRule.getDestIpAddress() != null) {
            final UserVm vm = ApiDBUtils.findUserVmById(ip.getAssociatedWithVmId());
            if (vm != null) {
                // vm might be destroyed
                response.setVirtualMachineId(vm.getUuid());
                response.setVirtualMachineName(vm.getHostName());
                if (vm.getDisplayName() != null) {
                    response.setVirtualMachineDisplayName(vm.getDisplayName());
                } else {
                    response.setVirtualMachineDisplayName(vm.getHostName());
                }
            }
        }
    }
    final FirewallRule.State state = fwRule.getState();
    String stateToSet = state.toString();
    if (state.equals(FirewallRule.State.Revoke)) {
        stateToSet = "Deleting";
    }
    response.setStartPort(fwRule.getSourcePortStart());
    response.setEndPort(fwRule.getSourcePortEnd());
    response.setProtocol(fwRule.getProtocol());
    response.setState(stateToSet);
    response.setObjectName("ipforwardingrule");
    return response;
}
Also used : UserVm(com.cloud.uservm.UserVm) IpAddress(com.cloud.network.IpAddress) FirewallRule(com.cloud.network.rules.FirewallRule) IpForwardingRuleResponse(com.cloud.api.response.IpForwardingRuleResponse)

Example 80 with UserVm

use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.

the class UserVmJoinDaoImpl method newUserVmView.

@Override
public List<UserVmJoinVO> newUserVmView(final UserVm... userVms) {
    final Hashtable<Long, UserVm> userVmDataHash = new Hashtable<>();
    for (final UserVm vm : userVms) {
        if (!userVmDataHash.containsKey(vm.getId())) {
            userVmDataHash.put(vm.getId(), vm);
        }
    }
    final Set<Long> vmIdSet = userVmDataHash.keySet();
    final List<UserVmJoinVO> uvms = searchByIds(vmIdSet.toArray(new Long[vmIdSet.size()]));
    // populate transit password field from UserVm
    if (uvms != null) {
        for (final UserVmJoinVO uvm : uvms) {
            final UserVm v = userVmDataHash.get(uvm.getId());
            uvm.setPassword(v.getPassword());
        }
    }
    return uvms;
}
Also used : UserVm(com.cloud.uservm.UserVm) Hashtable(java.util.Hashtable) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO)

Aggregations

UserVm (com.cloud.uservm.UserVm)196 ServerApiException (com.cloud.api.ServerApiException)59 UserVmResponse (com.cloud.api.response.UserVmResponse)59 ArrayList (java.util.ArrayList)54 ServerApiException (org.apache.cloudstack.api.ServerApiException)48 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)47 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)32 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)28 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)28 Network (com.cloud.network.Network)26 Account (com.cloud.user.Account)22 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)21 ManagementServerException (com.cloud.exception.ManagementServerException)21 HashMap (java.util.HashMap)16 ServiceOffering (com.cloud.offering.ServiceOffering)15 DataCenter (com.cloud.dc.DataCenter)14 List (java.util.List)14 ActionEvent (com.cloud.event.ActionEvent)12 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)12