Ejemplo n.º 1
0
 def __init__(self,
              aws_access_key_id=None,
              aws_secret_access_key=None,
              is_secure=True,
              port=None,
              proxy=None,
              proxy_port=None,
              proxy_user=None,
              proxy_pass=None,
              debug=0,
              https_connection_factory=None,
              region=None,
              path='/',
              security_token=None,
              validate_certs=True):
     if not region:
         region = RegionInfo(self, self.DefaultRegionName,
                             self.DefaultRegionEndpoint)
     self.region = region
     AWSQueryConnection.__init__(self,
                                 aws_access_key_id,
                                 aws_secret_access_key,
                                 is_secure,
                                 port,
                                 proxy,
                                 proxy_port,
                                 proxy_user,
                                 proxy_pass,
                                 self.region.endpoint,
                                 debug,
                                 https_connection_factory,
                                 path,
                                 security_token,
                                 validate_certs=validate_certs)
Ejemplo n.º 2
0
def connect_ec2_endpoint(url, aws_access_key_id=None,
                         aws_secret_access_key=None,
                         **kwargs):
    """
    Connect to an EC2 Api endpoint.  Additional arguments are passed
    through to connect_ec2.

    :type url: string
    :param url: A url for the ec2 api endpoint to connect to

    :type aws_access_key_id: string
    :param aws_access_key_id: Your AWS Access Key ID

    :type aws_secret_access_key: string
    :param aws_secret_access_key: Your AWS Secret Access Key

    :rtype: :class:`boto.ec2.connection.EC2Connection`
    :return: A connection to Eucalyptus server
    """
    from boto.ec2.regioninfo import RegionInfo

    purl = urlparse.urlparse(url)
    kwargs['port'] = purl.port
    kwargs['host'] = purl.hostname
    kwargs['path'] = purl.path
    if not 'is_secure' in kwargs:
        kwargs['is_secure'] = (purl.scheme == "https")

    kwargs['region'] = RegionInfo(name=purl.hostname,
                                  endpoint=purl.hostname)
    kwargs['aws_access_key_id'] = aws_access_key_id
    kwargs['aws_secret_access_key'] = aws_secret_access_key

    return(connect_ec2(**kwargs))
Ejemplo n.º 3
0
def connect_euca(host,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 port=8773,
                 path='/services/Eucalyptus',
                 is_secure=False,
                 **kwargs):
    """
    Connect to a Eucalyptus service.

    :type host: string
    :param host: the host name or ip address of the Eucalyptus server
    
    :type aws_access_key_id: string
    :param aws_access_key_id: Your AWS Access Key ID

    :type aws_secret_access_key: string
    :param aws_secret_access_key: Your AWS Secret Access Key

    :rtype: :class:`boto.ec2.connection.EC2Connection`
    :return: A connection to Eucalyptus server
    """
    from boto.ec2 import EC2Connection
    from boto.ec2.regioninfo import RegionInfo

    reg = RegionInfo(name='eucalyptus', endpoint=host)
    return EC2Connection(aws_access_key_id,
                         aws_secret_access_key,
                         region=reg,
                         port=port,
                         path=path,
                         is_secure=is_secure,
                         **kwargs)
Ejemplo n.º 4
0
    def __init__(self, config, *args, **kwargs):
        super(APIClientEC2, self).__init__(config, *args, **kwargs)
        aws_access = config.boto.aws_access
        aws_secret = config.boto.aws_secret
        purl = urlparse.urlparse(config.boto.ec2_url)

        region = RegionInfo(name=config.boto.aws_region,
                            endpoint=purl.hostname)
        port = purl.port
        if port is None:
            if purl.scheme is not "https":
                port = 80
            else:
                port = 443
        else:
            port = int(port)
        self.connection_data = {
            "aws_access_key_id": aws_access,
            "aws_secret_access_key": aws_secret,
            "is_secure": purl.scheme == "https",
            "region": region,
            "host": purl.hostname,
            "port": port,
            "path": purl.path
        }
Ejemplo n.º 5
0
 def __init__(self,
              aws_access_key_id=None,
              aws_secret_access_key=None,
              is_secure=True,
              port=None,
              proxy=None,
              proxy_port=None,
              proxy_user=None,
              proxy_pass=None,
              debug=0,
              https_connection_factory=None,
              region=None):
     """
     Init method to create a new connection to EC2.
     
     B{Note:} The host argument is overridden by the host specified in the boto configuration file.        
     """
     if not region:
         region = RegionInfo(self, self.DefaultRegionName,
                             self.DefaultRegionEndpoint)
     self.region = region
     AWSQueryConnection.__init__(self, aws_access_key_id,
                                 aws_secret_access_key, is_secure, port,
                                 proxy, proxy_port, proxy_user, proxy_pass,
                                 self.region.endpoint, debug,
                                 https_connection_factory)
Ejemplo n.º 6
0
 def __init__(self, clc_host, access_id, secret_key, token):
     #boto.set_stream_logger('foo')
     path = '/services/elb'
     port = 8773
     if clc_host[len(clc_host) - 13:] == 'amazonaws.com':
         clc_host = clc_host.replace('ec2', 'elasticloadbalancing', 1)
         path = '/'
         reg = None
         port = 443
     reg = RegionInfo(name='eucalyptus', endpoint=clc_host)
     if boto.__version__ < '2.6':
         self.conn = ELBConnection(access_id,
                                   secret_key,
                                   region=reg,
                                   port=port,
                                   path=path,
                                   is_secure=True,
                                   security_token=token,
                                   debug=0)
     else:
         self.conn = ELBConnection(access_id,
                                   secret_key,
                                   region=reg,
                                   port=port,
                                   path=path,
                                   validate_certs=False,
                                   is_secure=True,
                                   security_token=token,
                                   debug=0)
     self.conn.http_connection_kwargs['timeout'] = 30
Ejemplo n.º 7
0
    def __init__(self, job_description, resource_url,
                 pilot_compute_description):

        self.job_description = job_description
        logger.debug("URL: " + str(resource_url) + " Type: " +
                     str(type(resource_url)))
        self.resource_url = saga.Url(str(resource_url))
        self.pilot_compute_description = pilot_compute_description

        self.id = "bigjob-" + str(uuid.uuid1())
        self.network_ip = None

        self.ec2_conn = None

        if self.resource_url.scheme == "euca+ssh" or self.resource_url.scheme == "nova+ssh":
            host = self.resource_url.host
            path = "/services/Eucalyptus"
            if self.resource_url.path != None:
                path = self.resource_url.path
            port = 8773
            if self.resource_url.port != None:
                port = self.resource_url.port
            region = None
            logger.debug("Host: %s, Path: %s, Port: %d" % (host, path, port))
            if self.resource_url.scheme == "euca+ssh":
                region = RegionInfo(name="eucalyptus", endpoint=host)
            elif self.resource_url.scheme == "nova+ssh":
                region = RegionInfo(name="openstack", endpoint=host)
            logger.debug("Access Key: %s Secret: %s" %
                         (self.pilot_compute_description["access_key_id"],
                          self.pilot_compute_description["secret_access_key"]))
            self.ec2_conn = EC2Connection(
                aws_access_key_id=self.
                pilot_compute_description["access_key_id"],
                aws_secret_access_key=self.
                pilot_compute_description["secret_access_key"],
                region=region,
                is_secure=False,
                port=port,
                path=path)
        else:
            self.ec2_conn = EC2Connection(
                aws_access_key_id=self.
                pilot_compute_description["access_key_id"],
                aws_secret_access_key=self.
                pilot_compute_description["secret_access_key"])
        self.instance = None
def main(argv):
    def print_help(file=sys.stdout):
        print('server_deployment.py -a <EC2 Access Key> -s <EC2 Secret Key>',
              file=file)

    ec2_access_key = config.ec2AccessKey
    ec2_secret_key = config.ec2SecretKey
    # try:
    # 	opts, args = getopt.getopt(argv[1:], "ha:s:", ["ec2AccessKey=", "ec2SecretKey="])
    # except getopt.GetoptError:
    # 	print_help(file=sys.stderr)
    # 	sys.exit(2)

    # #print("opts:", opts, "args:", args)
    # for opt, arg in opts:
    # 	#print("option:", opt, "arg:", arg)
    # 	if opt == '-h':
    # 		print_help()
    # 		sys.exit()
    # 	elif opt in ("-a", "--ec2AccessKey"):
    # 		ec2_access_key = arg
    # 	elif opt in ("-s", "--ec2SecretKey"):
    # 		ec2_secret_key = arg

    region = RegionInfo(name='melbourne', endpoint='nova.rc.nectar.org.au')
    ec2_conn = boto.connect_ec2(aws_access_key_id=ec2_access_key,
                                aws_secret_access_key=ec2_secret_key,
                                is_secure=True,
                                region=region,
                                port=8773,
                                path='/services/Cloud',
                                validate_certs=False)

    reservations = ec2_conn.get_all_reservations()
    terminateID_list = []
    volumeID_list = []
    for res in reservations:
        terminateID_list.append(res.instances[0].id)
        print('\nID: {}\tIP: {}\tPlacement: {}'.format(
            res.instances[0].id, res.instances[0].private_ip_address,
            res.instances[0].placement))
    if terminateID_list:
        ec2_conn.terminate_instances(instance_ids=terminateID_list)

    while True:
        time.sleep(2)
        curr_r = ec2_conn.get_all_reservations()
        if (len(curr_r) == 0):
            print('ALL instances been terminated')
            break

    volumnes = ec2_conn.get_all_volumes()
    print('Index\tID\t\tSize')
    for idx, vol in enumerate(volumnes):
        volumeID_list.append(vol.id)
        print('{}\t{}\t{}'.format(idx, vol.id, vol.size))
    if volumeID_list:
        for v_id in volumeID_list:
            ec2_conn.delete_volume(volume_id=v_id)
Ejemplo n.º 9
0
def get_connection():
    return boto.connect_ec2(aws_access_key_id=ACCESS_KEY,
                            aws_secret_access_key=SECRET_KEY,
                            is_secure=False,
                            region=RegionInfo(None, REGION, CLC_IP),
                            port=CLC_PORT,
                            path='/services/Cloud',
                            debug=99)
Ejemplo n.º 10
0
def start_ec2_boto_connection():
    print "Starting Boto EC2 Connection."
    region = RegionInfo(name=aws_region, endpoint=aws_endpoint)
    ec2conn = boto.connect_ec2(
        aws_access_key_id=key_id,
        aws_secret_access_key=secret_key, 
        region=region)
    return ec2conn
Ejemplo n.º 11
0
def get_conn(i,regions,endpoints):
    # first create a region object and connection
    region = RegionInfo(name=regions[i], endpoint=endpoints[i])

    # first create a connection to the appropriate host, using your credentials
    ec2conn =  boto.connect_ec2(region = region)
    reservations = ec2conn.get_all_instances()
    return reservations
Ejemplo n.º 12
0
def regions():
    """
    Get all available regions for the Amazon Glacier service.

    :rtype: list
    :return: A list of :class:`boto.regioninfo.RegionInfo`
    """
    from boto.glacier.layer2 import Layer2
    return [RegionInfo(name='us-east-1',
                       endpoint='glacier.us-east-1.amazonaws.com',
                       connection_cls=Layer2),
            RegionInfo(name='us-west-1',
                       endpoint='glacier.us-west-1.amazonaws.com',
                       connection_cls=Layer2),
            RegionInfo(name='us-west-2',
                       endpoint='glacier.us-west-2.amazonaws.com',
                       connection_cls=Layer2),
            RegionInfo(name='ap-northeast-1',
                       endpoint='glacier.ap-northeast-1.amazonaws.com',
                       connection_cls=Layer2),
            RegionInfo(name='eu-west-1',
                       endpoint='glacier.eu-west-1.amazonaws.com',
                       connection_cls=Layer2),
            RegionInfo(name='ap-southeast-2',
                       endpoint='glacier.ap-southeast-2.amazonaws.com',
                       connection_cls=Layer2),
            RegionInfo(name='cn-north-1',
                       endpoint='glacier.cn-north-1.amazonaws.com.cn',
                       connection_cls=Layer2),
            ]
Ejemplo n.º 13
0
def regions():
    """
    Get all available regions for the Amazon Simple Workflow service.
        
    :rtype: list
    :return: A list of :class:`boto.regioninfo.RegionInfo`
    """
    import boto.swf.layer1
    return [
        RegionInfo(name='us-east-1',
                   endpoint='swf.us-east-1.amazonaws.com',
                   connection_cls=boto.swf.layer1.Layer1),
        RegionInfo(name='us-west-1',
                   endpoint='swf.us-west-1.amazonaws.com',
                   connection_cls=boto.swf.layer1.Layer1),
        RegionInfo(name='us-west-2',
                   endpoint='swf.us-west-2.amazonaws.com',
                   connection_cls=boto.swf.layer1.Layer1),
        RegionInfo(name='ap-northeast-1',
                   endpoint='swf.ap-northeast-1.amazonaws.com',
                   connection_cls=boto.swf.layer1.Layer1),
        RegionInfo(name='ap-southeast-1',
                   endpoint='swf.ap-southeast-1.amazonaws.com',
                   connection_cls=boto.swf.layer1.Layer1),
        RegionInfo(name='ap-southeast-2',
                   endpoint='swf.ap-southeast-2.amazonaws.com',
                   connection_cls=boto.swf.layer1.Layer1),
        RegionInfo(name='eu-west-1',
                   endpoint='swf.eu-west-1.amazonaws.com',
                   connection_cls=boto.swf.layer1.Layer1),
    ]
Ejemplo n.º 14
0
def regions():
    """
    Get all available regions for the Amazon DynamoDB service.
        
    :rtype: list
    :return: A list of :class:`boto.regioninfo.RegionInfo`
    """
    import boto.dynamodb.layer2
    return [
        RegionInfo(name='us-east-1',
                   endpoint='dynamodb.us-east-1.amazonaws.com',
                   connection_cls=boto.dynamodb.layer2.Layer2),
        RegionInfo(name='us-west-1',
                   endpoint='dynamodb.us-west-1.amazonaws.com',
                   connection_cls=boto.dynamodb.layer2.Layer2),
        RegionInfo(name='us-west-2',
                   endpoint='dynamodb.us-west-2.amazonaws.com',
                   connection_cls=boto.dynamodb.layer2.Layer2),
        RegionInfo(name='ap-northeast-1',
                   endpoint='dynamodb.ap-northeast-1.amazonaws.com',
                   connection_cls=boto.dynamodb.layer2.Layer2),
        RegionInfo(name='ap-southeast-1',
                   endpoint='dynamodb.ap-southeast-1.amazonaws.com',
                   connection_cls=boto.dynamodb.layer2.Layer2),
        RegionInfo(name='eu-west-1',
                   endpoint='dynamodb.eu-west-1.amazonaws.com',
                   connection_cls=boto.dynamodb.layer2.Layer2),
        RegionInfo(name='sa-east-1',
                   endpoint='dynamodb.sa-east-1.amazonaws.com',
                   connection_cls=boto.dynamodb.layer2.Layer2),
    ]
Ejemplo n.º 15
0
    def setup_sts_connection(self, endpoint=None, region=None, aws_access_key_id=None, aws_secret_access_key=None, path="/",port=443, is_secure=True, boto_debug=0):
        sts_region = RegionInfo()
        if region:
            self.debug("Check region: " + str(region))
            try:
                if not endpoint:
                    sts_region.endpoint = EC2RegionData[region]
                else:
                    sts_region.endpoint = endpoint
            except KeyError:
                raise Exception( 'Unknown region: %s' % region)
        else:
            sts_region.name = 'eucalyptus'
            if endpoint:
                sts_region.endpoint = endpoint
            else:
                sts_region.endpoint = self.get_ec2_ip()

        try:
            sts_connection_args = { 'aws_access_key_id' : aws_access_key_id,
                                    'aws_secret_access_key': aws_secret_access_key,
                                    'is_secure': is_secure,
                                    'debug':boto_debug,
                                    'port' : port,
                                    'path' : path,
                                    'region' : sts_region}
            self.debug("Attempting to create STS connection to " + self.get_ec2_ip() + ':' + str(port) + path)
            self.tokens = boto.connect_sts(**sts_connection_args)
        except Exception, e:
            self.critical("Was unable to create STS connection because of exception: " + str(e))
Ejemplo n.º 16
0
def regions(**kw_params):
    """
    Get all available regions for the Amazon Simple Workflow service.

    :rtype: list
    :return: A list of :class:`boto.regioninfo.RegionInfo`
    """
    return [RegionInfo(name=region_name, endpoint=REGION_ENDPOINTS[region_name],
                       connection_cls=boto.swf.layer1.Layer1)
            for region_name in REGION_ENDPOINTS]
Ejemplo n.º 17
0
def create_connection():
    region = RegionInfo(name='melbourne', endpoint='nova.rc.nectar.org.au')
    ec2 = boto.connect_ec2(aws_access_key_id=nectar_access_key_id,
                           aws_secret_access_key=nectar_secret_access_key,
                           is_secure=True,
                           region=region,
                           port=8773,
                           path='/services/Cloud',
                           validate_certs=False)
    return ec2
Ejemplo n.º 18
0
def connect_dynamodb(region):
    """
    connect to the right dynamodb 
    """

    endpoint = "dynamodb.{0}.amazonaws.com".format(region)
    region_info = RegionInfo(name=region, endpoint=endpoint)

    dDB = boto.connect_dynamodb( os.environ.get('DYNAMODB_ACCESS_KEY'), os.environ.get('DYNAMODB_SECRET_ACCESS_KEY'), region=region_info)
    return dDB
Ejemplo n.º 19
0
    def connect(self):
        """ Connects to the cloud using boto interface """

        self.region = RegionInfo(name=self.cloud_type, endpoint=self.cloud_uri)
        self.conn = EC2Connection(self.access_id,
                                  self.secret_key,
                                  port=self.cloud_port,
                                  region=self.region)
        self.conn.host = self.cloud_uri
        LOG.debug("Connected to cloud: %s" % (self.name))
Ejemplo n.º 20
0
def start_ec2_boto_connection():
    print "Starting Boto Connection."
    region = RegionInfo(name=cloud_name, endpoint=ec2_host)
    ec2conn = boto.connect_ec2(aws_access_key_id=key_id,
                               aws_secret_access_key=secret_key,
                               is_secure=False,
                               port=8773,
                               path=ec2_service_path,
                               region=region)
    return ec2conn
Ejemplo n.º 21
0
def purge_snapshots(key, access, name, snapshots):
    region_info = RegionInfo(name=region,
                             endpoint="ec2.{0}.amazonaws.com".format(region))
    ec2 = EC2Connection(key, access, region=region_info)

    for snapshot in snapshots:
        if ec2.delete_snapshot(snapshot['snapshot']):
            print "deleting snapshot: {0}".format(snapshot['snapshot'])
            administration.delete_snapshot(key, access, name,
                                           snapshot['snapshot'])
Ejemplo n.º 22
0
def main(argv):
    def print_help(file=sys.stdout):
        print('create_snapshot.py -a <EC2 Access Key> -s <EC2 Secret Key>',
              file=file)

    ec2_access_key = ""
    ec2_secret_key = ""
    try:
        opts, args = getopt.getopt(argv[1:], "ha:s:",
                                   ["ec2AccessKey=", "ec2SecretKey="])
    except getopt.GetoptError:
        print_help(file=sys.stderr)
        sys.exit(2)

    #print("opts:", opts, "args:", args)
    for opt, arg in opts:
        #print("option:", opt, "arg:", arg)
        if opt == '-h':
            print_help()
            sys.exit()
        elif opt in ("-a", "--ec2AccessKey"):
            ec2_access_key = arg
        elif opt in ("-s", "--ec2SecretKey"):
            ec2_secret_key = arg

    region = RegionInfo(name='melbourne', endpoint='nova.rc.nectar.org.au')
    ec2_conn = boto.connect_ec2(aws_access_key_id=ec2_access_key,
                                aws_secret_access_key=ec2_secret_key,
                                is_secure=True,
                                region=region,
                                port=8773,
                                path='/services/Cloud',
                                validate_certs=False)

    reservations = ec2_conn.get_all_reservations()
    # image_IDs = []
    # volumeID_list = []
    for res in reservations:
        print('\nID: {}\tIP: {}\tPlacement: {}'.format(
            res.instances[0].id, res.instances[0].private_ip_address,
            res.instances[0].placement))
        ec2_conn.create_image(instance_id=res.instances[0].id, name=res.id)

    # while True:
    # 	time.sleep(2)
    # 	curr_r = ec2_conn.get_all_reservations()
    # 	if (len(curr_r) == 0):
    # 		print ('ALL instances been terminated')
    # 		break

    volumnes = ec2_conn.get_all_volumes()
    print('Index\tID\t\tSize')
    for idx, vol in enumerate(volumnes):
        print('{}\t{}\t{}'.format(idx, vol.id, vol.size))
        ec2_conn.create_snapshot(vol.id)
def auth(id, key):
    region = RegionInfo(name='melbourne', endpoint='nova.rc.nectar.org.au')
    ec2_conn = boto.connect_ec2(aws_access_key_id=id,
                                aws_secret_access_key=key,
                                is_secure=True,
                                region=region,
                                port=8773,
                                path='/services/Cloud',
                                validate_certs=False)
    print("AUTH SUCCESS")
    return ec2_conn
Ejemplo n.º 24
0
def connect():
    region = RegionInfo(name='melbourne', endpoint='nova.rc.nectar.org.au')

    ec2_conn = boto.connect_ec2(aws_access_key_id=AWS_ACCESS_KEY,
                                aws_secret_access_key=AWS_SECRET_KEY,
                                is_secure=True,
                                region=region,
                                port=8773,
                                path='/services/Cloud',
                                validate_certs=False)
    return ec2_conn
def auth():
    region = RegionInfo(name='melbourne', endpoint='nova.rc.nectar.org.au')
    ec2_conn = boto.connect_ec2(
        aws_access_key_id='7176ba4f906c43038cb33debbd058782',
        aws_secret_access_key='b1cf0de2b19344e69bc5e984db1b183f',
        is_secure=True,
        region=region,
        port=8773,
        path='/services/Cloud',
        validate_certs=False)
    return ec2_conn
Ejemplo n.º 26
0
 def set_endpoint(self, endpoint):
     #boto.set_stream_logger('foo')
     reg = RegionInfo(name='eucalyptus', endpoint=endpoint)
     path = '/services/LoadBalancing'
     port = 8773
     if endpoint[len(endpoint) - 13:] == 'amazonaws.com':
         endpoint = endpoint.replace('ec2', 'elasticloadbalancing', 1)
         path = '/'
         reg = RegionInfo(endpoint=endpoint)
         port = 443
     self.conn = ELBConnection(self.access_id,
                               self.secret_key,
                               region=reg,
                               port=port,
                               path=path,
                               is_secure=True,
                               security_token=self.token,
                               debug=0)
     self.conn.https_validate_certificates = False
     self.conn.http_connection_kwargs['timeout'] = 30
Ejemplo n.º 27
0
 def __init__(self):
     access_key_id = Config(DEPLOY_CONFIG_PATH).get('nectar/access_key_id')
     access_key_secret = Config(DEPLOY_CONFIG_PATH).get('nectar/access_key_secret')
     region = RegionInfo(name='melbourne', endpoint='nova.rc.nectar.org.au')
     self.ec2_conn = boto.connect_ec2(aws_access_key_id=access_key_id,
                                      aws_secret_access_key=access_key_secret,
                                      is_secure=True,
                                      region=region,
                                      port=8773,
                                      path='/Services/Cloud',
                                      validate_certs=False)
Ejemplo n.º 28
0
    def __init__(self,
                 credpath=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 region=None,
                 ec2_ip=None,
                 s3_ip=None,
                 boto_debug=0):
        """This class is intended to setup boto connections for the various services that the *ops classes will use.

        :param credpath: Path to a valid eucarc file.
        :param aws_access_key_id: Used in conjuction with aws_secret_access_key allows for creation of connections without needing a credpath.
        :param aws_secret_access_key: Used in conjuction with aws_access_key_id allows for creation of connections without needing a credpath.
        :param region: When connecting to Amazon EC2 allows you to point to a specific region.
        :param ec2_ip: Hostname or IP of the EC2 endpoint to connect to. Can be used in the absence of region.
        :param s3_ip: Hostname or IP of the S3 endpoint to connect to.
        :param boto_debug: Hostname or IP of the S3 endpoint to connect to.
        :rtype: :class:`eutester.Eutester` or ``None``
        :returns: A Eutester object with all connections that were able to be created. Currently EC2, S3, IAM, and STS.
        """
        ### Default values for configuration
        self.boto_debug = boto_debug
        self.credpath = credpath
        self.region = RegionInfo()

        ### Eutester logs
        if self.logger is None:
            self.logger = eulogger.Eulogger(identifier="EUTESTER")
            self.debug = self.logger.log.debug
            self.critical = self.logger.log.critical
            self.info = self.logger.log.info

        ### LOGS to keep for printing later
        self.fail_log = []
        self.running_log = self.logger.log

        ### Pull the access and secret keys from the eucarc or use the ones provided to the constructor
        if self.credpath is not None:
            self.debug("Extracting keys from " + self.credpath)
            self.aws_access_key_id = self.get_access_key()
            self.aws_secret_access_key = self.get_secret_key()
        else:
            self.aws_access_key_id = aws_access_key_id
            self.aws_secret_access_key = aws_secret_access_key

        ### If you have credentials for the boto connections, create them
        if (self.aws_access_key_id
                is not None) and (self.aws_secret_access_key != None):
            if not boto.config.has_section('Boto'):
                boto.config.add_section('Boto')
            boto.config.set('Boto', 'num_retries', '2')
            self.setup_boto_connections(region=region,
                                        ec2_ip=ec2_ip,
                                        s3_ip=s3_ip)
Ejemplo n.º 29
0
    def __init__(self,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 is_secure=False,
                 port=None,
                 proxy=None,
                 proxy_port=None,
                 proxy_user=None,
                 proxy_pass=None,
                 debug=0,
                 https_connection_factory=None,
                 region=None,
                 path='/',
                 security_token=None,
                 validate_certs=True):
        """
        Init method to create a new connection to EC2 Load Balancing Service.

        note:: The region argument is overridden by the region specified in
            the boto configuration file.
        """
        if not region:
            region = RegionInfo(self, self.DefaultRegionName,
                                self.DefaultRegionEndpoint)
        self.region = region
        self.cw_con = CloudWatchConnection(aws_access_key_id,
                                           aws_secret_access_key,
                                           is_secure,
                                           port,
                                           proxy,
                                           proxy_port,
                                           proxy_user,
                                           proxy_pass,
                                           debug,
                                           https_connection_factory,
                                           region,
                                           path,
                                           security_token,
                                           validate_certs=validate_certs)
        ELBConnection.__init__(self,
                               aws_access_key_id,
                               aws_secret_access_key,
                               is_secure,
                               port,
                               proxy,
                               proxy_port,
                               proxy_user,
                               proxy_pass,
                               debug,
                               https_connection_factory,
                               region,
                               path,
                               security_token,
                               validate_certs=validate_certs)
Ejemplo n.º 30
0
 def _boto_ec2_conn(self, key, secret, ec2_url, region='eucalyptus',
         version='eucalyptus', config_path='/services/Configuration'):
     parsed_url = urlparse(ec2_url)
     region = RegionInfo(None, region, parsed_url.hostname)
     image_conn = connect_ec2(
         aws_access_key_id=key,
         aws_secret_access_key=secret,
         is_secure=False, region=region,
         port=parsed_url.port, path=config_path)
     image_conn.APIVersion = version
     return image_conn
Ejemplo n.º 31
0
    def setup_cfn_connection(self, endpoint=None, region=None, aws_access_key_id=None, aws_secret_access_key=None, path="/",port=443, is_secure=True, boto_debug=0):
        cfn_region = RegionInfo()
        if region:
            self.debug("Check region: " + str(region))
            try:
                if not endpoint:
                    cfn_region.endpoint = "cloudformation.{0}.amazonaws.com".format(region)
                else:
                    cfn_region.endpoint = endpoint
            except KeyError:
                raise Exception( 'Unknown region: %s' % region)
        else:
            cfn_region.name = 'eucalyptus'
            if endpoint:
                cfn_region.endpoint = endpoint
            else:
                cfn_region.endpoint = self.get_cfn_ip()

        try:
            cfn_connection_args = { 'aws_access_key_id' : aws_access_key_id,
                                    'aws_secret_access_key': aws_secret_access_key,
                                    'is_secure': is_secure,
                                    'debug':boto_debug,
                                    'port' : port,
                                    'path' : path,
                                    'region' : cfn_region}
            self.debug("Attempting to create cloudformation connection to " + self.get_cfn_ip() + ':' + str(port) + path)
            self.cloudformation = boto.connect_cloudformation(**cfn_connection_args)
        except Exception, e:
            self.critical("Was unable to create cloudformation connection because of exception: " + str(e))
Ejemplo n.º 32
0
    def setup_sts_connection(self, endpoint=None, region=None, aws_access_key_id=None, aws_secret_access_key=None, path="/",port=443, is_secure=True, boto_debug=0):
        sts_region = RegionInfo()
        if region:
            self.debug("Check region: " + str(region))
            try:
                if not endpoint:
                    sts_region.endpoint = EC2RegionData[region]
                else:
                    sts_region.endpoint = endpoint
            except KeyError:
                raise Exception( 'Unknown region: %s' % region)
        else:
            sts_region.name = 'eucalyptus'
            if endpoint:
                sts_region.endpoint = endpoint
            else:
                sts_region.endpoint = self.get_ec2_ip()

        try:
            sts_connection_args = { 'aws_access_key_id' : aws_access_key_id,
                                    'aws_secret_access_key': aws_secret_access_key,
                                    'is_secure': is_secure,
                                    'debug':boto_debug,
                                    'port' : port,
                                    'path' : path,
                                    'region' : sts_region}
            self.debug("Attempting to create STS connection to " + self.get_ec2_ip() + str(port) + path)
            self.tokens = boto.connect_sts(**sts_connection_args)
        except Exception, e:
            self.critical("Was unable to create STS connection because of exception: " + str(e))
Ejemplo n.º 33
0
    def setup_elb_connection(self, endpoint=None, aws_access_key_id=None, aws_secret_access_key=None, is_secure=True,
                             host=None,
                             region=None, path="/", port=443, boto_debug=0):
        """

        :param endpoint:
        :param aws_access_key_id:
        :param aws_secret_access_key:
        :param is_secure:
        :param host:
        :param region:
        :param path:
        :param port:
        :param boto_debug:
        :raise:
        """
        elb_region = RegionInfo()
        if region:
            self.debug("Check region: " + str(region))
            try:
                if not endpoint:
                    elb_region.endpoint = ELBRegionData[region]
                else:
                    elb_region.endpoint = endpoint
            except KeyError:
                raise Exception('Unknown region: %s' % region)
        else:
            elb_region.name = 'eucalyptus'
            if not host:
                if endpoint:
                    elb_region.endpoint = endpoint
                else:
                    elb_region.endpoint = self.get_elb_ip()
        connection_args = {'aws_access_key_id': aws_access_key_id,
                           'aws_secret_access_key': aws_secret_access_key,
                           'is_secure': is_secure,
                           'debug': boto_debug,
                           'port': port,
                           'path': path,
                           'region': elb_region}

        if re.search('2.6', boto.__version__):
            connection_args['validate_certs'] = False

        try:
            elb_connection_args = copy.copy(connection_args)
            elb_connection_args['path'] = path
            elb_connection_args['region'] = elb_region
            self.debug(
                "Attempting to create load balancer connection to " + elb_region.endpoint + ':' + str(port) + path)
            self.elb = boto.connect_elb(**elb_connection_args)
        except Exception, e:
            self.critical("Was unable to create elb connection because of exception: " + str(e))
Ejemplo n.º 34
0
    def setup_cw_connection(self, endpoint=None, aws_access_key_id=None, aws_secret_access_key=None, is_secure=True,
                            host=None,
                            region=None, path='/', port=443, boto_debug=0):
        '''

        :param endpoint:
        :param aws_access_key_id:
        :param aws_secret_access_key:
        :param is_secure:
        :param host:
        :param region:
        :param path:
        :param port:
        :param boto_debug:
        :raise:
        '''
        cw_region = RegionInfo()
        if region:
            self.debug('Check region: ' + str(region))
            try:
                if not endpoint:
                    cw_region.endpoint = CWRegionData[region]
                else:
                    cw_region.endpoint = endpoint
            except KeyError:
                raise Exception('Unknown region: %s' % region)
        else:
            cw_region.name = 'eucalyptus'
            if not host:
                if endpoint:
                    cw_region.endpoint = endpoint
                else:
                    cw_region.endpoint = self.get_cw_ip()
        connection_args = {'aws_access_key_id': aws_access_key_id,
                           'aws_secret_access_key': aws_secret_access_key,
                           'is_secure': is_secure,
                           'debug': boto_debug,
                           'port': port,
                           'path': path,
                           'region': cw_region}

        if re.search('2.6', boto.__version__):
            connection_args['validate_certs'] = False

        try:
            cw_connection_args = copy.copy(connection_args)
            cw_connection_args['path'] = path
            cw_connection_args['region'] = cw_region
            self.debug('Attempting to create cloud watch connection to ' + cw_region.endpoint + ':' + str(port) + path)
            self.cw = boto.connect_cloudwatch(**cw_connection_args)
        except Exception, e:
            self.critical('Was unable to create Cloud Watch connection because of exception: ' + str(e))
Ejemplo n.º 35
0
    def get_cw_connection_args(self, endpoint=None, aws_access_key_id=None,
                               aws_secret_access_key=None, is_secure=True,
                               host=None, region=None, path='/', port=443, boto_debug=0):
        '''

        :param endpoint:
        :param aws_access_key_id:
        :param aws_secret_access_key:
        :param is_secure:
        :param host:
        :param region:
        :param path:
        :param port:
        :param boto_debug:
        :raise:
        '''
        cw_region = RegionInfo()
        if region:
            self.debug('Check region: ' + str(region))
            try:
                if not endpoint:
                    cw_region.endpoint = CWRegionData[region]
                else:
                    cw_region.endpoint = endpoint
            except KeyError:
                raise Exception('Unknown region: %s' % region)
        else:
            cw_region.name = 'eucalyptus'
            if not host:
                if endpoint:
                    cw_region.endpoint = endpoint
                else:
                    cw_region.endpoint = self.get_cw_ip()
        connection_args = {'aws_access_key_id': aws_access_key_id,
                           'aws_secret_access_key': aws_secret_access_key,
                           'is_secure': is_secure,
                           'debug': boto_debug,
                           'port': port,
                           'path': path,
                           'region': cw_region}

        if re.search('2.6', boto_version):
            connection_args['validate_certs'] = False
        cw_connection_args = copy.copy(connection_args)
        cw_connection_args['path'] = path
        cw_connection_args['region'] = cw_region
        return cw_connection_args
Ejemplo n.º 36
0
    def setup_sts_connection(
        self,
        endpoint=None,
        region=None,
        aws_access_key_id=None,
        aws_secret_access_key=None,
        path="/",
        port=443,
        is_secure=True,
        boto_debug=0,
    ):
        sts_region = RegionInfo()
        if region:
            self.debug("Check region: " + str(region))
            try:
                if not endpoint:
                    sts_region.endpoint = EC2RegionData[region]
                else:
                    sts_region.endpoint = endpoint
            except KeyError:
                raise Exception("Unknown region: %s" % region)
        else:
            sts_region.name = "eucalyptus"
            if endpoint:
                sts_region.endpoint = endpoint
            else:
                sts_region.endpoint = self.get_sts_ip()

        try:
            sts_connection_args = {
                "aws_access_key_id": aws_access_key_id,
                "aws_secret_access_key": aws_secret_access_key,
                "is_secure": is_secure,
                "debug": boto_debug,
                "port": port,
                "path": path,
                "region": sts_region,
            }
            self.debug("Attempting to create STS connection to " + sts_region.endpoint + ":" + str(port) + path)
            self.tokens = boto.connect_sts(**sts_connection_args)
        except Exception, e:
            self.critical("Was unable to create STS connection because of exception: " + str(e))
Ejemplo n.º 37
0
    group = [g for g in groups if g.name == name]
    if len(group) > 0:
        return group[0]
    else:
        print "Creating security group " + name
        return conn.create_security_group(name, "EC2 group")

if __name__ == "__main__":

    import sys
    deleteContent("just_ip")
    deleteContent("role_ip")
    counter = 0 
    for i in range(0, 8):

        r=RegionInfo(name='melbourne',endpoint='nova.rc.nectar.org.au')
        ec2_conn = boto.connect_ec2(aws_access_key_id='63dd8a98739a465880ecb1aa9a6b57ee',aws_secret_access_key='a6f60c56a8db42e0b4acf2da5f744d25',is_secure=True,region=r, port=8773,path='/services/Cloud',validate_certs=False)

        images = ec2_conn.get_all_images()
        for img in images:
            if "NeCTAR Ubuntu 13.10" in img.name:
                image_id = img.id
                break
        print img.id
        #print 'id:',img.id,',name:',img.name,',state:',img.state

        myKey = sys.argv[1]
        print myKey

        my_security_gp = get_or_make_group(ec2_conn,"ssh")
        if my_security_gp.rules == []: # Group was just now created
Ejemplo n.º 38
0
import boto.ec2
from boto.ec2.regioninfo import RegionInfo

port=80
access_id = "Your ACCESS_ID"
access_secret = "Your ACCESS_KEY"

regions = boto.ec2.regions(aws_access_key_id=access_id, aws_secret_access_key=access_secret)
print regions
print regions[3].name
print regions[3].endpoint

region_name = "ap-northeast-1"
region_endpoint = "ec2.ap-northeast-1.amazonaws.com"

# first create a region object and connection
region = RegionInfo(name=region_name, endpoint=region_endpoint)

regconn = region.connect(aws_access_key_id=access_id, aws_secret_access_key=access_secret)
groups = regconn.get_all_security_groups()
print groups

# first create a connection to the appropriate host, using your credentials
ec2conn =  boto.connect_ec2(access_id, access_secret, port=port, region=region)

reservations = ec2conn.get_all_instances()
instances = [i for r in reservations for i in r.instances]
for i in instances:
    pprint(i.__dict__)
#    break # remove this to list all instances
Ejemplo n.º 39
0
    def setup_elb_connection(
        self,
        endpoint=None,
        aws_access_key_id=None,
        aws_secret_access_key=None,
        is_secure=True,
        host=None,
        region=None,
        path="/",
        port=443,
        boto_debug=0,
    ):
        """

        :param endpoint:
        :param aws_access_key_id:
        :param aws_secret_access_key:
        :param is_secure:
        :param host:
        :param region:
        :param path:
        :param port:
        :param boto_debug:
        :raise:
        """
        elb_region = RegionInfo()
        if region:
            self.debug("Check region: " + str(region))
            try:
                if not endpoint:
                    elb_region.endpoint = ELBRegionData[region]
                else:
                    elb_region.endpoint = endpoint
            except KeyError:
                raise Exception("Unknown region: %s" % region)
        else:
            elb_region.name = "eucalyptus"
            if not host:
                if endpoint:
                    elb_region.endpoint = endpoint
                else:
                    elb_region.endpoint = self.get_elb_ip()
        connection_args = {
            "aws_access_key_id": aws_access_key_id,
            "aws_secret_access_key": aws_secret_access_key,
            "is_secure": is_secure,
            "debug": boto_debug,
            "port": port,
            "path": path,
            "region": elb_region,
        }

        if re.search("2.6", boto.__version__):
            connection_args["validate_certs"] = False

        try:
            elb_connection_args = copy.copy(connection_args)
            elb_connection_args["path"] = path
            elb_connection_args["region"] = elb_region
            self.debug(
                "Attempting to create load balancer connection to " + elb_region.endpoint + ":" + str(port) + path
            )
            self.elb = boto.connect_elb(**elb_connection_args)
        except Exception, e:
            self.critical("Was unable to create elb connection because of exception: " + str(e))