Package com.amazonaws.services.ec2.model

Examples of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult


        }

        /* Generate key pair in Amazon if necessary */
        try {
            /* Get current key pair in Amazon */
            DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
            ec2.describeKeyPairs(describeKeyPairsRequest.withKeyNames(keyPairName));

            /* If key exists and new key is created, delete old key and replace
             * with new one. Else, do nothing */
            if (newKey) {
                DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(keyPairName);
View Full Code Here


   *
   * @return list of keypairs
   */
  public static List<String> loadKeypairs(){
    List<String> resultList = new ArrayList<String>();
    DescribeKeyPairsResult results = getEC2Client().describeKeyPairs();
    for (KeyPairInfo key : results.getKeyPairs()) {
      resultList.add(key.getKeyName());
    }
    return resultList;
  }
View Full Code Here

    @PostConstruct
    private void setup()
    {
        log.info("Checking if security group \"" + groupName + "\" is set up.");

        DescribeSecurityGroupsResult describeResult = ec2Client.describeSecurityGroups(new DescribeSecurityGroupsRequest().
                withFilters(new Filter().withName("group-name").withValues(groupName),
                            new Filter().withName("ip-permission.cidr").withValues(cidr),
                            new Filter().withName("ip-permission.from-port").withValues(new Integer(port).toString()),
                            new Filter().withName("ip-permission.to-port").withValues(new Integer(port).toString()),
                            new Filter().withName("ip-permission.protocol").withValues("tcp")));

        if (!describeResult.getSecurityGroups().isEmpty())
        {
            groupId = describeResult.getSecurityGroups().get(0).getGroupId();
        }
        else
        {
            log.info("Security group \"" + groupName + "\" is not set up. Checking if it exists.");
            describeResult = ec2Client.describeSecurityGroups(new DescribeSecurityGroupsRequest().
                    withFilters(new Filter().withName("group-name").withValues(groupName)));
            if (!describeResult.getSecurityGroups().isEmpty())
            {
                log.info("Security group \"" + groupName + "\" exists.");
                groupId = describeResult.getSecurityGroups().get(0).getGroupId();
            }
            else
            {
                log.info("Security group \"" + groupName + "\" does not exists. Creating it.");
                groupId = ec2Client.createSecurityGroup(new CreateSecurityGroupRequest().
View Full Code Here

        return Sets.difference(ingressRules, ImmutableSet.of(ConvertIpPermissionToRule.FUNCTION.apply(permission)));
    }

    public void assertSecurityGroupExistsWithRules(String groupName, final Set<Rule> ingressRules) {
        DescribeSecurityGroupsResult result = client.describeSecurityGroups(
            new DescribeSecurityGroupsRequest().withGroupNames(groupName));

        assertThat(result.getSecurityGroups()).hasSize(1);
        SecurityGroup group = getOnlyElement(result.getSecurityGroups());

        assertThat(group.getIpPermissions()).hasSize(ingressRules.size());
        assertThat(ingressRules).containsAll(transform(group.getIpPermissions(),
            ConvertIpPermissionToRule.FUNCTION));
    }
View Full Code Here

        synchronizeIngressRules(client, groupName, pool.getNetwork());
    }

    private void synchronizeIngressRules(AmazonEC2 client, String groupName, Network network) {
        DescribeSecurityGroupsResult result = client.describeSecurityGroups(
            new DescribeSecurityGroupsRequest().withGroupNames(groupName));

        Set<IpPermission> existingPermissions = ImmutableSet.copyOf(getOnlyElement(
            result.getSecurityGroups()).getIpPermissions());

        Set<IpPermission> expectedPermissions = ImmutableSet.copyOf(
            Iterables.transform(network.getIngress(), ConvertRuleToIpPermission.FUNCTION));

        authorizeIngressRules(client, groupName, difference(expectedPermissions, existingPermissions));
View Full Code Here

            LOGGER.info(String.format("Getting EC2 security groups for %d names in region %s.", groupNames.length,
                    region));
            request.withGroupNames(groupNames);
        }

        DescribeSecurityGroupsResult result;
        try {
            result = ec2Client.describeSecurityGroups(request);
        } catch (AmazonServiceException e) {
            if (e.getErrorCode().equals("InvalidGroup.NotFound")) {
                LOGGER.info("Got InvalidGroup.NotFound error for security groups; returning empty list");
                return Collections.emptyList();
            }
            throw e;
        }

        List<SecurityGroup> securityGroups = result.getSecurityGroups();
        LOGGER.info(String.format("Got %d EC2 security groups in region %s.", securityGroups.size(), region));
        return securityGroups;
    }
View Full Code Here

        try
        {
            client = getEc2Client();
            List<String> ipPermissions = new ArrayList<String>();
            DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withGroupNames(Arrays.asList(config.getACLGroupName()));
            DescribeSecurityGroupsResult result = client.describeSecurityGroups(req);
            for (SecurityGroup group : result.getSecurityGroups())
                for (IpPermission perm : group.getIpPermissions())
                    if (perm.getFromPort() == from && perm.getToPort() == to)
                        ipPermissions.addAll(perm.getIpRanges());
            return ipPermissions;
        }
View Full Code Here

        synchronizeIngressRules(client, groupName, pool.getNetwork());
    }

    private void synchronizeIngressRules(AmazonEC2 client, String groupName, Network network) {
        DescribeSecurityGroupsResult result = client.describeSecurityGroups(
            new DescribeSecurityGroupsRequest().withGroupNames(groupName));

        Set<IpPermission> existingPermissions = ImmutableSet.copyOf(getOnlyElement(
            result.getSecurityGroups()).getIpPermissions());

        Set<IpPermission> expectedPermissions = ImmutableSet.copyOf(
            Iterables.transform(network.getIngress(), ConvertRuleToIpPermission.FUNCTION));

        authorizeIngressRules(client, groupName, difference(expectedPermissions, existingPermissions));
View Full Code Here

        return Sets.difference(ingressRules, ImmutableSet.of(ConvertIpPermissionToRule.FUNCTION.apply(permission)));
    }

    public void assertSecurityGroupExistsWithRules(String groupName, final Set<Rule> ingressRules) {
        DescribeSecurityGroupsResult result = client.describeSecurityGroups(
            new DescribeSecurityGroupsRequest().withGroupNames(groupName));

        assertThat(result.getSecurityGroups()).hasSize(1);
        SecurityGroup group = getOnlyElement(result.getSecurityGroups());

        assertThat(group.getIpPermissions()).hasSize(ingressRules.size());
        assertThat(ingressRules).containsAll(transform(group.getIpPermissions(),
            ConvertIpPermissionToRule.FUNCTION));
    }
View Full Code Here

     * For backwards compatibility, we preserve the existing List<String> of
     * security group names by explicitly populating it from the full list
     * of security group info.
     */
      if (response instanceof DescribeSpotInstanceRequestsResult) {
        DescribeSpotInstanceRequestsResult result = (DescribeSpotInstanceRequestsResult)response;
        for (SpotInstanceRequest spotInstanceRequest : result.getSpotInstanceRequests()) {
          LaunchSpecification launchSpecification = spotInstanceRequest.getLaunchSpecification();
          populateLaunchSpecificationSecurityGroupNames(launchSpecification);
        }
      } else if (response instanceof RequestSpotInstancesResult) {
        RequestSpotInstancesResult result = (RequestSpotInstancesResult)response;
        for (SpotInstanceRequest spotInstanceRequest : result.getSpotInstanceRequests()) {
          LaunchSpecification launchSpecification = spotInstanceRequest.getLaunchSpecification();
          populateLaunchSpecificationSecurityGroupNames(launchSpecification);
        }
      } else if (response instanceof DescribeInstancesResult) {
        DescribeInstancesResult result = (DescribeInstancesResult)response;
        for (Reservation reservation : result.getReservations()) {
          populateReservationSecurityGroupNames(reservation);
        }
      } else if (response instanceof RunInstancesResult) {
        RunInstancesResult result = (RunInstancesResult)response;
        populateReservationSecurityGroupNames(result.getReservation());
      }
  }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult

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.