Merge "Cleanup derive parameters playbooks and modules"

This commit is contained in:
Zuul 2021-02-15 21:46:42 +00:00 committed by Gerrit Code Review
commit 2c3460cc2c
6 changed files with 12 additions and 253 deletions

View File

@ -1,14 +0,0 @@
==================================
Module - tripleo_get_flatten_stack
==================================
This module provides for the following ansible plugin:
* tripleo_get_flatten_stack
.. ansibleautoplugin::
:module: tripleo_ansible/ansible_plugins/modules/tripleo_get_flatten_stack.py
:documentation: true
:examples: true

View File

@ -1,14 +0,0 @@
==============================
Module - tripleo_get_role_list
==============================
This module provides for the following ansible plugin:
* tripleo_get_role_list
.. ansibleautoplugin::
:module: tripleo_ansible/ansible_plugins/modules/tripleo_get_role_list.py
:documentation: true
:examples: true

View File

@ -35,7 +35,7 @@ description:
- "When collocating Ceph OSDs on Nova Compute hosts (hyperconverged or hci) the Nova Scheduler does not take into account the CPU/Memory needs of the OSDs. This module returns recommended NovaReservedHostMemory and NovaCPUAllocationRatio parmaters so that the host reseves memory and CPU for Ceph. The values are based on workload description, deployment configuration, and Ironic data. The workload description is the expected average_guest_cpu_utilization_percentage and average_guest_memory_size_in_mb."
options:
tripleo_environment_parameters:
description: Map from key environment_parameters from output of the tripleo_get_flatten_stack module stack_data. Used to determine number of OSDs in deployment per role
description: Map from key environment_parameters from stack_data. Used to determine number of OSDs in deployment per role
required: True
type: map
tripleo_role_name:

View File

@ -1,94 +0,0 @@
# 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 ansible.module_utils import tripleo_common_utils as tc
from ansible.module_utils.openstack import openstack_full_argument_spec
from ansible.module_utils.openstack import openstack_module_kwargs
from ansible.module_utils.openstack import openstack_cloud_from_module
DOCUMENTATION = """
---
module: tripleo_get_flatten_stack
short_description: Get the heat stack tree and parameters in flattened structure
extends_documentation_fragment: openstack
author:
- "Kevin Carter (@cloudnull)"
version_added: "2.10"
description:
- This method validates the stack of the container and returns the
parameters and the heat stack tree. The heat stack tree is
flattened for easy consumption.
options:
container:
description:
- Name of plan / container
type: str
required: true
requirements: ["openstacksdk", "tripleo-common"]
"""
EXAMPLES = """
- name: Get flattened stack
tripleo_get_flatten_stack:
cloud: undercloud
container: overcloud
register: flattened_params
"""
import yaml
from tripleo_common.utils import stack_parameters as stack_param_utils
def main():
result = dict(
success=False,
changed=False,
error=None,
)
module = AnsibleModule(
openstack_full_argument_spec(
**yaml.safe_load(DOCUMENTATION)['options']
),
**openstack_module_kwargs()
)
_, conn = openstack_cloud_from_module(module)
tripleo = tc.TripleOCommon(session=conn.session)
object_client = tripleo.get_object_client()
heat = tripleo.get_orchestration_client()
try:
result['stack_data'] = stack_param_utils.get_flattened_parameters(
swift=object_client,
heat=heat,
container=module.params["container"]
)
except Exception as exp:
result['error'] = str(exp)
result['msg'] = 'Error flattening stack data for plan {}: {}'.format(
module.params["container"],
exp
)
module.fail_json(**result)
else:
result['success'] = True
module.exit_json(**result)
if __name__ == "__main__":
main()

View File

@ -1,111 +0,0 @@
# 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 ansible.module_utils import tripleo_common_utils as tc
from ansible.module_utils.openstack import openstack_full_argument_spec
from ansible.module_utils.openstack import openstack_module_kwargs
from ansible.module_utils.openstack import openstack_cloud_from_module
DOCUMENTATION = """
---
module: tripleo_get_role_list
short_description: Lists deployment roles
extends_documentation_fragment: openstack
author:
- "Kevin Carter (@cloudnull)"
version_added: "2.10"
description:
- This action lists all deployment roles residing in the undercloud. A
deployment plan consists of a container marked with metadata
'x-container-meta-usage-tripleo'.
options:
container:
description:
- Name of plan / container
type: str
required: true
role_file_name:
description:
- File name
type: str
default: roles_data.yaml
detail:
description:
- If false displays role names only.
If true, returns all roles data.
type: bool
default: false
valid:
description:
- check if the role has count > 0 in heat environment
type: bool
default: true
requirements: ["openstacksdk", "tripleo-common"]
"""
EXAMPLES = """
- name: configure boot
tripleo_get_role_list:
register: role_list
"""
import os
import yaml
from tripleo_common.utils import roles as roles_utils
def main():
result = dict(
success=False,
changed=False,
error=None,
)
module = AnsibleModule(
openstack_full_argument_spec(
**yaml.safe_load(DOCUMENTATION)['options']
),
**openstack_module_kwargs()
)
_, conn = openstack_cloud_from_module(module)
tripleo = tc.TripleOCommon(session=conn.session)
object_client = tripleo.get_object_client()
heat = None
if module.params['valid']:
heat = tripleo.get_orchestration_client()
try:
result['roles'] = roles_utils.get_roles_from_plan(
swift=object_client,
heat=heat,
container=module.params['container'],
role_file_name=module.params['role_file_name'],
detail=module.params['detail'],
valid=module.params['valid']
)
except Exception as exp:
result['error'] = str(exp)
result['msg'] = 'Error listing roles: {}'.format(exp)
module.fail_json(**result)
else:
result['success'] = True
module.exit_json(**result)
if __name__ == "__main__":
main()

View File

@ -32,27 +32,19 @@
when:
- (tripleo_target_host is defined) | ternary('ssh', 'local') == 'local'
tasks:
- name: Get flatten params
tripleo_get_flatten_stack:
container: "{{ plan }}"
register: tripleo_get_flatten_params
- name: Fail if stack_data is not defined
when:
- tripleo_get_flatten_params is undefined
- name: Get role list
tripleo_get_role_list:
container: "{{ plan }}"
valid: false
register: tripleo_role_list
when:
- tripleo_role_list is undefined
- name: Fail if stack_data has not been extracted
when:
- tripleo_get_flatten_params.stack_data is not defined
- tripleo_get_flatten_params.stack_data is not defined or
stack_data is not defined
fail:
msg: "{{ plan }} is mising stack_data"
msg: "Missing stack_data"
- name: Fail if role_list is not defined
when:
- tripleo_role_list.roles is not defined or
role_list is not defined
fail:
msg: "Missing valid roles"
- name: Derive params for each role
include_role: