Search in sources :

Example 6 with RouteTable

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

the class TestAWSNetworkService method testEnvironmentCreation.

/*
     * Test covers the necessary elements for a successful environment creation
     * These environmental elements are necessary before any VM instances can be
     * created
     *
     * - Internet Gateway
     * - VPC
     * - Subnet
     * - Route to IG
     *
     */
@Test
public void testEnvironmentCreation() throws Throwable {
    boolean attached = false;
    String gatewayID = this.netClient.createInternetGateway();
    assertTrue(gatewayID != null);
    String vpcID = this.netClient.createVPC(AWS_DEFAULT_SUBNET_CIDR);
    assertTrue(vpcID != null);
    String subnetID = this.netClient.createSubnet(AWS_DEFAULT_SUBNET_CIDR, vpcID).getSubnetId();
    this.netClient.attachInternetGateway(vpcID, gatewayID);
    InternetGateway gw = this.netClient.getInternetGateway(gatewayID);
    List<InternetGatewayAttachment> attachments = gw.getAttachments();
    // ensure we are attached to newly created vpc
    for (InternetGatewayAttachment attachment : attachments) {
        if (attachment.getVpcId().equalsIgnoreCase(vpcID)) {
            attached = true;
            break;
        }
    }
    assertTrue(attached);
    RouteTable routeTable = this.netClient.getMainRouteTable(vpcID);
    this.netClient.createInternetRoute(gatewayID, routeTable.getRouteTableId(), "0.0.0.0/0");
    // remove resources
    this.netClient.detachInternetGateway(vpcID, gatewayID);
    this.netClient.deleteInternetGateway(gatewayID);
    this.netClient.deleteSubnet(subnetID);
    this.netClient.deleteVPC(vpcID);
}
Also used : RouteTable(com.amazonaws.services.ec2.model.RouteTable) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) InternetGatewayAttachment(com.amazonaws.services.ec2.model.InternetGatewayAttachment) Test(org.junit.Test)

Aggregations

RouteTable (com.amazonaws.services.ec2.model.RouteTable)6 Test (org.junit.Test)3 DescribeRouteTablesRequest (com.amazonaws.services.ec2.model.DescribeRouteTablesRequest)2 Subnet (com.amazonaws.services.ec2.model.Subnet)2 Address (com.amazonaws.services.ec2.model.Address)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 CreateRouteTableRequest (com.amazonaws.services.ec2.model.CreateRouteTableRequest)1 CreateRouteTableResult (com.amazonaws.services.ec2.model.CreateRouteTableResult)1 DescribeAddressesRequest (com.amazonaws.services.ec2.model.DescribeAddressesRequest)1 DescribeNatGatewaysRequest (com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest)1 DescribeRouteTablesResult (com.amazonaws.services.ec2.model.DescribeRouteTablesResult)1 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)1 Filter (com.amazonaws.services.ec2.model.Filter)1 InternetGateway (com.amazonaws.services.ec2.model.InternetGateway)1 InternetGatewayAttachment (com.amazonaws.services.ec2.model.InternetGatewayAttachment)1 NatGateway (com.amazonaws.services.ec2.model.NatGateway)1 Route (com.amazonaws.services.ec2.model.Route)1 Vpc (com.amazonaws.services.ec2.model.Vpc)1 AWSNetworkClient (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkClient)1 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)1