Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DB03EE72B for ; Wed, 13 Mar 2013 17:13:57 +0000 (UTC) Received: (qmail 31038 invoked by uid 500); 13 Mar 2013 17:13:56 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 30968 invoked by uid 500); 13 Mar 2013 17:13:56 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 30910 invoked by uid 99); 13 Mar 2013 17:13:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Mar 2013 17:13:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 78DD3DDB7; Wed, 13 Mar 2013 17:13:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bfederle@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [33/35] git commit: refs/heads/ui-multiple-nics - CLOUDSTACK-1595 removeIpFromNic using uuid and response changes Message-Id: <20130313171356.78DD3DDB7@tyr.zones.apache.org> Date: Wed, 13 Mar 2013 17:13:56 +0000 (UTC) CLOUDSTACK-1595 removeIpFromNic using uuid and response changes Signed-off-by: Abhinandan Prateek Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/b4bab5a1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/b4bab5a1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/b4bab5a1 Branch: refs/heads/ui-multiple-nics Commit: b4bab5a152726c01af0ecc977ac6af69c7bc0187 Parents: 0f8c4d0 Author: Jayapal Uradi Authored: Mon Mar 11 12:44:39 2013 +0530 Committer: Abhinandan Prateek Committed: Wed Mar 13 14:46:31 2013 +0530 ---------------------------------------------------------------------- .../api/command/user/vm/AddIpToVmNicCmd.java | 2 +- .../api/command/user/vm/RemoveIpFromVmNicCmd.java | 21 +++++--- .../api/response/NicSecondaryIpResponse.java | 38 +++++++++----- server/src/com/cloud/api/ApiResponseHelper.java | 9 ++- .../src/com/cloud/network/NetworkServiceImpl.java | 2 +- 5 files changed, 45 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b4bab5a1/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 cc34b7b..df6b399 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 @@ -171,7 +171,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd { s_logger.info("Associated ip address to NIC : " + secondaryIp); NicSecondaryIpResponse response = new NicSecondaryIpResponse(); - response = _responseGenerator.createSecondaryIPToNicResponse(ip, getNicId(), getNetworkId()); + response = _responseGenerator.createSecondaryIPToNicResponse(secondaryIp, getNicId(), getNetworkId()); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b4bab5a1/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java index d9ab7e0..21a9a0c 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java @@ -30,6 +30,7 @@ import com.cloud.async.AsyncJob; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.event.EventTypes; +import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; import com.cloud.user.Account; @@ -40,7 +41,7 @@ import com.cloud.vm.NicSecondaryIp; @APICommand(name = "removeIpFromNic", description="Assigns secondary IP to NIC.", responseObject=SuccessResponse.class) public class RemoveIpFromVmNicCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(RemoveIpFromVmNicCmd.class.getName()); - private static final String s_name = "unassignsecondaryipaddrtonicresponse"; + private static final String s_name = "removeipfromnicresponse"; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -129,7 +130,7 @@ public class RemoveIpFromVmNicCmd extends BaseAsyncCmd { @Override public void execute() throws InvalidParameterValueException { - UserContext.current().setEventDetails("Ip Id: " + getIpAddressId()); + UserContext.current().setEventDetails("Ip Id: " + id); NicSecondaryIp nicSecIp = getIpEntry(); if (nicSecIp == null) { @@ -145,12 +146,16 @@ public class RemoveIpFromVmNicCmd extends BaseAsyncCmd { } } - boolean result = _networkService.releaseSecondaryIpFromNic(getIpAddressId()); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove secondary ip address for the nic"); + try { + boolean result = _networkService.releaseSecondaryIpFromNic(id); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove secondary ip address for the nic"); + } + } catch (InvalidParameterValueException e) { + throw new InvalidParameterValueException("Removing guest ip from nic failed"); } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b4bab5a1/api/src/org/apache/cloudstack/api/response/NicSecondaryIpResponse.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/response/NicSecondaryIpResponse.java b/api/src/org/apache/cloudstack/api/response/NicSecondaryIpResponse.java index 3464a63..695468f 100644 --- a/api/src/org/apache/cloudstack/api/response/NicSecondaryIpResponse.java +++ b/api/src/org/apache/cloudstack/api/response/NicSecondaryIpResponse.java @@ -20,28 +20,38 @@ import java.util.List; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import com.cloud.network.rules.FirewallRule; import com.cloud.serializer.Param; +import com.cloud.vm.NicSecondaryIp; import com.google.gson.annotations.SerializedName; +@EntityReference(value=NicSecondaryIp.class) @SuppressWarnings("unused") public class NicSecondaryIpResponse extends BaseResponse { + @SerializedName(ApiConstants.ID) @Param(description="the ID of the secondary private IP addr") - private Long id; + private String id; @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="Secondary IP address") private String ipAddr; @SerializedName(ApiConstants.NIC_ID) @Param(description="the ID of the nic") - private Long nicId; + private String nicId; @SerializedName(ApiConstants.NETWORK_ID) @Param(description="the ID of the network") - private Long nwId; + private String nwId; @SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description="the ID of the vm") - private Long vmId; + private String vmId; + + @Override + public String getObjectId() { + return this.getId(); + } - public Long getId() { + public String getId() { return id; } @@ -53,32 +63,32 @@ public class NicSecondaryIpResponse extends BaseResponse { this.ipAddr = ipAddr; } - public Long getNicId() { + public String getNicId() { return nicId; } - public void setNicId(Long nicId) { - this.nicId = nicId; + public void setNicId(String string) { + this.nicId = string; } - public Long getNwId() { + public String getNwId() { return nwId; } - public void setNwId(Long nwId) { + public void setNwId(String nwId) { this.nwId = nwId; } - public Long getVmId() { + public String getVmId() { return vmId; } - public void setVmId(Long vmId) { + public void setVmId(String vmId) { this.vmId = vmId; } - public Long setId(Long id) { - return id; + public void setId(String id) { + this.id = id; } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b4bab5a1/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 fbfc955..2546f29 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -184,6 +184,7 @@ 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.NicSecondaryIp; import com.cloud.vm.VirtualMachine; @@ -3447,9 +3448,11 @@ public class ApiResponseHelper implements ResponseGenerator { public NicSecondaryIpResponse createSecondaryIPToNicResponse(String ipAddr, Long nicId, Long networkId) { NicSecondaryIpResponse response = new NicSecondaryIpResponse(); + NicVO nic = _entityMgr.findById(NicVO.class, nicId); + NetworkVO network = _entityMgr.findById(NetworkVO.class, networkId); response.setIpAddr(ipAddr); - response.setNicId(nicId); - response.setNwId(networkId); + response.setNicId(nic.getUuid()); + response.setNwId(network.getUuid()); response.setObjectName("nicsecondaryip"); return response; } @@ -3465,7 +3468,7 @@ public class ApiResponseHelper implements ResponseGenerator { List ipList = new ArrayList(); for (NicSecondaryIpVO ip: secondaryIps) { NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse(); - ipRes.setId(ip.getId()); + ipRes.setId(ip.getUuid()); ipRes.setIpAddr(ip.getIp4Address()); ipList.add(ipRes); } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b4bab5a1/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 ba55ff8..52e81e5 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -597,7 +597,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { _accountMgr.checkAccess(caller, null, true, network); Long nicId = secIpVO.getNicId(); - s_logger.debug("ip id and nic id " + ipAddressId + "..." + nicId); + s_logger.debug("ip id = " + ipAddressId + " nic id = " + nicId); //check is this the last secondary ip for NIC List ipList = _nicSecondaryIpDao.listByNicId(nicId); boolean lastIp = false;