4 from cloudify import ctx
5 from cloudify.state import ctx_parameters as inputs
8 def execute_command(_command):
10 ctx.logger.debug('_command {0}.'.format(_command))
13 'args': _command.split(),
14 'stdout': subprocess.PIPE,
15 'stderr': subprocess.PIPE
18 ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args))
20 process = subprocess.Popen(**subprocess_args)
21 output, error = process.communicate()
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))
28 if process.returncode:
29 ctx.logger.error('Running `{0}` returns error.'.format(_command))
35 if __name__ == '__main__':
37 join_command = inputs['join_command']
38 join_command = 'sudo {0} --skip-preflight-checks'.format(join_command)
39 execute_command(join_command)
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')
48 hostname = execute_command('hostname')
49 ctx.instance.runtime_properties['hostname'] = hostname.rstrip('\n')