Search in sources :

Example 11 with Subnet

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);
}
Also used : CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest)

Example 12 with Subnet

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 -> {
    });
}
Also used : AssociateRouteTableResult(com.amazonaws.services.ec2.model.AssociateRouteTableResult) AssociateRouteTableRequest(com.amazonaws.services.ec2.model.AssociateRouteTableRequest)

Example 13 with Subnet

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));
}
Also used : CreateNatGatewayRequest(com.amazonaws.services.ec2.model.CreateNatGatewayRequest) CreateNatGatewayResult(com.amazonaws.services.ec2.model.CreateNatGatewayResult)

Example 14 with Subnet

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);
}
Also used : DeleteSubnetResult(com.amazonaws.services.ec2.model.DeleteSubnetResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception)

Example 15 with Subnet

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);
}
Also used : NetSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NetSpec) ArrayList(java.util.ArrayList) Subnet(com.amazonaws.services.ec2.model.Subnet) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) NicSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NicSpec)

Aggregations

DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)26 Subnet (com.amazonaws.services.ec2.model.Subnet)22 Vpc (com.amazonaws.services.ec2.model.Vpc)22 HashMap (java.util.HashMap)22 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)21 Test (org.junit.Test)20 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)17 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)14 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)14 Group (com.sequenceiq.cloudbreak.cloud.model.Group)14 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)14 Location (com.sequenceiq.cloudbreak.cloud.model.Location)14 Network (com.sequenceiq.cloudbreak.cloud.model.Network)14 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)14 ArrayList (java.util.ArrayList)12 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)11 Filter (com.amazonaws.services.ec2.model.Filter)9 HashSet (java.util.HashSet)7