tripleo-ansible/tripleo_ansible/ansible_plugins/modules/tripleo_baremetal_populate_environment.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

132 lines
4.2 KiB
Python

#!/usr/bin/python
# Copyright 2020 Red Hat, Inc.
# 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.
__metaclass__ = type
from ansible.module_utils import baremetal_deploy as bd
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_cloud_from_module
from ansible.module_utils.openstack import openstack_full_argument_spec
from ansible.module_utils.openstack import openstack_module_kwargs
import metalsmith
import yaml
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
---
module: tripleo_baremetal_populate_environment
short_description: Add parameters to a heat environment with instance data
version_added: "2.9"
author: "Steve Baker (@stevebaker)"
description:
- Takes a list of existing instances and a heat environment file
and appends to that environment with instance-specific parameters such
as the port map.
options:
instances:
description:
- List of instance uuids to use for building the environment.
required: true
type: list
elements: dict
suboptions:
id:
description
- Node UUID to look up node details
type: str
environment:
description:
- Existing heat environment data to add to
type: dict
default: {}
ctlplane_network:
description:
- Name of control plane network
default: ctlplane
'''
RETURN = '''
environment:
description: Heat environment data to be used with the overcloud deploy.
This is only a partial environment, further changes are
required once instance changes have been made.
returned: changed
type: dict
sample: {
"parameter_defaults": {
"ComputeDeployedServerCount": 3,
"ComputeDeployedServerHostnameFormat": "%stackname%-novacompute-%index%",
"ControllerDeployedServerCount": 3,
"ControllerDeployedServerHostnameFormat": "%stackname%-controller-%index%",
"DeployedServerPortMap": {}
"HostnameMap": {
"overcloud-controller-0": "overcloud-controller-0",
"overcloud-controller-1": "overcloud-controller-1",
"overcloud-controller-2": "overcloud-controller-2",
"overcloud-novacompute-0": "overcloud-novacompute-0",
"overcloud-novacompute-1": "overcloud-novacompute-1",
"overcloud-novacompute-2": "overcloud-novacompute-2"
}
},
"resource_registry": {
"OS::TripleO::DeployedServer::ControlPlanePort": "/usr/share/openstack-tripleo-heat-templates/deployed-server/deployed-neutron-port.yaml"
}
}
''' # noqa
def main():
argument_spec = openstack_full_argument_spec(
**yaml.safe_load(DOCUMENTATION)['options']
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=False,
**module_kwargs
)
sdk, cloud = openstack_cloud_from_module(module)
provisioner = metalsmith.Provisioner(cloud_region=cloud.config)
instance_uuids = [i['id'] for i in module.params['instances']]
try:
env = bd.populate_environment(
instance_uuids=instance_uuids,
provisioner=provisioner,
environment=module.params['environment'],
ctlplane_network=module.params['ctlplane_network']
)
module.exit_json(
changed=False,
environment=env
)
except Exception as e:
module.fail_json(msg=str(e))
if __name__ == '__main__':
main()