@Override public String getEventDescription() { return "associating ip to nic id: " + this._uuidMgr.getUuid(Network.class, getNetworkId()) + " in zone " + this._uuidMgr.getUuid(DataCenter.class, getZoneId()); }
@Override public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { CallContext.current().setEventDetails("Nic Id: " + getNicId() ); String ip; if ((ip = getIpaddress()) != null) { if (!NetUtils.isValidIp4(ip)) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid ip address " + ip); } } UserVm vm = _userVmService.updateNicIpForVirtualMachine(this); ArrayList<VMDetails> dc = new ArrayList<VMDetails>(); dc.add(VMDetails.valueOf("nics")); EnumSet<VMDetails> details = EnumSet.copyOf(dc); if (vm != null){ 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."); } }
@Override public UserVm updateNicIpForVirtualMachine(UpdateVmNicIpCmd cmd) { Long nicId = cmd.getNicId(); String ipaddr = cmd.getIpaddress(); Account caller = CallContext.current().getCallingAccount();
@Override public Long getSyncObjId() { return getNetworkId(); }
@Test public void testFailure() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { UserVmService userVmService = Mockito.mock(UserVmService.class); updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class); Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(null); updateVmNicIpCmd._userVmService = userVmService; updateVmNicIpCmd._responseGenerator = responseGenerator; try { updateVmNicIpCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to update ip address on vm NIC. Refer to server logs for details.", exception.getDescription()); } }
private long getZoneId() { Network ntwk = _entityMgr.findById(Network.class, getNetworkId()); if (ntwk == null) { throw new InvalidParameterValueException("Can't find zone id for specified"); } return ntwk.getDataCenterId(); }
@Test public void testSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { UserVmService userVmService = Mockito.mock(UserVmService.class); updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class); UserVm userVm = Mockito.mock(UserVm.class); Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(userVm); updateVmNicIpCmd._userVmService = userVmService; responseGenerator = Mockito.mock(ResponseGenerator.class); List<UserVmResponse> list = new LinkedList<UserVmResponse>(); UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class); list.add(userVmResponse); Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list); updateVmNicIpCmd._responseGenerator = responseGenerator; updateVmNicIpCmd.execute(); }
public NetworkType getNetworkType() { Network ntwk = _entityMgr.findById(Network.class, getNetworkId()); DataCenter dc = _entityMgr.findById(DataCenter.class, ntwk.getDataCenterId()); return dc.getNetworkType(); }