Add host setup command
authorMartin Schwenke <martin@meltin.net>
Thu, 28 Feb 2019 01:29:20 +0000 (12:29 +1100)
committerMartin Schwenke <martin@meltin.net>
Mon, 25 Mar 2019 05:52:25 +0000 (16:52 +1100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
autocluster.py

index 3e9f5536604e76c5d7325f92c093fd18e0e1d6c5..f897e781583a10011b3120b8ff0929c4b5b0f9a1 100755 (executable)
@@ -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()