cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/rbac to a6d03cd
Date Fri, 13 Dec 2013 01:21:49 GMT
Updated Branches:
  refs/heads/rbac add277a4a -> a6d03cd82


Separate IpAddress related cmds to use two different views.

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

Branch: refs/heads/rbac
Commit: a6d03cd82670a0ec313b739b949d3166a5b033ad
Parents: add277a
Author: Min Chen <min.chen@citrix.com>
Authored: Thu Dec 12 17:20:34 2013 -0800
Committer: Min Chen <min.chen@citrix.com>
Committed: Thu Dec 12 17:20:34 2013 -0800

----------------------------------------------------------------------
 .../cloudstack/api/ResponseGenerator.java       |  2 +-
 .../address/AssociateIPAddrCmdByAdmin.java      | 65 ++++++++++++++++++++
 .../ListPublicIpAddressesCmdByAdmin.java        | 53 ++++++++++++++++
 .../user/address/AssociateIPAddrCmd.java        |  5 +-
 .../user/address/ListPublicIpAddressesCmd.java  | 11 ++--
 server/src/com/cloud/api/ApiResponseHelper.java |  7 +--
 6 files changed, 132 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d03cd8/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 91677cf..bd42f2b 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -234,7 +234,7 @@ public interface ResponseGenerator {
 
     VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan);
 
-    IPAddressResponse createIPAddressResponse(IpAddress ipAddress);
+    IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddress);
 
     GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(GuestVlan result);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d03cd8/api/src/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
b/api/src/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
new file mode 100644
index 0000000..dbff93f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
@@ -0,0 +1,65 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.address;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
+import org.apache.cloudstack.api.response.IPAddressResponse;
+import org.apache.cloudstack.context.CallContext;
+
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.IpAddress;
+
+@APICommand(name = "associateIpAddress", description = "Acquires and associates a public
IP to an account.", responseObject = IPAddressResponse.class, responseView = ResponseView.Full)
+public class AssociateIPAddrCmdByAdmin extends AssociateIPAddrCmd {
+    public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmdByAdmin.class.getName());
+
+
+    @Override
+    public void execute() throws ResourceUnavailableException, ResourceAllocationException,
+                                    ConcurrentOperationException, InsufficientCapacityException
{
+        CallContext.current().setEventDetails("Ip Id: " + getEntityId());
+
+        IpAddress result = null;
+
+        if (getVpcId() != null) {
+            result = _vpcService.associateIPToVpc(getEntityId(), getVpcId());
+        } else if (getNetworkId() != null) {
+            result = _networkService.associateIPToNetwork(getEntityId(), getNetworkId());
+        }
+
+        if (result != null) {
+            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full,
result);
+            ipResponse.setResponseName(getCommandName());
+            setResponseObject(ipResponse);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign ip
address");
+        }
+    }
+
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d03cd8/api/src/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
b/api/src/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
new file mode 100644
index 0000000..3762e5f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.address;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
+import org.apache.cloudstack.api.response.IPAddressResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+
+import com.cloud.network.IpAddress;
+import com.cloud.utils.Pair;
+
+@APICommand(name = "listPublicIpAddresses", description = "Lists all public ip addresses",
responseObject = IPAddressResponse.class, responseView = ResponseView.Full)
+public class ListPublicIpAddressesCmdByAdmin extends ListPublicIpAddressesCmd {
+    public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmdByAdmin.class.getName());
+
+    @Override
+    public void execute(){
+        Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
+        ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
+        List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
+        for (IpAddress ipAddress : result.first()) {
+            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full,
ipAddress);
+            ipResponse.setObjectName("publicipaddress");
+            ipAddrResponses.add(ipResponse);
+        }
+
+        response.setResponses(ipAddrResponses, result.second());
+        response.setResponseName(getCommandName());
+        setResponseObject(response);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d03cd8/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 48ffd12..a93218e 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
@@ -28,6 +28,7 @@ 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.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.IPAddressResponse;
@@ -55,7 +56,7 @@ import com.cloud.offering.NetworkOffering;
 import com.cloud.projects.Project;
 import com.cloud.user.Account;
 
-@APICommand(name = "associateIpAddress", description="Acquires and associates a public IP
to an account.", responseObject=IPAddressResponse.class)
+@APICommand(name = "associateIpAddress", description = "Acquires and associates a public
IP to an account.", responseObject = IPAddressResponse.class, responseView = ResponseView.Restricted)
 public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
     public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmd.class.getName());
     private static final String s_name = "associateipaddressresponse";
@@ -307,7 +308,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
         }
 
         if (result != null) {
-            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
+            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted,
result);
             ipResponse.setResponseName(getCommandName());
             setResponseObject(ipResponse);
         } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d03cd8/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
b/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
index bc179b2..ebe7a75 100644
--- a/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
@@ -19,11 +19,14 @@ package org.apache.cloudstack.api.command.user.address;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiCommandJobType;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.response.IPAddressResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.NetworkResponse;
@@ -31,12 +34,11 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
 import org.apache.cloudstack.api.response.VlanIpRangeResponse;
 import org.apache.cloudstack.api.response.VpcResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.network.IpAddress;
 import com.cloud.utils.Pair;
 
-@APICommand(name = "listPublicIpAddresses", description="Lists all public ip addresses",
responseObject=IPAddressResponse.class)
+@APICommand(name = "listPublicIpAddresses", description = "Lists all public ip addresses",
responseObject = IPAddressResponse.class, responseView = ResponseView.Restricted)
 public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
     public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName());
 
@@ -149,16 +151,17 @@ public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd
{
         ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
         List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
         for (IpAddress ipAddress : result.first()) {
-            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ipAddress);
+            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted,
ipAddress);
             ipResponse.setObjectName("publicipaddress");
             ipAddrResponses.add(ipResponse);
         }
 
         response.setResponses(ipAddrResponses, result.second());
         response.setResponseName(getCommandName());
-        this.setResponseObject(response);
+        setResponseObject(response);
     }
 
+    @Override
     public ApiCommandJobType getInstanceType() {
         return ApiCommandJobType.IpAddress;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d03cd8/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 2aacb78..556f3e5 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -620,7 +620,7 @@ public class ApiResponseHelper implements ResponseGenerator {
     }
 
     @Override
-    public IPAddressResponse createIPAddressResponse(IpAddress ipAddr) {
+    public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddr)
{
         VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
         boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
         long zoneId = ipAddr.getDataCenterId();
@@ -705,9 +705,8 @@ public class ApiResponseHelper implements ResponseGenerator {
             }
         }
 
-        // show this info to admin only
-        Account account = CallContext.current().getCallingAccount();
-        if (_accountMgr.isRootAdmin(account.getId())) {
+        // show this info to full view only
+        if (view == ResponseView.Full) {
             VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId());
             if (vl != null) {
                 ipResponse.setVlanId(vl.getUuid());


Mime
View raw message