Merge "Add a new set of modules to support derived params"

This commit is contained in:
Zuul 2020-05-04 23:20:26 +00:00 committed by Gerrit Code Review
commit 43282081d0
21 changed files with 565 additions and 9 deletions

View File

@ -0,0 +1,14 @@
==================================
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

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

View File

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

View File

@ -0,0 +1,14 @@
==============================
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

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

View File

@ -154,13 +154,12 @@ class TripleOCommon(object):
if 'swift_client' in self.client_cache:
return self.client_cache['swift_client']
else:
self.client_cache['swift_client'] = \
swift_client.Connection(
session=self.sess,
retries=10,
starting_backoff=3,
max_backoff=120
)
self.client_cache['swift_client'] = swift_client.Connection(
session=self.sess,
retries=10,
starting_backoff=3,
max_backoff=120
)
return self.client_cache['swift_client']
def baremetal_configure_boot(self, kwargs):

View File

@ -64,6 +64,7 @@ options:
author:
- Adriano Petrich (@frac)
requirements: ["openstacksdk", "tripleo-common"]
'''

View File

@ -46,7 +46,7 @@ options:
type: dict
required: true
requirements: ["openstacksdk"]
requirements: ["openstacksdk", "tripleo-common"]
"""
EXAMPLES = """

View File

@ -53,6 +53,7 @@ options:
default: overcloud
author:
- Rabi Mishra (@ramishra)
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''

View File

@ -0,0 +1,92 @@
# 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)
try:
result['stack_data'] = stack_param_utils.get_flattened_parameters(
tripleo.get_object_client(),
tripleo.get_orchestration_client(),
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

@ -0,0 +1,94 @@
# 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_flavor_profile
short_description: Get the flavor profile data
extends_documentation_fragment: openstack
author:
- "Kevin Carter (@cloudnull)"
version_added: "2.10"
description:
- Pull profile from a given flavor
options:
flavor_name:
description:
- Name of flavor
type: str
required: true
requirements: ["openstacksdk", "tripleo-common"]
"""
EXAMPLES = """
- name: Get flavor profile
tripleo_get_flavor_profile:
flavor_name: m1.tiny
register: flavor_profile
"""
import os
import yaml
from tripleo_common import exception
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)
try:
result['profile'] = tripleo.return_flavor_profile(
module.params["flavor_name"]
)
except exception.DeriveParamsError:
result['profile'] = None
result['success'] = True
module.exit_json(**result)
except Exception as exp:
result['error'] = str(exp)
result['msg'] = 'Error pulling flavor properties for {}: {}'.format(
module.params["flavor_name"],
exp
)
module.fail_json(**result)
else:
result['success'] = True
module.exit_json(**result)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,89 @@
# 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_introspected_data
short_description: Retrieve introspection data
extends_documentation_fragment: openstack
author:
- "Kevin Carter (@cloudnull)"
version_added: "2.10"
description:
- Pull introspection data from a baremetal node.
options:
node_id:
description:
- ID of the baremetal node
type: str
required: true
requirements: ["openstacksdk", "tripleo-common"]
"""
EXAMPLES = """
- name: Get introspected data
tripleo_get_introspected_data:
node_id: xxx
register: introspected_data
"""
import os
import yaml
from tripleo_common import exception
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)
try:
result['data'] = tripleo.return_introspected_node_data(
node_id=module.params["node_id"]
)
except Exception as exp:
result['error'] = str(exp)
result['msg'] = 'Error pulling introspection data for {}: {}'.format(
module.params["node_id"],
exp
)
module.fail_json(**result)
else:
result['success'] = True
module.exit_json(**result)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,107 @@
# 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()
try:
result['roles'] = roles_utils.get_roles_from_plan(
object_client,
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

@ -59,6 +59,7 @@ options:
default: false
author:
- Rabi Mishra (@ramishra)
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''

View File

@ -65,7 +65,7 @@ options:
- Fallback to image download if scp fails
default: false
requirements: ["openstacksdk"]
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''

View File

@ -63,6 +63,7 @@ options:
no_log: true
author:
- Rabi Mishra (@ramishra)
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''

View File

@ -65,6 +65,7 @@ options:
author:
- Rabi Mishra (@ramishra)
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''

View File

@ -70,6 +70,7 @@ options:
author:
- Rabi Mishra (@ramishra)
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''

View File

@ -0,0 +1,97 @@
# 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_reset_params
short_description: Reset params
extends_documentation_fragment: openstack
author:
- "Kevin Carter (@cloudnull)"
version_added: "2.10"
description:
- This method will reset params for a given parmeter key.
options:
container:
description:
- Name of plan / container
type: str
required: true
parameter_key:
description:
- Heat parameter key
type: str
default: parameter_defaults
requirements: ["openstacksdk", "tripleo-common"]
"""
EXAMPLES = """
- name: configure boot
tripleo_reset_params:
cloud: undercloud
container: overcloud
parameter_key: parameter_defaults
"""
import os
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)
try:
stack_param_utils.reset_parameters(
swift=tripleo.get_object_client(),
container=module.params["container"],
key=module.params["parameter_key"]
)
result['changed'] = True
except Exception as exp:
result['error'] = str(exp)
result['msg'] = 'Error resetting params 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

@ -65,6 +65,7 @@ options:
author:
- Rabi Mishra (@ramishra)
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''

View File

@ -59,6 +59,7 @@ options:
default: '/usr/share/openstack-tripleo-heat-templates/'
author:
- Rabi Mishra (@ramishra)
requirements: ["openstacksdk", "tripleo-common"]
'''
EXAMPLES = '''