Package com.amazonaws.services.ec2

Examples of com.amazonaws.services.ec2.AmazonEC2Client


       */

      if (newKey) {
        DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(KEY_PAIR_NAME);
        ec2.deleteKeyPair(deleteKeyPairRequest);
        ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(KEY_PAIR_NAME, encodedPublicKey);
        ec2.importKeyPair(importKeyPairRequest);
      }

    } catch (AmazonServiceException ase) {
      /*
       * Key doesn't exists, import new key.
       */
      if(ase.getErrorCode().equals("InvalidKeyPair.NotFound")){     
        ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(KEY_PAIR_NAME, encodedPublicKey);
        ec2.importKeyPair(importKeyPairRequest);
      }else{
        throw ase;
      }
    }
View Full Code Here


            /* 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);
                ec2.deleteKeyPair(deleteKeyPairRequest);
                ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(keyPairName, encodedPublicKey);
                ec2.importKeyPair(importKeyPairRequest);
            }

        } catch (AmazonServiceException ase) {
            /* Key doesn't exists, import new key. */
            if (ase.getErrorCode().equals("InvalidKeyPair.NotFound")) {
                ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(keyPairName, encodedPublicKey);
                ec2.importKeyPair(importKeyPairRequest);
            } else {
                throw ase;
            }
        }
View Full Code Here

    }
  }

  private boolean anyInstancesStateEqual(List<Instance> instances, InstanceStateName name) {
    for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) {
      Instance instance = (Instance) iterator.next();

      // if one of instance is not running, return false
      if (InstanceStateName.fromValue(instance.getState().getName()) == name) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

    return false;
  }

  private boolean allInstancesStateEqual(List<Instance> instances, InstanceStateName name) {
    for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) {
      Instance instance = (Instance) iterator.next();

      // if one of instance is not running, return false
      if (InstanceStateName.fromValue(instance.getState().getName()) != name) {
        return false;
      }
    }
    return true;
  }
View Full Code Here

  }

  private List<String> getInstanceIDs(List<Instance> instances) {
    List<String> ret = new ArrayList<String>();
    for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) {
      Instance instance = (Instance) iterator.next();
      ret.add(instance.getInstanceId());
    }
    return ret;
 
View Full Code Here

        log.info("Added tag: {}={} to {}", key, value, id);
    }

    private InstancePrivateIpAddress findUnusedIp(InstanceNetworkInterface networkInterface) {
        InstanceNetworkInterfaceAssociation unused = null;
        for (InstancePrivateIpAddress privateIpAddress : networkInterface.getPrivateIpAddresses()) {
            InstanceNetworkInterfaceAssociation association = privateIpAddress.getAssociation();
            if (association == null) {
                return privateIpAddress;
            }
        }
        return null;
View Full Code Here

    }

    private InstanceNetworkInterface findNetworkInterface(Instance ec2Instance, int deviceIndex) {
        InstanceNetworkInterface networkInterface = null;
        for (InstanceNetworkInterface i : ec2Instance.getNetworkInterfaces()) {
            InstanceNetworkInterfaceAttachment attachment = i.getAttachment();
            if (attachment == null) {
                log.error("EC2 network attachment on instance was null");
                continue;
            }

            Integer attachmentDeviceIndex = attachment.getDeviceIndex();
            if (attachmentDeviceIndex == null) {
                log.error("EC2 device index was null");
                continue;
            }
View Full Code Here

                if (filterByTag) {
                    logger.trace("filtering out instance {} based tags {}, not part of {}", instance.getInstanceId(), tags, instance.getTags());
                    continue;
                }

                InstanceState state = instance.getState();
                if (state.getName().equalsIgnoreCase("pending") || state.getName().equalsIgnoreCase("running")) {
                    String address = null;
                    switch (hostType) {
                        case PRIVATE_DNS:
                            address = instance.getPrivateDnsName();
                            break;
View Full Code Here

      /*
       * Make sure port 22 is connectable
       */
      for (GroupIdentifier g : this.instance.getSecurityGroups()) {
        IpPermission ip = new IpPermission();
        ip.setIpProtocol("tcp");
        ip.setFromPort(22);
        ip.setToPort(22);
        AuthorizeSecurityGroupIngressRequest r = new AuthorizeSecurityGroupIngressRequest();
        r = r.withIpPermissions(ip.withIpRanges("0.0.0.0/0"));
        r.setGroupId(g.getGroupId());
        try {
          ec2client.authorizeSecurityGroupIngress(r);
        } catch (AmazonServiceException as) {
          /*
 
View Full Code Here

  public static List<Instance> loadInstances() {
    List<Instance> resultList = new ArrayList<Instance>();
    DescribeInstancesResult describeInstancesResult = getEC2Client().describeInstances();
    List<Reservation> reservations = describeInstancesResult.getReservations();
    for (Iterator<Reservation> iterator = reservations.iterator(); iterator.hasNext();) {
      Reservation reservation = iterator.next();
      for (Instance instance : reservation.getInstances()) {
        resultList.add(instance);
      }
    }
    return resultList;
  }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.ec2.AmazonEC2Client

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.