Search in sources :

Example 46 with Vpc

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

the class AWSNetworkClient method getDefaultVPC.

/**
 * Get the default VPC - return null if no default specified
 */
public Vpc getDefaultVPC() {
    DescribeVpcsRequest req = new DescribeVpcsRequest();
    DescribeVpcsResult result = this.client.describeVpcs(req);
    List<Vpc> vpcs = result.getVpcs();
    for (Vpc vpc : vpcs) {
        if (vpc.isDefault()) {
            return vpc;
        }
    }
    return null;
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Vpc(com.amazonaws.services.ec2.model.Vpc)

Example 47 with Vpc

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

the class AWSNetworkClient method deleteVPC.

/**
 * Delete the specified VPC
 */
public void deleteVPC(String vpcId) {
    DeleteVpcRequest req = new DeleteVpcRequest().withVpcId(vpcId);
    this.client.deleteVpc(req);
}
Also used : DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest)

Example 48 with Vpc

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

the class AWSNetworkClient method allocateElasticIPAddress.

/**
 * Allocate an elastic IP address
 */
public DeferredResult<String> allocateElasticIPAddress() {
    AllocateAddressRequest req = new AllocateAddressRequest().withDomain(DomainType.Vpc);
    String message = "Allocate AWS Elastic IP Address for use with instances in a VPC.";
    AWSDeferredResultAsyncHandler<AllocateAddressRequest, AllocateAddressResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
    this.client.allocateAddressAsync(req, handler);
    return handler.toDeferredResult().thenApply(AllocateAddressResult::getAllocationId);
}
Also used : AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult)

Example 49 with Vpc

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

the class AWSNetworkUtils method mapVPCToNetworkState.

public static NetworkState mapVPCToNetworkState(Vpc vpc, String regionId, String resourcePoolLink, String endpointLink, String authCredentialsLink, String parentComputeLink, List<String> tenantLinks, URI adapterUri) {
    if (vpc == null) {
        throw new IllegalArgumentException("Cannot map VPC to network state for null instance");
    }
    NetworkState networkState = new NetworkState();
    networkState.id = vpc.getVpcId();
    // calculate vpc name
    if (vpc.getTags() == null) {
        networkState.name = vpc.getVpcId();
    } else {
        networkState.name = vpc.getTags().stream().filter(tag -> tag.getKey().equals(AWS_TAG_NAME)).map(tag -> tag.getValue()).findFirst().orElse(vpc.getVpcId());
    }
    networkState.subnetCIDR = vpc.getCidrBlock();
    networkState.regionId = regionId;
    networkState.resourcePoolLink = resourcePoolLink;
    networkState.endpointLink = endpointLink;
    if (networkState.endpointLinks == null) {
        networkState.endpointLinks = new HashSet<>();
    }
    networkState.endpointLinks.add(endpointLink);
    networkState.authCredentialsLink = authCredentialsLink;
    networkState.instanceAdapterReference = adapterUri;
    networkState.tenantLinks = tenantLinks;
    networkState.computeHostLink = parentComputeLink;
    networkState.customProperties = new HashMap<>();
    networkState.customProperties.put("defaultInstance", String.valueOf(vpc.isDefault()));
    return networkState;
}
Also used : AWSEnumerationUtils.getTagValue(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getTagValue) Arrays(java.util.Arrays) QueryTask(com.vmware.xenon.services.common.QueryTask) HashMap(java.util.HashMap) StringUtil(io.netty.util.internal.StringUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) URI(java.net.URI) Subnet(com.amazonaws.services.ec2.model.Subnet) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) 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) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) List(java.util.List) UriUtils(com.vmware.xenon.common.UriUtils) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Example 50 with Vpc

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

the class AWSSecurityGroupClient method createSecurityGroupAsync.

public DeferredResult<String> createSecurityGroupAsync(String name, String description, String vpcId) {
    CreateSecurityGroupRequest req = new CreateSecurityGroupRequest().withDescription(description).withGroupName(name);
    // set vpc for the security group if provided
    if (vpcId != null) {
        req = req.withVpcId(vpcId);
    }
    String message = "Create AWS Security Group with name [" + name + "] on VPC [" + vpcId + "].";
    AWSDeferredResultAsyncHandler<CreateSecurityGroupRequest, CreateSecurityGroupResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
    this.client.createSecurityGroupAsync(req, handler);
    return handler.toDeferredResult().thenApply(CreateSecurityGroupResult::getGroupId);
}
Also used : CreateSecurityGroupResult(com.amazonaws.services.ec2.model.CreateSecurityGroupResult) CreateSecurityGroupRequest(com.amazonaws.services.ec2.model.CreateSecurityGroupRequest)

Aggregations

Vpc (com.amazonaws.services.ec2.model.Vpc)27 HashMap (java.util.HashMap)25 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)21 Test (org.junit.Test)21 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)19 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)18 ArrayList (java.util.ArrayList)15 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 Filter (com.amazonaws.services.ec2.model.Filter)12 Subnet (com.amazonaws.services.ec2.model.Subnet)10 HashSet (java.util.HashSet)8 RouteTable (com.amazonaws.services.ec2.model.RouteTable)7 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)7