From 80b7266ed1b10fb302a507d250d28a964ce14e49 Mon Sep 17 00:00:00 2001 From: SamYaple Date: Fri, 29 Jan 2016 16:40:54 +0000 Subject: Rename kolla_ansible to kolla_toolbox This change is needed for clarity. We have a kolla-ansible script. We have a kolla-mesos repo. We plan to have a kolla-ansible repo. Already we have had far too much confusion about whether we are talking about the container or the project. Naming this kolla-toolbox eliminates all of that confusion and its probably a bit more accurate of a name too. Closes-Bug: #1541053 Change-Id: I8fd1f49d5a22b36ede5b10f46b9fe02ddda9007e --- docker/kolla-ansible/Dockerfile.j2 | 62 ------------- docker/kolla-ansible/ansible.cfg | 2 - docker/kolla-ansible/find_disks.py | 115 ------------------------- docker/kolla-ansible/kolla_keystone_service.py | 86 ------------------ docker/kolla-ansible/kolla_keystone_user.py | 88 ------------------- docker/kolla-ansible/kolla_sanity.py | 63 -------------- docker/kolla-ansible/kolla_zookeeper.py | 66 -------------- docker/kolla-toolbox/Dockerfile.j2 | 62 +++++++++++++ docker/kolla-toolbox/ansible.cfg | 2 + docker/kolla-toolbox/find_disks.py | 115 +++++++++++++++++++++++++ docker/kolla-toolbox/kolla_keystone_service.py | 86 ++++++++++++++++++ docker/kolla-toolbox/kolla_keystone_user.py | 88 +++++++++++++++++++ docker/kolla-toolbox/kolla_sanity.py | 63 ++++++++++++++ docker/kolla-toolbox/kolla_zookeeper.py | 66 ++++++++++++++ 14 files changed, 482 insertions(+), 482 deletions(-) delete mode 100644 docker/kolla-ansible/Dockerfile.j2 delete mode 100644 docker/kolla-ansible/ansible.cfg delete mode 100644 docker/kolla-ansible/find_disks.py delete mode 100644 docker/kolla-ansible/kolla_keystone_service.py delete mode 100644 docker/kolla-ansible/kolla_keystone_user.py delete mode 100644 docker/kolla-ansible/kolla_sanity.py delete mode 100644 docker/kolla-ansible/kolla_zookeeper.py create mode 100644 docker/kolla-toolbox/Dockerfile.j2 create mode 100644 docker/kolla-toolbox/ansible.cfg create mode 100644 docker/kolla-toolbox/find_disks.py create mode 100644 docker/kolla-toolbox/kolla_keystone_service.py create mode 100644 docker/kolla-toolbox/kolla_keystone_user.py create mode 100644 docker/kolla-toolbox/kolla_sanity.py create mode 100644 docker/kolla-toolbox/kolla_zookeeper.py (limited to 'docker') diff --git a/docker/kolla-ansible/Dockerfile.j2 b/docker/kolla-ansible/Dockerfile.j2 deleted file mode 100644 index fe80db693..000000000 --- a/docker/kolla-ansible/Dockerfile.j2 +++ /dev/null @@ -1,62 +0,0 @@ -FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }} -MAINTAINER {{ maintainer }} - -{% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] %} - -# TODO(mandre) remove MariaDB-shared once Percona has fixed its packaging issue -RUN yum -y install \ - gcc \ - git \ - libffi-devel \ - libxml2-devel \ - libxslt-devel \ - mariadb-devel \ - mariadb-libs \ - MariaDB-shared \ - openssl-devel \ - python-devel \ - openssh-clients \ - && yum clean all - -{% elif base_distro in ['ubuntu', 'debian'] %} - -RUN apt-get -y --no-install-recommends install \ - build-essential \ - ca-certificates \ - git \ - libffi-dev \ - libmariadbclient-dev \ - libssl-dev \ - libxslt1-dev \ - python-dev \ - && apt-get clean - -{% endif %} - -RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ - && python get-pip.py \ - && rm get-pip.py \ - && pip --no-cache-dir install --upgrade wheel \ - && pip --no-cache-dir install \ - MySQL-python \ - os-client-config==1.13.1 \ - pyudev \ - shade==1.3.0 - -RUN git clone --depth 1 -b v2.0.0-0.7.rc2 https://github.com/ansible/ansible.git \ - && cd ansible \ - && git submodule update --init --recursive \ - && pip --no-cache-dir install . - -RUN mkdir -p /etc/ansible /usr/share/ansible /home/ansible \ - && echo 'localhost ansible_connection=local' > /etc/ansible/hosts \ - && useradd --user-group ansible --groups kolla - -COPY find_disks.py kolla_keystone_service.py kolla_keystone_user.py kolla_sanity.py kolla_zookeeper.py /usr/share/ansible/ -COPY ansible.cfg /home/ansible/.ansible.cfg - -CMD ["/bin/sleep", "infinity"] - -{{ include_footer }} - -USER ansible diff --git a/docker/kolla-ansible/ansible.cfg b/docker/kolla-ansible/ansible.cfg deleted file mode 100644 index c45b65ae1..000000000 --- a/docker/kolla-ansible/ansible.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[defaults] -remote_tmp = /tmp diff --git a/docker/kolla-ansible/find_disks.py b/docker/kolla-ansible/find_disks.py deleted file mode 100644 index 6ebf2b6a2..000000000 --- a/docker/kolla-ansible/find_disks.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Sam Yaple -# -# 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. - -# This module has been relicensed from the source below: -# https://github.com/SamYaple/yaodu/blob/master/ansible/library/ceph_osd_list - -DOCUMENTATION = ''' ---- -module: find_disks -short_description: Return list of devices containing a specfied name or label -description: - - This will return a list of all devices with either GPT partition name - or filesystem label of the name specified. -options: - match_mode: - description: - - Label match mode, either strict or prefix - default: 'strict' - required: False - choices: [ "strict", "prefix" ] - type: str - name: - description: - - Partition name or filesystem label - required: True - type: str - aliases: [ 'partition_name' ] -author: Sam Yaple -''' - -EXAMPLES = ''' -- hosts: ceph-osd - tasks: - - name: Return all valid formated devices with the name KOLLA_CEPH_OSD - find_disks: - name: 'KOLLA_CEPH_OSD' - register: osds - -- hosts: swift-object-server - tasks: - - name: Return all valid devices with the name KOLLA_SWIFT - find_disks: - name: 'KOLLA_SWIFT' - register: swift_disks - -- hosts: swift-object-server - tasks: - - name: Return all valid devices with wildcard name 'swift_d*' - find_disks: - name: 'swift_d' match_mode: 'prefix' - register: swift_disks -''' - -import json -import pyudev - - -def main(): - argument_spec = dict( - match_mode=dict(required=False, choices=['strict', 'prefix'], - default='strict'), - name=dict(aliases=['partition_name'], required=True, type='str') - ) - module = AnsibleModule(argument_spec) - match_mode = module.params.get('match_mode') - name = module.params.get('name') - - def is_dev_matched_by_name(dev, name): - if dev.get('DEVTYPE', '') == 'partition': - dev_name = dev.get('ID_PART_ENTRY_NAME', '') - else: - dev_name = dev.get('ID_FS_LABEL', '') - - if match_mode == 'strict': - return dev_name == name - elif match_mode == 'prefix': - return dev_name.startswith(name) - else: - return False - - try: - ret = list() - ct = pyudev.Context() - for dev in ct.list_devices(subsystem='block'): - if is_dev_matched_by_name(dev, name): - fs_uuid = dev.get('ID_FS_UUID', '') - fs_label = dev.get('ID_FS_LABEL', '') - if dev.get('DEVTYPE', '') == 'partition': - device_node = dev.find_parent('block').device_node - else: - device_node = dev.device_node - ret.append({'device': device_node, - 'fs_uuid': fs_uuid, - 'fs_label': fs_label}) - module.exit_json(disks=json.dumps(ret)) - except Exception as e: - module.exit_json(failed=True, msg=repr(e)) - -# import module snippets -from ansible.module_utils.basic import * # noqa -if __name__ == '__main__': - main() diff --git a/docker/kolla-ansible/kolla_keystone_service.py b/docker/kolla-ansible/kolla_keystone_service.py deleted file mode 100644 index 7c03d00e1..000000000 --- a/docker/kolla-ansible/kolla_keystone_service.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Sam Yaple -# -# 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. - -# This file is a barebones file needed to file a gap until Ansible 2.0. No -# error checking, no deletions, no updates. Idempotent creation only. - -# If you look closely, you will see we arent _really_ using the shade module -# we just use it to slightly abstract the authentication model. As patches land -# in upstream shade we will be able to use more of the shade module. Until then -# if we want to be 'stable' we really need to be using it as a passthrough - -import shade - - -def main(): - argument_spec = openstack_full_argument_spec( - description=dict(required=True, type='str'), - service_name=dict(required=True, type='str'), - service_type=dict(required=True, type='str'), - admin_url=dict(required=True, type='str'), - internal_url=dict(required=True, type='str'), - public_url=dict(required=True, type='str'), - endpoint_region=dict(required=True, type='str') - ) - module = AnsibleModule(argument_spec) - - try: - description = module.params.pop('description') - service_name = module.params.pop('service_name') - service_type = module.params.pop('service_type') - admin_url = module.params.pop('admin_url') - internal_url = module.params.pop('internal_url') - public_url = module.params.pop('public_url') - endpoint_region = module.params.pop('endpoint_region') - - changed = False - service = None - endpoint = None - - cloud = shade.operator_cloud(**module.params) - - for _service in cloud.keystone_client.services.list(): - if _service.type == service_type: - service = _service - - if service is not None: - for _endpoint in cloud.keystone_client.endpoints.list(): - if _endpoint.service_id == service.id: - endpoint = _endpoint - else: - service = cloud.keystone_client.services.create( - name=service_name, - service_type=service_type, - description=description) - - if endpoint is None: - changed = True - cloud.keystone_client.endpoints.create( - service_id=service.id, - adminurl=admin_url, - internalurl=internal_url, - publicurl=public_url, - region=endpoint_region) - - module.exit_json(changed=changed) - except Exception as e: - module.exit_json(failed=True, changed=True, msg=e) - -# import module snippets -from ansible.module_utils.basic import * # noqa -from ansible.module_utils.openstack import * # noqa -if __name__ == '__main__': - main() diff --git a/docker/kolla-ansible/kolla_keystone_user.py b/docker/kolla-ansible/kolla_keystone_user.py deleted file mode 100644 index 2d1a739c5..000000000 --- a/docker/kolla-ansible/kolla_keystone_user.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Sam Yaple -# -# 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. - -# This file is a barebones file needed to file a gap until Ansible 2.0. No -# error checking, no deletions, no updates. Idempotent creation only. - -# If you look closely, you will see we arent _really_ using the shade module -# we just use it to slightly abstract the authentication model. As patches land -# in upstream shade we will be able to use more of the shade module. Until then -# if we want to be 'stable' we really need to be using it as a passthrough - -import shade - - -def main(): - argument_spec = openstack_full_argument_spec( - password=dict(required=True, type='str'), - project=dict(required=True, type='str'), - role=dict(required=True, type='str'), - user=dict(required=True, type='str') - ) - module = AnsibleModule(argument_spec) - - try: - password = module.params.pop('password') - project_name = module.params.pop('project') - role_name = module.params.pop('role') - user_name = module.params.pop('user') - - changed = False - project = None - role = None - user = None - - cloud = shade.operator_cloud(**module.params) - - for _project in cloud.keystone_client.tenants.list(): - if _project.name == project_name: - project = _project - - for _role in cloud.keystone_client.roles.list(): - if _role.name == role_name: - role = _role - - for _user in cloud.keystone_client.users.list(): - if _user.name == user_name: - user = _user - - if not project: - changed = True - project = cloud.keystone_client.tenants.create( - tenant_name=project_name) - - if not role: - changed = True - role = cloud.keystone_client.roles.create(name=role_name) - - if not user: - changed = True - user = cloud.keystone_client.users.create(name=user_name, - password=password, - tenant_id=project.id) - cloud.keystone_client.roles.add_user_role(role=role.id, - user=user.id, - tenant=project.id) - - module.exit_json(changed=changed) - except Exception as e: - module.exit_json(failed=True, changed=True, msg=e) - -# import module snippets -from ansible.module_utils.basic import * # noqa -from ansible.module_utils.openstack import * # noqa -if __name__ == '__main__': - main() diff --git a/docker/kolla-ansible/kolla_sanity.py b/docker/kolla-ansible/kolla_sanity.py deleted file mode 100644 index 7f4eea9fc..000000000 --- a/docker/kolla-ansible/kolla_sanity.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Intel corporation -# -# 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. - -# This file is a barebones file needed to file a gap until Ansible 2.0. No -# error checking, no deletions, no updates. Idempotent creation only. - -# If you look closely, you will see we arent _really_ using the shade module -# we just use it to slightly abstract the authentication model. As patches land -# in upstream shade we will be able to use more of the shade module. Until then -# if we want to be 'stable' we really need to be using it as a passthrough - -import shade - - -class SanityChecks(object): - @staticmethod - def keystone(cloud): - [tenant for tenant in cloud.keystone_client.tenants.list()] - - @staticmethod - def glance(cloud): - [image for image in cloud.glance_client.images.list()] - - -def main(): - module = AnsibleModule( - argument_spec=openstack_full_argument_spec( - password=dict(required=True, type='str'), - project=dict(required=True, type='str'), - role=dict(required=True, type='str'), - user=dict(required=True, type='str'), - service=dict(required=True, type='str'), - ) - ) - - try: - changed = True - cloud = shade.operator_cloud(**module.params) - - getattr(SanityChecks, module.params.pop("service"))(cloud) - - module.exit_json(changed=changed) - except Exception as e: - module.exit_json(failed=True, changed=True, msg=e) - -# import module snippets -from ansible.module_utils.basic import * # noqa -from ansible.module_utils.openstack import * # noqa -if __name__ == '__main__': - main() diff --git a/docker/kolla-ansible/kolla_zookeeper.py b/docker/kolla-ansible/kolla_zookeeper.py deleted file mode 100644 index d6326f46a..000000000 --- a/docker/kolla-ansible/kolla_zookeeper.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Mirantis, Inc. -# -# 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. - -import contextlib - -import kazoo.client -import kazoo.exceptions - - -@contextlib.contextmanager -def zk_connection(zk_host, zk_port): - zk = kazoo.client.KazooClient(hosts='{}:{}'.format(zk_host, zk_port)) - zk.start() - yield zk - zk.stop() - - -def main(): - module = AnsibleModule( - argument_spec=dict( - zk_host=dict(required=True, type='str'), - zk_port=dict(required=True, type='str'), - path=dict(required=True, type='str'), - value=dict(required=False, default=None, type='str') - ) - ) - - try: - zk_host = module.params.pop('zk_host') - zk_port = module.params.pop('zk_port') - path = module.params.pop('path') - value = module.params.pop('value') - - changed = False - with zk_connection(zk_host, zk_port) as zk: - try: - zk.get(path) - except kazoo.exceptions.NoNodeError: - if value is None: - zk.create(path, makepath=True) - else: - zk.create(path, value=value.encode(), makepath=True) - changed = True - - module.exit_json(changed=changed) - except Exception as e: - module.exit_json(failed=True, changed=True, msg=e) - - -# import module snippets -from ansible.module_utils.basic import * # noqa -if __name__ == '__main__': - main() diff --git a/docker/kolla-toolbox/Dockerfile.j2 b/docker/kolla-toolbox/Dockerfile.j2 new file mode 100644 index 000000000..fe80db693 --- /dev/null +++ b/docker/kolla-toolbox/Dockerfile.j2 @@ -0,0 +1,62 @@ +FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }} +MAINTAINER {{ maintainer }} + +{% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] %} + +# TODO(mandre) remove MariaDB-shared once Percona has fixed its packaging issue +RUN yum -y install \ + gcc \ + git \ + libffi-devel \ + libxml2-devel \ + libxslt-devel \ + mariadb-devel \ + mariadb-libs \ + MariaDB-shared \ + openssl-devel \ + python-devel \ + openssh-clients \ + && yum clean all + +{% elif base_distro in ['ubuntu', 'debian'] %} + +RUN apt-get -y --no-install-recommends install \ + build-essential \ + ca-certificates \ + git \ + libffi-dev \ + libmariadbclient-dev \ + libssl-dev \ + libxslt1-dev \ + python-dev \ + && apt-get clean + +{% endif %} + +RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ + && python get-pip.py \ + && rm get-pip.py \ + && pip --no-cache-dir install --upgrade wheel \ + && pip --no-cache-dir install \ + MySQL-python \ + os-client-config==1.13.1 \ + pyudev \ + shade==1.3.0 + +RUN git clone --depth 1 -b v2.0.0-0.7.rc2 https://github.com/ansible/ansible.git \ + && cd ansible \ + && git submodule update --init --recursive \ + && pip --no-cache-dir install . + +RUN mkdir -p /etc/ansible /usr/share/ansible /home/ansible \ + && echo 'localhost ansible_connection=local' > /etc/ansible/hosts \ + && useradd --user-group ansible --groups kolla + +COPY find_disks.py kolla_keystone_service.py kolla_keystone_user.py kolla_sanity.py kolla_zookeeper.py /usr/share/ansible/ +COPY ansible.cfg /home/ansible/.ansible.cfg + +CMD ["/bin/sleep", "infinity"] + +{{ include_footer }} + +USER ansible diff --git a/docker/kolla-toolbox/ansible.cfg b/docker/kolla-toolbox/ansible.cfg new file mode 100644 index 000000000..c45b65ae1 --- /dev/null +++ b/docker/kolla-toolbox/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +remote_tmp = /tmp diff --git a/docker/kolla-toolbox/find_disks.py b/docker/kolla-toolbox/find_disks.py new file mode 100644 index 000000000..6ebf2b6a2 --- /dev/null +++ b/docker/kolla-toolbox/find_disks.py @@ -0,0 +1,115 @@ +#!/usr/bin/python + +# Copyright 2015 Sam Yaple +# +# 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. + +# This module has been relicensed from the source below: +# https://github.com/SamYaple/yaodu/blob/master/ansible/library/ceph_osd_list + +DOCUMENTATION = ''' +--- +module: find_disks +short_description: Return list of devices containing a specfied name or label +description: + - This will return a list of all devices with either GPT partition name + or filesystem label of the name specified. +options: + match_mode: + description: + - Label match mode, either strict or prefix + default: 'strict' + required: False + choices: [ "strict", "prefix" ] + type: str + name: + description: + - Partition name or filesystem label + required: True + type: str + aliases: [ 'partition_name' ] +author: Sam Yaple +''' + +EXAMPLES = ''' +- hosts: ceph-osd + tasks: + - name: Return all valid formated devices with the name KOLLA_CEPH_OSD + find_disks: + name: 'KOLLA_CEPH_OSD' + register: osds + +- hosts: swift-object-server + tasks: + - name: Return all valid devices with the name KOLLA_SWIFT + find_disks: + name: 'KOLLA_SWIFT' + register: swift_disks + +- hosts: swift-object-server + tasks: + - name: Return all valid devices with wildcard name 'swift_d*' + find_disks: + name: 'swift_d' match_mode: 'prefix' + register: swift_disks +''' + +import json +import pyudev + + +def main(): + argument_spec = dict( + match_mode=dict(required=False, choices=['strict', 'prefix'], + default='strict'), + name=dict(aliases=['partition_name'], required=True, type='str') + ) + module = AnsibleModule(argument_spec) + match_mode = module.params.get('match_mode') + name = module.params.get('name') + + def is_dev_matched_by_name(dev, name): + if dev.get('DEVTYPE', '') == 'partition': + dev_name = dev.get('ID_PART_ENTRY_NAME', '') + else: + dev_name = dev.get('ID_FS_LABEL', '') + + if match_mode == 'strict': + return dev_name == name + elif match_mode == 'prefix': + return dev_name.startswith(name) + else: + return False + + try: + ret = list() + ct = pyudev.Context() + for dev in ct.list_devices(subsystem='block'): + if is_dev_matched_by_name(dev, name): + fs_uuid = dev.get('ID_FS_UUID', '') + fs_label = dev.get('ID_FS_LABEL', '') + if dev.get('DEVTYPE', '') == 'partition': + device_node = dev.find_parent('block').device_node + else: + device_node = dev.device_node + ret.append({'device': device_node, + 'fs_uuid': fs_uuid, + 'fs_label': fs_label}) + module.exit_json(disks=json.dumps(ret)) + except Exception as e: + module.exit_json(failed=True, msg=repr(e)) + +# import module snippets +from ansible.module_utils.basic import * # noqa +if __name__ == '__main__': + main() diff --git a/docker/kolla-toolbox/kolla_keystone_service.py b/docker/kolla-toolbox/kolla_keystone_service.py new file mode 100644 index 000000000..7c03d00e1 --- /dev/null +++ b/docker/kolla-toolbox/kolla_keystone_service.py @@ -0,0 +1,86 @@ +#!/usr/bin/python + +# Copyright 2015 Sam Yaple +# +# 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. + +# This file is a barebones file needed to file a gap until Ansible 2.0. No +# error checking, no deletions, no updates. Idempotent creation only. + +# If you look closely, you will see we arent _really_ using the shade module +# we just use it to slightly abstract the authentication model. As patches land +# in upstream shade we will be able to use more of the shade module. Until then +# if we want to be 'stable' we really need to be using it as a passthrough + +import shade + + +def main(): + argument_spec = openstack_full_argument_spec( + description=dict(required=True, type='str'), + service_name=dict(required=True, type='str'), + service_type=dict(required=True, type='str'), + admin_url=dict(required=True, type='str'), + internal_url=dict(required=True, type='str'), + public_url=dict(required=True, type='str'), + endpoint_region=dict(required=True, type='str') + ) + module = AnsibleModule(argument_spec) + + try: + description = module.params.pop('description') + service_name = module.params.pop('service_name') + service_type = module.params.pop('service_type') + admin_url = module.params.pop('admin_url') + internal_url = module.params.pop('internal_url') + public_url = module.params.pop('public_url') + endpoint_region = module.params.pop('endpoint_region') + + changed = False + service = None + endpoint = None + + cloud = shade.operator_cloud(**module.params) + + for _service in cloud.keystone_client.services.list(): + if _service.type == service_type: + service = _service + + if service is not None: + for _endpoint in cloud.keystone_client.endpoints.list(): + if _endpoint.service_id == service.id: + endpoint = _endpoint + else: + service = cloud.keystone_client.services.create( + name=service_name, + service_type=service_type, + description=description) + + if endpoint is None: + changed = True + cloud.keystone_client.endpoints.create( + service_id=service.id, + adminurl=admin_url, + internalurl=internal_url, + publicurl=public_url, + region=endpoint_region) + + module.exit_json(changed=changed) + except Exception as e: + module.exit_json(failed=True, changed=True, msg=e) + +# import module snippets +from ansible.module_utils.basic import * # noqa +from ansible.module_utils.openstack import * # noqa +if __name__ == '__main__': + main() diff --git a/docker/kolla-toolbox/kolla_keystone_user.py b/docker/kolla-toolbox/kolla_keystone_user.py new file mode 100644 index 000000000..2d1a739c5 --- /dev/null +++ b/docker/kolla-toolbox/kolla_keystone_user.py @@ -0,0 +1,88 @@ +#!/usr/bin/python + +# Copyright 2015 Sam Yaple +# +# 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. + +# This file is a barebones file needed to file a gap until Ansible 2.0. No +# error checking, no deletions, no updates. Idempotent creation only. + +# If you look closely, you will see we arent _really_ using the shade module +# we just use it to slightly abstract the authentication model. As patches land +# in upstream shade we will be able to use more of the shade module. Until then +# if we want to be 'stable' we really need to be using it as a passthrough + +import shade + + +def main(): + argument_spec = openstack_full_argument_spec( + password=dict(required=True, type='str'), + project=dict(required=True, type='str'), + role=dict(required=True, type='str'), + user=dict(required=True, type='str') + ) + module = AnsibleModule(argument_spec) + + try: + password = module.params.pop('password') + project_name = module.params.pop('project') + role_name = module.params.pop('role') + user_name = module.params.pop('user') + + changed = False + project = None + role = None + user = None + + cloud = shade.operator_cloud(**module.params) + + for _project in cloud.keystone_client.tenants.list(): + if _project.name == project_name: + project = _project + + for _role in cloud.keystone_client.roles.list(): + if _role.name == role_name: + role = _role + + for _user in cloud.keystone_client.users.list(): + if _user.name == user_name: + user = _user + + if not project: + changed = True + project = cloud.keystone_client.tenants.create( + tenant_name=project_name) + + if not role: + changed = True + role = cloud.keystone_client.roles.create(name=role_name) + + if not user: + changed = True + user = cloud.keystone_client.users.create(name=user_name, + password=password, + tenant_id=project.id) + cloud.keystone_client.roles.add_user_role(role=role.id, + user=user.id, + tenant=project.id) + + module.exit_json(changed=changed) + except Exception as e: + module.exit_json(failed=True, changed=True, msg=e) + +# import module snippets +from ansible.module_utils.basic import * # noqa +from ansible.module_utils.openstack import * # noqa +if __name__ == '__main__': + main() diff --git a/docker/kolla-toolbox/kolla_sanity.py b/docker/kolla-toolbox/kolla_sanity.py new file mode 100644 index 000000000..7f4eea9fc --- /dev/null +++ b/docker/kolla-toolbox/kolla_sanity.py @@ -0,0 +1,63 @@ +#!/usr/bin/python + +# Copyright 2015 Intel corporation +# +# 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. + +# This file is a barebones file needed to file a gap until Ansible 2.0. No +# error checking, no deletions, no updates. Idempotent creation only. + +# If you look closely, you will see we arent _really_ using the shade module +# we just use it to slightly abstract the authentication model. As patches land +# in upstream shade we will be able to use more of the shade module. Until then +# if we want to be 'stable' we really need to be using it as a passthrough + +import shade + + +class SanityChecks(object): + @staticmethod + def keystone(cloud): + [tenant for tenant in cloud.keystone_client.tenants.list()] + + @staticmethod + def glance(cloud): + [image for image in cloud.glance_client.images.list()] + + +def main(): + module = AnsibleModule( + argument_spec=openstack_full_argument_spec( + password=dict(required=True, type='str'), + project=dict(required=True, type='str'), + role=dict(required=True, type='str'), + user=dict(required=True, type='str'), + service=dict(required=True, type='str'), + ) + ) + + try: + changed = True + cloud = shade.operator_cloud(**module.params) + + getattr(SanityChecks, module.params.pop("service"))(cloud) + + module.exit_json(changed=changed) + except Exception as e: + module.exit_json(failed=True, changed=True, msg=e) + +# import module snippets +from ansible.module_utils.basic import * # noqa +from ansible.module_utils.openstack import * # noqa +if __name__ == '__main__': + main() diff --git a/docker/kolla-toolbox/kolla_zookeeper.py b/docker/kolla-toolbox/kolla_zookeeper.py new file mode 100644 index 000000000..d6326f46a --- /dev/null +++ b/docker/kolla-toolbox/kolla_zookeeper.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +# Copyright 2015 Mirantis, Inc. +# +# 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. + +import contextlib + +import kazoo.client +import kazoo.exceptions + + +@contextlib.contextmanager +def zk_connection(zk_host, zk_port): + zk = kazoo.client.KazooClient(hosts='{}:{}'.format(zk_host, zk_port)) + zk.start() + yield zk + zk.stop() + + +def main(): + module = AnsibleModule( + argument_spec=dict( + zk_host=dict(required=True, type='str'), + zk_port=dict(required=True, type='str'), + path=dict(required=True, type='str'), + value=dict(required=False, default=None, type='str') + ) + ) + + try: + zk_host = module.params.pop('zk_host') + zk_port = module.params.pop('zk_port') + path = module.params.pop('path') + value = module.params.pop('value') + + changed = False + with zk_connection(zk_host, zk_port) as zk: + try: + zk.get(path) + except kazoo.exceptions.NoNodeError: + if value is None: + zk.create(path, makepath=True) + else: + zk.create(path, value=value.encode(), makepath=True) + changed = True + + module.exit_json(changed=changed) + except Exception as e: + module.exit_json(failed=True, changed=True, msg=e) + + +# import module snippets +from ansible.module_utils.basic import * # noqa +if __name__ == '__main__': + main() -- cgit v1.2.3