mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
05280976e5
commit
f839ad7b53
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ) {
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue