aboutsummaryrefslogtreecommitdiff
path: root/kolla
diff options
context:
space:
mode:
authorSamYaple <sam@yaple.net>2016-03-16 21:45:25 +0000
committerSam Yaple <sam@yaple.net>2016-03-21 17:02:23 +0000
commitf03e06e09bc486a1a26d5642cce278d7dbb7bd92 (patch)
treeee9393a00f36c0c1004db6532a56f41a5e61bb9b /kolla
parentff3095f56ec4ea7a60c044dffe048aaedbfaafe2 (diff)
downloadkolla-f03e06e09bc486a1a26d5642cce278d7dbb7bd92.tar.gz
kolla-f03e06e09bc486a1a26d5642cce278d7dbb7bd92.zip
Add generate_passwords.py to generate passwords
As with all tools, this is a first pass at the generation. Perhaps we even want to move this into kolla/kolla/cmd and be generated with tox itself in the future. This tool, when run, will only populate empty fields that have no values meaning that it is safe to run repeatedly on the same file. Of note, there is no way to preserve comments in the file after it has been processed by the yaml parser in python. Comments and sections will remain in the passwords.yml template for additional documentation if the user wishes to populate the file themselves. Use SystemRandom and clean up the docs a bit to not use pronouns. Co-Authored-By: Steven Dake <stdake@cisco.com> Closes-Bug: #1559266 Change-Id: I2932d592df8871f1b7811059206d0b4d0553a687
Diffstat (limited to 'kolla')
-rwxr-xr-xkolla/cmd/genpwd.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/kolla/cmd/genpwd.py b/kolla/cmd/genpwd.py
new file mode 100755
index 000000000..728dd458b
--- /dev/null
+++ b/kolla/cmd/genpwd.py
@@ -0,0 +1,51 @@
+#!/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 random
+import string
+import uuid
+import yaml
+
+
+def main():
+ # These keys should be random uuids
+ uuid_keys = ['ceph_cluster_fsid', 'rbd_secret_uuid']
+
+ # If these keys are None, leave them as None
+ blank_keys = ['docker_registry_password']
+
+ # length of password
+ length = 40
+
+ with open('/etc/kolla/passwords.yml', 'r') as f:
+ passwords = yaml.load(f.read())
+
+ for k, v in passwords.items():
+ if v is None:
+ if k in blank_keys and v is None:
+ continue
+ if k in uuid_keys:
+ passwords[k] = str(uuid.uuid4())
+ else:
+ passwords[k] = ''.join([
+ random.SystemRandom().choice(
+ string.ascii_letters + string.digits)
+ for n in range(length)
+ ])
+
+ with open('/etc/kolla/passwords.yml', 'w') as f:
+ f.write(yaml.dump(passwords, default_flow_style=False))
+
+if __name__ == '__main__':
+ main()