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;
}
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);
}
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);
}
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;
}
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);
}
Aggregations