add image_name_to_id filter
This commit is contained in:
parent
c724d5a41b
commit
4ecb5624df
1 changed files with 13 additions and 0 deletions
|
@ -35,9 +35,22 @@ def image_id_to_name(host_vars, user, password, tenant, auth_url):
|
|||
except glanceclient.exc.HTTPNotFound:
|
||||
raise errors.AnsibleFilterError('There is no image of id {0}'.format(host_vars))
|
||||
|
||||
def image_name_to_id(host_vars, user, password, tenant, auth_url):
|
||||
auth = identity.Password(auth_url=auth_url, username=user,
|
||||
password=password, tenant_name=tenant)
|
||||
sess = session.Session(auth=auth)
|
||||
token = auth.get_token(sess)
|
||||
endpoint = auth.get_endpoint(sess, service_name='glance', service_type='image')
|
||||
glance = GlanceClient('2', endpoint=endpoint, token=token)
|
||||
for i in glance.images.list():
|
||||
if i.name == host_vars:
|
||||
return i.id
|
||||
raise errors.AnsibleFilterError('There is no image of name {0}'.format(host_vars))
|
||||
|
||||
class FilterModule (object):
|
||||
def filters(self):
|
||||
return {"flavor_id_to_name": flavor_id_to_name,
|
||||
"flavor_name_to_id": flavor_name_to_id,
|
||||
"image_id_to_name": image_id_to_name,
|
||||
"image_name_to_id": image_name_to_id,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue