5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
21 from shade import meta
28 module: os_node_power_check
29 short_description: Retrieve facts about ironic nodes list provided,
30 Returns a list of nodes which are not in specified power state
33 - Retrieve facts about ironic nodes list provided,
34 Returns a list of nodes which are not in specified power state
41 - List of dicts [{uuid: <ironic_node_id>, name: <ironic_node_name>},....], containing ironic node ids and names.
46 - The ironic URL to connect to
51 - The specified power state in which nodes are expected to be
56 extends_documentation_fragment: openstack
60 - os_node_power_check:
66 power_state: 'power on'
70 argument_spec = openstack_full_argument_spec(
71 nodes_details=dict(type='list', required=True),
72 ironic_url=dict(required=False),
73 power_state=dict(required=True),
75 module_kwargs = openstack_module_kwargs()
76 module = AnsibleModule(argument_spec, **module_kwargs)
79 module.fail_json(msg='shade is required for this module')
80 if (module.params['auth_type'] in [None, 'None'] and
81 module.params['ironic_url'] is None):
82 module.fail_json(msg="Authentication appears to be disabled, "
83 "Please define an ironic_url parameter")
85 if (module.params['ironic_url'] and
86 module.params['auth_type'] in [None, 'None']):
87 module.params['auth'] = dict(
88 endpoint=module.params['ironic_url']
92 cloud = shade.operator_cloud(**module.params)
94 nodes_details = module.params['nodes_details']
95 power_state = module.params['power_state']
96 power_pending_list = []
98 for node in nodes_details:
99 node_name = node['uuid']
100 node_details = cloud.get_machine(node_name)
102 if not node_details['power_state'] == power_state:
103 power_pending_list.append(node_name)
105 module.exit_json(changed=False, ansible_facts=dict(power_pending_list=power_pending_list))
107 except shade.OpenStackCloudException as e:
108 module.fail_json(msg=str(e))
110 # this is magic, see lib/ansible/module_common.py
111 from ansible.module_utils.basic import *
112 from ansible.module_utils.openstack import *
113 if __name__ == '__main__':