4 from cloudify import ctx
5 from cloudify.exceptions import OperationRetry
8 def check_command(command):
11 process = subprocess.Popen(
17 output, error = process.communicate()
19 ctx.logger.debug('command: {0} '.format(command))
20 ctx.logger.debug('output: {0} '.format(output))
21 ctx.logger.debug('error: {0} '.format(error))
22 ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
24 if process.returncode:
25 ctx.logger.error('Running `{0}` returns error.'.format(command))
31 def execute_command(_command):
33 ctx.logger.debug('_command {0}.'.format(_command))
36 'args': _command.split(),
37 'stdout': subprocess.PIPE,
38 'stderr': subprocess.PIPE
41 ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args))
43 process = subprocess.Popen(**subprocess_args)
44 output, error = process.communicate()
46 ctx.logger.debug('command: {0} '.format(_command))
47 ctx.logger.debug('output: {0} '.format(output))
48 ctx.logger.debug('error: {0} '.format(error))
49 ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
51 if process.returncode:
52 ctx.logger.error('Running `{0}` returns error.'.format(_command))
58 if __name__ == '__main__':
60 docker_command = 'docker ps'
62 if not check_command(docker_command):
63 raise OperationRetry('Waiting for docker to be installed.')
66 ps = execute_command('ps -ef')
67 for line in ps.split('\n'):
68 if '/usr/bin/python /usr/bin/cloud-init modules' in line:
69 ctx.logger.error('in line')
70 raise OperationRetry('Waiting for Cloud Init to finish.')
72 ctx.logger.info('Docker is ready and Cloud Init finished.')