use of software.amazon.awssdk.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;
}
use of software.amazon.awssdk.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);
}
}
use of software.amazon.awssdk.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);
}
use of software.amazon.awssdk.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;
}
use of software.amazon.awssdk.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;
});
}
Aggregations