Updated Branches: refs/heads/master 1f97b528c -> d5c3f8790
CLOUDSTACK-1741 Added ip uuid into the AddIptoVmNicCmd response Signed-off-by: Abhinandan Prateek <aprat...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d5c3f879 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d5c3f879 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d5c3f879 Branch: refs/heads/master Commit: d5c3f87903ffa4362c9dc9688c199c10700c0ccb Parents: 1f97b52 Author: Jayapal <jayapalreddy.ur...@citrix.com> Authored: Mon Apr 22 14:06:12 2013 +0530 Committer: Abhinandan Prateek <aprat...@apache.org> Committed: Thu Apr 25 15:16:26 2013 +0530 ---------------------------------------------------------------------- api/src/com/cloud/network/NetworkService.java | 2 +- .../apache/cloudstack/api/ResponseGenerator.java | 4 +- .../api/command/user/vm/AddIpToVmNicCmd.java | 9 +++++-- .../api/command/test/AddIpToVmNicTest.java | 6 +++- server/src/com/cloud/api/ApiResponseHelper.java | 18 +++++---------- .../src/com/cloud/network/NetworkServiceImpl.java | 17 +++++++++++-- .../com/cloud/network/MockNetworkManagerImpl.java | 2 +- .../test/com/cloud/vpc/MockNetworkManagerImpl.java | 2 +- 8 files changed, 35 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/api/src/com/cloud/network/NetworkService.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 5a6054d..6c9bebc 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -158,7 +158,7 @@ public interface NetworkService { throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException; /* Requests an IP address for the guest nic */ - String allocateSecondaryGuestIP(Account account, long zoneId, Long nicId, + NicSecondaryIp allocateSecondaryGuestIP(Account account, long zoneId, Long nicId, Long networkId, String ipaddress) throws InsufficientAddressCapacityException; boolean releaseSecondaryIpFromNic(long ipAddressId); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/api/src/org/apache/cloudstack/api/ResponseGenerator.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java index a3aa9de..cbf8bb2 100644 --- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java @@ -20,6 +20,7 @@ import java.text.DecimalFormat; import java.util.EnumSet; import java.util.List; +import com.cloud.vm.NicSecondaryIp; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.ApiConstants.HostDetails; @@ -389,8 +390,7 @@ public interface ResponseGenerator { TrafficMonitorResponse createTrafficMonitorResponse(Host trafficMonitor); VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot); - NicSecondaryIpResponse createSecondaryIPToNicResponse(String ip, - Long nicId, Long networkId); + NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp result); public NicResponse createNicResponse(Nic result); AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java index df6b399..ae5482b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java @@ -16,6 +16,7 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; +import com.cloud.vm.NicSecondaryIp; import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -146,6 +147,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd { UserContext.current().setEventDetails("Nic Id: " + getNicId() ); String ip; + NicSecondaryIp result; String secondaryIp = null; if ((ip = getIpaddress()) != null) { if (!NetUtils.isValidIp(ip)) { @@ -154,12 +156,13 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd { } try { - secondaryIp = _networkService.allocateSecondaryGuestIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNicId(), getNetworkId(), getIpaddress()); + result = _networkService.allocateSecondaryGuestIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNicId(), getNetworkId(), getIpaddress()); } catch (InsufficientAddressCapacityException e) { throw new InvalidParameterValueException("Allocating guest ip for nic failed"); } - if (secondaryIp != null) { + if (result != null) { + secondaryIp = result.getIp4Address(); if (getNetworkType() == NetworkType.Basic) { // add security group rules for the secondary ip addresses boolean success = false; @@ -171,7 +174,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd { s_logger.info("Associated ip address to NIC : " + secondaryIp); NicSecondaryIpResponse response = new NicSecondaryIpResponse(); - response = _responseGenerator.createSecondaryIPToNicResponse(secondaryIp, getNicId(), getNetworkId()); + response = _responseGenerator.createSecondaryIPToNicResponse(result); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/api/test/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java ---------------------------------------------------------------------- diff --git a/api/test/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java b/api/test/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java index 106589d..e5015cb 100644 --- a/api/test/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java +++ b/api/test/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java @@ -16,6 +16,7 @@ // under the License. package org.apache.cloudstack.api.command.test; +import com.cloud.vm.NicSecondaryIp; import junit.framework.Assert; import junit.framework.TestCase; @@ -64,15 +65,16 @@ public class AddIpToVmNicTest extends TestCase { NetworkService networkService = Mockito.mock(NetworkService.class); AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class); + NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class); Mockito.when( - networkService.allocateSecondaryGuestIP(Mockito.any(Account.class), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyString())).thenReturn("10.1.1.2"); + networkService.allocateSecondaryGuestIP(Mockito.any(Account.class), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyString())).thenReturn(secIp); ipTonicCmd._networkService = networkService; responseGenerator = Mockito.mock(ResponseGenerator.class); NicSecondaryIpResponse ipres = Mockito.mock(NicSecondaryIpResponse.class); - Mockito.when(responseGenerator.createSecondaryIPToNicResponse(Mockito.anyString(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(ipres); + Mockito.when(responseGenerator.createSecondaryIPToNicResponse(secIp)).thenReturn(ipres); ipTonicCmd._responseGenerator = responseGenerator; ipTonicCmd.execute(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/server/src/com/cloud/api/ApiResponseHelper.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index c181495..6090ff0 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -34,6 +34,7 @@ import java.util.TimeZone; import javax.inject.Inject; +import com.cloud.vm.*; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.api.ApiConstants.HostDetails; @@ -264,13 +265,6 @@ import com.cloud.uservm.UserVm; import com.cloud.utils.Pair; import com.cloud.utils.StringUtils; import com.cloud.utils.net.NetUtils; -import com.cloud.vm.ConsoleProxyVO; -import com.cloud.vm.InstanceGroup; -import com.cloud.vm.Nic; -import com.cloud.vm.NicProfile; -import com.cloud.vm.NicVO; -import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.dao.NicSecondaryIpVO; import com.cloud.vm.snapshot.VMSnapshot; @@ -288,7 +282,6 @@ import org.apache.cloudstack.region.Region; import org.apache.cloudstack.usage.Usage; import org.apache.cloudstack.usage.UsageService; import org.apache.cloudstack.usage.UsageTypes; -import com.cloud.vm.VmStats; import com.cloud.vm.dao.UserVmData; import com.cloud.vm.dao.UserVmData.NicData; import com.cloud.vm.dao.UserVmData.SecurityGroupData; @@ -3646,11 +3639,12 @@ public class ApiResponseHelper implements ResponseGenerator { return response; } - public NicSecondaryIpResponse createSecondaryIPToNicResponse(String ipAddr, Long nicId, Long networkId) { + public NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp result) { NicSecondaryIpResponse response = new NicSecondaryIpResponse(); - NicVO nic = _entityMgr.findById(NicVO.class, nicId); - NetworkVO network = _entityMgr.findById(NetworkVO.class, networkId); - response.setIpAddr(ipAddr); + NicVO nic = _entityMgr.findById(NicVO.class, result.getNicId()); + NetworkVO network = _entityMgr.findById(NetworkVO.class, result.getNetworkId()); + response.setId(result.getUuid()); + response.setIpAddr(result.getIp4Address()); response.setNicId(nic.getUuid()); response.setNwId(network.getUuid()); response.setObjectName("nicsecondaryip"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/server/src/com/cloud/network/NetworkServiceImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index 7653a08..7bc2e54 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -483,7 +483,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { } - public String allocateSecondaryGuestIP (Account ipOwner, long zoneId, Long nicId, Long networkId, String requestedIp) throws InsufficientAddressCapacityException { + public NicSecondaryIp allocateSecondaryGuestIP (Account ipOwner, long zoneId, Long nicId, Long networkId, String requestedIp) throws InsufficientAddressCapacityException { Long accountId = null; Long domainId = null; @@ -565,6 +565,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { return null; } + NicSecondaryIpVO secondaryIpVO; if (ipaddr != null) { // we got the ip addr so up the nics table and secodary ip Transaction txn = Transaction.currentTxn(); @@ -580,11 +581,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { s_logger.debug("Setting nic_secondary_ip table ..."); vmId = nicVO.getInstanceId(); - NicSecondaryIpVO secondaryIpVO = new NicSecondaryIpVO(nicId, ipaddr, vmId, accountId, domainId, networkId); + secondaryIpVO = new NicSecondaryIpVO(nicId, ipaddr, vmId, accountId, domainId, networkId); _nicSecondaryIpDao.persist(secondaryIpVO); txn.commit(); + return getNicSecondaryIp(secondaryIpVO.getId()); + } else { + return null; } - return ipaddr; } @DB @@ -676,6 +679,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { return true; } + NicSecondaryIp getNicSecondaryIp (long id) { + NicSecondaryIp nicSecIp = _nicSecondaryIpDao.findById(id); + if (nicSecIp == null) { + return null; + } + return nicSecIp; + } + @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NET_IP_RELEASE, eventDescription = "disassociating Ip", async = true) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/server/test/com/cloud/network/MockNetworkManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 6a0263e..e9987bd 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -835,7 +835,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage } @Override - public String allocateSecondaryGuestIP(Account account, long zoneId, + public NicSecondaryIp allocateSecondaryGuestIP(Account account, long zoneId, Long nicId, Long networkId, String ipaddress) { // TODO Auto-generated method stub return null; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d5c3f879/server/test/com/cloud/vpc/MockNetworkManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java index bfcccf5..9b18358 100644 --- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java @@ -1316,7 +1316,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage } @Override - public String allocateSecondaryGuestIP(Account account, long zoneId, + public NicSecondaryIp allocateSecondaryGuestIP(Account account, long zoneId, Long nicId, Long networkId, String ipaddress) { // TODO Auto-generated method stub return null;