/** * 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); }
@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()); } }
@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()); } } }
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); }); }
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); }); }
@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; }
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); }
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())); } } } } }
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)); }
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); }
/** * 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); }
/** * 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)); } }
/** * 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(); } }
/** * 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(); }
/** * 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(); }
/** * This implementation uses the DescribeSubnets API. */ @Override public List<Subnet> getSubnets(Collection<String> subnetIds, AwsParamsDto awsParamsDto) { AmazonEC2Client ec2Client = getEc2Client(awsParamsDto); DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest(); describeSubnetsRequest.setSubnetIds(subnetIds); try { DescribeSubnetsResult describeSubnetsResult = ec2Operations.describeSubnets(ec2Client, describeSubnetsRequest); return describeSubnetsResult.getSubnets(); } catch (AmazonServiceException amazonServiceException) { /* * AWS throws a 400 error when any one of the specified subnet ID is not found. * We want to catch it and throw as an handled herd error as a 404 not found. */ if (ERROR_CODE_SUBNET_ID_NOT_FOUND.equals(amazonServiceException.getErrorCode())) { throw new ObjectNotFoundException(amazonServiceException.getErrorMessage(), amazonServiceException); } // Any other type of error we throw as is because they are unexpected. else { throw amazonServiceException; } } }
@Override @Cacheable(value = CachingConfiguration.SUBNET_CACHE, key = "#vpcId", condition = "#bypassCache == false") public List<Subnet> getSubnetsForVpcInRegion(String vpcId, final String region, boolean bypassCache) { Preconditions.checkArgument(StringUtils.isNotBlank(vpcId), "vpcId may not be null or blank"); Preconditions.checkArgument(StringUtils.isNotBlank(region), "region may not be null or blank"); LOG.info("Retrieving subnets for VPC {} in region {} ({})", vpcId, region, bypassCache); DescribeSubnetsRequest request = new DescribeSubnetsRequest() .withFilters(new Filter() .withName("vpc-id") .withValues(vpcId)); DescribeSubnetsResult result = getClientForRegion(region).describeSubnets(request); return result.getSubnets(); }
/** * {@inheritDoc} */ @Override public List<Subnet> getSubnets(Long userNo, Long platformNo) { // VPCかどうかのチェック PlatformAws platformAws = platformAwsDao.read(platformNo); if (BooleanUtils.isNotTrue(platformAws.getVpc())) { // 非VPCの場合、サブネットはない return new ArrayList<Subnet>(); } // サブネットを取得 AwsProcessClient awsProcessClient = awsProcessClientFactory.createAwsProcessClient(userNo, platformNo); DescribeSubnetsRequest request = new DescribeSubnetsRequest(); request.withFilters(new Filter().withName("vpc-id").withValues(platformAws.getVpcId())); DescribeSubnetsResult result = awsProcessClient.getEc2Client().describeSubnets(request); List<Subnet> subnets = result.getSubnets(); // プラットフォームにサブネットが指定されている場合、そのサブネットのみに制限する if (StringUtils.isNotEmpty(awsProcessClient.getPlatformAws().getSubnetId())) { List<String> subnetIds = new ArrayList<String>(); for (String subnetId : StringUtils.split(awsProcessClient.getPlatformAws().getSubnetId(), ",")) { subnetIds.add(subnetId.trim()); } List<Subnet> subnets2 = new ArrayList<Subnet>(); for (Subnet subnet : subnets) { if (subnetIds.contains(subnet.getSubnetId())) { subnets2.add(subnet); } } subnets = subnets2; } // ソート Collections.sort(subnets, Comparators.COMPARATOR_SUBNET); return subnets; }
public List<Subnet> describeSubnetsByVpcId(AwsProcessClient awsProcessClient, String vpcId) { DescribeSubnetsRequest request = new DescribeSubnetsRequest(); request.withFilters(new Filter().withName("vpc-id").withValues(vpcId)); DescribeSubnetsResult result = awsProcessClient.getEc2Client().describeSubnets(request); List<Subnet> subnets = result.getSubnets(); return subnets; }
@Override public SubnetCollection getSubnets(DescribeSubnetsRequest request) { ResourceCollectionImpl result = resource.getCollection("Subnets", request); if (result == null) return null; return new SubnetCollectionImpl(result); }
@Override public SubnetCollection getSubnets(DescribeSubnetsRequest request) { ResourceCollectionImpl result = service.getCollection("Subnets", request); if (result == null) return null; return new SubnetCollectionImpl(result); }
private List<String> getExistingSubnetCidr(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); DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest().withSubnetIds(awsNetworkView.getSubnetList()); List<Subnet> subnets = ec2Client.describeSubnets(subnetsRequest).getSubnets(); if (subnets.isEmpty()) { throw new CloudConnectorException("The specified subnet does not exist (maybe it's in a different region)."); } List<String> cidrs = Lists.newArrayList(); for (Subnet subnet : subnets) { cidrs.add(subnet.getCidrBlock()); } return cidrs; }
private boolean isMapPublicOnLaunch(AwsNetworkView awsNetworkView, AmazonEC2Client amazonEC2Client) { boolean mapPublicIpOnLaunch = true; if (awsNetworkView.isExistingVPC() && awsNetworkView.isExistingSubnet()) { DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest(); describeSubnetsRequest.setSubnetIds(awsNetworkView.getSubnetList()); DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(describeSubnetsRequest); if (!describeSubnetsResult.getSubnets().isEmpty()) { mapPublicIpOnLaunch = describeSubnetsResult.getSubnets().get(0).isMapPublicIpOnLaunch(); } } return mapPublicIpOnLaunch; }
@Override public List<AbstractResource<?>> describeSubnets(Account account, Region region, DateTime dt, Ec2Filter... filters) { AmazonEC2 ec2 = findClient(account, region); DescribeSubnetsRequest req = new DescribeSubnetsRequest(); for (Ec2Filter filter : filters) { Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues()); req.withFilters(f); } log.debug("start describing subnets for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region); DescribeSubnetsResult res = ec2.describeSubnets(req); return converter.toVpcSubnets(res.getSubnets(), account.getId(), region, dt); }
private Subnet getSubnetDetails(String physicalId) { DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest(); Collection<String> subnetIds = new LinkedList<>(); subnetIds.add(physicalId); describeSubnetsRequest.setSubnetIds(subnetIds); DescribeSubnetsResult result = ec2Client.describeSubnets(describeSubnetsRequest); assertEquals(1, result.getSubnets().size()); return result.getSubnets().get(0); }
/** * Describe Subnet. * * @return Subnet */ protected final Subnet getSubnet() { Subnet subnet = null; DescribeSubnetsRequest req = new DescribeSubnetsRequest(); DescribeSubnetsResult result = amazonEC2Client.describeSubnets(req); if (result != null && !result.getSubnets().isEmpty()) { subnet = result.getSubnets().get(0); } return subnet; }
/** * Describe Subnets. * @return List of Subnet */ protected final List<Subnet> getSubnets() { List<Subnet> subnets = null; DescribeSubnetsRequest req = new DescribeSubnetsRequest(); DescribeSubnetsResult result = amazonEC2Client.describeSubnets(req); if (result != null && !result.getSubnets().isEmpty()) { subnets = result.getSubnets(); } return subnets; }
@Override public DescribeSubnetsResult describeSubnets(DescribeSubnetsRequest describeSubnetsRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
@Override public DescribeSubnetsResult describeSubnets(AmazonEC2Client ec2Client, DescribeSubnetsRequest describeSubnetsRequest) { return ec2Client.describeSubnets(describeSubnetsRequest); }
/** * In-memory implementation of describeSubnets. Returns the subnets from the pre-configured subnets. The method can be ordered to throw an * AmazonServiceException with a specified error code by specifying a subnet ID with prefix "throw." followed by a string indicating the error code to * throw. The exception thrown in this manner will always set the status code to 500. */ @Override public DescribeSubnetsResult describeSubnets(AmazonEC2Client ec2Client, DescribeSubnetsRequest describeSubnetsRequest) { List<Subnet> subnets = new ArrayList<>(); List<String> requestedSubnetIds = describeSubnetsRequest.getSubnetIds(); // add all subnets if request is empty (this is AWS behavior) if (requestedSubnetIds.isEmpty()) { requestedSubnetIds.addAll(mockSubnets.keySet()); } for (String requestedSubnetId : requestedSubnetIds) { MockSubnet mockSubnet = mockSubnets.get(requestedSubnetId); // Throw exception if any of the subnet ID do not exist if (mockSubnet == null) { AmazonServiceException amazonServiceException; if (requestedSubnetId.startsWith("throw.")) { String errorCode = requestedSubnetId.substring("throw.".length()); amazonServiceException = new AmazonServiceException(errorCode); amazonServiceException.setErrorCode(errorCode); amazonServiceException.setStatusCode(500); } else { amazonServiceException = new AmazonServiceException("The subnet ID '" + requestedSubnetId + "' does not exist"); amazonServiceException.setErrorCode(Ec2DaoImpl.ERROR_CODE_SUBNET_ID_NOT_FOUND); amazonServiceException.setStatusCode(400); } throw amazonServiceException; } subnets.add(mockSubnet.toAwsObject()); } DescribeSubnetsResult describeSubnetsResult = new DescribeSubnetsResult(); describeSubnetsResult.setSubnets(subnets); return describeSubnetsResult; }
public List<com.amazonaws.services.ec2.model.Subnet> describeSubnets(List<String> subnetIds) { return ec2.describeSubnets(new DescribeSubnetsRequest().withSubnetIds(subnetIds)).getSubnets(); }
private void loadRemoteSubnets(Map<String, Subnet> remoteSubnets) { DescribeSubnetsResult result = AWS.vpc.ec2.describeSubnets(new DescribeSubnetsRequest().withSubnetIds(remoteSubnets.keySet())); for (com.amazonaws.services.ec2.model.Subnet remoteSubnet : result.getSubnets()) { remoteSubnets.get(remoteSubnet.getSubnetId()).remoteSubnets.add(remoteSubnet); } }
@Override public boolean load(DescribeSubnetsRequest request) { return load(request, null); }
@Override public boolean load(DescribeSubnetsRequest request, ResultCapture<DescribeSubnetsResult> extractor) { return resource.load(request, extractor); }
@Override public SubnetCollection getSubnets() { return getSubnets((DescribeSubnetsRequest)null); }
private DescribeSubnetsRequest createVpcDescribeRequest(Vpc vpc) { return new DescribeSubnetsRequest().withFilters(new Filter("vpc-id", singletonList(vpc.getVpcId()))); }
private ModelAndView showWorkerInstanceOptions( JobInput input ) throws IOException { if ( input.getWorkerInstanceOptions() == null ) { WorkerInstanceOptions defaultOptions = new WorkerInstanceOptions(); input.setWorkerInstanceOptions( defaultOptions ); } ModelAndView mav = new ModelAndView( "create/worker_options.vm" ).addObject( "input", input ).addObject( "inputData", input.serializeTo() ); AWSCredentials creds = new BasicAWSCredentials( input.getAwsAccessKeyId(), input.getAwsSecretKey() ); // Fetch all keypairs mav.addObject( "allKeyPairs", ec2.describeKeyPairs( decorate( new DescribeKeyPairsRequest(), creds ) ).getKeyPairs() ); // Fetch all security groups String vpcId = null; switch ( input.getActionType() ) { case BACKUP_INSTANCE: DBInstance instance = rds.describeDBInstances( decorate( new DescribeDBInstancesRequest().withDBInstanceIdentifier( input.getSourceAndDestination().getDatabaseInstanceId() ), creds ) ).getDBInstances().get( 0 ); mav.addObject( "sourceDatabaseInstance", instance ); if ( instance.getDBSubnetGroup() != null ) { vpcId = instance.getDBSubnetGroup().getVpcId(); } break; case CONVERT_SNAPSHOT: DBSnapshot snapshot = rds.describeDBSnapshots( decorate( new DescribeDBSnapshotsRequest().withDBSnapshotIdentifier( input.getSourceAndDestination().getDatabaseSnapshotId() ), creds ) ).getDBSnapshots().get( 0 ); mav.addObject( "sourceDatabaseSnapshot", snapshot ); vpcId = snapshot.getVpcId(); break; default: throw new IllegalStateException( "Action type " + input.getActionType() + " is not expected" ); } mav.addObject( "vpcId", vpcId ); List<SecurityGroup> availableGroups = new ArrayList<SecurityGroup>(); for ( SecurityGroup group : ec2.describeSecurityGroups( decorate( new DescribeSecurityGroupsRequest(), creds ) ).getSecurityGroups() ) { if ( StringUtils.equals( vpcId, group.getVpcId() ) && !group.getGroupName().startsWith( "awseb-e-" ) ) { availableGroups.add( group ); } } mav.addObject( "allSecurityGroups", availableGroups ); if ( vpcId != null ) { List<Subnet> availableSubnets = new ArrayList<Subnet>(); for ( Subnet subnet : ec2.describeSubnets( decorate( new DescribeSubnetsRequest(), creds ) ).getSubnets() ) { if ( StringUtils.equals( subnet.getVpcId(), vpcId ) ) { availableSubnets.add( subnet ); } } mav.addObject( "allSubnets", availableSubnets ); } mav.addObject( "workerOptions", input.getWorkerInstanceOptions() ); return mav; }
/** * {@link AmazonEC2#describeSubnets()} * * @param ec2Client {@link AmazonEC2} to use. * @param describeSubnetsRequest The request object. * @return {@link DescribeSubnetsResult} */ public DescribeSubnetsResult describeSubnets(AmazonEC2Client ec2Client, DescribeSubnetsRequest describeSubnetsRequest);