Merge pull request #3091 from jmunhoz/s3-ceph

Add Ceph RGW S3 compatibility
This commit is contained in:
Ryan Brown 2016-06-21 15:34:59 -04:00 committed by GitHub
commit 47e22248c4

View file

@ -131,9 +131,14 @@ options:
version_added: "2.0" version_added: "2.0"
s3_url: s3_url:
description: description:
- S3 URL endpoint for usage with Eucalypus, fakes3, etc. Otherwise assumes AWS - S3 URL endpoint for usage with Ceph, Eucalypus, fakes3, etc. Otherwise assumes AWS
default: null default: null
aliases: [ S3_URL ] aliases: [ S3_URL ]
rgw:
description:
- Enable Ceph RGW S3 support. This option requires an explicit url via s3_url.
default: false
version_added: "2.2"
src: src:
description: description:
- The source file path when performing a PUT operation. - The source file path when performing a PUT operation.
@ -152,6 +157,9 @@ EXAMPLES = '''
# Simple PUT operation # Simple PUT operation
- s3: bucket=mybucket object=/my/desired/key.txt src=/usr/local/myfile.txt mode=put - s3: bucket=mybucket object=/my/desired/key.txt src=/usr/local/myfile.txt mode=put
# Simple PUT operation in Ceph RGW S3
- s3: bucket=mybucket object=/my/desired/key.txt src=/usr/local/myfile.txt mode=put rgw=true s3_url=http://localhost:8000
# Simple GET operation # Simple GET operation
- s3: bucket=mybucket object=/my/desired/key.txt dest=/usr/local/myfile.txt mode=get - s3: bucket=mybucket object=/my/desired/key.txt dest=/usr/local/myfile.txt mode=get
@ -384,6 +392,7 @@ def main():
prefix = dict(default=None), prefix = dict(default=None),
retries = dict(aliases=['retry'], type='int', default=0), retries = dict(aliases=['retry'], type='int', default=0),
s3_url = dict(aliases=['S3_URL']), s3_url = dict(aliases=['S3_URL']),
rgw = dict(default='no', type='bool'),
src = dict(), src = dict(),
), ),
) )
@ -408,6 +417,7 @@ def main():
prefix = module.params.get('prefix') prefix = module.params.get('prefix')
retries = module.params.get('retries') retries = module.params.get('retries')
s3_url = module.params.get('s3_url') s3_url = module.params.get('s3_url')
rgw = module.params.get('rgw')
src = module.params.get('src') src = module.params.get('src')
for acl in module.params.get('permission'): for acl in module.params.get('permission'):
@ -437,6 +447,10 @@ def main():
if not s3_url and 'S3_URL' in os.environ: if not s3_url and 'S3_URL' in os.environ:
s3_url = os.environ['S3_URL'] s3_url = os.environ['S3_URL']
# rgw requires an explicit url
if rgw and not s3_url:
module.fail_json(msg='rgw flavour requires s3_url')
# bucket names with .'s in them need to use the calling_format option, # bucket names with .'s in them need to use the calling_format option,
# otherwise the connection will fail. See https://github.com/boto/boto/issues/2836 # otherwise the connection will fail. See https://github.com/boto/boto/issues/2836
# for more details. # for more details.
@ -444,9 +458,18 @@ def main():
aws_connect_kwargs['calling_format'] = OrdinaryCallingFormat() aws_connect_kwargs['calling_format'] = OrdinaryCallingFormat()
# Look at s3_url and tweak connection settings # Look at s3_url and tweak connection settings
# if connecting to Walrus or fakes3 # if connecting to RGW, Walrus or fakes3
try: try:
if is_fakes3(s3_url): if s3_url and rgw:
rgw = urlparse.urlparse(s3_url)
s3 = boto.connect_s3(
is_secure=rgw.scheme == 'https',
host=rgw.hostname,
port=rgw.port,
calling_format=OrdinaryCallingFormat(),
**aws_connect_kwargs
)
elif is_fakes3(s3_url):
fakes3 = urlparse.urlparse(s3_url) fakes3 = urlparse.urlparse(s3_url)
s3 = S3Connection( s3 = S3Connection(
is_secure=fakes3.scheme == 'fakes3s', is_secure=fakes3.scheme == 'fakes3s',