incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [2/2] git commit: refs/heads/4.1 - CLOUDSTACK-1121: [EC2 Query API] RunInstances, instance is always deployed in the default security group
Date Mon, 11 Feb 2013 19:34:04 GMT
Updated Branches:
  refs/heads/4.1 2b593dd89 -> b1d0d8d5f


CLOUDSTACK-1121: [EC2 Query API] RunInstances, instance is always deployed in the default
security group

During EC2RunInstances, even if the security group the instance is to be deployed in specified
the instance gets deployed in the default security group


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

Branch: refs/heads/4.1
Commit: b1d0d8d5f9beb834e6f8674f1ea17a535f977345
Parents: e63fc4c
Author: Likitha Shetty <Likitha.Shetty@citrix.com>
Authored: Mon Feb 11 11:19:44 2013 -0800
Committer: Prachi Damle <prachi@cloud.com>
Committed: Mon Feb 11 11:24:06 2013 -0800

----------------------------------------------------------------------
 .../com/cloud/bridge/service/EC2RestServlet.java   |   17 ++++++++++++--
 .../cloud/bridge/service/EC2SoapServiceImpl.java   |   12 +++++-----
 .../cloud/bridge/service/core/ec2/EC2Engine.java   |   12 +++++++---
 .../cloud/bridge/service/core/ec2/EC2Instance.java |   12 +++++-----
 .../service/core/ec2/EC2InstanceFilterSet.java     |    7 +++--
 5 files changed, 38 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b1d0d8d5/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
index ca910e0..5788b35 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
@@ -86,6 +86,7 @@ import com.amazon.ec2.DescribeVolumesResponse;
 import com.amazon.ec2.DetachVolumeResponse;
 import com.amazon.ec2.DisassociateAddressResponse;
 import com.amazon.ec2.GetPasswordDataResponse;
+import com.amazon.ec2.GroupItemType;
 import com.amazon.ec2.ImportKeyPairResponse;
 import com.amazon.ec2.LaunchPermissionItemType;
 import com.amazon.ec2.ModifyImageAttributeResponse;
@@ -1168,6 +1169,16 @@ public class EC2RestServlet extends HttpServlet {
             EC2request.setKeyName(keyName[0]);
         }
 
+        Enumeration<?> names = request.getParameterNames();
+        while( names.hasMoreElements()) {
+            String key = (String)names.nextElement();
+            if ( key.startsWith("SecurityGroup")) {
+                String[] value = request.getParameterValues(key);
+                if (null != value && 0 < value.length)
+                    EC2request.addGroupName( value[0]);
+            }
+        }
+
         // -> execute the request
         EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
         RunInstancesResponse EC2response = EC2SoapServiceImpl.toRunInstancesResponse( engine.runInstances(
EC2request ), engine);
@@ -1681,10 +1692,10 @@ public class EC2RestServlet extends HttpServlet {
         Enumeration<?> names = request.getParameterNames();
         while( names.hasMoreElements()) {
             String key = (String)names.nextElement();
-            if (key.startsWith("KeyName")) {
-                String[] value = request.getParameterValues( key );
+            if ( key.startsWith("KeyName")) {
+                String[] value = request.getParameterValues( key);
                 if (null != value && 0 < value.length)
-                    ec2Request.addKeyName(value[0]);
+                    ec2Request.addKeyName( value[0]);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b1d0d8d5/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java b/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
index 6fae480..bf3c13e 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
@@ -1354,15 +1354,15 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface
 {
 			GroupSetType  param4 = new GroupSetType();
 			
 	        
-            String[] groups = inst.getGroupSet();
+            EC2SecurityGroup[] groups = inst.getGroupSet();
             if (null == groups || 0 == groups.length) {
                 GroupItemType param5 = new GroupItemType();
                 param5.setGroupId("");
                 param4.addItem( param5 );
             } else {
-                for (String group : groups) {
+                for (EC2SecurityGroup group : groups) {
                     GroupItemType param5 = new GroupItemType();
-                    param5.setGroupId(group);
+                    param5.setGroupId(group.getId());
                     param4.addItem( param5 );
                 }
             }
@@ -1681,16 +1681,16 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface
 {
 		
 	        param1.setOwnerId(ownerId);
 			
-            String[] groups = inst.getGroupSet();
+	        EC2SecurityGroup[] groups = inst.getGroupSet();
             GroupSetType  param2 = new GroupSetType();
             if (null == groups || 0 == groups.length) {
                 GroupItemType param3 = new GroupItemType();
                 param3.setGroupId("");
                 param2.addItem( param3 );
             } else {
-                for (String group : groups) {
+                for (EC2SecurityGroup group : groups) {
                     GroupItemType param3 = new GroupItemType();
-                    param3.setGroupId(group);
+                    param3.setGroupId(group.getId());
                     param2.addItem( param3 );   
                 }
             }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b1d0d8d5/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
index 2f45b03..e64cdfc 100644
--- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
+++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
@@ -1459,10 +1459,12 @@ public class EC2Engine extends ManagerBase {
                 vm.setZoneName(resp.getZoneName());
                 vm.setTemplateId(resp.getTemplateId().toString());
                 if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size()
> 0) {
-                    // TODO, we have a list of security groups, just return the first one?
                     List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList();
                     for (CloudStackSecurityGroup securityGroup : securityGroupList) {
-                        vm.addGroupName(securityGroup.getName());
+                        EC2SecurityGroup param = new EC2SecurityGroup();
+                        param.setId(securityGroup.getId());
+                        param.setName(securityGroup.getName());
+                        vm.addGroupName(param);
                     }
                 }
                 vm.setState(resp.getState());
@@ -1883,10 +1885,12 @@ public class EC2Engine extends ManagerBase {
                 }
 
                 if (cloudVm.getSecurityGroupList() != null && cloudVm.getSecurityGroupList().size()
> 0) {
-                    // TODO, we have a list of security groups, just return the first one?
                     List<CloudStackSecurityGroup> securityGroupList = cloudVm.getSecurityGroupList();
                     for (CloudStackSecurityGroup securityGroup : securityGroupList) {
-                        ec2Vm.addGroupName(securityGroup.getName());
+                        EC2SecurityGroup param = new EC2SecurityGroup();
+                        param.setId(securityGroup.getId());
+                        param.setName(securityGroup.getName());
+                        ec2Vm.addGroupName(param);
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b1d0d8d5/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Instance.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Instance.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Instance.java
index 9b43cb7..9dfd1ca 100644
--- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Instance.java
+++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Instance.java
@@ -41,7 +41,7 @@ public class EC2Instance {
     private String      rootDeviceType;
     private String      rootDeviceId;
     private String      keyPairName;
-    private List<String>    groupSet;
+    private List<EC2SecurityGroup>  groupSet;
     private List<EC2TagKeyValue>    tagsSet;
     
 	public EC2Instance() {
@@ -62,7 +62,7 @@ public class EC2Instance {
 		rootDeviceType   = null;
 		rootDeviceId     = null;
 		keyPairName		 = null;
-		groupSet         = new ArrayList<String>();
+        groupSet         = new ArrayList<EC2SecurityGroup>();
         tagsSet          = new ArrayList<EC2TagKeyValue>();
 	}
 	
@@ -202,12 +202,12 @@ public class EC2Instance {
 		keyPairName = param;
     }
 
-    public void addGroupName( String param ) {
+    public void addGroupName( EC2SecurityGroup param ) {
         groupSet.add( param );
     }
-		
-    public String[] getGroupSet() {
-        return groupSet.toArray(new String[0]);
+
+    public EC2SecurityGroup[] getGroupSet() {
+        return groupSet.toArray(new EC2SecurityGroup[0]);
     }
 
     public void addResourceTag( EC2TagKeyValue param ) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b1d0d8d5/awsapi/src/com/cloud/bridge/service/core/ec2/EC2InstanceFilterSet.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2InstanceFilterSet.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2InstanceFilterSet.java
index 449d89e..e0aae73 100644
--- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2InstanceFilterSet.java
+++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2InstanceFilterSet.java
@@ -159,9 +159,10 @@ public class EC2InstanceFilterSet {
 	    }
         else if (filterName.equalsIgnoreCase( "group-id"))
         {
-            String[] groupSet = vm.getGroupSet();
-            for (String group : groupSet)
-                if (containsString(group, valueSet)) return true;
+            EC2SecurityGroup[] groupSet = vm.getGroupSet();
+            for (EC2SecurityGroup group: groupSet) {
+                if( containsString(group.getId(), valueSet)) return true;
+            }
             return false;
         }
         else if (filterName.equalsIgnoreCase("tag-key"))


Mime
View raw message