tripleo-ansible/tripleo_ansible/ansible_plugins/modules/baremetal_nodes_validate.py
Hervé Beraud c09f624891 Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: I088f435bfc0dfeb67b4b2c3400aaa08eb41d7c59
2020-06-02 21:02:57 +02:00

104 lines
2.3 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2018 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ansible.module_utils.basic import AnsibleModule
from tripleo_common import exception
from tripleo_common.utils import nodes
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
---
module: baremetal_nodes_validate
short_description: Baremetal nodes
version_added: "2.8"
description:
- "Baremetal nodes functions."
options:
node_list:
description:
- List of the nodes to be validated
required: true
author:
- Adriano Petrich (@frac)
'''
EXAMPLES = '''
# Pass in a message
- name: Test with a message
baremetal_nodes_validate:
nodes_list:
- _comment: 'This is a comment'
pm_type: 'pxe_ipmitool'
pm_addr: '192.168.0.1'
pm_user: 'root'
pm_password: 'p@$$w0rd'
- pm_type: 'ipmi'
pm_addr: '192.168.1.1'
pm_user: 'root'
pm_password: 'p@$$w0rd'
'''
def run_module():
module_args = dict(
nodes_list=dict(type='list', required=True),
)
result = dict(
success=False,
error=''
)
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
if module.check_mode:
module.exit_json(**result)
try:
nodes_json = nodes.convert_nodes_json_mac_to_ports(
module.params['nodes_list']
)
nodes.validate_nodes(nodes_json)
result['success'] = True
except exception.InvalidNode as exc:
result['error'] = str(exc)
module.fail_json(msg='Validation Failed', **result)
module.exit_json(**result)
def main():
run_module()
if __name__ == '__main__':
main()