cloudstack: use paging for listVirtualMachines (#40018)

Paging wasn't implemented, so once a cs domain has over 500 (default page size) VMs, Ansible can no longer find newly created VM.
pull/40042/head
Peter Farmer 7 years ago committed by René Moser
parent 06f76d6407
commit 16994bbdca

@ -147,11 +147,11 @@ class CloudStackInventory(object):
sys.exit(1)
def get_host(self, name, project_id=None, domain_id=None, **kwargs):
hosts = self.cs.listVirtualMachines(projectid=project_id, domainid=domain_id, **kwargs)
hosts = self.cs.listVirtualMachines(projectid=project_id, domainid=domain_id, fetch_list=True, **kwargs)
data = {}
if not hosts:
return data
for host in hosts['virtualmachine']:
for host in hosts:
host_name = host['displayname']
if name == host_name:
data['zone'] = host['zonename']
@ -202,10 +202,10 @@ class CloudStackInventory(object):
'hosts': []
}
hosts = self.cs.listVirtualMachines(projectid=project_id, domainid=domain_id, **kwargs)
hosts = self.cs.listVirtualMachines(projectid=project_id, domainid=domain_id, fetch_list=True, **kwargs)
if not hosts:
return data
for host in hosts['virtualmachine']:
for host in hosts:
host_name = host['displayname']
data['all']['hosts'].append(host_name)
data['_meta']['hostvars'][host_name] = {}

@ -413,10 +413,11 @@ class AnsibleCloudStack:
'domainid': self.get_domain(key='id'),
'projectid': self.get_project(key='id'),
'zoneid': self.get_zone(key='id') if filter_zone else None,
'fetch_list': True,
}
vms = self.query_api('listVirtualMachines', **args)
if vms:
for v in vms['virtualmachine']:
for v in vms:
if vm.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]:
self.vm = v
return self._get_by_key(key, self.vm)

@ -457,11 +457,12 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
'account': self.get_account(key='name'),
'domainid': self.get_domain(key='id'),
'projectid': self.get_project(key='id'),
'fetch_list': True,
}
# Do not pass zoneid, as the instance name must be unique across zones.
instances = self.query_api('listVirtualMachines', **args)
if instances:
for v in instances['virtualmachine']:
for v in instances:
if instance_name.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]:
self.instance = v
break

@ -206,11 +206,12 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
'account': self.get_account(key='name'),
'domainid': self.get_domain(key='id'),
'projectid': self.get_project(key='id'),
'fetch_list': True,
}
# Do not pass zoneid, as the instance name must be unique across zones.
instances = self.query_api('listVirtualMachines', **args)
if instances:
for v in instances['virtualmachine']:
for v in instances:
if instance_name.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]:
self.instance = v
break

@ -269,10 +269,11 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
return rule
args = self._get_common_args()
args['fetch_list'] = True
vms = self.query_api('listVirtualMachines', **args)
to_change_ids = []
for name in to_change:
for vm in vms.get('virtualmachine', []):
for vm in vms:
if vm['name'] == name:
to_change_ids.append(vm['id'])
break

Loading…
Cancel
Save