3 # ============LICENSE_START==========================================
4 # ===================================================================
5 # Copyright (c) 2017 AT&T
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #============LICENSE_END============================================
20 # This tack will be triggered after VM created. It will check whether docker is up and running.
23 from cloudify import ctx
24 from cloudify.exceptions import OperationRetry
27 def check_command(command):
30 process = subprocess.Popen(
36 output, error = process.communicate()
38 ctx.logger.debug('command: {0} '.format(command))
39 ctx.logger.debug('output: {0} '.format(output))
40 ctx.logger.debug('error: {0} '.format(error))
41 ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
43 if process.returncode:
44 ctx.logger.error('Running `{0}` returns error.'.format(command))
50 def execute_command(_command):
52 ctx.logger.debug('_command {0}.'.format(_command))
55 'args': _command.split(),
56 'stdout': subprocess.PIPE,
57 'stderr': subprocess.PIPE
60 ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args))
62 process = subprocess.Popen(**subprocess_args)
63 output, error = process.communicate()
65 ctx.logger.debug('command: {0} '.format(_command))
66 ctx.logger.debug('error: {0} '.format(error))
67 ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
69 if process.returncode:
70 ctx.logger.error('Running `{0}` returns error.'.format(_command))
76 if __name__ == '__main__':
78 # Check if Docker PS works
79 docker = check_command('docker ps')
82 'Docker is not present on the system.')
83 ctx.logger.info('Docker is present on the system.')
85 # Next check if Cloud Init is running.
87 ps = execute_command('ps -ef')
88 for line in ps.split('\n'):
89 if '/usr/bin/python /usr/bin/cloud-init modules' in line:
91 'You provided a Cloud-init Cloud Config to configure instances. '
92 'Waiting for Cloud-init to complete.')
93 ctx.logger.info('Cloud-init finished.')