@ -1,4 +1,4 @@
#!/usr/bin/python -tt
#!/usr/bin/python
# (c) 2013, Paul Durivage <paul.durivage@rackspace.com>
# (c) 2013, Paul Durivage <paul.durivage@rackspace.com>
#
#
@ -143,9 +143,9 @@ from ansible import __version__
try:
try:
import pyrax
import pyrax
HAS_PYRAX = True
except ImportError, e:
except ImportError, e:
print("failed=True msg='pyrax is required for this module'")
HAS_PYRAX = False
sys.exit(1)
EXIT_DICT = dict(success=True)
EXIT_DICT = dict(success=True)
META_PREFIX = 'x-container-meta-'
META_PREFIX = 'x-container-meta-'
@ -200,7 +200,8 @@ def meta(cf, module, container_, state, meta_, clear_meta):
module.exit_json(**EXIT_DICT)
module.exit_json(**EXIT_DICT)
def container(cf, module, container_, state, meta_, clear_meta, ttl, public, private, web_index, web_error):
def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
private, web_index, web_error):
if public and private:
if public and private:
module.fail_json(msg='container cannot be simultaneously '
module.fail_json(msg='container cannot be simultaneously '
'set to public and private')
'set to public and private')
@ -297,9 +298,8 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public, pri
EXIT_DICT['container'] = c.name
EXIT_DICT['container'] = c.name
EXIT_DICT['objs_in_container'] = c.object_count
EXIT_DICT['objs_in_container'] = c.object_count
EXIT_DICT['total_bytes'] = c.total_bytes
EXIT_DICT['total_bytes'] = c.total_bytes
_locals = locals().keys()
_locals = locals().keys()
if ('cont_deleted' in _locals
if ('cont_deleted' in _locals
or 'meta_set' in _locals
or 'meta_set' in _locals
or 'cont_public' in _locals
or 'cont_public' in _locals
@ -311,15 +311,23 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public, pri
module.exit_json(**EXIT_DICT)
module.exit_json(**EXIT_DICT)
def cloudfiles(module, container_, state, meta_, clear_meta, typ, ttl, public, private, web_index, web_error):
def cloudfiles(module, container_, state, meta_, clear_meta, typ, ttl, public,
""" Dispatch from here to work with metadata or file objects """
private, web_index, web_error):
cf = pyrax.cloudfiles
""" Dispatch from here to work with metadata or file objects """
cf.user_agent = USER_AGENT
cf = pyrax.cloudfiles
if typ == "container":
if cf is None:
container(cf, module, container_, state, meta_, clear_meta, ttl, public, private, web_index, web_error)
module.fail_json(msg='Failed to instantiate client. This '
else:
'typically indicates an invalid region or an '
meta(cf, module, container_, state, meta_, clear_meta)
'incorrectly capitalized region name.')
cf.user_agent = USER_AGENT
if typ == "container":
container(cf, module, container_, state, meta_, clear_meta, ttl,
public, private, web_index, web_error)
else:
meta(cf, module, container_, state, meta_, clear_meta)
def main():
def main():
@ -327,7 +335,8 @@ def main():
argument_spec.update(
argument_spec.update(
dict(
dict(
container=dict(),
container=dict(),
state=dict(choices=['present', 'absent', 'list'], default='present'),
state=dict(choices=['present', 'absent', 'list'],
default='present'),
meta=dict(type='dict', default=dict()),
meta=dict(type='dict', default=dict()),
clear_meta=dict(default=False, type='bool'),
clear_meta=dict(default=False, type='bool'),
type=dict(choices=['container', 'meta'], default='container'),
type=dict(choices=['container', 'meta'], default='container'),
@ -344,6 +353,9 @@ def main():
required_together=rax_required_together()
required_together=rax_required_together()
)
)
if not HAS_PYRAX:
module.fail_json(msg='pyrax is required for this module')
container_ = module.params.get('container')
container_ = module.params.get('container')
state = module.params.get('state')
state = module.params.get('state')
meta_ = module.params.get('meta')
meta_ = module.params.get('meta')
@ -358,10 +370,12 @@ def main():
if state in ['present', 'absent'] and not container_:
if state in ['present', 'absent'] and not container_:
module.fail_json(msg='please specify a container name')
module.fail_json(msg='please specify a container name')
if clear_meta and not typ == 'meta':
if clear_meta and not typ == 'meta':
module.fail_json(msg='clear_meta can only be used when setting metadata')
module.fail_json(msg='clear_meta can only be used when setting '
'metadata')
setup_rax_module(module, pyrax)
setup_rax_module(module, pyrax)
cloudfiles(module, container_, state, meta_, clear_meta, typ, ttl, public, private, web_index, web_error)
cloudfiles(module, container_, state, meta_, clear_meta, typ, ttl, public,
private, web_index, web_error)
from ansible.module_utils.basic import *
from ansible.module_utils.basic import *