Example usage for com.amazonaws.services.ec2.model CreateSubnetRequest withAvailabilityZone

List of usage examples for com.amazonaws.services.ec2.model CreateSubnetRequest withAvailabilityZone

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model CreateSubnetRequest withAvailabilityZone.

Prototype


public CreateSubnetRequest withAvailabilityZone(String availabilityZone) 

Source Link

Document

The Availability Zone for the subnet.

Usage

From source file:de.unibi.cebitec.bibigrid.meta.aws.CreateClusterEnvironmentAWS.java

@Override
public CreateClusterEnvironmentAWS createSubnet() {

    ///////////////////////////////////////////////////////////////////////
    ///// check for unused Subnet Cidr and create one
    DescribeSubnetsRequest describesubnetsreq = new DescribeSubnetsRequest();
    DescribeSubnetsResult describesubnetres = cluster.getEc2().describeSubnets(describesubnetsreq);
    List<Subnet> loSubnets = describesubnetres.getSubnets();

    List<String> listofUsedCidr = new ArrayList<>(); // contains all subnet.cidr which are in current vpc
    for (Subnet sn : loSubnets) {
        if (sn.getVpcId().equals(vpc.getVpcId())) {
            listofUsedCidr.add(sn.getCidrBlock());
        }// w w  w.  j ava  2  s .  c  o m
    }

    SubNets subnets = new SubNets(vpc.getCidrBlock(), 24);
    String SUBNETCIDR = subnets.nextCidr(listofUsedCidr);

    log.debug(V, "Use {} for generated SubNet.", SUBNETCIDR);

    // create new subnetdir      
    CreateSubnetRequest createsubnetreq = new CreateSubnetRequest(vpc.getVpcId(), SUBNETCIDR);
    createsubnetreq.withAvailabilityZone(cluster.getConfig().getAvailabilityZone());
    CreateSubnetResult createsubnetres = cluster.getEc2().createSubnet(createsubnetreq);
    subnet = createsubnetres.getSubnet();

    return this;
}