mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-07 13:53:15 +00:00
Redesign OpenstackModule class
don't inherit OpenstackModule class from AnsibleModule class to prevent occasional overriding Ansible methods or vars and failing module. Change-Id: Ic34fff0c938eb87cc0d2c5e98fbafed64bf349f6
This commit is contained in:
@@ -10,33 +10,33 @@ short_description: Retrieve information about one or more compute instances
|
||||
author: Monty (@emonty)
|
||||
description:
|
||||
- Retrieve information about server instances from OpenStack.
|
||||
- This module was called C(openstack.cloud.server_facts) before Ansible 2.9, returning C(ansible_facts).
|
||||
- This module was called C(os_server_facts) before Ansible 2.9, returning C(ansible_facts).
|
||||
Note that the M(openstack.cloud.server_info) module no longer returns C(ansible_facts)!
|
||||
notes:
|
||||
- The result contains a list of servers.
|
||||
options:
|
||||
server:
|
||||
description:
|
||||
- restrict results to servers with names or UUID matching
|
||||
this glob expression (e.g., <web*>).
|
||||
type: str
|
||||
detailed:
|
||||
description:
|
||||
- when true, return additional detail about servers at the expense
|
||||
of additional API calls.
|
||||
type: bool
|
||||
default: 'no'
|
||||
filters:
|
||||
description:
|
||||
- restrict results to servers matching a dictionary of
|
||||
filters
|
||||
type: dict
|
||||
all_projects:
|
||||
description:
|
||||
- Whether to list servers from all projects or just the current auth
|
||||
scoped project.
|
||||
type: bool
|
||||
default: 'no'
|
||||
server:
|
||||
description:
|
||||
- restrict results to servers with names or UUID matching
|
||||
this glob expression (e.g., <web*>).
|
||||
type: str
|
||||
detailed:
|
||||
description:
|
||||
- when true, return additional detail about servers at the expense
|
||||
of additional API calls.
|
||||
type: bool
|
||||
default: 'no'
|
||||
filters:
|
||||
description:
|
||||
- restrict results to servers matching a dictionary of
|
||||
filters
|
||||
type: dict
|
||||
all_projects:
|
||||
description:
|
||||
- Whether to list servers from all projects or just the current auth
|
||||
scoped project.
|
||||
type: bool
|
||||
default: 'no'
|
||||
requirements:
|
||||
- "python >= 3.6"
|
||||
- "openstacksdk"
|
||||
@@ -57,13 +57,13 @@ EXAMPLES = '''
|
||||
msg: "{{ result.openstack_servers }}"
|
||||
'''
|
||||
|
||||
import fnmatch
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
|
||||
|
||||
class ServerInfoModule(OpenStackModule):
|
||||
|
||||
deprecated_names = ('os_server_info', 'openstack.cloud.os_server_info')
|
||||
|
||||
argument_spec = dict(
|
||||
server=dict(required=False),
|
||||
detailed=dict(required=False, type='bool', default=False),
|
||||
@@ -72,26 +72,16 @@ class ServerInfoModule(OpenStackModule):
|
||||
)
|
||||
|
||||
def run(self):
|
||||
is_old_facts = self._name == 'openstack.cloud.server_facts'
|
||||
if is_old_facts:
|
||||
self.deprecate("The 'openstack.cloud.server_facts' module has been renamed to 'openstack.cloud.server_info', "
|
||||
"and the renamed one no longer returns ansible_facts", version='2.13')
|
||||
openstack_servers = self.conn.search_servers(
|
||||
detailed=self.params['detailed'], filters=self.params['filters'],
|
||||
all_projects=self.params['all_projects'])
|
||||
|
||||
kwargs = self.check_versioned(
|
||||
detailed=self.params['detailed'],
|
||||
filters=self.params['filters'],
|
||||
all_projects=self.params['all_projects']
|
||||
)
|
||||
if self.params['server']:
|
||||
# filter servers by name
|
||||
pattern = self.params['server']
|
||||
# TODO(mordred) This is handled by sdk now
|
||||
openstack_servers = [server for server in openstack_servers
|
||||
if fnmatch.fnmatch(server['name'], pattern)
|
||||
or fnmatch.fnmatch(server['id'], pattern)]
|
||||
if is_old_facts:
|
||||
self.exit_json(changed=False, ansible_facts=dict(
|
||||
openstack_servers=openstack_servers))
|
||||
else:
|
||||
self.exit_json(changed=False, openstack_servers=openstack_servers)
|
||||
kwargs['name_or_id'] = self.params['server']
|
||||
openstack_servers = self.conn.search_servers(**kwargs)
|
||||
self.exit(changed=False, openstack_servers=openstack_servers)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user