aboutsummaryrefslogtreecommitdiff
path: root/kolla_ansible/cmd
diff options
context:
space:
mode:
authorJeffrey Zhang <zhang.lei.fly@gmail.com>2017-02-15 11:51:52 +0800
committerJeffrey Zhang <zhang.lei.fly@gmail.com>2017-02-15 16:34:51 +0800
commit177fbea79a1babdcd4e8230341380d373eef6df4 (patch)
tree0527ddbb7332a1c7aa5757cc66a2673d536e5443 /kolla_ansible/cmd
parent397d79c2968811e983f8b38054526a96181367e4 (diff)
downloadkolla-ansible-177fbea79a1babdcd4e8230341380d373eef6df4.tar.gz
kolla-ansible-177fbea79a1babdcd4e8230341380d373eef6df4.zip
Rename kolla namespace to kolla_ansible
* Rename kolla namespace to kolla_ansible * remove oslo.config.opts entry points which is uesless * delete useless tools/version-check.py script Change-Id: I005dd7223ff23afbb2ce8cbfd0ebec0969102798
Diffstat (limited to 'kolla_ansible/cmd')
-rw-r--r--kolla_ansible/cmd/__init__.py0
-rwxr-xr-xkolla_ansible/cmd/genpwd.py106
-rwxr-xr-xkolla_ansible/cmd/mergepwd.py39
3 files changed, 145 insertions, 0 deletions
diff --git a/kolla_ansible/cmd/__init__.py b/kolla_ansible/cmd/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/kolla_ansible/cmd/__init__.py
diff --git a/kolla_ansible/cmd/genpwd.py b/kolla_ansible/cmd/genpwd.py
new file mode 100755
index 000000000..11d15fbd8
--- /dev/null
+++ b/kolla_ansible/cmd/genpwd.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+
+# 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 argparse
+import hmac
+import os
+import random
+import string
+import sys
+
+from Crypto.PublicKey import RSA
+from hashlib import md5
+from oslo_utils import uuidutils
+import yaml
+
+# NOTE(SamYaple): Update the search path to prefer PROJECT_ROOT as the source
+# of packages to import if we are using local tools instead of
+# pip installed kolla tools
+PROJECT_ROOT = os.path.abspath(os.path.join(
+ os.path.dirname(os.path.realpath(__file__)), '../..'))
+if PROJECT_ROOT not in sys.path:
+ sys.path.insert(0, PROJECT_ROOT)
+
+
+def generate_RSA(bits=4096):
+ new_key = RSA.generate(bits, os.urandom)
+ private_key = new_key.exportKey("PEM")
+ public_key = new_key.publickey().exportKey("OpenSSH")
+ return private_key, public_key
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ '-p', '--passwords', type=str,
+ default=os.path.abspath('/etc/kolla/passwords.yml'),
+ help=('Path to the passwords yml file'))
+
+ args = parser.parse_args()
+ passwords_file = os.path.expanduser(args.passwords)
+
+ # These keys should be random uuids
+ uuid_keys = ['ceph_cluster_fsid', 'rbd_secret_uuid',
+ 'gnocchi_project_id', 'gnocchi_resource_id',
+ 'gnocchi_user_id', 'designate_pool_id',
+ 'karbor_openstack_infra_id']
+
+ # SSH key pair
+ ssh_keys = ['kolla_ssh_key', 'nova_ssh_key',
+ 'keystone_ssh_key', 'bifrost_ssh_key']
+
+ # If these keys are None, leave them as None
+ blank_keys = ['docker_registry_password']
+
+ # HMAC-MD5 keys
+ hmac_md5_keys = ['designate_rndc_key']
+
+ # length of password
+ length = 40
+
+ with open(passwords_file, 'r') as f:
+ passwords = yaml.safe_load(f.read())
+
+ for k, v in passwords.items():
+ if (k in ssh_keys and
+ (v is None
+ or v.get('public_key') is None
+ and v.get('private_key') is None)):
+ private_key, public_key = generate_RSA()
+ passwords[k] = {
+ 'private_key': private_key,
+ 'public_key': public_key
+ }
+ continue
+ if v is None:
+ if k in blank_keys and v is None:
+ continue
+ if k in uuid_keys:
+ passwords[k] = uuidutils.generate_uuid()
+ elif k in hmac_md5_keys:
+ passwords[k] = (hmac.new(
+ uuidutils.generate_uuid(), '', md5)
+ .digest().encode('base64')[:-1])
+ else:
+ passwords[k] = ''.join([
+ random.SystemRandom().choice(
+ string.ascii_letters + string.digits)
+ for n in range(length)
+ ])
+
+ with open(passwords_file, 'w') as f:
+ f.write(yaml.dump(passwords, default_flow_style=False))
+
+if __name__ == '__main__':
+ main()
diff --git a/kolla_ansible/cmd/mergepwd.py b/kolla_ansible/cmd/mergepwd.py
new file mode 100755
index 000000000..44053f8e1
--- /dev/null
+++ b/kolla_ansible/cmd/mergepwd.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+# 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 argparse
+import yaml
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--old", help="old password file", required=True)
+ parser.add_argument("--new", help="new password file", required=True)
+ parser.add_argument("--final", help="merged password file", required=True)
+ args = parser.parse_args()
+
+ with open(args.old, "r") as old_file:
+ old_passwords = yaml.safe_load(old_file)
+
+ with open(args.new, "r") as new_file:
+ new_passwords = yaml.safe_load(new_file)
+
+ new_passwords.update(old_passwords)
+
+ with open(args.final, "w") as destination:
+ yaml.dump(new_passwords, destination, default_flow_style=False)
+
+
+if __name__ == '__main__':
+ main()