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.
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
25
26
from boto.pyami.config import Config, BotoConfigLocations
26
27
from boto.storage_uri import BucketStorageUri, FileStorageUri
30
31
import logging.config
31
33
from boto.exception import InvalidUriError
34
36
Version = __version__ # for backware compatibility
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):
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
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
117
119
@rtype: L{GSConnection<boto.gs.connection.GSConnection>}
118
120
@return: A connection to Google's Storage service
317
319
from boto.route53 import Route53Connection
318
320
return Route53Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
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):
324
:type aws_access_key_id: string
325
:param aws_access_key_id: Your AWS Access Key ID
327
:type aws_secret_access_key: string
328
:param aws_secret_access_key: Your AWS Secret Access Key
330
:rtype: :class:`boto.cloudformation.CloudFormationConnection`
331
:return: A connection to Amazon's CloudFormation Service
333
from boto.cloudformation import CloudFormationConnection
334
return CloudFormationConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
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,
338
354
from boto.ec2 import EC2Connection
339
355
from boto.ec2.regioninfo import RegionInfo
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',
362
if not aws_secret_access_key:
363
aws_secret_access_key = config.get('Credentials',
364
'euca_secret_access_key',
367
host = config.get('Boto', 'eucalyptus_host', None)
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)
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,
377
Connect to an EC2 Api endpoint. Additional arguments are passed
378
through to connect_ec2.
381
:param url: A url for the ec2 api endpoint to connect to
383
:type aws_access_key_id: string
384
:param aws_access_key_id: Your AWS Access Key ID
386
:type aws_secret_access_key: string
387
:param aws_secret_access_key: Your AWS Secret Access Key
389
:rtype: :class:`boto.ec2.connection.EC2Connection`
390
:return: A connection to Eucalyptus server
392
from boto.ec2.regioninfo import RegionInfo
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")
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
406
return(connect_ec2(**kwargs))
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,
364
426
from boto.s3.connection import S3Connection
365
427
from boto.s3.connection import OrdinaryCallingFormat
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',
434
if not aws_secret_access_key:
435
aws_secret_access_key = config.get('Credentials',
436
'euca_secret_access_key',
439
host = config.get('Boto', 'walrus_host', None)
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)
460
def connect_sts(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
462
:type aws_access_key_id: string
463
:param aws_access_key_id: Your AWS Access Key ID
465
:type aws_secret_access_key: string
466
:param aws_secret_access_key: Your AWS Secret Access Key
468
:rtype: :class:`boto.sts.STSConnection`
469
:return: A connection to Amazon's STS
471
from boto.sts import STSConnection
472
return STSConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
386
474
def connect_ia(ia_access_key_id=None, ia_secret_access_key=None,
387
475
is_secure=False, **kwargs):
394
482
section called "ia_access_key_id"
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"
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)
506
def connect_dynamodb(aws_access_key_id=None,
507
aws_secret_access_key=None,
510
:type aws_access_key_id: string
511
:param aws_access_key_id: Your AWS Access Key ID
513
:type aws_secret_access_key: string
514
:param aws_secret_access_key: Your AWS Secret Access Key
516
:rtype: :class:`boto.dynamodb.layer2.Layer2`
517
:return: A connection to the Layer2 interface for DynamoDB.
519
from boto.dynamodb.layer2 import Layer2
520
return Layer2(aws_access_key_id, aws_secret_access_key, **kwargs)
522
def connect_swf(aws_access_key_id=None,
523
aws_secret_access_key=None,
526
:type aws_access_key_id: string
527
:param aws_access_key_id: Your AWS Access Key ID
529
:type aws_secret_access_key: string
530
:param aws_secret_access_key: Your AWS Secret Access Key
532
:rtype: :class:`boto.swf.layer1.Layer1`
533
:return: A connection to the Layer1 interface for SWF.
535
from boto.swf.layer1 import Layer1
536
return Layer1(aws_access_key_id, aws_secret_access_key, **kwargs)
417
538
def check_extensions(module_name, module_path):
419
540
This function checks for extensions to boto modules. It should be called in the
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):
457
579
Instantiate a StorageUri from a URI string.
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.
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)
636
return FileStorageUri(path, debug, is_stream)
511
638
path_parts = path.split('/', 1)
512
639
bucket_name = path_parts[0]
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)
529
658
def storage_uri_for_key(key):
530
659
"""Returns a StorageUri for the given key.