CLOUDSTACK-3258. In AWSAPI provide Tags support for resource 'security group'

This commit is contained in:
Likitha Shetty 2013-06-27 16:57:27 +05:30
parent 9d56244f41
commit 96d466dcd7
5 changed files with 75 additions and 2 deletions

View File

@ -2127,6 +2127,8 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
param4.addItem(param5);
}
param3.setIpPermissions(param4);
EC2TagKeyValue[] tags = group.getResourceTags();
param3.setTagSet(setResourceTags(tags));
param2.addItem(param3);
}
param1.setSecurityGroupInfo(param2);

View File

@ -2062,7 +2062,14 @@ public class EC2Engine extends ManagerBase {
ec2Group.setDomainId(group.getDomainId());
ec2Group.setId(group.getId().toString());
toPermission(ec2Group, group);
List<CloudStackKeyValue> resourceTags = group.getTags();
for(CloudStackKeyValue resourceTag : resourceTags) {
EC2TagKeyValue param = new EC2TagKeyValue();
param.setKey(resourceTag.getKey());
if (resourceTag.getValue() != null)
param.setValue(resourceTag.getValue());
ec2Group.addResourceTag(param);
}
groupSet.addGroup(ec2Group);
}
return groupSet;
@ -2511,6 +2518,8 @@ public class EC2Engine extends ManagerBase {
return("template");
else if(resourceType.equalsIgnoreCase("instance"))
return("userVm");
else if (resourceType.equalsIgnoreCase("security-group"))
return("securityGroup");
else
return resourceType;
}
@ -2526,6 +2535,8 @@ public class EC2Engine extends ManagerBase {
return("image");
else if(resourceType.equalsIgnoreCase("userVm"))
return("instance");
else if(resourceType.equalsIgnoreCase("securityGroup"))
return("security-group");
else
return (resourceType.toLowerCase());
}

View File

@ -45,6 +45,8 @@ public class EC2GroupFilterSet {
filterTypes.put( "ip-permission.group-name","string" );
filterTypes.put( "ip-permission.user-id", "string" );
filterTypes.put( "owner-id", "string" );
filterTypes.put( "tag-key", "string" );
filterTypes.put( "tag-value", "string" );
}
@ -119,6 +121,42 @@ public class EC2GroupFilterSet {
String owner = new String( sg.getDomainId() + ":" + sg.getAccountName());
return containsString( owner, valueSet );
}
else if (filterName.equalsIgnoreCase("tag-key"))
{
EC2TagKeyValue[] tagSet = sg.getResourceTags();
for (EC2TagKeyValue tag : tagSet)
if (containsString(tag.getKey(), valueSet)) return true;
return false;
}
else if (filterName.equalsIgnoreCase("tag-value"))
{
EC2TagKeyValue[] tagSet = sg.getResourceTags();
for (EC2TagKeyValue tag : tagSet){
if (tag.getValue() == null) {
if (containsEmptyValue(valueSet)) return true;
}
else {
if (containsString(tag.getValue(), valueSet)) return true;
}
}
return false;
}
else if (filterName.startsWith("tag:"))
{
String key = filterName.split(":")[1];
EC2TagKeyValue[] tagSet = sg.getResourceTags();
for (EC2TagKeyValue tag : tagSet){
if (tag.getKey().equalsIgnoreCase(key)) {
if (tag.getValue() == null) {
if (containsEmptyValue(valueSet)) return true;
}
else {
if (containsString(tag.getValue(), valueSet)) return true;
}
}
}
return false;
}
else return false;
}
@ -182,4 +220,10 @@ public class EC2GroupFilterSet {
return false;
}
private boolean containsEmptyValue( String[] set ) {
for( int i=0; i < set.length; i++ )
if (set[i].isEmpty()) return true;
return false;
}
}

View File

@ -27,6 +27,7 @@ public class EC2SecurityGroup {
private String accountName;
private String domainId;
private List<EC2IpPermission> permissionSet = new ArrayList<EC2IpPermission>();
private List<EC2TagKeyValue> tagsSet = new ArrayList<EC2TagKeyValue>();
public EC2SecurityGroup() {
id = null;
@ -91,5 +92,13 @@ public class EC2SecurityGroup {
public void setDomainId(String domainId) {
this.domainId = domainId;
}
public void addResourceTag( EC2TagKeyValue param ) {
tagsSet.add( param );
}
public EC2TagKeyValue[] getResourceTags() {
return tagsSet.toArray(new EC2TagKeyValue[0]);
}
}

View File

@ -39,6 +39,8 @@ public class CloudStackSecurityGroup {
private String name;
@SerializedName(ApiConstants.INGRESS_RULE)
private List<CloudStackIngressRule> ingressRules;
@SerializedName(ApiConstants.TAGS)
private List<CloudStackKeyValue> tags;
public CloudStackSecurityGroup() {
@ -79,4 +81,9 @@ public class CloudStackSecurityGroup {
public List<CloudStackIngressRule> getIngressRules() {
return ingressRules;
}
public List<CloudStackKeyValue> getTags() {
return tags;
}
}