1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

nova_compute: fix for partial match b/w params['name'] and an existing name

When there is an Openstack instance that has a name that's a partial match
for module.params['name'], but a server with name module.params['name']
doesn't yet exist, this module would fail with a list index out of bounds
error. This fixes that by filtering by exact name and only then getting the
server from the list if the list is still not empty.
This commit is contained in:
Joshua Conner 2014-02-28 18:05:52 -08:00
parent 16d3be03af
commit ce5939c507

View file

@ -193,7 +193,11 @@ def _get_server_state(module, nova):
try: try:
servers = nova.servers.list(True, {'name': module.params['name']}) servers = nova.servers.list(True, {'name': module.params['name']})
if servers: if servers:
server = [x for x in servers if x.name == module.params['name']][0] # the {'name': module.params['name']} will also return servers
# with names that partially match the server name, so we have to
# strictly filter here
servers = [x for x in servers if x.name == module.params['name']]
server = servers[0] if servers else None
except Exception, e: except Exception, e:
module.fail_json(msg = "Error in getting the server list: %s" % e.message) module.fail_json(msg = "Error in getting the server list: %s" % e.message)
if server and module.params['state'] == 'present': if server and module.params['state'] == 'present':