當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。