Skip to content

Commit

Permalink
CLOUDSTACK-3258. In AWSAPI provide Tags support for resource 'securit…
Browse files Browse the repository at this point in the history
…y group'

Signed-off-by: Likitha Shetty <likitha.shetty@citrix.com>
  • Loading branch information
Likitha Shetty committed Jul 4, 2013
1 parent 135b688 commit 3cfaa92
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
2 changes: 2 additions & 0 deletions awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
Expand Up @@ -2127,6 +2127,8 @@ public static DescribeSecurityGroupsResponse toDescribeSecurityGroupsResponse(
param4.addItem(param5);
}
param3.setIpPermissions(param4);
EC2TagKeyValue[] tags = group.getResourceTags();
param3.setTagSet(setResourceTags(tags));
param2.addItem(param3);
}
param1.setSecurityGroupInfo(param2);
Expand Down
13 changes: 12 additions & 1 deletion awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
Expand Up @@ -2062,7 +2062,14 @@ private EC2DescribeSecurityGroupsResponse listSecurityGroups( String[] intereste
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;
Expand Down Expand Up @@ -2511,6 +2518,8 @@ private String mapToCloudStackResourceType( String resourceType) {
return("template");
else if(resourceType.equalsIgnoreCase("instance"))
return("userVm");
else if (resourceType.equalsIgnoreCase("security-group"))
return("securityGroup");
else
return resourceType;
}
Expand All @@ -2526,6 +2535,8 @@ private String mapToAmazonResourceType( String resourceType) {
return("image");
else if(resourceType.equalsIgnoreCase("userVm"))
return("instance");
else if(resourceType.equalsIgnoreCase("securityGroup"))
return("security-group");
else
return (resourceType.toLowerCase());
}
Expand Down
Expand Up @@ -45,6 +45,8 @@ public 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" );
}


Expand Down Expand Up @@ -119,6 +121,42 @@ else if (filterName.equalsIgnoreCase( "owner-id" )) {
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;
}

Expand Down Expand Up @@ -182,4 +220,10 @@ private boolean containsString( String lookingFor, String[] set )
return false;
}

private boolean containsEmptyValue( String[] set ) {
for( int i=0; i < set.length; i++ )
if (set[i].isEmpty()) return true;
return false;
}

}
Expand Up @@ -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;
Expand Down Expand Up @@ -91,5 +92,13 @@ public String getDomainId() {
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]);
}

}
Expand Up @@ -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() {
Expand Down Expand Up @@ -79,4 +81,9 @@ public Integer getJobStatus() {
public List<CloudStackIngressRule> getIngressRules() {
return ingressRules;
}

public List<CloudStackKeyValue> getTags() {
return tags;
}

}

0 comments on commit 3cfaa92

Please sign in to comment.