diff options
author | Martin Schwenke <martin@meltin.net> | 2019-02-28 12:29:20 +1100 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2019-03-25 16:52:25 +1100 |
commit | 2ab28f1c6dd7892653929891ea5b55d54115d020 (patch) | |
tree | 78fac689b41c4e35bd539def63f5d285e28faa2d | |
parent | acab4ff108c902fec404582e9a6fb50cc81a2c04 (diff) | |
download | autocluster-2ab28f1c6dd7892653929891ea5b55d54115d020.tar.gz autocluster-2ab28f1c6dd7892653929891ea5b55d54115d020.tar.xz autocluster-2ab28f1c6dd7892653929891ea5b55d54115d020.zip |
Add host setup command
Signed-off-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-x | autocluster.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/autocluster.py b/autocluster.py index 3e9f553..f897e78 100755 --- a/autocluster.py +++ b/autocluster.py @@ -63,6 +63,8 @@ def usage(): ssh_config Install cluster SSH configuration in current account setup Perform configuration/setup of cluster nodes build Short for: destroy, generate create ssh_config setup + + host <platform> setup ''' % sys.argv[0]) @@ -704,6 +706,38 @@ def cluster_command(cluster, command): usage() +def get_platform_file(platform): + '''Return the name of the host setup file for platform''' + + return os.path.join(INSTALL_DIR, + 'ansible/host', + 'autocluster_setup_%s.yml' % platform) + + +def sanity_check_platform_name(platform): + '''Ensure that host platform is supported''' + + platform_file = get_platform_file(platform) + + if not os.access(platform_file, os.R_OK): + sys.exit('Host platform "%s" not supported' % platform) + + +def host_setup(platform): + '''Set up host machine for use with Autocluster''' + + announce('host', platform, 'setup') + + platform_file = get_platform_file(platform) + os.environ['ANSIBLE_RETRY_FILES_ENABLED'] = 'false' + args = ['ansible-playbook', platform_file] + + try: + subprocess.check_call(args) + except subprocess.CalledProcessError as err: + sys.exit('ERROR: host setup exited with %d' % err.returncode) + + def main(): '''Main autocluster command-line handling''' @@ -721,6 +755,18 @@ def main(): for command in sys.argv[3:]: cluster_command(cluster, command) + elif sys.argv[1] == 'host': + if len(sys.argv) < 4: + usage() + + platform = sys.argv[2] + + sanity_check_platform_name(platform) + + for command in sys.argv[3:]: + if command == 'setup': + host_setup(platform) + else: usage() |