use of com.amazonaws.services.ec2.model.Subnet in project photon-model by vmware.
the class AWSNetworkClient method createSubnetAsync.
/**
* Async create the subnet and return it.
*/
public DeferredResult<Subnet> createSubnetAsync(String subnetCidr, String vpcId, String zoneId) {
CreateSubnetRequest req = new CreateSubnetRequest().withCidrBlock(subnetCidr).withVpcId(vpcId).withAvailabilityZone(zoneId);
String message = "Create AWS Subnet with CIDR [" + subnetCidr + "] for vpc id [" + vpcId + "].";
AWSDeferredResultAsyncHandler<CreateSubnetRequest, CreateSubnetResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
this.client.createSubnetAsync(req, handler);
return handler.toDeferredResult().thenApply(CreateSubnetResult::getSubnet);
}
use of com.amazonaws.services.ec2.model.Subnet in project photon-model by vmware.
the class AWSNetworkClient method associateSubnetToRouteTable.
/**
* Associate a subnet to an existing route table
*/
public DeferredResult<Void> associateSubnetToRouteTable(String routeTableId, String subnetId) {
AssociateRouteTableRequest req = new AssociateRouteTableRequest().withSubnetId(subnetId).withRouteTableId(routeTableId);
String message = "Associate AWS Subnet [" + subnetId + "] to route table [" + routeTableId + "].";
AWSDeferredResultAsyncHandler<AssociateRouteTableRequest, AssociateRouteTableResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
this.client.associateRouteTableAsync(req, handler);
return handler.toDeferredResult().thenAccept(ignore -> {
});
}
use of com.amazonaws.services.ec2.model.Subnet in project photon-model by vmware.
the class AWSNetworkClient method createNatGateway.
/**
* Create a NAT Gateway
* It waits for the NAT gateway to become available before returning the gateway id.
*/
public DeferredResult<String> createNatGateway(String publicSubnetId, String allocationId, TaskManager taskManager, long taskExpirationMicros) {
CreateNatGatewayRequest req = new CreateNatGatewayRequest().withSubnetId(publicSubnetId).withAllocationId(allocationId);
String message = "Create AWS NAT Gateway for subnet [" + publicSubnetId + "] with elastic IP allocation id [" + allocationId + "].";
AWSDeferredResultAsyncHandler<CreateNatGatewayRequest, CreateNatGatewayResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
this.client.createNatGatewayAsync(req, handler);
return handler.toDeferredResult().thenApply(CreateNatGatewayResult::getNatGateway).thenApply(NatGateway::getNatGatewayId).thenCompose(natGatewayId -> waitForNatGatewayState(natGatewayId, taskManager, taskExpirationMicros, AWSTaskStatusChecker.AWS_AVAILABLE_NAME));
}
use of com.amazonaws.services.ec2.model.Subnet in project photon-model by vmware.
the class AWSNetworkClient method deleteSubnetAsync.
public DeferredResult<Void> deleteSubnetAsync(String subnetId) {
DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(subnetId);
String message = "Delete AWS Subnet with id [" + subnetId + "].";
AWSDeferredResultAsyncHandler<DeleteSubnetRequest, DeleteSubnetResult> handler = new AWSDeferredResultAsyncHandler<DeleteSubnetRequest, DeleteSubnetResult>(this.service, message) {
@Override
protected Exception consumeError(Exception exception) {
if (exception instanceof AmazonEC2Exception) {
AmazonEC2Exception amazonExc = (AmazonEC2Exception) exception;
if (STATUS_CODE_SUBNET_NOT_FOUND.equals(amazonExc.getErrorCode())) {
// AWS subnet doesn't exist.
this.service.logWarning(() -> String.format("Unable to delete AWS " + "subnet with id [%s], as it does not exist.", subnetId));
return RECOVERED;
}
}
return exception;
}
};
this.client.deleteSubnetAsync(req, handler);
return handler.toDeferredResult().thenApply(result -> (Void) null);
}
use of com.amazonaws.services.ec2.model.Subnet in project photon-model by vmware.
the class TestAWSSetupUtils method setUpTestVpc.
public static void setUpTestVpc(AmazonEC2AsyncClient client, Map<String, Object> awsTestContext, boolean isMock, String zoneId) {
// If the pre-set VPC does not exist, get the test VPC for the given account and use it in the tests.
if (!isMock && !vpcIdExists(client, AWS_DEFAULT_VPC_ID)) {
String vpcId = createorGetVPCForAccount(client);
awsTestContext.put(VPC_KEY, vpcId);
Subnet subnet = createOrGetSubnet(client, AWS_DEFAULT_SUBNET_CIDR, vpcId, zoneId);
awsTestContext.put(SUBNET_KEY, subnet.getSubnetId());
String internetGatewayId = createOrGetInternetGatewayForGivenVPC(client, vpcId);
awsTestContext.put(INTERNET_GATEWAY_KEY, internetGatewayId);
SecurityGroup sg = createOrGetDefaultSecurityGroupForGivenVPC(client, vpcId);
awsTestContext.put(SECURITY_GROUP_KEY, sg.getGroupId());
awsTestContext.put(SECURITY_GROUP_NAME_KEY, sg.getGroupName());
NetSpec network = new NetSpec(vpcId, vpcId, AWS_DEFAULT_VPC_CIDR);
List<NetSpec> subnets = new ArrayList<>();
subnets.add(new NetSpec(subnet.getSubnetId(), AWS_DEFAULT_SUBNET_NAME, subnet.getCidrBlock(), zoneId == null ? TestAWSSetupUtils.zoneId + avalabilityZoneIdentifier : zoneId));
NicSpec nicSpec = NicSpec.create().withSubnetSpec(subnets.get(0)).withDynamicIpAssignment();
awsTestContext.put(NIC_SPECS_KEY, new AwsNicSpecs(network, Collections.singletonList(nicSpec)));
return;
}
awsTestContext.put(VPC_KEY, AWS_DEFAULT_VPC_ID);
awsTestContext.put(NIC_SPECS_KEY, SINGLE_NIC_SPEC);
awsTestContext.put(SUBNET_KEY, AWS_DEFAULT_SUBNET_ID);
awsTestContext.put(SECURITY_GROUP_KEY, AWS_DEFAULT_GROUP_ID);
awsTestContext.put(SECURITY_GROUP_NAME_KEY, AWS_DEFAULT_GROUP_NAME);
}
Aggregations