|
|
|
@ -144,7 +144,7 @@ def _get_glance_client(module, kwargs):
|
|
|
|
|
'token': token,
|
|
|
|
|
}
|
|
|
|
|
try:
|
|
|
|
|
client = glanceclient.Client('1', endpoint, **kwargs)
|
|
|
|
|
client = glanceclient.Client('1', endpoint, **kwargs)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
module.fail_json(msg = "Error in connecting to glance: %s" %e.message)
|
|
|
|
|
return client
|
|
|
|
@ -179,7 +179,7 @@ def _glance_image_create(module, params, client):
|
|
|
|
|
break
|
|
|
|
|
time.sleep(5)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
module.fail_json(msg = "Error in creating image: %s" %e.message )
|
|
|
|
|
module.fail_json(msg = "Error in creating image: %s" %e.message)
|
|
|
|
|
if image.status == 'active':
|
|
|
|
|
module.exit_json(changed = True, result = image.status, id=image.id)
|
|
|
|
|
else:
|
|
|
|
@ -197,38 +197,38 @@ def _glance_delete_image(module, params, client):
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
|
argument_spec = dict(
|
|
|
|
|
login_username = dict(default='admin'),
|
|
|
|
|
login_password = dict(required=True),
|
|
|
|
|
login_tenant_name = dict(required=True),
|
|
|
|
|
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
|
|
|
|
|
region_name = dict(default=None),
|
|
|
|
|
name = dict(required=True),
|
|
|
|
|
disk_format = dict(default='qcow2', choices=['aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso']),
|
|
|
|
|
container_format = dict(default='bare', choices=['aki', 'ari', 'bare', 'ovf']),
|
|
|
|
|
owner = dict(default=None),
|
|
|
|
|
min_disk = dict(default=None),
|
|
|
|
|
min_ram = dict(default=None),
|
|
|
|
|
is_public = dict(default=True),
|
|
|
|
|
copy_from = dict(default= None),
|
|
|
|
|
timeout = dict(default=180),
|
|
|
|
|
file = dict(default=None),
|
|
|
|
|
state = dict(default='present', choices=['absent', 'present'])
|
|
|
|
|
argument_spec = dict(
|
|
|
|
|
login_username = dict(default='admin'),
|
|
|
|
|
login_password = dict(required=True),
|
|
|
|
|
login_tenant_name = dict(required=True),
|
|
|
|
|
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
|
|
|
|
|
region_name = dict(default=None),
|
|
|
|
|
name = dict(required=True),
|
|
|
|
|
disk_format = dict(default='qcow2', choices=['aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso']),
|
|
|
|
|
container_format = dict(default='bare', choices=['aki', 'ari', 'bare', 'ovf']),
|
|
|
|
|
owner = dict(default=None),
|
|
|
|
|
min_disk = dict(default=None),
|
|
|
|
|
min_ram = dict(default=None),
|
|
|
|
|
is_public = dict(default=True),
|
|
|
|
|
copy_from = dict(default= None),
|
|
|
|
|
timeout = dict(default=180),
|
|
|
|
|
file = dict(default=None),
|
|
|
|
|
state = dict(default='present', choices=['absent', 'present'])
|
|
|
|
|
),
|
|
|
|
|
mutually_exclusive = [['file','copy_from']],
|
|
|
|
|
mutually_exclusive = [['file','copy_from']],
|
|
|
|
|
)
|
|
|
|
|
if module.params['state'] == 'present':
|
|
|
|
|
if not module.params['file'] and not module.params['copy_from']:
|
|
|
|
|
module.fail_json(msg = "Either file or copy_from variable should be set to create the image")
|
|
|
|
|
client = _get_glance_client(module, module.params)
|
|
|
|
|
id = _glance_image_present(module, module.params, client)
|
|
|
|
|
id = _glance_image_present(module, module.params, client)
|
|
|
|
|
if not id:
|
|
|
|
|
_glance_image_create(module, module.params, client)
|
|
|
|
|
module.exit_json(changed = False, id = id, result = "success")
|
|
|
|
|
|
|
|
|
|
if module.params['state'] == 'absent':
|
|
|
|
|
client = _get_glance_client(module, module.params)
|
|
|
|
|
id = _glance_image_present(module, module.params, client)
|
|
|
|
|
id = _glance_image_present(module, module.params, client)
|
|
|
|
|
if not id:
|
|
|
|
|
module.exit_json(changed = False, result = "Success")
|
|
|
|
|
else:
|
|
|
|
|