Skip to content
Snippets Groups Projects
  • SamYaple's avatar
    80b7266e
    Rename kolla_ansible to kolla_toolbox · 80b7266e
    SamYaple authored
    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
    80b7266e
    History
    Rename kolla_ansible to kolla_toolbox
    SamYaple authored
    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
kolla_zookeeper.py 1.95 KiB
#!/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()