blob: 9cfa206b54350a481d021625f34b13b7b36c0a4a [file] [log] [blame]
earthmant5e1853a2017-08-04 09:02:48 +03001#!/usr/bin/env python
2
3import subprocess
4from cloudify import ctx
5from cloudify.state import ctx_parameters as inputs
6
7
8def execute_command(_command):
9
10 ctx.logger.debug('_command {0}.'.format(_command))
11
12 subprocess_args = {
13 'args': _command.split(),
14 'stdout': subprocess.PIPE,
15 'stderr': subprocess.PIPE
16 }
17
18 ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args))
19
20 process = subprocess.Popen(**subprocess_args)
21 output, error = process.communicate()
22
23 ctx.logger.debug('command: {0} '.format(_command))
24 ctx.logger.debug('output: {0} '.format(output))
25 ctx.logger.debug('error: {0} '.format(error))
26 ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
27
28 if process.returncode:
29 ctx.logger.error('Running `{0}` returns error.'.format(_command))
30 return False
31
32 return output
33
34
35if __name__ == '__main__':
36
37 join_command = inputs['join_command']
38 join_command = 'sudo {0} --skip-preflight-checks'.format(join_command)
39 execute_command(join_command)
40
41 # Install weave-related utils
42 execute_command('sudo curl -L git.io/weave -o /usr/local/bin/weave')
43 execute_command('sudo chmod a+x /usr/local/bin/weave')
44 execute_command('sudo curl -L git.io/scope -o /usr/local/bin/scope')
45 execute_command('sudo chmod a+x /usr/local/bin/scope')
46 execute_command('/usr/local/bin/scope launch')
47
48 hostname = execute_command('hostname')
49 ctx.instance.runtime_properties['hostname'] = hostname.rstrip('\n')