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

Allow to skip searching via all tenants in Openstack #467

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions wrapanapi/systems/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def session(self):
password=self.password, project_name=self.tenant)
if self.keystone_version == 3:
auth_kwargs.update(dict(user_domain_id=self.domain_id,
project_domain_name=self.domain_id))
project_domain_id=self.domain_id))
pass_auth = Password(**auth_kwargs)
self._session = Session(auth=pass_auth, verify=False)
return self._session
Expand Down Expand Up @@ -793,18 +793,18 @@ def _generic_paginator(self, f):
break
return lists

def list_vms(self, filter_tenants=True):
call = partial(self.api.servers.list, True, {'all_tenants': True})
def list_vms(self, filter_tenants=True, all_tenants=True):
call = partial(self.api.servers.list, True, {'all_tenants': all_tenants})
instances = self._generic_paginator(call)
if filter_tenants:
if filter_tenants and all_tenants:
# Filter instances based on their tenant ID
# needed for CFME 5.3 and higher
tenants = self._get_tenants()
ids = [tenant.id for tenant in tenants]
instances = [i for i in instances if i.tenant_id in ids]
return [OpenstackInstance(system=self, uuid=i.id, raw=i) for i in instances]

def find_vms(self, name=None, id=None, ip=None):
def find_vms(self, name=None, id=None, ip=None, all_tenants=True):
"""
Find VM based on name OR IP OR ID

Expand All @@ -826,7 +826,7 @@ def find_vms(self, name=None, id=None, ip=None):
if not any((name, ip, id)):
raise ValueError("Any of these parameters must be specified: name, ip, or id")
matches = []
instances = self.list_vms()
instances = self.list_vms(all_tenants=all_tenants)
for instance in instances:
# Use 'instance.raw' below so we don't refresh the properties, since we
# *just* pulled down this list of VMs and stored the raw data in list_vms()
Expand All @@ -840,7 +840,7 @@ def find_vms(self, name=None, id=None, ip=None):
matches.append(instance)
return matches

def get_vm(self, name=None, id=None, ip=None):
def get_vm(self, name=None, id=None, ip=None, all_tenants=True):
"""
Get a VM based on name, or ID, or IP

Expand All @@ -862,7 +862,7 @@ def get_vm(self, name=None, id=None, ip=None):
kwargs = {'name': name, 'id': id, 'ip': ip}
kwargs = {key: val for key, val in kwargs.items() if val is not None}

matches = self.find_vms(**kwargs)
matches = self.find_vms(**kwargs, all_tenants=all_tenants)
if not matches:
raise VMInstanceNotFound('match criteria: {}'.format(kwargs))
elif len(matches) > 1:
Expand Down