Package org.jclouds.ec2

Examples of org.jclouds.ec2.EC2Api


  
   public void testFilterWhenResponseIs404() throws Exception {

      HttpResponse filterResponse = HttpResponse.builder().statusCode(404).build();

      EC2Api apiWhenDontExist = requestSendsResponse(filter, filterResponse);

      assertEquals(apiWhenDontExist.getSubnetApi().get().filter(ImmutableMultimap.<String, String> builder()
                                                                .put("subnet-id", "subnet-9d4a7b6c")
                                                                .build()).toSet(), ImmutableSet.of());
   }
View Full Code Here


         * Authorizes access to the specified ports of the node, from the specified source.
         */
        @Override
        public void authorize(ComputeService service, NodeMetadata node, String source, int... ports) {
            String region = AWSUtils.parseHandle(node.getId())[0];
            EC2Api ec2Api = service.getContext().unwrapApi(EC2Api.class);
            String groupName = "jclouds#" + node.getGroup();
            for (int port : ports) {
                try {
                    ec2Api.getSecurityGroupApi().get()
                        .authorizeSecurityGroupIngressInRegion(region, groupName,
                        IpProtocol.TCP, port, port, source);
                } catch (IllegalStateException e) {
                    //noop
                }
View Full Code Here

         * Revokes access to the specified ports of the node, from the specified source.
         */
        @Override
        public void revoke(ComputeService service, NodeMetadata node, String source, int... ports) {
            String region = AWSUtils.parseHandle(node.getId())[0];
            EC2Api ec2Api = service.getContext().unwrapApi(EC2Api.class);
            String groupName = "jclouds#" + node.getGroup() + "#" + region;
            for (int port : ports) {
                try {
                    ec2Api.getSecurityGroupApi().get()
                            .revokeSecurityGroupIngressInRegion(region, groupName,
                            IpProtocol.TCP, port, port, source);
                } catch (IllegalStateException e) {
                    //noop
                }
View Full Code Here

         * Removes all rules.
         */
        @Override
        public void flush(ComputeService service, NodeMetadata node) {
            String region = AWSUtils.parseHandle(node.getId())[0];
            EC2Api ec2Api = service.getContext().unwrapApi(EC2Api.class);
            String groupName = "jclouds#" + node.getGroup() + "#" + region;
            Set<SecurityGroup> matchedSecurityGroups = ec2Api.getSecurityGroupApi().get().describeSecurityGroupsInRegion(region, groupName);
            for (SecurityGroup securityGroup : matchedSecurityGroups) {
                for (IpPermission ipPermission : securityGroup) {
                    for (String cdr : ipPermission.getCidrBlocks()) {
                        ec2Api.getSecurityGroupApi().get().revokeSecurityGroupIngressInRegion(region, groupName,
                                IpProtocol.TCP, ipPermission.getFromPort(), ipPermission.getToPort(),
                                cdr
                        );
                    }
                }
View Full Code Here

   public void testGetPasswordDataWhenResponseIs2xx() throws Exception {

      HttpResponse getResponse = HttpResponse.builder().statusCode(200)
            .payload(payloadFromResourceWithContentType("/get_passworddata.xml", "text/xml")).build();

      EC2Api apiWhenExist = requestSendsResponse(get, getResponse);

      assertEquals(apiWhenExist.getWindowsApi().get().getPasswordDataForInstance("i-2574e22a").toString(), new GetPasswordDataResponseTest().expected().toString());
   }
View Full Code Here

   public void testGetPasswordDataWhenResponseIs404() throws Exception {

      HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();

      EC2Api apiWhenDontExist = requestSendsResponse(get, getResponse);

      assertNull(apiWhenDontExist.getWindowsApi().get().getPasswordDataForInstance("i-2574e22a"));
   }
View Full Code Here

   public void testFilterBundleTasksWhenResponseIs2xx() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(200)
              .payload(payloadFromResourceWithContentType("/describe_bundle_tasks.xml", "text/xml")).build();

      EC2Api apiWhenExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse);

      BundleTask task = getOnlyElement(apiWhenExist.getWindowsApi().get().describeBundleTasksInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("instance-id", "i-12345678")
                      .build()));

      assertEquals(task.getBundleId(), "bun-c1a540a8");
View Full Code Here

   }

   public void testFilterBundleTasksWhenResponseIs404() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(404).build();

      EC2Api apiWhenNotExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse);

      assertEquals(apiWhenNotExist.getWindowsApi().get().describeBundleTasksInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("instance-id", "i-12345678")
                      .build()),
              ImmutableSet.of());
   }
View Full Code Here

   public void testFilterWhenResponseIs2xx() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(200)
              .payload(payloadFromResourceWithContentType("/describe_keypairs.xml", "text/xml")).build();

      EC2Api apiWhenExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse);

      KeyPair keyPair = getOnlyElement(apiWhenExist.getKeyPairApi().get().describeKeyPairsInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("key-name", "gsg-keypair")
                      .build()));

      assertEquals(keyPair.getKeyName(), "gsg-keypair");
View Full Code Here

   }

   public void testFilterWhenResponseIs404() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(404).build();

      EC2Api apiWhenNotExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse);

      assertEquals(apiWhenNotExist.getKeyPairApi().get().describeKeyPairsInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("key-name", "gsg-keypair")
                      .build()),
              ImmutableSet.of());
   }
View Full Code Here

TOP

Related Classes of org.jclouds.ec2.EC2Api

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.