Created
February 1, 2018 04:43
-
-
Save jason-kane/50a1ae98f5f1c5431004fb982fd14819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
tnemyolped <deployment name> | |
""" | |
import docopt | |
import sh | |
import sys | |
import yaml | |
import os | |
DEPLOYMENT = "rabbitmq" | |
def main(): | |
# args = docopt.parse(__doc__) | |
args = { | |
"--deployment": DEPLOYMENT | |
} | |
# list manifests for the given deployment | |
manifests_raw = sh.gcloud( | |
"deployment-manager", | |
"manifests", | |
"list", | |
"--deployment", args['--deployment'], | |
"--simple-list" | |
) | |
manifests = manifests_raw.split() | |
if len(manifests) > 1: | |
print("I don't know how to handle multiple manifests. Sorry.") | |
sys.exit(1) | |
# run gcloud to pull the deployment jinja | |
our_manifest = sh.gcloud( | |
"deployment-manager", | |
"manifests", | |
"describe", | |
"--deployment", args['--deployment'], | |
manifests[0] | |
) | |
with open(manifests[0] + ".jinja", "w") as h: | |
h.write(our_manifest.stdout) | |
parsed_manifest = yaml.load(our_manifest.stdout) | |
# parse it to extract files/directories into the cwd | |
for manifest_import in parsed_manifest["imports"]: | |
print('Working on %s' % manifest_import['name']) | |
import_dir = os.path.dirname(manifest_import['name']) | |
if import_dir and not os.path.isdir(import_dir): | |
print('Creating %s' % import_dir) | |
os.makedirs(import_dir) | |
with open(manifest_import['name'], 'w') as h: | |
h.write(manifest_import['content']) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment