Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Cloudstack paging work for listVirtualMachines #40018

Merged
merged 1 commit into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions contrib/inventory/cloudstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ def get_project_id(self, project, domain_id=None):
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']
Expand Down Expand Up @@ -202,10 +202,10 @@ def get_list(self, project_id=None, domain_id=None, **kwargs):
'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] = {}
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/module_utils/cloudstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,11 @@ def get_vm(self, key=None, filter_zone=True):
'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)
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/modules/cloud/cloudstack/cs_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,12 @@ def get_instance(self):
'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
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ def get_instance(self):
'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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,11 @@ def _ensure_members(self, operation):
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
Expand Down