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.");
}
}
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");
}
}
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();
}
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;
}
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;
}
Aggregations