Ejemplo n.º 1
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),
    ]
Ejemplo n.º 2
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:
            aws_region = None
            if self.pilot_compute_description.has_key("region"):
                region = self.pilot_compute_description["region"]
                logger.debug("Connect to region: %s" % (str(region)))
                aws_region = boto.ec2.get_region(
                    region,
                    aws_access_key_id=self.
                    pilot_compute_description["access_key_id"],
                    aws_secret_access_key=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=aws_region)

        self.instance = None
Ejemplo n.º 3
0
    def connection_for_env(self, **kwargs):
        """
        Returns a boto ec2 connection for the current environment.
        """
        access_key = os.getenv('EC2_ACCESS_KEY')
        secret_key = os.getenv('EC2_SECRET_KEY')
        clc_url = os.getenv('EC2_URL')

        if not access_key or not secret_key or not clc_url:
            raise Exception('Missing EC2 environment variables. Please source '
                            'the appropriate novarc file before running this '
                            'test.')

        parts = self.split_clc_url(clc_url)
        if FLAGS.use_ipv6:
            return boto_v6.connect_ec2(aws_access_key_id=access_key,
                                aws_secret_access_key=secret_key,
                                is_secure=parts['is_secure'],
                                region=RegionInfo(None,
                                                  'nova',
                                                  parts['ip']),
                                port=parts['port'],
                                path='/services/Cloud',
                                **kwargs)

        return boto.connect_ec2(aws_access_key_id=access_key,
                                aws_secret_access_key=secret_key,
                                is_secure=parts['is_secure'],
                                region=RegionInfo(None,
                                                  'nova',
                                                  parts['ip']),
                                port=parts['port'],
                                path='/services/Cloud',
                                **kwargs)
Ejemplo n.º 4
0
def regions():
    """
    Get all available regions for the Amazon CloudSearch service.

    :rtype: list
    :return: A list of :class:`boto.regioninfo.RegionInfo`
    """
    import boto.cloudsearch.layer1
    return [
        RegionInfo(name='us-east-1',
                   endpoint='cloudsearch.us-east-1.amazonaws.com',
                   connection_cls=boto.cloudsearch.layer1.Layer1),
        RegionInfo(name='eu-west-1',
                   endpoint='cloudsearch.eu-west-1.amazonaws.com',
                   connection_cls=boto.cloudsearch.layer1.Layer1),
        RegionInfo(name='us-west-1',
                   endpoint='cloudsearch.us-west-1.amazonaws.com',
                   connection_cls=boto.cloudsearch.layer1.Layer1),
        RegionInfo(name='us-west-2',
                   endpoint='cloudsearch.us-west-2.amazonaws.com',
                   connection_cls=boto.cloudsearch.layer1.Layer1),
        RegionInfo(name='ap-southeast-1',
                   endpoint='cloudsearch.ap-southeast-1.amazonaws.com',
                   connection_cls=boto.cloudsearch.layer1.Layer1),
    ]
Ejemplo n.º 5
0
def aws_connect(creds_fname=None):
    credentials_ec2 = creds_fname
    if not credentials_ec2:
        config = get_cloudsim_config()
        # log("config: %s" % config)
        credentials_ec2 = config['boto_path']
    ec2_region_name, aws_access_key_id, aws_secret_access_key, region_endpoint\
        = read_boto_file(credentials_ec2)
    if ec2_region_name == 'nova':
        # TODO: remove hardcoded OpenStack endpoint
        region = RegionInfo(None, 'cloudsim', region_endpoint)  # 172.16.0.201
        ec2conn = EC2Connection(aws_access_key_id,
                                aws_secret_access_key,
                                is_secure=False,
                                region=region,
                                port=8773,
                                path='/services/Cloud')
        vpcconn = VPCConnection(aws_access_key_id,
                                aws_secret_access_key,
                                is_secure=False,
                                region=region,
                                port=8773,
                                path='/services/Cloud')
    else:
        region = RegionInfo(None, ec2_region_name, region_endpoint)
        ec2conn = boto.connect_ec2(aws_access_key_id,
                                   aws_secret_access_key,
                                   region=region)
        vpcconn = boto.connect_vpc(aws_access_key_id,
                                   aws_secret_access_key,
                                   region=region)
    return ec2conn, vpcconn
Ejemplo n.º 6
0
    def get_euca_connection(self, project_name=None):
        if not has_boto:
            logger.info('Unable to access EC2 API - boto library not found.')
            return None

        if not self.access_key or not self.secret_key:
            self.init_context(project_name)
        
        url = self.config.SFA_NOVA_API_URL
        host = None
        port = None    
        path = "/"
        use_ssl = False
        # Split the url into parts 
        if url.find('https://') >= 0:
            use_ssl  = True
            url = url.replace('https://', '')
        elif url.find('http://') >= 0:
            use_ssl  = False
            url = url.replace('http://', '')
        parts = url.split(':')
        host = parts[0]
        if len(parts) > 1:
            parts = parts[1].split('/')
            port = int(parts[0])
            parts = parts[1:]
            path = '/'+'/'.join(parts)
        return boto.connect_ec2(aws_access_key_id=self.access_key,
                                aws_secret_access_key=self.secret_key,
                                is_secure=use_ssl,
                                region=RegionInfo(None, 'eucalyptus', host),
                                host=host,
                                port=port,
                                path=path) 
Ejemplo n.º 7
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.º 8
0
def make_snapshot(key,
                  access,
                  cluster,
                  name="main",
                  expiration='weekly',
                  device="/dev/sdf"):
    # first get the mountpoint (requires some energy, but we can...)
    df = subprocess.Popen(["/bin/df", device], stdout=subprocess.PIPE)
    output = df.communicate()[0]
    dummy, size, used, available, percent, mountpoint = \
          output.split("\n")[1].split()
    region_info = RegionInfo(name=region,
                             endpoint="ec2.{0}.amazonaws.com".format(region))
    ec2 = EC2Connection(key, access, region=region_info)

    # if we have the device (/dev/sdf) just don't do anything anymore
    mapping = ec2.get_instance_attribute(instance_id, 'blockDeviceMapping')
    try:
        volume_id = mapping['blockDeviceMapping'][device].volume_id

        os.system("/usr/sbin/xfs_freeze -f {0}".format(mountpoint))
        snapshot = ec2.create_snapshot(
            volume_id, "Backup of {0} - for {1}/{2} - expires {3}".format(
                volume_id, cluster, name, expires[expiration]))
        os.system("/usr/sbin/xfs_freeze -u {0}".format(mountpoint))
    except Exception as e:
        print e

    return ["{0}".format(snapshot.id), expires[expiration]]
Ejemplo n.º 9
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.º 10
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.º 11
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(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.º 12
0
def connect_ec2(a_key, s_key, cloud):
    """ Create and return an EC2-compatible connection object.
    """
    #ci = _get_cloud_info(cloud)
    ci = {}
    ci["region_name"] = 'us-east-1'
    ci["region_endpoint"] = 'ec2.amazonaws.com'
    ci["is_secure"] = True
    ci["ec2_port"] = None
    ci["ec2_conn_path"] = '/'
    ci["cloud_type"] = "ec2"

    # AWS connection values
    # region_name = 'us-east-1'
    # region_endpoint = 'ec2.amazonaws.com'
    # is_secure = True
    # ec2_port = None
    # ec2_conn_path = '/'
    r = RegionInfo(name=ci['region_name'], endpoint=ci['region_endpoint'])
    ec2_conn = boto.connect_ec2(
        aws_access_key_id=a_key,
        aws_secret_access_key=s_key,
        # api_version is needed for availability zone support for EC2
        api_version='2011-11-01' if ci['cloud_type'] == 'ec2' else None,
        is_secure=ci['is_secure'],
        region=r,
        port=ci['ec2_port'],
        path=ci['ec2_conn_path'])
    return ec2_conn
Ejemplo n.º 13
0
    def __connect_icu(self, url, aws_access_key_id='', aws_secret_access_key='', login='', password='', **kwargs):
        """
        Connect to an ICU Api endpoint.
        Additional arguments are passed to ICUConnection.

        :param str url: Url for the icu api endpoint to connect to
        :param str aws_access_key_id: Your AWS Access Key ID
        :param str aws_secret_access_key: Your AWS Secret Access Key
        :param str login: Your login email ID
        :param str password: Your raw password to login
        :param dict kwargs:
        :return class: `outscale.boto.icu.ICUConnection`
        """
        if not url.startswith('https://'):
            url = 'https://{0}'.format(url)
        purl = urlparse.urlparse(url)
        kwargs['port'] = purl.port
        kwargs['path'] = purl.path
        if not 'is_secure' in kwargs:
            kwargs['is_secure'] = (purl.scheme == "https")

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

        return ICUConnection(**kwargs)
Ejemplo n.º 14
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, profile_name=None):
     if not region:
         region = RegionInfo(self, self.DefaultRegionName,
                             self.DefaultRegionEndpoint)
     self.region = region
     super(EmrConnection, self).__init__(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,
                                 profile_name=profile_name)
     # Many of the EMR hostnames are of the form:
     #     <region>.<service_name>.amazonaws.com
     # rather than the more common:
     #     <service_name>.<region>.amazonaws.com
     # so we need to explicitly set the region_name and service_name
     # for the SigV4 signing.
     self.auth_region_name = self.region.name
     self.auth_service_name = 'elasticmapreduce'
Ejemplo n.º 15
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.º 16
0
def register_key_with_iaas(iaas_url, keytext, keyname, access_key,
                           access_secret):

    up = urlparse.urlparse(iaas_url)

    ssl = up.scheme == "https"
    host = up.hostname
    port = up.port

    region = RegionInfo(name="nimbus", endpoint=host)
    ec2conn = boto.connect_ec2(access_key,
                               access_secret,
                               region=region,
                               port=port,
                               validate_certs=False)

    # Workaround for a bug in Nimbus <= 2.10.1:
    # import_key_pair does not properly update an existing key
    try:
        if ec2conn.get_key_pair(keyname) is not None:
            ec2conn.delete_key_pair(keyname)
    except IndexError:
        # This exception is raised when boto can't find a key on Nimbus
        pass
    ec2conn.import_key_pair(keyname, keytext)
Ejemplo n.º 17
0
 def __init__(self,
              aws_access_key_id=None,
              aws_secret_access_key=None,
              is_secure=True,
              host=None,
              port=None,
              proxy=None,
              proxy_port=None,
              proxy_user=None,
              proxy_pass=None,
              debug=0,
              https_connection_factory=None,
              region=None,
              path='/'):
     """
     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, path)
Ejemplo n.º 18
0
def EucalyptusProvider_config_get_ubuntu_images_by_region(conf=None):
    if conf is not None:
        access_key = conf['aws_access_key']
        secret_key = conf['aws_secret_key']
        ec2_url = conf['ec2_url']
    else:
        access_key = os.environ.get('EC2_ACCESS_KEY')
        secret_key = os.environ.get('EC2_SECRET_KEY')
        ec2_url = os.environ.get('EC2_URL')

    try:
        o = urlparse(ec2_url)
        ec2_host = o.hostname
        ec2_port = o.port
        ec2_path = o.path
        # Setup connection to Eucalyptus
        conn = boto.connect_ec2(aws_access_key_id=access_key,
                                aws_secret_access_key=secret_key,
                                is_secure=False,
                                region=RegionInfo(name="eucalyptus",
                                                  endpoint=ec2_host),
                                port=ec2_port,
                                path=ec2_path)

        # Run commands
        images = conn.get_all_images()
        for i in images:
            if 'trusty' in i.name.lower():
                return i.id
    except Exception as e:
        logging.debug(
            'EucalyptusProvider_config_get_ubuntu_images_by_region() caught exception {0}'
            .format(e))
    return None
Ejemplo n.º 19
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.º 20
0
    def __init__(self,
                 team_id,
                 access_key,
                 secret_key,
                 bucket='cs144students'):
        """
        (constructor)

        Creates a new instance of the Rankmaniac class for a specific
        team using the provided credentials.

        Arguments:
            team_id       <str>     the team identifier, which may be
                                    differ slightly from the actual team
                                    name.

            access_key    <str>     the AWS access key identifier.
            secret_key    <str>     the AWS secret acess key.

        Keyword arguments:
            bucket        <str>     the S3 bucket name.
        """

        region = RegionInfo(None, self.DefaultRegionName,
                            self.DefaultRegionEndpoint)

        self._s3_bucket = bucket
        self._s3_conn = S3Connection(access_key, secret_key)
        self._emr_conn = EmrConnection(access_key, secret_key, region=region)

        self.team_id = team_id
        self.job_id = None

        self._reset()
        self._num_instances = 1
Ejemplo n.º 21
0
def connect_fcu_endpoint(url, aws_access_key_id, aws_secret_access_key, **kwargs):
    """
    Connect to an FCU Api endpoint.  Additional arguments are passed
    through to FCUConnection.

    :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:`osc_cloud_builder.vendor.outscale.fcu.FCUConnection`
    """
    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 FCUConnection(**kwargs)
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.º 23
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.º 24
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.º 25
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.º 26
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.º 27
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.º 28
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.log.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.º 29
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.º 30
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