Add tripleo_templates_upload module
This adds a new module to upload templates to plan as a tar file. Change-Id: I7ac4c328ec7f4dd0fb4aa7495945fbc57feb4bbc Depends-On: https://review.opendev.org/712599 Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
parent
d1e0e37146
commit
e8c9b421f9
14
doc/source/modules/modules-tripleo_templates_upload.rst
Normal file
14
doc/source/modules/modules-tripleo_templates_upload.rst
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
=================================
|
||||||
|
Module - tripleo_templates_upload
|
||||||
|
=================================
|
||||||
|
|
||||||
|
|
||||||
|
This module provides for the following ansible plugin:
|
||||||
|
|
||||||
|
* tripleo_templates_upload
|
||||||
|
|
||||||
|
|
||||||
|
.. ansibleautoplugin::
|
||||||
|
:module: tripleo_ansible/ansible_plugins/modules/tripleo_templates_upload.py
|
||||||
|
:documentation: true
|
||||||
|
:examples: true
|
9
tox.ini
9
tox.ini
@ -5,7 +5,7 @@ skipdist = True
|
|||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/master/upper-constraints.txt} {opts} {packages}
|
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/master/upper-constraints.txt} -c{toxinidir}/constraints.txt {opts} {packages}
|
||||||
passenv = *
|
passenv = *
|
||||||
setenv =
|
setenv =
|
||||||
VIRTUAL_ENV={envdir}
|
VIRTUAL_ENV={envdir}
|
||||||
@ -63,7 +63,6 @@ commands =
|
|||||||
basepython = python3
|
basepython = python3
|
||||||
deps =
|
deps =
|
||||||
-r {toxinidir}/doc/requirements.txt
|
-r {toxinidir}/doc/requirements.txt
|
||||||
-c {toxinidir}/constraints.txt
|
|
||||||
commands =
|
commands =
|
||||||
sphinx-build -a -E -W -d releasenotes/build/doctrees --keep-going -b html releasenotes/source releasenotes/build/html
|
sphinx-build -a -E -W -d releasenotes/build/doctrees --keep-going -b html releasenotes/source releasenotes/build/html
|
||||||
|
|
||||||
@ -71,8 +70,12 @@ commands =
|
|||||||
basepython = python3
|
basepython = python3
|
||||||
deps =
|
deps =
|
||||||
-r {toxinidir}/doc/requirements.txt
|
-r {toxinidir}/doc/requirements.txt
|
||||||
-c {toxinidir}/constraints.txt
|
|
||||||
commands=
|
commands=
|
||||||
|
# NOTE(cloudnull): This will ensure we always have the latest version of
|
||||||
|
# tripleo-common installed, which is required for documentation
|
||||||
|
# to build when running with in development modules which use
|
||||||
|
# tripleo-common as a library.
|
||||||
|
pip install tripleo-common -c{toxinidir}/constraints.txt --force --upgrade
|
||||||
doc8 doc
|
doc8 doc
|
||||||
sphinx-build -a -E -W -d doc/build/doctrees --keep-going -b html doc/source doc/build/html -T
|
sphinx-build -a -E -W -d doc/build/doctrees --keep-going -b html doc/source doc/build/html -T
|
||||||
|
|
||||||
|
@ -0,0 +1,129 @@
|
|||||||
|
#!/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 __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
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
|
||||||
|
|
||||||
|
# NOTE: This is still using the legacy clients. We've not
|
||||||
|
# changed to using the OpenStackSDK fully because
|
||||||
|
# tripleo-common expects the legacy clients. Once
|
||||||
|
# we've updated tripleo-common to use the SDK we
|
||||||
|
# should revise this.
|
||||||
|
from swiftclient import client as swift_client
|
||||||
|
|
||||||
|
from tripleo_common.utils import template as template_utils
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {
|
||||||
|
'metadata_version': '1.1',
|
||||||
|
'status': ['preview'],
|
||||||
|
'supported_by': 'community'
|
||||||
|
}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: tripleo_templates_upload
|
||||||
|
|
||||||
|
short_description: Upload Templates
|
||||||
|
|
||||||
|
version_added: "2.8"
|
||||||
|
|
||||||
|
description:
|
||||||
|
- "Upload Templates to plan"
|
||||||
|
|
||||||
|
options:
|
||||||
|
container:
|
||||||
|
description:
|
||||||
|
- Overcloud plan container name
|
||||||
|
type: str
|
||||||
|
default: overcloud
|
||||||
|
templates_dir:
|
||||||
|
description:
|
||||||
|
- templates_dir
|
||||||
|
type: str
|
||||||
|
default: '/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
author:
|
||||||
|
- Rabi Mishra (@ramishra)
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: Upload templates to plan
|
||||||
|
tripleo_templates_upload:
|
||||||
|
container: overcloud
|
||||||
|
templates_dir: '/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
def run_module():
|
||||||
|
result = dict(
|
||||||
|
success=False,
|
||||||
|
changed=False,
|
||||||
|
error="",
|
||||||
|
)
|
||||||
|
|
||||||
|
argument_spec = openstack_full_argument_spec(
|
||||||
|
**yaml.safe_load(DOCUMENTATION)['options']
|
||||||
|
)
|
||||||
|
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec,
|
||||||
|
supports_check_mode=False,
|
||||||
|
**openstack_module_kwargs()
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_object_client(session):
|
||||||
|
return swift_client.Connection(
|
||||||
|
session=session,
|
||||||
|
retries=10,
|
||||||
|
starting_backoff=3,
|
||||||
|
max_backoff=120)
|
||||||
|
|
||||||
|
try:
|
||||||
|
container = module.params.get('container')
|
||||||
|
templates_dir = module.params.get('templates_dir')
|
||||||
|
_, conn = openstack_cloud_from_module(module)
|
||||||
|
session = conn.session
|
||||||
|
|
||||||
|
swift = get_object_client(session)
|
||||||
|
template_utils.upload_templates_as_tarball(
|
||||||
|
swift, container, templates_dir)
|
||||||
|
result['success'] = True
|
||||||
|
result['changed'] = True
|
||||||
|
except Exception as err:
|
||||||
|
result['error'] = str(err)
|
||||||
|
result['msg'] = ("Error uploading templates for plan %s: %s" % (
|
||||||
|
container, err))
|
||||||
|
module.fail_json(**result)
|
||||||
|
|
||||||
|
# in the event of a successful module execution, you will want to
|
||||||
|
# simple AnsibleModule.exit_json(), passing the key/value results
|
||||||
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
run_module()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user