You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2013/06/25 00:34:28 UTC

git commit: updated refs/heads/master to 8b2aae0

Updated Branches:
  refs/heads/master 388e80efb -> 8b2aae0bf


CLOUDSTACK-3169: ipAssoc - set account id of the ip to the project account. Used to be set to the network owner which is System in Shared network case, and the further verification used to fail because of that


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8b2aae0b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8b2aae0b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8b2aae0b

Branch: refs/heads/master
Commit: 8b2aae0bfecde3db7e804a328fc99b136513bee7
Parents: 388e80e
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Mon Jun 24 15:25:05 2013 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Mon Jun 24 15:25:05 2013 -0700

----------------------------------------------------------------------
 .../user/address/AssociateIPAddrCmd.java        | 47 +++++++++++++++++---
 1 file changed, 40 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b2aae0b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
index b99ca63..c97a5e4 100644
--- a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
@@ -16,21 +16,42 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.address;
 
+import java.util.List;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.IPAddressResponse;
+import org.apache.cloudstack.api.response.NetworkResponse;
+import org.apache.cloudstack.api.response.ProjectResponse;
+import org.apache.cloudstack.api.response.RegionResponse;
+import org.apache.cloudstack.api.response.VpcResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.log4j.Logger;
+
 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.*;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.IpAddress;
 import com.cloud.network.Network;
 import com.cloud.network.vpc.Vpc;
+import com.cloud.projects.Project;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
-import org.apache.cloudstack.api.*;
-import org.apache.cloudstack.api.response.*;
-import org.apache.log4j.Logger;
-
-import java.util.List;
 
 @APICommand(name = "associateIpAddress", description="Acquires and associates a public IP to an account.", responseObject=IPAddressResponse.class)
 public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
@@ -175,7 +196,19 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
         if (accountName != null && domainId != null) {
             Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
             return account.getId();
-        } else if (networkId != null){
+        } else if (projectId != null) {
+            Project project = _projectService.getProject(projectId);
+            if (project != null) {
+                if (project.getState() == Project.State.Active) {
+                    return project.getProjectAccountId();
+                } else {
+                    throw new PermissionDeniedException("Can't add resources to the project with specified projectId in state="
+                           + project.getState() + " as it's no longer active");
+                }
+            } else {
+                throw new InvalidParameterValueException("Unable to find project by id");
+            }
+       } else if (networkId != null){
             Network network = _networkService.getNetwork(networkId);
             return network.getAccountId();
         } else if (vpcId != null) {