[OOM-71] Message Router Kubernetes-Tosca Templates
Change-Id: I6f3afcea03a033a502b85aa7e7729b42e9e5dd4f
Signed-off-by: earthmant <trammell@cloudify.co>
diff --git a/cloudify/scripts/configure_node.py b/cloudify/scripts/configure_node.py
new file mode 100644
index 0000000..9cfa206
--- /dev/null
+++ b/cloudify/scripts/configure_node.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+import subprocess
+from cloudify import ctx
+from cloudify.state import ctx_parameters as inputs
+
+
+def execute_command(_command):
+
+ ctx.logger.debug('_command {0}.'.format(_command))
+
+ subprocess_args = {
+ 'args': _command.split(),
+ 'stdout': subprocess.PIPE,
+ 'stderr': subprocess.PIPE
+ }
+
+ ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args))
+
+ process = subprocess.Popen(**subprocess_args)
+ output, error = process.communicate()
+
+ ctx.logger.debug('command: {0} '.format(_command))
+ ctx.logger.debug('output: {0} '.format(output))
+ ctx.logger.debug('error: {0} '.format(error))
+ ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
+
+ if process.returncode:
+ ctx.logger.error('Running `{0}` returns error.'.format(_command))
+ return False
+
+ return output
+
+
+if __name__ == '__main__':
+
+ join_command = inputs['join_command']
+ join_command = 'sudo {0} --skip-preflight-checks'.format(join_command)
+ execute_command(join_command)
+
+ # Install weave-related utils
+ execute_command('sudo curl -L git.io/weave -o /usr/local/bin/weave')
+ execute_command('sudo chmod a+x /usr/local/bin/weave')
+ execute_command('sudo curl -L git.io/scope -o /usr/local/bin/scope')
+ execute_command('sudo chmod a+x /usr/local/bin/scope')
+ execute_command('/usr/local/bin/scope launch')
+
+ hostname = execute_command('hostname')
+ ctx.instance.runtime_properties['hostname'] = hostname.rstrip('\n')
diff --git a/cloudify/scripts/create.py b/cloudify/scripts/create.py
new file mode 100644
index 0000000..eb362a4
--- /dev/null
+++ b/cloudify/scripts/create.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+
+import subprocess
+from cloudify import ctx
+from cloudify.exceptions import OperationRetry
+
+
+def check_command(command):
+
+ try:
+ process = subprocess.Popen(
+ command.split()
+ )
+ except OSError:
+ return False
+
+ output, error = process.communicate()
+
+ ctx.logger.debug('command: {0} '.format(command))
+ ctx.logger.debug('output: {0} '.format(output))
+ ctx.logger.debug('error: {0} '.format(error))
+ ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
+
+ if process.returncode:
+ ctx.logger.error('Running `{0}` returns error.'.format(command))
+ return False
+
+ return True
+
+
+def execute_command(_command):
+
+ ctx.logger.debug('_command {0}.'.format(_command))
+
+ subprocess_args = {
+ 'args': _command.split(),
+ 'stdout': subprocess.PIPE,
+ 'stderr': subprocess.PIPE
+ }
+
+ ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args))
+
+ process = subprocess.Popen(**subprocess_args)
+ output, error = process.communicate()
+
+ ctx.logger.debug('command: {0} '.format(_command))
+ ctx.logger.debug('output: {0} '.format(output))
+ ctx.logger.debug('error: {0} '.format(error))
+ ctx.logger.debug('process.returncode: {0} '.format(process.returncode))
+
+ if process.returncode:
+ ctx.logger.error('Running `{0}` returns error.'.format(_command))
+ return False
+
+ return output
+
+
+if __name__ == '__main__':
+
+ docker_command = 'docker ps'
+
+ if not check_command(docker_command):
+ raise OperationRetry('Waiting for docker to be installed.')
+
+ finished = False
+ ps = execute_command('ps -ef')
+ for line in ps.split('\n'):
+ if '/usr/bin/python /usr/bin/cloud-init modules' in line:
+ ctx.logger.error('in line')
+ raise OperationRetry('Waiting for Cloud Init to finish.')
+
+ ctx.logger.info('Docker is ready and Cloud Init finished.')
diff --git a/cloudify/scripts/tasks.py b/cloudify/scripts/tasks.py
new file mode 100644
index 0000000..035a780
--- /dev/null
+++ b/cloudify/scripts/tasks.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+from fabric.api import run
+
+
+def label_node(labels, hostname):
+ if labels:
+ label_list = []
+ for key, value in labels.items():
+ label_pair_string = '%s=%s' % (key, value)
+ label_list.append(label_pair_string)
+ label_string = ' '.join(label_list)
+ command = 'kubectl label nodes %s %s' % (hostname, label_string)
+ run(command)
+
+
+def stop_node(hostname):
+ command = 'kubectl drain %s' % (hostname)
+ run(command)
+
+
+def delete_node(hostname):
+ command = 'kubectl delete no %s' % (hostname)
+ run(command)