use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSSecurityGroupClient method getSecurityGroups.
public List<SecurityGroup> getSecurityGroups(List<String> names, String vpcId) {
DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest();
req.withFilters(new Filter(AWS_GROUP_NAME_FILTER, names));
if (vpcId != null) {
req.withFilters(new Filter(AWS_VPC_ID_FILTER, Collections.singletonList(vpcId)));
}
DescribeSecurityGroupsResult groups = this.client.describeSecurityGroups(req);
return groups != null ? groups.getSecurityGroups() : Collections.emptyList();
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSSecurityGroupClient method getDefaultSecurityGroup.
public SecurityGroup getDefaultSecurityGroup(String vpcId) {
SecurityGroup cellGroup = null;
DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withFilters(new Filter("group-name", Collections.singletonList(DEFAULT_SECURITY_GROUP_NAME)));
if (vpcId != null) {
req.withFilters(new Filter("vpc-id", Collections.singletonList(vpcId)));
}
DescribeSecurityGroupsResult cellGroups = this.client.describeSecurityGroups(req);
if (cellGroups != null && !cellGroups.getSecurityGroups().isEmpty()) {
cellGroup = cellGroups.getSecurityGroups().get(0);
}
return cellGroup;
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class AWSSecurityGroupClient method getSecurityGroup.
public SecurityGroup getSecurityGroup(String name, String vpcId) {
SecurityGroup cellGroup = null;
DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withFilters(new Filter("group-name", Collections.singletonList(name)));
if (vpcId != null) {
req.withFilters(new Filter("vpc-id", Collections.singletonList(vpcId)));
}
DescribeSecurityGroupsResult cellGroups = this.client.describeSecurityGroups(req);
if (cellGroups != null && !cellGroups.getSecurityGroups().isEmpty()) {
cellGroup = cellGroups.getSecurityGroups().get(0);
}
return cellGroup;
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class TestAWSSetupUtils method createOrGetSubnet.
/**
* Creates a Subnet if not exist and return the Subnet id.
*/
public static Subnet createOrGetSubnet(AmazonEC2AsyncClient client, String subnetCidr, String vpcId, String zoneId) {
List<Filter> filters = new ArrayList<>();
Filter vpcFilter = new Filter();
vpcFilter.withName(VPC_KEY);
vpcFilter.withValues(vpcId);
filters.add(vpcFilter);
if (zoneId != null) {
Filter azFilter = new Filter();
azFilter.withName(AVAILABILITY_ZONE_FILTER);
azFilter.withValues(zoneId);
filters.add(azFilter);
}
DescribeSubnetsResult result = client.describeSubnets(new DescribeSubnetsRequest().withFilters(filters));
List<Subnet> defaultSubnets = new ArrayList<>();
result.getSubnets().stream().forEach(subnet -> {
subnet.getTags().stream().filter(tag -> tag.getKey().equalsIgnoreCase(TAG_KEY_FOR_TEST_RESOURCES) && tag.getValue().equalsIgnoreCase(AWS_DEFAULT_SUBNET_NAME)).forEach(tag -> defaultSubnets.add(subnet));
});
if (defaultSubnets != null && !defaultSubnets.isEmpty()) {
return defaultSubnets.get(0);
} else {
CreateSubnetRequest req = new CreateSubnetRequest().withCidrBlock(subnetCidr).withVpcId(vpcId);
if (zoneId != null) {
req.withAvailabilityZone(zoneId);
}
CreateSubnetResult res = client.createSubnet(req);
String subnetId = res.getSubnet().getSubnetId();
tagResources(client, Arrays.asList(subnetId), TAG_KEY_FOR_TEST_RESOURCES, AWS_DEFAULT_SUBNET_NAME);
return res.getSubnet();
}
}
use of com.amazonaws.services.s3.model.Filter in project photon-model by vmware.
the class TestAWSImageEnumerationTask method beforeTest.
@Before
public final void beforeTest() throws Throwable {
CommandLineArgumentParser.parseFromProperties(this);
if (this.isMock) {
return;
}
if (AMAZON_PARAVIRTUAL_IMAGE_NAME == null || AMAZON_HVM_IMAGE_NAME == null) {
// create credentials
AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
creds.privateKey = this.secretKey;
creds.privateKeyId = this.accessKey;
AmazonEC2AsyncClient client = AWSUtils.getAsyncClient(creds, this.regionId, getExecutor());
// Get arbitrary PARAVIRTUAL image name
AMAZON_PARAVIRTUAL_IMAGE_NAME = lookupAwsImage(client, AWSConstants.AWS_IMAGE_VIRTUALIZATION_TYPE_PARAVIRTUAL);
// Get arbitrary HVM image name
AMAZON_HVM_IMAGE_NAME = lookupAwsImage(client, AWSConstants.AWS_IMAGE_VIRTUALIZATION_TYPE_HVM);
{
Filter nameFilter = new Filter("name").withValues(AMAZON_PARAVIRTUAL_IMAGE_NAME);
// Serialize the list of filters to JSON string
AMAZON_PUBLIC_IMAGE_FILTER_SINGLE = Utils.toJson(Arrays.asList(nameFilter));
}
{
Filter nameFilter = new Filter("name").withValues(AMAZON_PARAVIRTUAL_IMAGE_NAME, AMAZON_HVM_IMAGE_NAME);
// Serialize the list of filters to JSON string
AMAZON_PUBLIC_IMAGE_FILTER_PARTITIONING = Utils.toJson(Arrays.asList(nameFilter));
}
}
}
Aggregations