Search in sources :

Example 1 with DescribeVpcsRequest

use of com.amazonaws.services.ec2.model.DescribeVpcsRequest in project photon-model by vmware.

the class AWSNetworkClient method getVPC.

public Vpc getVPC(String vpcId) {
    DescribeVpcsRequest req = new DescribeVpcsRequest().withVpcIds(vpcId);
    DescribeVpcsResult result = this.client.describeVpcs(req);
    List<Vpc> vpcs = result.getVpcs();
    if (vpcs != null && vpcs.size() == 1) {
        return vpcs.get(0);
    }
    return null;
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Vpc(com.amazonaws.services.ec2.model.Vpc)

Example 2 with DescribeVpcsRequest

use of com.amazonaws.services.ec2.model.DescribeVpcsRequest in project aws-doc-sdk-examples by awsdocs.

the class DescribeVPCs method describeEC2Vpcs.

// snippet-start:[ec2.java2.describe_vpc.main]
public static void describeEC2Vpcs(Ec2Client ec2, String vpcId) {
    try {
        DescribeVpcsRequest request = DescribeVpcsRequest.builder().vpcIds(vpcId).build();
        DescribeVpcsResponse response = ec2.describeVpcs(request);
        for (Vpc vpc : response.vpcs()) {
            System.out.printf("Found VPC with id %s, " + "vpc state %s " + "and tennancy %s", vpc.vpcId(), vpc.stateAsString(), vpc.instanceTenancyAsString());
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DescribeVpcsRequest(software.amazon.awssdk.services.ec2.model.DescribeVpcsRequest) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) Vpc(software.amazon.awssdk.services.ec2.model.Vpc) DescribeVpcsResponse(software.amazon.awssdk.services.ec2.model.DescribeVpcsResponse)

Example 3 with DescribeVpcsRequest

use of com.amazonaws.services.ec2.model.DescribeVpcsRequest in project photon-model by vmware.

the class AWSNetworkStateEnumerationAdapterService method refreshVPCInformation.

private void refreshVPCInformation(AWSNetworkStateCreationContext aws, AWSNetworkStateCreationStage next) {
    DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest();
    AWSVPCAsyncHandler asyncHandler = new AWSVPCAsyncHandler(next, aws);
    aws.amazonEC2Client.describeVpcsAsync(vpcRequest, asyncHandler);
}
Also used : DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest)

Example 4 with DescribeVpcsRequest

use of com.amazonaws.services.ec2.model.DescribeVpcsRequest in project photon-model by vmware.

the class AWSNetworkClient method getDefaultVPC.

/**
 * Get the default VPC - return null if no default specified
 */
public Vpc getDefaultVPC() {
    DescribeVpcsRequest req = new DescribeVpcsRequest();
    DescribeVpcsResult result = this.client.describeVpcs(req);
    List<Vpc> vpcs = result.getVpcs();
    for (Vpc vpc : vpcs) {
        if (vpc.isDefault()) {
            return vpc;
        }
    }
    return null;
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Vpc(com.amazonaws.services.ec2.model.Vpc)

Example 5 with DescribeVpcsRequest

use of com.amazonaws.services.ec2.model.DescribeVpcsRequest in project photon-model by vmware.

the class AWSInstanceContext method getVPCs.

/**
 * For every NIC lookup associated AWS VPC as specified by
 * {@code AWSNicContext.networkState.id}. If any of the VPCs is not found then complete with an
 * exception.
 */
private DeferredResult<AWSInstanceContext> getVPCs(AWSInstanceContext context) {
    if (context.nics.isEmpty()) {
        return DeferredResult.completed(context);
    }
    List<DeferredResult<DescribeVpcsResult>> getVpcDRs = new ArrayList<>();
    for (AWSNicContext nicCtx : context.nics) {
        DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withFilters(new Filter(AWS_VPC_ID_FILTER, singletonList(nicCtx.networkState.id)));
        String msg = "Getting AWS VPC [" + nicCtx.networkState.id + "/" + nicCtx.networkState.name + "/" + "] for [" + nicCtx.nicStateWithDesc.name + "] NIC for [" + context.child.name + "] VM";
        AWSDeferredResultAsyncHandler<DescribeVpcsRequest, DescribeVpcsResult> handler = new AWSDeferredResultAsyncHandler<DescribeVpcsRequest, DescribeVpcsResult>(this.service, msg) {

            @Override
            protected DeferredResult<DescribeVpcsResult> consumeSuccess(DescribeVpcsRequest request, DescribeVpcsResult result) {
                if (result.getVpcs().isEmpty()) {
                    String msg = String.format("VPC with [%s] id is not found in AWS for [%s] NIC of [%s] VM.", nicCtx.networkState.id, nicCtx.nicStateWithDesc.name, context.child.name);
                    return DeferredResult.failed(new IllegalStateException(msg));
                }
                nicCtx.vpc = result.getVpcs().get(0);
                return DeferredResult.completed(result);
            }
        };
        context.amazonEC2Client.describeVpcsAsync(vpcRequest, handler);
        getVpcDRs.add(handler.toDeferredResult());
    }
    return DeferredResult.allOf(getVpcDRs).handle((all, exc) -> {
        if (exc != null) {
            String msg = String.format("Error getting VPCs from AWS for [%s] VM.", context.child.name);
            throw new IllegalStateException(msg, exc);
        }
        return context;
    });
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Filter(com.amazonaws.services.ec2.model.Filter) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) ArrayList(java.util.ArrayList) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)6 Vpc (com.amazonaws.services.ec2.model.Vpc)4 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 Filter (com.amazonaws.services.ec2.model.Filter)2 Subnet (com.amazonaws.services.ec2.model.Subnet)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)2 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)1 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 PlatformResourceVpcFilterView (com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceVpcFilterView)1 AWSDeferredResultAsyncHandler (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 DescribeVpcsRequest (software.amazon.awssdk.services.ec2.model.DescribeVpcsRequest)1 DescribeVpcsResponse (software.amazon.awssdk.services.ec2.model.DescribeVpcsResponse)1