/** * 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); }
/** * Creates the subnet and return it. */ public Subnet createSubnet(String subnetCidr, String vpcId) { CreateSubnetRequest req = new CreateSubnetRequest() .withCidrBlock(subnetCidr) .withVpcId(vpcId); CreateSubnetResult res = this.client.createSubnet(req); return res.getSubnet(); }
/** * Creates a Subnet if not exist and return the Subnet id. */ public static String createOrGetSubnet(AmazonEC2AsyncClient client, String subnetCidr, String vpcId, String zoneId) { List<Filter> filters = new ArrayList<>(); Filter cidrBlockFilter = new Filter(); cidrBlockFilter.withName("cidrBlock"); cidrBlockFilter.withValues(subnetCidr); filters.add(cidrBlockFilter); if (zoneId != null) { Filter azFilter = new Filter(); azFilter.withName("availabilityZone"); azFilter.withValues(zoneId); filters.add(azFilter); } DescribeSubnetsResult result = client.describeSubnets(new DescribeSubnetsRequest() .withFilters(filters)); if (result.getSubnets() != null && !result.getSubnets().isEmpty()) { return result.getSubnets().get(0).getSubnetId(); } else { CreateSubnetRequest req = new CreateSubnetRequest() .withCidrBlock(subnetCidr) .withVpcId(vpcId); if (zoneId != null) { req.withAvailabilityZone(zoneId); } CreateSubnetResult res = client.createSubnet(req); return res.getSubnet().getSubnetId(); } }
@Override public Subnet createSubnet(CreateSubnetRequest request, ResultCapture<CreateSubnetResult> extractor) { ActionResult result = resource.performAction("CreateSubnet", request, extractor); if (result == null) return null; return new SubnetImpl(result.getResource()); }
@Override public Subnet createSubnet(String cidrBlock, ResultCapture<CreateSubnetResult> extractor) { CreateSubnetRequest request = new CreateSubnetRequest() .withCidrBlock(cidrBlock); return createSubnet(request, extractor); }
@Override public Subnet createSubnet(CreateSubnetRequest request, ResultCapture<CreateSubnetResult> extractor) { ActionResult result = service.performAction("CreateSubnet", request, extractor); if (result == null) return null; return new SubnetImpl(result.getResource()); }
@Override public Subnet createSubnet(String cidrBlock, String vpcId, ResultCapture<CreateSubnetResult> extractor) { CreateSubnetRequest request = new CreateSubnetRequest() .withCidrBlock(cidrBlock) .withVpcId(vpcId); return createSubnet(request, extractor); }
/** * Create Subnet. * * @param cidrBlock the cidr block * @param vpcId the vpc id * @return Subnet */ protected final Subnet createSubnet(final String cidrBlock, final String vpcId) { Subnet subnet = null; CreateSubnetRequest req = new CreateSubnetRequest(); req.setCidrBlock(cidrBlock); req.setVpcId(vpcId); CreateSubnetResult result = amazonEC2Client.createSubnet(req); if (result != null) { subnet = result.getSubnet(); } return subnet; }
@Override public CreateSubnetResult createSubnet(CreateSubnetRequest createSubnetRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
@Override public Subnet createSubnet(String cidrBlock) { return createSubnet(cidrBlock, (ResultCapture<CreateSubnetResult>)null); }
@Override public Subnet createSubnet(String cidrBlock, String vpcId) { return createSubnet(cidrBlock, vpcId, (ResultCapture<CreateSubnetResult>)null); }
/** * Performs the <code>CreateSubnet</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>Vpc</code> resource, and any conflicting parameter value set in the * request will be overridden: * <ul> * <li> * <b><code>VpcId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @return The <code>Subnet</code> resource object associated with the * result of this action. * @see CreateSubnetRequest */ Subnet createSubnet(CreateSubnetRequest request, ResultCapture<CreateSubnetResult> extractor);
/** * The convenient method form for the <code>CreateSubnet</code> action. * * @see #createSubnet(CreateSubnetRequest, ResultCapture) */ Subnet createSubnet(String cidrBlock, ResultCapture<CreateSubnetResult> extractor);
/** * Performs the <code>CreateSubnet</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * * @return The <code>Subnet</code> resource object associated with the * result of this action. * @see CreateSubnetRequest */ com.amazonaws.resources.ec2.Subnet createSubnet(CreateSubnetRequest request, ResultCapture<CreateSubnetResult> extractor);
/** * The convenient method form for the <code>CreateSubnet</code> action. * * @see #createSubnet(CreateSubnetRequest, ResultCapture) */ com.amazonaws.resources.ec2.Subnet createSubnet(String cidrBlock, String vpcId, ResultCapture<CreateSubnetResult> extractor);