Java Code Examples for com.amazonaws.services.ec2.model.DescribeVpcsResult#getVpcs()

The following examples show how to use com.amazonaws.services.ec2.model.DescribeVpcsResult#getVpcs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VpcTableProvider.java    From aws-athena-query-federation with Apache License 2.0 6 votes vote down vote up
/**
 * Calls DescribeVPCs on the AWS EC2 Client returning all VPCs that match the supplied predicate and attempting
 * to push down certain predicates (namely queries for specific VPCs) to EC2.
 *
 * @See TableProvider
 */
@Override
public void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker)
{
    DescribeVpcsRequest request = new DescribeVpcsRequest();

    ValueSet idConstraint = recordsRequest.getConstraints().getSummary().get("id");
    if (idConstraint != null && idConstraint.isSingleValue()) {
        request.setVpcIds(Collections.singletonList(idConstraint.getSingleValue().toString()));
    }

    DescribeVpcsResult response = ec2.describeVpcs(request);
    for (Vpc vpc : response.getVpcs()) {
        instanceToRow(vpc, spiller);
    }
}
 
Example 2
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private Set<CloudNetwork> getCloudNetworks(AmazonEC2Client ec2Client,
        DescribeRouteTablesResult describeRouteTablesResult, DescribeVpcsResult describeVpcsResult) {

    Set<CloudNetwork> cloudNetworks = new HashSet<>();
    LOGGER.debug("Processing VPCs");
    for (Vpc vpc : describeVpcsResult.getVpcs()) {
        List<Subnet> awsSubnets = getSubnets(ec2Client, vpc);
        Set<CloudSubnet> subnets = convertAwsSubnetsToCloudSubnets(describeRouteTablesResult, awsSubnets);

        Map<String, Object> properties = prepareNetworkProperties(vpc);
        Optional<String> name = getName(vpc.getTags());
        if (name.isPresent()) {
            cloudNetworks.add(new CloudNetwork(name.get(), vpc.getVpcId(), subnets, properties));
        } else {
            cloudNetworks.add(new CloudNetwork(vpc.getVpcId(), vpc.getVpcId(), subnets, properties));
        }
    }
    return cloudNetworks;
}
 
Example 3
Source File: AwsNetworkConnector.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public NetworkCidr getNetworkCidr(Network network, CloudCredential credential) {
    AwsCredentialView awsCredentialView = new AwsCredentialView(credential);
    AmazonEC2Client awsClientAccess = awsClient.createAccess(awsCredentialView, network.getStringParameter(AwsNetworkView.REGION));
    AwsNetworkView awsNetworkView = new AwsNetworkView(network);
    String existingVpc = awsNetworkView.getExistingVpc();
    DescribeVpcsResult describeVpcsResult = awsClientAccess.describeVpcs(new DescribeVpcsRequest().withVpcIds(existingVpc));
    List<String> vpcCidrs = new ArrayList<>();
    for (Vpc vpc : describeVpcsResult.getVpcs()) {
        if (vpc.getCidrBlockAssociationSet() != null) {
            LOGGER.info("The VPC {} has associated CIDR block so using the CIDR blocks in the VPC.", vpc.getVpcId());
            List<String> cidrs = vpc.getCidrBlockAssociationSet()
                    .stream()
                    .map(VpcCidrBlockAssociation::getCidrBlock)
                    .collect(Collectors.toList());
            LOGGER.info("The VPC {} CIDRs block are {}.", vpc.getVpcId(), cidrs);
            vpcCidrs.addAll(cidrs);
        } else {
            LOGGER.info("The VPC {} has no associated CIDR block so using the CIDR block in the VPC.", vpc.getVpcId());
            vpcCidrs.add(vpc.getCidrBlock());
        }
    }

    if (vpcCidrs.isEmpty()) {
        throw new BadRequestException("VPC cidr could not fetch from AWS: " + existingVpc);
    }
    if (vpcCidrs.size() > 1) {
        LOGGER.info("More than one vpc cidrs for VPC {}. We will use the first one: {}", existingVpc, vpcCidrs.get(0));
    }
    return new NetworkCidr(vpcCidrs.get(0), vpcCidrs);
}
 
Example 4
Source File: BaseTest.java    From aws-mock with MIT License 5 votes vote down vote up
/**
 * Describe VPCs.
 *
 * @return List of vpcs
 */
protected final List<Vpc> describeVpcs() {
    DescribeVpcsRequest req = new DescribeVpcsRequest();
    DescribeVpcsResult result = amazonEC2Client.describeVpcs(req);
    List<Vpc> vpcs = result.getVpcs();
    return vpcs;
}
 
Example 5
Source File: Ec2Utils.java    From pacbot with Apache License 2.0 3 votes vote down vote up
/**
    * Gets the vpcs for region.
    *
    * @param ec2ServiceClient the ec 2 service client
    * @param region the region
    * @param request the request
    * @return the vpcs for region
    */
public static List<Vpc> getVpcsForRegion(AmazonEC2 ec2ServiceClient,
		Region region, DescribeVpcsRequest request) {
	ec2ServiceClient.setRegion(region);
	DescribeVpcsResult describeVpcsResult =  ec2ServiceClient.describeVpcs(request);
	return  describeVpcsResult.getVpcs();
	
}