public NicSecondaryIp getIpEntry() { NicSecondaryIp nicSecIp = _entityMgr.findById(NicSecondaryIp.class, getIpAddressId()); return nicSecIp; }
@Override public void execute() throws InvalidParameterValueException { CallContext.current().setEventDetails("Ip Id: " + id); NicSecondaryIp nicSecIp = getIpEntry(); if (isZoneSGEnabled()) { boolean result = _networkService.releaseSecondaryIpFromNic(id); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove secondary ip address for the nic");
private boolean isZoneSGEnabled() { Network ntwk = _entityMgr.findById(Network.class, getNetworkId()); DataCenter dc = _entityMgr.findById(DataCenter.class, ntwk.getDataCenterId()); return dc.isSecurityGroupEnabled(); }
@Test public void testRemoveIpFromVmNicSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(true); removeIpFromNic._networkService = networkService; removeIpFromNic.execute(); }
public NetworkType getNetworkType() { Network ntwk = _entityMgr.findById(Network.class, getNetworkId()); if (ntwk != null) { DataCenter dc = _entityMgr.findById(DataCenter.class, ntwk.getDataCenterId()); return dc.getNetworkType(); } return null; }
@Test public void testRemoveIpFromVmNicFailure() throws InsufficientAddressCapacityException { NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(false); removeIpFromNic._networkService = networkService; successResponseGenerator = Mockito.mock(SuccessResponse.class); try { removeIpFromNic.execute(); } catch (InvalidParameterValueException exception) { Assert.assertEquals("Failed to remove secondary ip address for the nic", exception.getLocalizedMessage()); } } }
public Long getNetworkId() { NicSecondaryIp nicSecIp = _entityMgr.findById(NicSecondaryIp.class, getIpAddressId()); if (nicSecIp != null) { Long networkId = nicSecIp.getNetworkId(); return networkId; } else { return null; } }