~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/__init__.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2012-04-15 20:21:21 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120415202121-3fpf6q355s0xqpyu
Tags: 2.3.0-1
* New upstream release (Closes: #664478)
* Update debian/watch for Boto's move to Github.  Thanks Scott
  Moser. (Closes: #650480)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/
 
1
# Copyright (c) 2006-2012 Mitch Garnaat http://garnaat.org/
2
2
# Copyright (c) 2010-2011, Eucalyptus Systems, Inc.
 
3
# Copyright (c) 2011, Nexenta Systems Inc.
 
4
# Copyright (c) 2012 Amazon.com, Inc. or its affiliates.
3
5
# All rights reserved.
4
6
#
5
7
# Permission is hereby granted, free of charge, to any person obtaining a
21
23
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
24
# IN THE SOFTWARE.
23
25
#
24
 
import boto
25
26
from boto.pyami.config import Config, BotoConfigLocations
26
27
from boto.storage_uri import BucketStorageUri, FileStorageUri
27
28
import boto.plugin
28
29
import os, re, sys
29
30
import logging
30
31
import logging.config
 
32
import urlparse
31
33
from boto.exception import InvalidUriError
32
34
 
33
 
__version__ = '2.0'
 
35
__version__ = '2.3.0'
34
36
Version = __version__ # for backware compatibility
35
37
 
36
38
UserAgent = 'Boto/%s (%s)' % (__version__, sys.platform)
109
111
def connect_gs(gs_access_key_id=None, gs_secret_access_key=None, **kwargs):
110
112
    """
111
113
    @type gs_access_key_id: string
112
 
    @param gs_access_key_id: Your Google Storage Access Key ID
 
114
    @param gs_access_key_id: Your Google Cloud Storage Access Key ID
113
115
 
114
116
    @type gs_secret_access_key: string
115
 
    @param gs_secret_access_key: Your Google Storage Secret Access Key
 
117
    @param gs_secret_access_key: Your Google Cloud Storage Secret Access Key
116
118
 
117
119
    @rtype: L{GSConnection<boto.gs.connection.GSConnection>}
118
120
    @return: A connection to Google's Storage service
264
266
    """
265
267
    :type aws_access_key_id: string
266
268
    :param aws_access_key_id: Your AWS Access Key ID
267
 
   
 
269
 
268
270
    :type aws_secret_access_key: string
269
271
    :param aws_secret_access_key: Your AWS Secret Access Key
270
 
   
 
272
 
271
273
    :rtype: :class:`boto.emr.EmrConnection`
272
274
    :return: A connection to Elastic mapreduce
273
275
    """
317
319
    from boto.route53 import Route53Connection
318
320
    return Route53Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
319
321
 
320
 
def connect_euca(host, aws_access_key_id=None, aws_secret_access_key=None,
 
322
def connect_cloudformation(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
 
323
    """
 
324
    :type aws_access_key_id: string
 
325
    :param aws_access_key_id: Your AWS Access Key ID
 
326
 
 
327
    :type aws_secret_access_key: string
 
328
    :param aws_secret_access_key: Your AWS Secret Access Key
 
329
 
 
330
    :rtype: :class:`boto.cloudformation.CloudFormationConnection`
 
331
    :return: A connection to Amazon's CloudFormation Service
 
332
    """
 
333
    from boto.cloudformation import CloudFormationConnection
 
334
    return CloudFormationConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
 
335
 
 
336
def connect_euca(host=None, aws_access_key_id=None, aws_secret_access_key=None,
321
337
                 port=8773, path='/services/Eucalyptus', is_secure=False,
322
338
                 **kwargs):
323
339
    """
325
341
 
326
342
    :type host: string
327
343
    :param host: the host name or ip address of the Eucalyptus server
328
 
    
 
344
 
329
345
    :type aws_access_key_id: string
330
346
    :param aws_access_key_id: Your AWS Access Key ID
331
347
 
338
354
    from boto.ec2 import EC2Connection
339
355
    from boto.ec2.regioninfo import RegionInfo
340
356
 
 
357
    # Check for values in boto config, if not supplied as args
 
358
    if not aws_access_key_id:
 
359
        aws_access_key_id = config.get('Credentials',
 
360
                                       'euca_access_key_id',
 
361
                                       None)
 
362
    if not aws_secret_access_key:
 
363
        aws_secret_access_key = config.get('Credentials',
 
364
                                           'euca_secret_access_key',
 
365
                                           None)
 
366
    if not host:
 
367
        host = config.get('Boto', 'eucalyptus_host', None)
 
368
 
341
369
    reg = RegionInfo(name='eucalyptus', endpoint=host)
342
370
    return EC2Connection(aws_access_key_id, aws_secret_access_key,
343
371
                         region=reg, port=port, path=path,
344
372
                         is_secure=is_secure, **kwargs)
345
373
 
346
 
def connect_walrus(host, aws_access_key_id=None, aws_secret_access_key=None,
 
374
def connect_ec2_endpoint(url, aws_access_key_id=None, aws_secret_access_key=None, 
 
375
                         **kwargs):
 
376
    """
 
377
    Connect to an EC2 Api endpoint.  Additional arguments are passed
 
378
    through to connect_ec2.
 
379
 
 
380
    :type url: string
 
381
    :param url: A url for the ec2 api endpoint to connect to
 
382
 
 
383
    :type aws_access_key_id: string
 
384
    :param aws_access_key_id: Your AWS Access Key ID
 
385
 
 
386
    :type aws_secret_access_key: string
 
387
    :param aws_secret_access_key: Your AWS Secret Access Key
 
388
 
 
389
    :rtype: :class:`boto.ec2.connection.EC2Connection`
 
390
    :return: A connection to Eucalyptus server
 
391
    """
 
392
    from boto.ec2.regioninfo import RegionInfo
 
393
 
 
394
    purl = urlparse.urlparse(url)
 
395
    kwargs['port'] = purl.port
 
396
    kwargs['host'] = purl.hostname
 
397
    kwargs['path'] = purl.path
 
398
    if not 'is_secure' in kwargs:
 
399
        kwargs['is_secure'] = (purl.scheme == "https")
 
400
 
 
401
    kwargs['region'] = RegionInfo(name = purl.hostname,
 
402
        endpoint = purl.hostname)
 
403
    kwargs['aws_access_key_id']=aws_access_key_id
 
404
    kwargs['aws_secret_access_key']=aws_secret_access_key
 
405
 
 
406
    return(connect_ec2(**kwargs))
 
407
 
 
408
def connect_walrus(host=None, aws_access_key_id=None, aws_secret_access_key=None,
347
409
                   port=8773, path='/services/Walrus', is_secure=False,
348
410
                   **kwargs):
349
411
    """
351
413
 
352
414
    :type host: string
353
415
    :param host: the host name or ip address of the Walrus server
354
 
    
 
416
 
355
417
    :type aws_access_key_id: string
356
418
    :param aws_access_key_id: Your AWS Access Key ID
357
419
 
364
426
    from boto.s3.connection import S3Connection
365
427
    from boto.s3.connection import OrdinaryCallingFormat
366
428
 
 
429
    # Check for values in boto config, if not supplied as args
 
430
    if not aws_access_key_id:
 
431
        aws_access_key_id = config.get('Credentials',
 
432
                                       'euca_access_key_id',
 
433
                                       None)
 
434
    if not aws_secret_access_key:
 
435
        aws_secret_access_key = config.get('Credentials',
 
436
                                           'euca_secret_access_key',
 
437
                                           None)
 
438
    if not host:
 
439
        host = config.get('Boto', 'walrus_host', None)
 
440
        
367
441
    return S3Connection(aws_access_key_id, aws_secret_access_key,
368
442
                        host=host, port=port, path=path,
369
443
                        calling_format=OrdinaryCallingFormat(),
383
457
    from boto.ses import SESConnection
384
458
    return SESConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
385
459
 
 
460
def connect_sts(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
 
461
    """
 
462
    :type aws_access_key_id: string
 
463
    :param aws_access_key_id: Your AWS Access Key ID
 
464
 
 
465
    :type aws_secret_access_key: string
 
466
    :param aws_secret_access_key: Your AWS Secret Access Key
 
467
 
 
468
    :rtype: :class:`boto.sts.STSConnection`
 
469
    :return: A connection to Amazon's STS
 
470
    """
 
471
    from boto.sts import STSConnection
 
472
    return STSConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
 
473
 
386
474
def connect_ia(ia_access_key_id=None, ia_secret_access_key=None,
387
475
               is_secure=False, **kwargs):
388
476
    """
394
482
                             section called "ia_access_key_id"
395
483
 
396
484
    :type ia_secret_access_key: string
397
 
    :param ia_secret_access_key: Your IA Secret Access Key.  This will also look in your
398
 
                                 boto config file for an entry in the Credentials
399
 
                                 section called "ia_secret_access_key"
 
485
    :param ia_secret_access_key: Your IA Secret Access Key.  This will also
 
486
                                 look in your boto config file for an entry
 
487
                                 in the Credentials section called
 
488
                                 "ia_secret_access_key"
400
489
 
401
490
    :rtype: :class:`boto.s3.connection.S3Connection`
402
491
    :return: A connection to the Internet Archive
414
503
                        calling_format=OrdinaryCallingFormat(),
415
504
                        is_secure=is_secure, **kwargs)
416
505
 
 
506
def connect_dynamodb(aws_access_key_id=None,
 
507
                     aws_secret_access_key=None,
 
508
                     **kwargs):
 
509
    """
 
510
    :type aws_access_key_id: string
 
511
    :param aws_access_key_id: Your AWS Access Key ID
 
512
 
 
513
    :type aws_secret_access_key: string
 
514
    :param aws_secret_access_key: Your AWS Secret Access Key
 
515
 
 
516
    :rtype: :class:`boto.dynamodb.layer2.Layer2`
 
517
    :return: A connection to the Layer2 interface for DynamoDB.
 
518
    """
 
519
    from boto.dynamodb.layer2 import Layer2
 
520
    return Layer2(aws_access_key_id, aws_secret_access_key, **kwargs)
 
521
 
 
522
def connect_swf(aws_access_key_id=None,
 
523
                aws_secret_access_key=None,
 
524
                **kwargs):
 
525
    """
 
526
    :type aws_access_key_id: string
 
527
    :param aws_access_key_id: Your AWS Access Key ID
 
528
 
 
529
    :type aws_secret_access_key: string
 
530
    :param aws_secret_access_key: Your AWS Secret Access Key
 
531
 
 
532
    :rtype: :class:`boto.swf.layer1.Layer1`
 
533
    :return: A connection to the Layer1 interface for SWF.
 
534
    """
 
535
    from boto.swf.layer1 import Layer1
 
536
    return Layer1(aws_access_key_id, aws_secret_access_key, **kwargs)
 
537
 
417
538
def check_extensions(module_name, module_path):
418
539
    """
419
540
    This function checks for extensions to boto modules.  It should be called in the
452
573
    return obj
453
574
 
454
575
def storage_uri(uri_str, default_scheme='file', debug=0, validate=True,
455
 
                bucket_storage_uri_class=BucketStorageUri):
 
576
                bucket_storage_uri_class=BucketStorageUri,
 
577
                suppress_consec_slashes=True):
456
578
    """
457
579
    Instantiate a StorageUri from a URI string.
458
580
 
466
588
    :param validate: whether to check for bucket name validity.
467
589
    :type bucket_storage_uri_class: BucketStorageUri interface.
468
590
    :param bucket_storage_uri_class: Allows mocking for unit tests.
 
591
    :param suppress_consec_slashes: If provided, controls whether
 
592
        consecutive slashes will be suppressed in key paths.
469
593
 
470
594
    We allow validate to be disabled to allow caller
471
595
    to implement bucket-level wildcarding (outside the boto library;
506
630
    if scheme == 'file':
507
631
        # For file URIs we have no bucket name, and use the complete path
508
632
        # (minus 'file://') as the object name.
509
 
        return FileStorageUri(path, debug)
 
633
        is_stream = False
 
634
        if path == '-':
 
635
            is_stream = True
 
636
        return FileStorageUri(path, debug, is_stream)
510
637
    else:
511
638
        path_parts = path.split('/', 1)
512
639
        bucket_name = path_parts[0]
524
651
        object_name = ''
525
652
        if len(path_parts) > 1:
526
653
            object_name = path_parts[1]
527
 
        return bucket_storage_uri_class(scheme, bucket_name, object_name, debug)
 
654
        return bucket_storage_uri_class(
 
655
            scheme, bucket_name, object_name, debug,
 
656
            suppress_consec_slashes=suppress_consec_slashes)
528
657
 
529
658
def storage_uri_for_key(key):
530
659
    """Returns a StorageUri for the given key.