aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Rostecki <mrostecki@mirantis.com>2015-11-12 08:17:53 +0100
committerMichal Rostecki <mrostecki@mirantis.com>2015-11-13 19:39:07 +0100
commit1dfb79111690a43fbf780119c153e096be9c122e (patch)
treeff870ed36ffde836fcd8219c7b9ee243be3c336d
parentb6212875d3c40ad10f7c599987559fac30248cec (diff)
downloadkolla-1dfb79111690a43fbf780119c153e096be9c122e.tar.gz
kolla-1dfb79111690a43fbf780119c153e096be9c122e.zip
Add ZooKeeper support in kolla-ansible
In kolla-mesos, ZK will be used for storing information about actions done in bootstrap. Change-Id: Id7067a493b457cf7b73eb007852df7b13f4363b3 Partially-Implements: blueprint zookeeper
-rw-r--r--docker/kolla-ansible/kolla_zookeeper.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/docker/kolla-ansible/kolla_zookeeper.py b/docker/kolla-ansible/kolla_zookeeper.py
new file mode 100644
index 000000000..da692605a
--- /dev/null
+++ b/docker/kolla-ansible/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
+
+
+@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)
+ else:
+ zk.create(path, value=value.encode())
+ 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 *
+
+if __name__ == '__main__':
+ main()