当前位置: 首页>>代码示例>>Java>>正文


Java Subnet类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.Subnet的典型用法代码示例。如果您正苦于以下问题:Java Subnet类的具体用法?Java Subnet怎么用?Java Subnet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Subnet类属于com.amazonaws.services.ec2.model包,在下文中一共展示了Subnet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveSubnet

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的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);

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:EC2Communication.java

示例2: createSubnetState

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
/**
 * Create SubnetState representing AWS Subnet instance.
 */
private void createSubnetState(Subnet subnet, AWSNetworkContext context, AWSNetworkStage next) {
    SubnetState subnetState = new SubnetState();
    subnetState.id = subnet.getSubnetId();
    subnetState.name = subnet.getSubnetId();
    subnetState.subnetCIDR = subnet.getCidrBlock();
    subnetState.networkLink = context.network.documentSelfLink;
    subnetState.tenantLinks = context.network.tenantLinks;

    sendRequest(
            Operation.createPost(this.getHost(), SubnetService.FACTORY_LINK)
                    .setBody(subnetState)
                    .setCompletion((o, e) -> {
                        if (e != null) {
                            handleStages(context, e);
                            return;
                        }
                        handleStages(context, next);
                    }));
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:23,代码来源:AWSNetworkService.java

示例3: createSubnetAsync

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:20,代码来源:AWSNetworkClient.java

示例4: testCreateSubnet

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的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());
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:19,代码来源:AWSSubnetTaskServiceTest.java

示例5: testDeleteSubnet

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的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());
        }
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:23,代码来源:AWSSubnetTaskServiceTest.java

示例6: updateInstanceDefinitionsWithBestPrice

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
/**
 * Updates the given definition with the given subnet and EMR pricing information.
 * <p/>
 * Sets the subnet with the given subnet ID. Removes any maxSearchPrice and onDemandThreshold that were set. Sets the spotPrice only if the given cluster
 * price is a spot.
 *
 * @param emrClusterDefinition the definition to update
 * @param bestEmrClusterSubnet the subnet to use
 * @param bestEmrClusterPrice the EMR pricing information for each instance
 */
private void updateInstanceDefinitionsWithBestPrice(EmrClusterDefinition emrClusterDefinition, Subnet bestEmrClusterSubnet,
    EmrClusterPriceDto bestEmrClusterPrice)
{
    emrClusterDefinition.setSubnetId(bestEmrClusterSubnet.getSubnetId());

    emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceMaxSearchPrice(null);
    emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceOnDemandThreshold(null);
    emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getMasterPrice()));

    if (bestEmrClusterPrice.getCorePrice() != null)
    {
        emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceMaxSearchPrice(null);
        emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceOnDemandThreshold(null);
        emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getCorePrice()));
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:27,代码来源:EmrPricingHelper.java

示例7: getAvailabilityZonesForSubnetIds

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
/**
 * This implementation uses the DescribeAvailabilityZones API to get the list of AZs.
 */
@Override
public List<AvailabilityZone> getAvailabilityZonesForSubnetIds(Collection<Subnet> subnets, AwsParamsDto awsParamsDto)
{
    Set<String> zoneNames = new HashSet<>();
    for (Subnet subnet : subnets)
    {
        zoneNames.add(subnet.getAvailabilityZone());
    }

    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
    describeAvailabilityZonesRequest.setZoneNames(zoneNames);
    DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Operations.describeAvailabilityZones(ec2Client, describeAvailabilityZonesRequest);
    return describeAvailabilityZonesResult.getAvailabilityZones();
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:19,代码来源:Ec2DaoImpl.java

示例8: SubnetDTO

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
public SubnetDTO(final Subnet subnet) {
    this.subnetId = subnet.getSubnetId();
    this.vpcId = subnet.getVpcId();
    this.state = subnet.getState();
    this.availabilityZone = subnet.getAvailabilityZone();
    this.cidrBlock = subnet.getCidrBlock();

    this.tags.addAll(
        subnet.getTags()
            .stream()
            .map(TagDTO::new)
            .collect(Collectors.toList()));

    this.name = subnet.getTags()
        .stream()
        .filter(t -> t.getKey().equals("Name"))
        .findFirst()
        .map(Tag::getValue)
        .orElse("n/a");
}
 
开发者ID:kylesm,项目名称:vpcviewer,代码行数:21,代码来源:SubnetDTO.java

示例9: planAddedCountBySubnet

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
private Map<String, Integer> planAddedCountBySubnet() {
    Map<String, Integer> instanceCount = Maps.newHashMap();
    for (Subnet remoteSubnet : resource.subnet.remoteSubnets) {
        instanceCount.put(remoteSubnet.getSubnetId(), 0);
    }
    for (com.amazonaws.services.ec2.model.Instance remoteInstance : resource.remoteInstances) {
        instanceCount.compute(remoteInstance.getSubnetId(), (key, oldValue) -> oldValue + 1);
    }

    Map<String, Integer> addedInstanceCount = Maps.newHashMap();
    for (String subnetId : instanceCount.keySet()) {
        addedInstanceCount.put(subnetId, 0);
    }

    for (int i = 0; i < count; i++) {
        String targetSubnet = findSubnetHasMinimalInstances(instanceCount);
        instanceCount.compute(targetSubnet, (key, oldValue) -> oldValue + 1);
        addedInstanceCount.compute(targetSubnet, (key, oldValue) -> oldValue + 1);
    }
    return addedInstanceCount;
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:22,代码来源:CreateInstanceTask.java

示例10: hasSubnets

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的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

示例11: findNonOverLappingCIDR

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的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);
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:18,代码来源:AwsResourceConnector.java

示例12: validateExistingSubnet

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的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()));
                }
            }
        }
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:19,代码来源:AwsSetup.java

示例13: testUploadArtifactsToS3AndAutopopulateAsParameters

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
@Test
public void testUploadArtifactsToS3AndAutopopulateAsParameters() {		
			
	Main main = new Main(CLIArgBuilder.createSubnetStackWithArtifactUpload(BUILD_NUMBER, testName));
	int result = main.parse();
	deletesStacks.ifPresent("CfnAssist9987TestsubnetWithS3Param");
	
	assertEquals("deploy failed", 0, result);
	
	Vpc vpcId = vpcRepository.getCopyOfVpc(projectAndEnv);
	List<Subnet> subnets = EnvironmentSetupForTests.getSubnetFors(ec2Client, vpcId);
	assertEquals(1, subnets.size());
	List<Tag> tags = subnets.get(0).getTags();

	List<Tag> expectedTags = new LinkedList<>();
	expectedTags.add(new Tag().withKey("urlATag").withValue(EnvironmentSetupForTests.S3_PREFIX+"/"+KEY_A));
	expectedTags.add(new Tag().withKey("urlBTag").withValue(EnvironmentSetupForTests.S3_PREFIX+"/"+KEY_B));
	assertTrue(tags.containsAll(expectedTags));
}
 
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:20,代码来源:TestCommandLineS3Operations.java

示例14: describeAllNetworksTest

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
/**
 * Test describing vpcs.
 */
@Test(timeout = TIMEOUT_LEVEL1)
public final void describeAllNetworksTest() {
    log.info("Start describing vpcs test");
    List<Vpc> vpcs = describeVpcs();

    Assert.assertNotNull("vpcs should not be null", vpcs);
    Assert.assertNotNull("vpc id should not be null", vpcs.get(0).getVpcId());
    log.info("Vpc Sizes " + vpcs.size());

    log.info("Start describing vpcs test");
    List<Subnet> subnets = getSubnets();

    Assert.assertNotNull("vpcs should not be null", subnets);
    Assert.assertNotNull("vpc id should not be null", subnets.get(0).getSubnetId());
    log.info("Subnets Sizes " + subnets.size());

    log.info("Start describing vpcs test");
    List<InternetGateway> internetGateways = getInternetGateways();

    Assert.assertNotNull("vpcs should not be null", internetGateways);
    Assert.assertNotNull("vpc id should not be null", internetGateways.get(0).getInternetGatewayId());
    log.info("Subnets Sizes " + internetGateways.size());

}
 
开发者ID:treelogic-swe,项目名称:aws-mock,代码行数:28,代码来源:Ec2NetworkTest.java

示例15: testResolveSubnet

import com.amazonaws.services.ec2.model.Subnet; //导入依赖的package包/类
@Test
public void testResolveSubnet() throws Exception {
    ec2mock.createDescribeSubnetsResult("subnet-a77430d0");
    Subnet subnet = ec2comm.resolveSubnet("subnet-a77430d0");
    assertNotNull(subnet);
    assertEquals("subnet-a77430d0", subnet.getSubnetId());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:8,代码来源:EC2CommunicationTest.java


注:本文中的com.amazonaws.services.ec2.model.Subnet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。