Search in sources :

Example 1 with CreateSubnetRequest

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

the class AWSSubnetTaskServiceTest method createAwsSubnet.

private Subnet createAwsSubnet() {
    if (this.isMock) {
        Subnet subnet = new Subnet();
        subnet.setSubnetId(UUID.randomUUID().toString());
        return subnet;
    }
    CreateSubnetRequest createRequest = new CreateSubnetRequest((String) this.awsTestContext.get(TestAWSSetupUtils.VPC_KEY), AWS_NON_EXISTING_SUBNET_CIDR);
    return this.client.createSubnet(createRequest).getSubnet();
}
Also used : Subnet(com.amazonaws.services.ec2.model.Subnet) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest)

Example 2 with CreateSubnetRequest

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

the class AWSInstanceContext method createSubnetsIfNotExist.

/**
 * For every NIC create AWS Subnet (as specified by {@code AWSNicContext.subnetState}) if it
 * does not exist.
 *
 * @see #getSubnets(AWSInstanceContext)
 */
private DeferredResult<AWSInstanceContext> createSubnetsIfNotExist(AWSInstanceContext context) {
    if (context.nics.isEmpty()) {
        return DeferredResult.completed(context);
    }
    List<DeferredResult<Void>> createSubnetDRs = new ArrayList<>();
    for (AWSNicContext nicCtx : context.nics) {
        if (nicCtx.subnet != null) {
            // No need to create
            continue;
        }
        // Create AWS subnet and set it to nicCtx.subnet {{
        CreateSubnetRequest subnetRequest = new CreateSubnetRequest().withVpcId(nicCtx.vpc.getVpcId()).withCidrBlock(nicCtx.subnetState.subnetCIDR);
        if (nicCtx.subnetState.zoneId != null) {
            subnetRequest.withAvailabilityZone(nicCtx.subnetState.zoneId);
        }
        String msg = "Create AWS subnet + [" + nicCtx.subnetState.name + "]";
        AWSDeferredResultAsyncHandler<CreateSubnetRequest, CreateSubnetResult> createAWSSubnet = new AWSDeferredResultAsyncHandler<CreateSubnetRequest, CreateSubnetResult>(this.service, msg) {

            @Override
            protected DeferredResult<CreateSubnetResult> consumeSuccess(CreateSubnetRequest request, CreateSubnetResult result) {
                nicCtx.subnet = result.getSubnet();
                AWSUtils.tagResourcesWithName(context.amazonEC2Client, nicCtx.subnetState.name, nicCtx.subnet.getSubnetId());
                return DeferredResult.completed(result);
            }
        };
        context.amazonEC2Client.createSubnetAsync(subnetRequest, createAWSSubnet);
        // }}
        // Once AWS subnet creation is done PATCH SubnetState.id {{
        Function<CreateSubnetResult, DeferredResult<Void>> patchSubnetState = (ignore) -> {
            SubnetState patchSubnet = new SubnetState();
            patchSubnet.id = nicCtx.subnet.getSubnetId();
            patchSubnet.documentSelfLink = nicCtx.subnetState.documentSelfLink;
            patchSubnet.customProperties = singletonMap(CREATE_CONTEXT_PROP_NAME, context.computeRequest.resourceLink());
            Operation op = Operation.createPatch(context.service.getHost(), patchSubnet.documentSelfLink).setBody(patchSubnet);
            return context.service.sendWithDeferredResult(op, SubnetState.class).thenAccept(patchedSubnet -> nicCtx.subnetState = patchedSubnet);
        };
        // }}
        // Chain AWS subnet creation with SubnetState patching
        createSubnetDRs.add(createAWSSubnet.toDeferredResult().thenCompose(patchSubnetState));
    }
    return DeferredResult.allOf(createSubnetDRs).handle((all, exc) -> {
        if (exc != null) {
            String msg = String.format("Error creating Subnets in AWS for [%s] VM.", context.child.name);
            throw new IllegalStateException(msg, exc);
        }
        return context;
    });
}
Also used : InstanceNetworkInterfaceSpecification(com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) CREATE_CONTEXT_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.CREATE_CONTEXT_PROP_NAME) Function(java.util.function.Function) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) URI_PARAM_INSTANCE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_INSTANCE_TYPE) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Filter(com.amazonaws.services.ec2.model.Filter) Collections.singletonMap(java.util.Collections.singletonMap) URI(java.net.URI) Subnet(com.amazonaws.services.ec2.model.Subnet) StatelessService(com.vmware.xenon.common.StatelessService) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) Vpc(com.amazonaws.services.ec2.model.Vpc) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Collectors(java.util.stream.Collectors) AWS_VPC_ID_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ID_FILTER) URI_PARAM_ENDPOINT(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_ENDPOINT) InstanceType(com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType) List(java.util.List) BaseComputeInstanceContext(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext) AWS_SUBNET_ID_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_SUBNET_ID_FILTER) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) DiskService(com.vmware.photon.controller.model.resources.DiskService) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 3 with CreateSubnetRequest

use of com.amazonaws.services.ec2.model.CreateSubnetRequest 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 4 with CreateSubnetRequest

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

the class TestAWSSetupUtils method createOrGetSubnet.

/**
 * Creates a Subnet if not exist and return the Subnet id.
 */
public static Subnet createOrGetSubnet(AmazonEC2AsyncClient client, String subnetCidr, String vpcId, String zoneId) {
    List<Filter> filters = new ArrayList<>();
    Filter vpcFilter = new Filter();
    vpcFilter.withName(VPC_KEY);
    vpcFilter.withValues(vpcId);
    filters.add(vpcFilter);
    if (zoneId != null) {
        Filter azFilter = new Filter();
        azFilter.withName(AVAILABILITY_ZONE_FILTER);
        azFilter.withValues(zoneId);
        filters.add(azFilter);
    }
    DescribeSubnetsResult result = client.describeSubnets(new DescribeSubnetsRequest().withFilters(filters));
    List<Subnet> defaultSubnets = new ArrayList<>();
    result.getSubnets().stream().forEach(subnet -> {
        subnet.getTags().stream().filter(tag -> tag.getKey().equalsIgnoreCase(TAG_KEY_FOR_TEST_RESOURCES) && tag.getValue().equalsIgnoreCase(AWS_DEFAULT_SUBNET_NAME)).forEach(tag -> defaultSubnets.add(subnet));
    });
    if (defaultSubnets != null && !defaultSubnets.isEmpty()) {
        return defaultSubnets.get(0);
    } else {
        CreateSubnetRequest req = new CreateSubnetRequest().withCidrBlock(subnetCidr).withVpcId(vpcId);
        if (zoneId != null) {
            req.withAvailabilityZone(zoneId);
        }
        CreateSubnetResult res = client.createSubnet(req);
        String subnetId = res.getSubnet().getSubnetId();
        tagResources(client, Arrays.asList(subnetId), TAG_KEY_FOR_TEST_RESOURCES, AWS_DEFAULT_SUBNET_NAME);
        return res.getSubnet();
    }
}
Also used : CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult) Arrays(java.util.Arrays) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) VerificationHost(com.vmware.xenon.common.test.VerificationHost) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest) AttachInternetGatewayRequest(com.amazonaws.services.ec2.model.AttachInternetGatewayRequest) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) InetAddress(java.net.InetAddress) AWSEnumerationAndDeletionAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEnumerationAndDeletionAdapterService) Utils(com.vmware.xenon.common.Utils) BlockDeviceMapping(com.amazonaws.services.ec2.model.BlockDeviceMapping) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) ImageService(com.vmware.photon.controller.model.resources.ImageService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) Path(java.nio.file.Path) AWSComputeStateCreationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSComputeStateCreationAdapterService) EnumSet(java.util.EnumSet) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) AWSComputeDescriptionEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSComputeDescriptionEnumerationAdapterService) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) CreateNetworkInterfaceResult(com.amazonaws.services.ec2.model.CreateNetworkInterfaceResult) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Set(java.util.Set) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) DeleteNetworkInterfaceRequest(com.amazonaws.services.ec2.model.DeleteNetworkInterfaceRequest) ServiceStats(com.vmware.xenon.common.ServiceStats) URI_PARAM_ENDPOINT(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_ENDPOINT) AWSUtils.getRegionId(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getRegionId) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) TagService(com.vmware.photon.controller.model.resources.TagService) AWSUtils.getAWSNonTerminatedInstancesFilter(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter) ProvisioningUtils.getVMCount(com.vmware.photon.controller.model.tasks.ProvisioningUtils.getVMCount) Assert.assertFalse(org.junit.Assert.assertFalse) DetachNetworkInterfaceRequest(com.amazonaws.services.ec2.model.DetachNetworkInterfaceRequest) Tag(com.amazonaws.services.ec2.model.Tag) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) DeleteSnapshotRequest(com.amazonaws.services.ec2.model.DeleteSnapshotRequest) TaskState(com.vmware.xenon.common.TaskState) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) InstanceNetworkInterface(com.amazonaws.services.ec2.model.InstanceNetworkInterface) NicSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NicSpec) DISK_IOPS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DISK_IOPS) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) SYSTEM(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.SYSTEM) AWSS3StorageEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSS3StorageEnumerationAdapterService) ArrayList(java.util.ArrayList) AWSEBSStorageEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEBSStorageEnumerationAdapterService) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Rule(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState.Rule) URI_PARAM_INSTANCE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_INSTANCE_TYPE) USER_DEFINED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.USER_DEFINED) Query(com.vmware.xenon.services.common.QueryTask.Query) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) Filter(com.amazonaws.services.ec2.model.Filter) Volume(com.amazonaws.services.ec2.model.Volume) CreateSnapshotResult(com.amazonaws.services.ec2.model.CreateSnapshotResult) CreateVpcRequest(com.amazonaws.services.ec2.model.CreateVpcRequest) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) SecurityGroupService(com.vmware.photon.controller.model.resources.SecurityGroupService) Assert.assertTrue(org.junit.Assert.assertTrue) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest) LocalDateTime(org.joda.time.LocalDateTime) UnknownHostException(java.net.UnknownHostException) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) AttachNetworkInterfaceResult(com.amazonaws.services.ec2.model.AttachNetworkInterfaceResult) Assert.assertNull(org.junit.Assert.assertNull) NetworkInterfaceAttachmentChanges(com.amazonaws.services.ec2.model.NetworkInterfaceAttachmentChanges) Paths(java.nio.file.Paths) DescribeSnapshotsResult(com.amazonaws.services.ec2.model.DescribeSnapshotsResult) AsyncHandler(com.amazonaws.handlers.AsyncHandler) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) CreateSnapshotRequest(com.amazonaws.services.ec2.model.CreateSnapshotRequest) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) DISCOVERED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.DISCOVERED) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) RegisterInstancesWithLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest) QueryTask(com.vmware.xenon.services.common.QueryTask) TimeoutException(java.util.concurrent.TimeoutException) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Random(java.util.Random) StatsAggregationTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService) ByteBuffer(java.nio.ByteBuffer) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) StatsAggregationTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) ProvisionDiskTaskService(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService) URI(java.net.URI) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) StatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService) Reservation(com.amazonaws.services.ec2.model.Reservation) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) LoadBalancerService(com.vmware.photon.controller.model.resources.LoadBalancerService) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) DeleteLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerRequest) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AmazonElasticLoadBalancingAsyncClient(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient) List(java.util.List) Snapshot(com.amazonaws.services.ec2.model.Snapshot) DescribeSnapshotsRequest(com.amazonaws.services.ec2.model.DescribeSnapshotsRequest) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) NetSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NetSpec) EndpointRemovalTaskState(com.vmware.photon.controller.model.tasks.EndpointRemovalTaskService.EndpointRemovalTaskState) ResourceRemovalTaskService(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) HashMap(java.util.HashMap) CreateNetworkInterfaceRequest(com.amazonaws.services.ec2.model.CreateNetworkInterfaceRequest) AWSEnumerationAndCreationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEnumerationAndCreationAdapterService) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) RegisterInstancesWithLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerResult) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) Level(java.util.logging.Level) HashSet(java.util.HashSet) AttachNetworkInterfaceRequest(com.amazonaws.services.ec2.model.AttachNetworkInterfaceRequest) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) Subnet(com.amazonaws.services.ec2.model.Subnet) Listener(com.amazonaws.services.elasticloadbalancing.model.Listener) Instance(com.amazonaws.services.ec2.model.Instance) AWSConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.getQueryResultLimit) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Assert.assertNotNull(org.junit.Assert.assertNotNull) Vpc(com.amazonaws.services.ec2.model.Vpc) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) Operation(com.vmware.xenon.common.Operation) RunInstancesRequest(com.amazonaws.services.ec2.model.RunInstancesRequest) DeleteSecurityGroupRequest(com.amazonaws.services.ec2.model.DeleteSecurityGroupRequest) AWS_VPC_ID_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ID_FILTER) ProvisioningUtils.createServiceURI(com.vmware.photon.controller.model.tasks.ProvisioningUtils.createServiceURI) TimeUnit(java.util.concurrent.TimeUnit) ModifyNetworkInterfaceAttributeRequest(com.amazonaws.services.ec2.model.ModifyNetworkInterfaceAttributeRequest) DeleteVolumeRequest(com.amazonaws.services.ec2.model.DeleteVolumeRequest) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) EndpointRemovalTaskService(com.vmware.photon.controller.model.tasks.EndpointRemovalTaskService) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) AWSEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEnumerationAdapterService) Collections(java.util.Collections) AWS_INVALID_VOLUME_ID_ERROR_CODE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_INVALID_VOLUME_ID_ERROR_CODE) AWSUtils.getAWSNonTerminatedInstancesFilter(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter) Filter(com.amazonaws.services.ec2.model.Filter) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) ArrayList(java.util.ArrayList) Subnet(com.amazonaws.services.ec2.model.Subnet) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 5 with CreateSubnetRequest

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

the class AWSNetworkClient method createSubnet.

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

Aggregations

CreateSubnetRequest (com.amazonaws.services.ec2.model.CreateSubnetRequest)5 CreateSubnetResult (com.amazonaws.services.ec2.model.CreateSubnetResult)4 Subnet (com.amazonaws.services.ec2.model.Subnet)3 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)2 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)2 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)2 Filter (com.amazonaws.services.ec2.model.Filter)2 Tag (com.amazonaws.services.ec2.model.Tag)2 Vpc (com.amazonaws.services.ec2.model.Vpc)2 AWS_VPC_ID_FILTER (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ID_FILTER)2 URI_PARAM_ENDPOINT (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_ENDPOINT)2 URI_PARAM_INSTANCE_TYPE (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_INSTANCE_TYPE)2 AWSSecurityGroupClient (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient)2 DiskService (com.vmware.photon.controller.model.resources.DiskService)2 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)2 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)2 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)2 Operation (com.vmware.xenon.common.Operation)2 UriUtils (com.vmware.xenon.common.UriUtils)2 URI (java.net.URI)2