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


Java AmazonEC2类代码示例

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


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

示例1: testEC2SetupNoProxy

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
@Test
public void testEC2SetupNoProxy() throws Exception {
    // Ask for connection
    AmazonEC2 client = ec2comm.getEC2();
    assertNotNull(client);
    assertNotNull(credProvider);
    assertNotNull(clientConfig);

    assertEquals(-1, clientConfig.getProxyPort());
    assertNull(clientConfig.getProxyHost());
    verify(ec2).setEndpoint("ec2.test.amazonaws.com");

    // Test again for validating cached value
    AmazonEC2 newClient = ec2comm.getEC2();
    assertTrue(client == newClient);

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

示例2: testEC2SetupProxy

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
@Test
public void testEC2SetupProxy() throws Exception {
    // Define proxy
    System.setProperty("https.proxyHost", "proxy");
    System.setProperty("https.proxyPort", "8080");

    // Ask for connection
    AmazonEC2 client = ec2comm.getEC2();
    assertNotNull(client);
    assertNotNull(credProvider);
    assertNotNull(clientConfig);

    assertEquals(8080, clientConfig.getProxyPort());
    assertEquals("proxy", clientConfig.getProxyHost());

    assertTrue(clientConfig.getProxyUsername() == null
            || clientConfig.getProxyUsername().isEmpty());
    assertTrue(clientConfig.getProxyPassword() == null
            || clientConfig.getProxyPassword().isEmpty());
    verify(ec2).setEndpoint("ec2.test.amazonaws.com");

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

示例3: testEC2SetupProxyWithCredentials

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
@Test
public void testEC2SetupProxyWithCredentials() throws Exception {
    // Define proxy
    System.setProperty("https.proxyHost", "proxy");
    System.setProperty("https.proxyPort", "8080");
    System.setProperty("https.proxyUser", PROXYUSER);
    System.setProperty("https.proxyPassword", PROXYPWD);

    // Ask for connection
    AmazonEC2 client = ec2comm.getEC2();
    assertNotNull(client);
    assertNotNull(credProvider);
    assertNotNull(clientConfig);
    clientConfig.getProxyUsername();
    assertEquals(8080, clientConfig.getProxyPort());
    assertEquals("proxy", clientConfig.getProxyHost());
    assertEquals(PROXYUSER, clientConfig.getProxyUsername());
    assertEquals(PROXYPWD, clientConfig.getProxyPassword());
    verify(ec2).setEndpoint("ec2.test.amazonaws.com");

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

示例4: testEC2SetupProxyWithEmptyCredentials

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
@Test
public void testEC2SetupProxyWithEmptyCredentials() throws Exception {
    // Define proxy
    System.setProperty("https.proxyHost", "proxy");
    System.setProperty("https.proxyPort", "8080");
    System.setProperty("https.proxyUser", "");
    System.setProperty("https.proxyPassword", "");

    // Ask for connection
    AmazonEC2 client = ec2comm.getEC2();
    assertNotNull(client);
    assertNotNull(credProvider);
    assertNotNull(clientConfig);

    assertEquals(8080, clientConfig.getProxyPort());
    assertEquals("proxy", clientConfig.getProxyHost());

    assertTrue(clientConfig.getProxyUsername() == null
            || clientConfig.getProxyUsername().isEmpty());
    assertTrue(clientConfig.getProxyPassword() == null
            || clientConfig.getProxyPassword().isEmpty());
    verify(ec2).setEndpoint("ec2.test.amazonaws.com");

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

示例5: testEC2SetupNonProxy

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
@Test
public void testEC2SetupNonProxy() throws Exception {
    // Define proxy
    System.setProperty("https.proxyHost", "proxy");
    System.setProperty("https.proxyPort", "8080");
    // But set endpoint as non proxy
    System.setProperty("http.nonProxyHosts", "*.amazonaws.com");

    // Ask for connection
    AmazonEC2 client = ec2comm.getEC2();
    assertNotNull(client);
    assertNotNull(credProvider);
    assertNotNull(clientConfig);

    assertEquals(8080, clientConfig.getProxyPort());
    assertTrue(clientConfig.getProxyUsername() == null
            || clientConfig.getProxyUsername().isEmpty());
    assertTrue(clientConfig.getProxyPassword() == null
            || clientConfig.getProxyPassword().isEmpty());
    verify(ec2).setEndpoint("ec2.test.amazonaws.com");

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

示例6: testAWSCredentials

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
@Test
public void testAWSCredentials() throws Exception {
    // Ask for connection
    AmazonEC2 client = ec2comm.getEC2();
    assertNotNull(client);
    assertNotNull(credProvider);

    AWSCredentials credentials = credProvider.getCredentials();
    assertEquals("access_key", credentials.getAWSAccessKeyId());
    assertEquals("secret_key", credentials.getAWSSecretKey());

    credProvider.refresh();
    credentials = credProvider.getCredentials();
    assertEquals("access_key", credentials.getAWSAccessKeyId());
    assertEquals("secret_key", credentials.getAWSSecretKey());

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

示例7: doFillRegionItems

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public ListBoxModel doFillRegionItems(@QueryParameter final String credentialsId,
                                      @QueryParameter final String region)
        throws IOException, ServletException {
    final List<Region> regionList;

    try {
        final AmazonEC2 client = connect(credentialsId, null);
        final DescribeRegionsResult regions=client.describeRegions();
        regionList=regions.getRegions();
    } catch(final Exception ex) {
        //Ignore bad exceptions
        return new ListBoxModel();
    }

    final ListBoxModel model = new ListBoxModel();
    for(final Region reg : regionList) {
        model.add(new ListBoxModel.Option(reg.getRegionName(), reg.getRegionName()));
    }
    return model;
}
 
开发者ID:awslabs,项目名称:ec2-spot-jenkins-plugin,代码行数:21,代码来源:EC2FleetCloud.java

示例8: getEC2SynchronousClient

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public static AmazonEC2 getEC2SynchronousClient(AuthCredentialsServiceState credentials,
        String region) {
    ClientConfiguration configuration = new ClientConfiguration();
    configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(),
            DEFAULT_BACKOFF_STRATEGY,
            DEFAULT_MAX_ERROR_RETRY,
            true));

    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(credentials.privateKeyId,
                    EncryptionUtils.decrypt(credentials.privateKey)));

    AmazonEC2ClientBuilder ec2ClientBuilder = AmazonEC2ClientBuilder.standard()
            .withCredentials(awsStaticCredentialsProvider)
            .withRegion(region)
            .withClientConfiguration(configuration);

    return ec2ClientBuilder.build();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:20,代码来源:TestUtils.java

示例9: main

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply an instance id\n" +
        "Ex: RebootInstnace <instance_id>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String instance_id = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    RebootInstancesRequest request = new RebootInstancesRequest()
        .withInstanceIds(instance_id);

    RebootInstancesResult response = ec2.rebootInstances(request);

    System.out.printf(
        "Successfully rebooted instance %s", instance_id);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:24,代码来源:RebootInstance.java

示例10: main

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply a security group id\n" +
        "Ex: DeleteSecurityGroup <security-group-id>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String group_id = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DeleteSecurityGroupRequest request = new DeleteSecurityGroupRequest()
        .withGroupId(group_id);

    DeleteSecurityGroupResult response = ec2.deleteSecurityGroup(request);

    System.out.printf(
        "Successfully deleted security group with id %s", group_id);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:24,代码来源:DeleteSecurityGroup.java

示例11: main

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public static void main(String[] args)
{
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DescribeAddressesResult response = ec2.describeAddresses();

    for(Address address : response.getAddresses()) {
        System.out.printf(
                "Found address with public IP %s, " +
                "domain %s, " +
                "allocation id %s " +
                "and NIC id %s",
                address.getPublicIp(),
                address.getDomain(),
                address.getAllocationId(),
                address.getNetworkInterfaceId());
    }
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:19,代码来源:DescribeAddresses.java

示例12: main

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply a key pair name\n" +
        "Ex: CreateKeyPair <key-pair-name>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String key_name = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    CreateKeyPairRequest request = new CreateKeyPairRequest()
        .withKeyName(key_name);

    CreateKeyPairResult response = ec2.createKeyPair(request);

    System.out.printf(
        "Successfulyl created key pair named %s",
        key_name);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:25,代码来源:CreateKeyPair.java

示例13: main

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply an allocation ID.\n" +
        "Ex: ReleaseAddress <allocation_id>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String alloc_id = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    ReleaseAddressRequest request = new ReleaseAddressRequest()
        .withAllocationId(alloc_id);

    ReleaseAddressResult response = ec2.releaseAddress(request);

    System.out.printf(
        "Successfully released elastic IP address %s", alloc_id);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:24,代码来源:ReleaseAddress.java

示例14: main

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply a key pair name\n" +
        "Ex: DeleteKeyPair <key-pair-name>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String key_name = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DeleteKeyPairRequest request = new DeleteKeyPairRequest()
        .withKeyName(key_name);

    DeleteKeyPairResult response = ec2.deleteKeyPair(request);

    System.out.printf(
        "Successfully deleted key pair named %s", key_name);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:24,代码来源:DeleteKeyPair.java

示例15: isAmiWithTagExistTrue

import com.amazonaws.services.ec2.AmazonEC2; //导入依赖的package包/类
@Test
public void isAmiWithTagExistTrue() {
    AmazonEC2 ec2Client = mock(AmazonEC2.class);
    AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);

    String amiId = "ami-1234abcd";
    String tagName = "sometag";
    String tagValue = "someval";

    when(ec2Client.describeImages(
            new DescribeImagesRequest()
                    .withFilters(new Filter().withName(tagName).withValues(tagValue))
                    .withFilters(new Filter().withName("image-id").withValues(amiId))
            )
    ).thenReturn(
            new DescribeImagesResult().withImages(new Image())
            );

    // invoke method under test
    assertTrue(amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:22,代码来源:AmiTagCheckServiceTest.java


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