Example usage for com.amazonaws.services.ec2.model DescribeVpcsResult getVpcs

List of usage examples for com.amazonaws.services.ec2.model DescribeVpcsResult getVpcs

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model DescribeVpcsResult getVpcs.

Prototype


public java.util.List<Vpc> getVpcs() 

Source Link

Document

Information about one or more VPCs.

Usage

From source file:com.infinitechaos.vpcviewer.service.impl.VpcServiceImpl.java

License:Open Source License

@Override
@Cacheable(value = CachingConfiguration.VPC_CACHE, key = "#vpcId", condition = "#bypassCache == false")
public Vpc getVpcInRegion(final String vpcId, final String region, boolean bypassCache) {
    Preconditions.checkArgument(StringUtils.isNotBlank(vpcId), "vpcId may not be null or blank");
    Preconditions.checkArgument(StringUtils.isNotBlank(region), "region may not be null or blank");

    LOG.info("Retrieving VPC {} in region {} ({})", vpcId, region, bypassCache);
    DescribeVpcsRequest request = new DescribeVpcsRequest().withVpcIds(vpcId);
    DescribeVpcsResult result = getClientForRegion(region).describeVpcs(request);

    List<Vpc> results = result.getVpcs();

    if (results.size() != 1) {
        throw new IllegalArgumentException("Did not get expected result");
    }/*from w w  w .  j  a  v a  2s . c  o  m*/

    return results.get(0);
}

From source file:com.infinitechaos.vpcviewer.service.impl.VpcServiceImpl.java

License:Open Source License

@Override
@Cacheable(value = CachingConfiguration.VPC_LISTS_CACHE, key = "#region", condition = "#bypassCache == false")
public List<Vpc> getVpcsInRegion(final String region, boolean bypassCache) {
    Preconditions.checkArgument(StringUtils.isNotBlank(region), "region may not be null or blank");

    LOG.info("Retrieving all VPCs in region {} ({})", region, bypassCache);
    DescribeVpcsResult result = getClientForRegion(region).describeVpcs();

    return result.getVpcs();
}

From source file:com.netflix.spinnaker.clouddriver.aws.deploy.handlers.MigrateLoadBalancerStrategy.java

License:Apache License

private Vpc getVpc(LoadBalancerLocation source) {
    if (source.getVpcId() != null) {
        DescribeVpcsResult vpcLookup = getAmazonClientProvider()
                .getAmazonEC2(source.getCredentials(), source.getRegion())
                .describeVpcs(new DescribeVpcsRequest().withVpcIds(source.getVpcId()));
        if (vpcLookup.getVpcs().isEmpty()) {
            throw new IllegalStateException(String.format("Could not find VPC %s in %s/%s", source.getVpcId(),
                    source.getCredentialAccount(), source.getRegion()));
        }//from www .  ja va2 s . c o  m

        return vpcLookup.getVpcs().get(0);
    }

    return null;
}

From source file:com.tvarit.plugin.VpcFinder.java

License:Open Source License

public String find(AmazonEC2Client amazonEC2Client, String projectName) {
    final DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest();
    describeVpcsRequest.withFilters(new Filter("tag-key", Collections.singletonList(projectName + ":vpc")));
    final DescribeVpcsResult describeVpcResult = amazonEC2Client.describeVpcs(describeVpcsRequest);
    return describeVpcResult.getVpcs().get(0).getVpcId();
}

From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.java

License:Open Source License

public Vpc getVPC(String vpcID, AmazonEC2AsyncClient client) {
    DescribeVpcsRequest req = new DescribeVpcsRequest().withVpcIds(vpcID);
    DescribeVpcsResult result = client.describeVpcs(req);
    List<Vpc> vpcs = result.getVpcs();
    if (vpcs != null && vpcs.size() == 1) {
        return vpcs.get(0);
    }/* w w  w.  j  a v a  2  s .  c o m*/
    return null;
}

From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.java

License:Open Source License

public Vpc getDefaultVPC(AmazonEC2AsyncClient client) {
    DescribeVpcsRequest req = new DescribeVpcsRequest();
    DescribeVpcsResult result = client.describeVpcs(req);
    List<Vpc> vpcs = result.getVpcs();
    for (Vpc vpc : vpcs) {
        if (vpc.isDefault()) {
            return vpc;
        }/* w  ww  .j ava 2s.c o m*/
    }
    return null;
}

From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.java

License:Open Source License

/**
 * Gets the subnet associated with the default VPC.
 *//*from  w ww  . j av  a  2s.  c  o  m*/
public static String getDefaultVPCSubnet(AWSAllocation aws) {
    String subnet = null;
    DescribeVpcsResult result = aws.amazonEC2Client.describeVpcs();
    List<Vpc> vpcs = result.getVpcs();

    for (Vpc vpc : vpcs) {
        if (vpc.isDefault()) {
            subnet = vpc.getCidrBlock();
        }
    }
    return subnet;
}

From source file:de.unibi.cebitec.bibigrid.meta.aws.CreateClusterEnvironmentAWS.java

/**
 * Return a VPC that currently exists in selected region. Returns either the
 * *default* vpc from all or the given vpcIds list. If only one vpcId is
 * given it is returned wether it is default or not. Return null in the case
 * no default or fitting VPC is found./*from  w  ww  .  j a v a 2s .  c  o  m*/
 *
 * @param ec2 - AmazonEC2Client
 * @param vpcIds - String...
 * @return
 */
private Vpc getVPC(String... vpcIds) {
    DescribeVpcsRequest dvreq = new DescribeVpcsRequest();
    dvreq.setVpcIds(Arrays.asList(vpcIds));

    DescribeVpcsResult describeVpcsResult = cluster.getEc2().describeVpcs(dvreq);
    List<Vpc> lvpcs = describeVpcsResult.getVpcs();

    if (vpcIds.length == 1 && lvpcs.size() == 1) {
        return lvpcs.get(0);
    }
    if (!lvpcs.isEmpty()) {
        for (Vpc vpc_d : lvpcs) {
            if (vpc_d.isDefault()) {
                return vpc_d;
            }
        }
    }
    return null;
}

From source file:io.macgyver.plugin.cloud.aws.scanner.VPCScanner.java

License:Apache License

@Override
public void scan(Region region) {

    AmazonEC2Client c = getAWSServiceClient().createEC2Client(region);

    DescribeVpcsResult result = c.describeVpcs();

    GraphNodeGarbageCollector gc = newGarbageCollector().region(region).label("AwsVpc");
    NeoRxClient neoRx = getNeoRxClient();
    Preconditions.checkNotNull(neoRx);/*from w w  w .j  a v  a  2 s  . com*/

    result.getVpcs().forEach(it -> {
        try {
            ObjectNode n = convertAwsObject(it, region);

            String cypher = "merge (x:AwsVpc {aws_arn:{aws_arn}}) set x+={props} set x.updateTs=timestamp() return x";

            String mapToSubnetCypher = "match (y:AwsSubnet {aws_vpcId:{aws_vpcId}}), "
                    + "(x:AwsVpc {aws_arn:{aws_arn}}) "
                    + "merge (x)-[r:CONTAINS]->(y) set r.updateTs=timestamp()";

            neoRx.execCypher(cypher, "aws_arn", n.path("aws_arn").asText(), "props", n)
                    .forEach(gc.MERGE_ACTION);
            neoRx.execCypher(mapToSubnetCypher, "aws_arn", n.path("aws_arn").asText(), "aws_vpcId",
                    n.path("aws_vpcId").asText());
        } catch (RuntimeException e) {
            logger.warn("problem scanning VPC", e);
        }
    });

    String mapAccountCypher = "match (x:AwsAccount {aws_account:{aws_account}}), (y:AwsVpc {aws_account:{aws_account}}) "
            + "merge (x)-[r:OWNS]->(y) set r.updateTs=timestamp()";
    String mapRegionCypher = "match (x:AwsVpc {aws_region:{aws_region}}), (y:AwsRegion {aws_regionName:{aws_region}, aws_account:{aws_account}}) "
            + "merge (x)-[r:RESIDES_IN]->(y) set r.updateTs=timestamp()";

    neoRx.execCypher(mapAccountCypher, "aws_account", getAccountId());
    neoRx.execCypher(mapRegionCypher, "aws_region", region.getName(), "aws_account", getAccountId());
    gc.invoke();
}

From source file:org.jenkinsci.plugins.amazonwebservices.cloud.EC2.java

License:Open Source License

public static List<String> getVPCs(AmazonEC2 ec2) {
    DescribeVpcsResult ec2res = ec2.describeVpcs();
    List<String> res = new ArrayList<String>();
    for (Vpc v : ec2res.getVpcs()) {
        res.add(v.getVpcId());/* ww w  .j a  va 2  s  .  c  om*/
    }
    return res;
}