2016-02-17 13:58:28 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# coding: utf-8 -*-
|
|
|
|
|
|
|
|
# (c) 2015-2016, Hewlett Packard Enterprise Development Company LP
|
2017-10-09 16:56:26 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2016-02-17 13:58:28 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2016-12-06 10:35:25 +00:00
|
|
|
|
2016-02-17 13:58:28 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: os_ironic_inspect
|
|
|
|
short_description: Explicitly triggers baremetal node introspection in ironic.
|
|
|
|
extends_documentation_fragment: openstack
|
|
|
|
author: "Julia Kreger (@juliakreger)"
|
|
|
|
version_added: "2.1"
|
|
|
|
description:
|
|
|
|
- Requests Ironic to set a node into inspect state in order to collect metadata regarding the node.
|
|
|
|
This command may be out of band or in-band depending on the ironic driver configuration.
|
|
|
|
This is only possible on nodes in 'manageable' and 'available' state.
|
|
|
|
options:
|
|
|
|
mac:
|
|
|
|
description:
|
|
|
|
- unique mac address that is used to attempt to identify the host.
|
|
|
|
uuid:
|
|
|
|
description:
|
|
|
|
- globally unique identifier (UUID) to identify the host.
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- unique name identifier to identify the host in Ironic.
|
|
|
|
ironic_url:
|
|
|
|
description:
|
|
|
|
- If noauth mode is utilized, this is required to be set to the endpoint URL for the Ironic API.
|
|
|
|
Use with "auth" and "auth_type" settings set to None.
|
|
|
|
timeout:
|
|
|
|
description:
|
|
|
|
- A timeout in seconds to tell the role to wait for the node to complete introspection if wait is set to True.
|
|
|
|
default: 1200
|
2017-02-17 20:49:03 +00:00
|
|
|
availability_zone:
|
|
|
|
description:
|
2017-06-12 06:55:19 +00:00
|
|
|
- Ignored. Present for backwards compatibility
|
2016-02-17 13:58:28 +00:00
|
|
|
|
2018-05-26 01:40:39 +00:00
|
|
|
requirements: ["openstacksdk"]
|
2016-02-17 13:58:28 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
ansible_facts:
|
|
|
|
description: Dictionary of new facts representing discovered properties of the node..
|
|
|
|
returned: changed
|
2017-04-27 11:01:11 +00:00
|
|
|
type: complex
|
2016-02-17 13:58:28 +00:00
|
|
|
contains:
|
|
|
|
memory_mb:
|
|
|
|
description: Amount of node memory as updated in the node properties
|
2018-12-18 21:25:30 +00:00
|
|
|
type: str
|
2016-02-17 13:58:28 +00:00
|
|
|
sample: "1024"
|
|
|
|
cpu_arch:
|
|
|
|
description: Detected CPU architecture type
|
2018-12-18 21:25:30 +00:00
|
|
|
type: str
|
2016-02-17 13:58:28 +00:00
|
|
|
sample: "x86_64"
|
|
|
|
local_gb:
|
|
|
|
description: Total size of local disk storage as updaed in node properties.
|
2018-12-18 21:25:30 +00:00
|
|
|
type: str
|
2016-02-17 13:58:28 +00:00
|
|
|
sample: "10"
|
|
|
|
cpus:
|
|
|
|
description: Count of cpu cores defined in the updated node properties.
|
2018-12-18 21:25:30 +00:00
|
|
|
type: str
|
2016-02-17 13:58:28 +00:00
|
|
|
sample: "1"
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Invoke node inspection
|
|
|
|
- os_ironic_inspect:
|
|
|
|
name: "testnode1"
|
|
|
|
'''
|
|
|
|
|
2017-10-09 16:56:26 +00:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2018-02-15 14:20:49 +00:00
|
|
|
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
|
2017-02-02 19:45:22 +00:00
|
|
|
|
2016-02-17 13:58:28 +00:00
|
|
|
|
|
|
|
def _choose_id_value(module):
|
|
|
|
if module.params['uuid']:
|
|
|
|
return module.params['uuid']
|
|
|
|
if module.params['name']:
|
|
|
|
return module.params['name']
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
argument_spec = openstack_full_argument_spec(
|
|
|
|
auth_type=dict(required=False),
|
|
|
|
uuid=dict(required=False),
|
|
|
|
name=dict(required=False),
|
|
|
|
mac=dict(required=False),
|
|
|
|
ironic_url=dict(required=False),
|
|
|
|
timeout=dict(default=1200, type='int', required=False),
|
|
|
|
)
|
|
|
|
module_kwargs = openstack_module_kwargs()
|
|
|
|
module = AnsibleModule(argument_spec, **module_kwargs)
|
|
|
|
|
|
|
|
if (module.params['auth_type'] in [None, 'None'] and
|
|
|
|
module.params['ironic_url'] is None):
|
|
|
|
module.fail_json(msg="Authentication appears to be disabled, "
|
|
|
|
"Please define an ironic_url parameter")
|
|
|
|
|
|
|
|
if (module.params['ironic_url'] and
|
|
|
|
module.params['auth_type'] in [None, 'None']):
|
|
|
|
module.params['auth'] = dict(
|
|
|
|
endpoint=module.params['ironic_url']
|
|
|
|
)
|
|
|
|
|
2018-05-26 01:40:39 +00:00
|
|
|
sdk, cloud = openstack_cloud_from_module(module)
|
2016-02-17 13:58:28 +00:00
|
|
|
try:
|
|
|
|
if module.params['name'] or module.params['uuid']:
|
|
|
|
server = cloud.get_machine(_choose_id_value(module))
|
|
|
|
elif module.params['mac']:
|
|
|
|
server = cloud.get_machine_by_mac(module.params['mac'])
|
|
|
|
else:
|
|
|
|
module.fail_json(msg="The worlds did not align, "
|
|
|
|
"the host was not found as "
|
|
|
|
"no name, uuid, or mac was "
|
|
|
|
"defined.")
|
|
|
|
if server:
|
|
|
|
cloud.inspect_machine(server['uuid'], module.params['wait'])
|
|
|
|
# TODO(TheJulia): diff properties, ?and ports? and determine
|
2016-12-11 02:50:09 +00:00
|
|
|
# if a change occurred. In theory, the node is always changed
|
2016-02-17 13:58:28 +00:00
|
|
|
# if introspection is able to update the record.
|
|
|
|
module.exit_json(changed=True,
|
|
|
|
ansible_facts=server['properties'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
module.fail_json(msg="node not found.")
|
|
|
|
|
2018-05-26 01:40:39 +00:00
|
|
|
except sdk.exceptions.OpenStackCloudException as e:
|
2016-02-17 13:58:28 +00:00
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|