本文整理汇总了Java中com.amazonaws.services.ec2.model.DescribeSubnetsRequest类的典型用法代码示例。如果您正苦于以下问题:Java DescribeSubnetsRequest类的具体用法?Java DescribeSubnetsRequest怎么用?Java DescribeSubnetsRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DescribeSubnetsRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了DescribeSubnetsRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
/**
* Checks whether exiting Subnet is present.
*
* @param subnetString
* @return <code>Subnet </code> if the matches one of the subnetString
*
*/
public Subnet resolveSubnet(String subnetString) throws APPlatformException {
DescribeSubnetsRequest request = new DescribeSubnetsRequest();
DescribeSubnetsResult result = getEC2().describeSubnets(
request.withSubnetIds(subnetString));
List<Subnet> subnets = result.getSubnets();
if (!subnets.isEmpty()) {
LOGGER.debug(" number of subnets found: " + subnets.size());
for (Subnet subnet : subnets) {
LOGGER.debug("return subnet with id " + subnet.getSubnetId());
return subnet;
}
}
throw new APPlatformException(
Messages.getAll("error_invalid_subnet_id") + subnetString);
}
示例2: testCreateSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
@Test
public void testCreateSubnet() throws Throwable {
SubnetState subnetState = provisionSubnet(AWS_NON_EXISTING_SUBNET_NAME,
AWS_NON_EXISTING_SUBNET_CIDR, null);
assertNotNull(subnetState.id);
assertEquals(LifecycleState.READY, subnetState.lifecycleState);
if (!this.isMock) {
// Verify that the subnet was created.
DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest()
.withSubnetIds(Collections.singletonList(subnetState.id));
List<Subnet> subnets = this.client.describeSubnets(describeRequest).getSubnets();
assertNotNull(subnets);
assertEquals(1, subnets.size());
}
}
示例3: testDeleteSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
@Test
public void testDeleteSubnet() throws Throwable {
Subnet awsSubnet = createAwsSubnet();
SubnetState subnetState = createSubnetState(awsSubnet.getSubnetId(), AWS_NON_EXISTING_SUBNET_NAME,
AWS_NON_EXISTING_SUBNET_CIDR, null);
kickOffSubnetProvision(InstanceRequestType.DELETE, subnetState, TaskStage.FINISHED);
if (!this.isMock) {
// Verify that the subnet was deleted.
DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest()
.withSubnetIds(Collections.singletonList(awsSubnet.getSubnetId()));
try {
this.client.describeSubnets(describeRequest).getSubnets();
fail("Subnet should not exist in AWS.");
} catch (AmazonEC2Exception ex) {
assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ex.getStatusCode());
}
}
}
示例4: deleteAwsSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
public void deleteAwsSubnet() {
if (this.isMock) {
return;
}
DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest()
.withFilters(
new Filter(AWS_VPC_ID_FILTER, singletonList(AWS_DEFAULT_VPC_ID)))
.withFilters(
new Filter(AWS_SUBNET_CIDR_FILTER,
singletonList(AWS_NON_EXISTING_SUBNET_CIDR)));
DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest);
subnetResult.getSubnets().forEach(subnet -> {
DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId());
this.client.deleteSubnet(deleteRequest);
});
}
示例5: deleteAwsPublicSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
public void deleteAwsPublicSubnet() {
if (this.isMock) {
return;
}
DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest()
.withFilters(
new Filter(AWS_VPC_ID_FILTER, singletonList(AWS_DEFAULT_VPC_ID)))
.withFilters(
new Filter(AWS_SUBNET_CIDR_FILTER,
singletonList(AWS_NON_EXISTING_PUBLIC_SUBNET_CIDR)));
DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest);
subnetResult.getSubnets().forEach(subnet -> {
DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId());
this.client.deleteSubnet(deleteRequest);
});
}
示例6: hasSubnets
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
@Override
public boolean hasSubnets(String vpcId) throws AutoException {
if (StringUtils.isEmpty(vpcId)) {
log.info(platform.getPlatformName() + " にvpcIdが有りません");
System.out.println("VPCID_EMPTY");
return false;
}
DescribeSubnetsRequest request = new DescribeSubnetsRequest();
request.withFilters(new Filter().withName("vpc-id").withValues(vpcId));
DescribeSubnetsResult result = ec2Client.describeSubnets(request);
List<Subnet> subnets = result.getSubnets();
if (subnets.isEmpty()) {
log.info(platform.getPlatformName() + " にサブネットが有りません");
System.out.println("SUBNET_EMPTY");
return false;
}
return true;
}
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:22,代码来源:AwsIaasGatewayScriptService.java
示例7: findNonOverLappingCIDR
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
protected String findNonOverLappingCIDR(AuthenticatedContext ac, CloudStack stack) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVPC());
Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0);
String vpcCidr = vpc.getCidrBlock();
LOGGER.info("Subnet cidr is empty, find a non-overlapping subnet for VPC cidr: {}", vpcCidr);
DescribeSubnetsRequest request = new DescribeSubnetsRequest().withFilters(new Filter("vpc-id", singletonList(awsNetworkView.getExistingVPC())));
List<Subnet> awsSubnets = ec2Client.describeSubnets(request).getSubnets();
List<String> subnetCidrs = awsSubnets.stream().map(Subnet::getCidrBlock).collect(Collectors.toList());
LOGGER.info("The selected VPCs: {}, has the following subnets: {}", vpc.getVpcId(), subnetCidrs.stream().collect(Collectors.joining(",")));
return calculateSubnet(ac.getCloudContext().getName(), vpc, subnetCidrs);
}
示例8: validateExistingSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
private void validateExistingSubnet(AwsNetworkView awsNetworkView, AmazonEC2Client amazonEC2Client) {
if (awsNetworkView.isExistingSubnet()) {
DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
describeSubnetsRequest.withSubnetIds(awsNetworkView.getSubnetList());
DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(describeSubnetsRequest);
if (describeSubnetsResult.getSubnets().size() < awsNetworkView.getSubnetList().size()) {
throw new CloudConnectorException(String.format(SUBNET_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet()));
} else {
for (Subnet subnet : describeSubnetsResult.getSubnets()) {
String vpcId = subnet.getVpcId();
if (vpcId != null && !vpcId.equals(awsNetworkView.getExistingVPC())) {
throw new CloudConnectorException(String.format(SUBNETVPC_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet(),
awsNetworkView.getExistingVPC()));
}
}
}
}
}
示例9: createDescribeSubnetsResult
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
public void createDescribeSubnetsResult(String... subnetIds) {
Collection<Subnet> subnets = new ArrayList<Subnet>();
for (int i = 0; i < subnetIds.length; i++) {
subnets.add(new Subnet().withSubnetId(subnetIds[i])
.withVpcId(subnetIds[i]));
}
DescribeSubnetsResult subnetResult = new DescribeSubnetsResult()
.withSubnets(subnets);
doReturn(subnetResult).when(ec2)
.describeSubnets(any(DescribeSubnetsRequest.class));
}
示例10: getSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
public Subnet getSubnet(String subnetId) {
DescribeSubnetsRequest req = new DescribeSubnetsRequest()
.withSubnetIds(subnetId);
DescribeSubnetsResult subnetResult = this.client.describeSubnets(req);
List<Subnet> subnets = subnetResult.getSubnets();
return subnets.isEmpty() ? null : subnets.get(0);
}
示例11: getSubnetInformation
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
/**
* Gets the Subnets that are attached to the VPCs that were discovered during the enumeration
* process.
*/
private void getSubnetInformation(AWSNetworkStateCreationContext context,
AWSNetworkStateCreationStage next) {
DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest();
List<String> vpcList = new ArrayList<>(context.vpcs.keySet());
Filter filter = new Filter(AWS_VPC_ID_FILTER, vpcList);
subnetRequest.getFilters().add(filter);
AWSSubnetAsyncHandler asyncHandler = new AWSSubnetAsyncHandler(next, context);
context.amazonEC2Client.describeSubnetsAsync(subnetRequest, asyncHandler);
}
示例12: consumeSuccess
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
/**
* Update the Subnet information for the VPC in question.
*/
@Override
protected void consumeSuccess(DescribeSubnetsRequest request,
DescribeSubnetsResult result) {
for (Subnet subnet : result.getSubnets()) {
if (!this.context.vpcs.containsKey(subnet.getVpcId())) {
logWarning(() -> String.format("AWS returned Subnet [%s] with VCP [%s] that is"
+ " missing locally.", subnet.getSubnetId(), subnet.getVpcId()));
continue;
}
SubnetState subnetState = mapSubnetToSubnetState(subnet,
this.context.request.tenantLinks,
this.context.request.regionId,
this.context.request.parentComputeLink,
this.context.request.request.endpointLink);
if (subnetState.subnetCIDR == null) {
logWarning(() -> String.format("AWS did not return CIDR information for Subnet"
+ " %s", subnet.toString()));
}
this.context.awsSubnets.put(subnet.getSubnetId(), subnet);
this.context.subnets.put(
subnet.getSubnetId(),
new AWSNetworkStateCreationContext.SubnetStateWithParentVpcId(
subnet.getVpcId(), subnetState));
}
}
示例13: createOrGetSubnet
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
/**
* 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();
}
}
示例14: checkSubnetId
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
/**
* Validates the configured subnet ID.
*
* @param client the EC2 client
* @param configuration the configuration to be validated
* @param accumulator the exception condition accumulator
* @param localizationContext the localization context
*
* @return the vpc id to subnet id mapping
*/
@VisibleForTesting
Map<String, String> checkSubnetId(AmazonEC2Client client,
Configured configuration,
PluginExceptionConditionAccumulator accumulator,
LocalizationContext localizationContext) {
String subnetId = configuration.getConfigurationValue(SUBNET_ID, localizationContext);
LOG.info(">> Describing subnet '{}'", subnetId);
try {
DescribeSubnetsResult result = client.describeSubnets(
new DescribeSubnetsRequest().withSubnetIds(subnetId));
checkCount(accumulator, SUBNET_ID, localizationContext, "Subnet",
result.getSubnets());
if (result.getSubnets().size() == 1) {
return ImmutableMap.of(Iterables.getOnlyElement(result.getSubnets()).getVpcId(), subnetId);
}
} catch (AmazonServiceException e) {
if (e.getErrorCode().startsWith(INVALID_SUBNET_ID)) {
addError(accumulator, SUBNET_ID, localizationContext,
null, INVALID_SUBNET_MSG, subnetId);
} else {
throw Throwables.propagate(e);
}
}
return ImmutableMap.of();
}
示例15: getAvailabilityZoneFromSubnetId
import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; //导入依赖的package包/类
/**
* Get the availability zone from a Subnet ID.
*
* @param subnetId the id of the subnet
* @return the availability zone of the subnet
*/
private String getAvailabilityZoneFromSubnetId(String subnetId) {
DescribeSubnetsRequest request = new DescribeSubnetsRequest().withSubnetIds(subnetId);
DescribeSubnetsResult result = client.describeSubnets(request);
Subnet subnet = Iterables.getOnlyElement(result.getSubnets());
return subnet.getAvailabilityZone();
}