Commit cb7e459e authored by Spiros Koulouzis's avatar Spiros Koulouzis

add ubunut 16.04

parent bab2b8a9
#! /usr/bin/env python # ! /usr/bin/env python
# Copyright 2017 --Yang Hu-- # Copyright 2017 --Yang Hu--
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
__author__ = 'Yang Hu' __author__ = 'Yang Hu'
...@@ -21,6 +21,7 @@ from vm_info import VmInfo ...@@ -21,6 +21,7 @@ from vm_info import VmInfo
import linecache import linecache
import sys import sys
import logging import logging
# from drip_logging.drip_logging_handler import * # from drip_logging.drip_logging_handler import *
...@@ -33,8 +34,8 @@ if not getattr(logger, 'handler_set', None): ...@@ -33,8 +34,8 @@ if not getattr(logger, 'handler_set', None):
logger.addHandler(h) logger.addHandler(h)
logger.handler_set = True logger.handler_set = True
retry = 0
retry=0
def PrintException(): def PrintException():
exc_type, exc_obj, tb = sys.exc_info() exc_type, exc_obj, tb = sys.exc_info()
...@@ -46,10 +47,9 @@ def PrintException(): ...@@ -46,10 +47,9 @@ def PrintException():
print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj) print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)
def install_manager(vm): def install_manager(vm):
try: try:
logger.info("Starting kubernetes master installation on: "+(vm.ip)) logger.info("Starting kubernetes master installation on: " + (vm.ip))
parentDir = os.path.dirname(os.path.abspath(vm.key)) parentDir = os.path.dirname(os.path.abspath(vm.key))
os.chmod(parentDir, 0o700) os.chmod(parentDir, 0o700)
os.chmod(vm.key, 0o600) os.chmod(vm.key, 0o600)
...@@ -63,8 +63,8 @@ def install_manager(vm): ...@@ -63,8 +63,8 @@ def install_manager(vm):
install_script = file_path + "/" + "docker_kubernetes.sh" install_script = file_path + "/" + "docker_kubernetes.sh"
sftp.put(install_script, "kubernetes_setup.sh") sftp.put(install_script, "kubernetes_setup.sh")
#stdin, stdout, stderr = ssh.exec_command("sudo hostname ip-%s" % (vm.ip.replace('.','-'))) # stdin, stdout, stderr = ssh.exec_command("sudo hostname ip-%s" % (vm.ip.replace('.','-')))
stdout.read() # stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/kubernetes_setup.sh") stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/kubernetes_setup.sh")
stdout.read() stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo kubeadm reset") stdin, stdout, stderr = ssh.exec_command("sudo kubeadm reset")
...@@ -79,23 +79,24 @@ def install_manager(vm): ...@@ -79,23 +79,24 @@ def install_manager(vm):
stdout.read() stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo chgrp %s /tmp/admin.conf" % (vm.user)) stdin, stdout, stderr = ssh.exec_command("sudo chgrp %s /tmp/admin.conf" % (vm.user))
stdout.read() stdout.read()
sftp.get("/tmp/admin.conf", file_path+"/admin.conf") sftp.get("/tmp/admin.conf", file_path + "/admin.conf")
logger.info("Finished kubernetes master installation on: "+(vm.ip)) logger.info("Finished kubernetes master installation on: " + (vm.ip))
except Exception as e: except Exception as e:
global retry global retry
#print '%s: %s' % (vm.ip, e) # print '%s: %s' % (vm.ip, e)
logger.error(vm.ip + " " + str(e)) logger.error(vm.ip + " " + str(e))
PrintException() PrintException()
return "ERROR:"+vm.ip+" "+str(e) return "ERROR:" + vm.ip + " " + str(e)
ssh.close() ssh.close()
return retstr[-1] return retstr[-1]
def install_worker(join_cmd, vm): def install_worker(join_cmd, vm):
try: try:
logger.info("Starting kubernetes slave installation on: "+(vm.ip)) logger.info("Starting kubernetes slave installation on: " + (vm.ip))
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vm.ip, username=vm.user, key_filename=vm.key,timeout=30) ssh.connect(vm.ip, username=vm.user, key_filename=vm.key, timeout=30)
parentDir = os.path.dirname(os.path.abspath(vm.key)) parentDir = os.path.dirname(os.path.abspath(vm.key))
os.chmod(parentDir, 0o700) os.chmod(parentDir, 0o700)
...@@ -106,7 +107,7 @@ def install_worker(join_cmd, vm): ...@@ -106,7 +107,7 @@ def install_worker(join_cmd, vm):
file_path = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.dirname(os.path.abspath(__file__))
install_script = file_path + "/" + "docker_kubernetes.sh" install_script = file_path + "/" + "docker_kubernetes.sh"
sftp.put(install_script, "kubernetes_setup.sh") sftp.put(install_script, "kubernetes_setup.sh")
stdin, stdout, stderr = ssh.exec_command("sudo hostname ip-%s" % (vm.ip.replace('.','-'))) stdin, stdout, stderr = ssh.exec_command("sudo hostname ip-%s" % (vm.ip.replace('.', '-')))
stdout.read() stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/kubernetes_setup.sh") stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/kubernetes_setup.sh")
stdout.read() stdout.read()
...@@ -114,15 +115,16 @@ def install_worker(join_cmd, vm): ...@@ -114,15 +115,16 @@ def install_worker(join_cmd, vm):
stdout.read() stdout.read()
stdin, stdout, stderr = ssh.exec_command("sudo %s" % (join_cmd)) stdin, stdout, stderr = ssh.exec_command("sudo %s" % (join_cmd))
stdout.read() stdout.read()
logger.info("Finished kubernetes slave installation on: "+(vm.ip)) logger.info("Finished kubernetes slave installation on: " + (vm.ip))
except Exception as e: except Exception as e:
#print '%s: %s' % (vm.ip, e) # print '%s: %s' % (vm.ip, e)
logger.error(vm.ip + " " + str(e)) logger.error(vm.ip + " " + str(e))
return "ERROR:"+vm.ip+" "+str(e) return "ERROR:" + vm.ip + " " + str(e)
ssh.close() ssh.close()
return "SUCCESS" return "SUCCESS"
def run(vm_list,rabbitmq_host,owner):
def run(vm_list, rabbitmq_host, owner):
# rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672,user=owner) # rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672,user=owner)
# logger.addHandler(rabbit) # logger.addHandler(rabbit)
for i in vm_list: for i in vm_list:
......
#! /bin/bash #! /bin/bash
sudo apt-get update && sudo apt-get install -y apt-transport-https sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y apt-transport-https
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update sudo apt-get update
......
#!/usr/bin/env python #!/usr/bin/env python
import pika import base64
import json import json
import logging
import os import os
import time import os.path
from vm_info import VmInfo
import docker_kubernetes
import docker_engine
import docker_swarm
import docker_compose
import docker_service
import docker_check
import control_agent
# import ansible_playbook # import ansible_playbook
import sys, argparse import sys
import time
from threading import Thread from threading import Thread
from time import sleep from time import sleep
import os.path
import logging import pika
import docker_check
import docker_compose
import docker_engine
import docker_kubernetes
import docker_service
import docker_swarm
from vm_info import VmInfo
global rabbitmq_host global rabbitmq_host
if len(sys.argv) > 1: if len(sys.argv) > 1:
...@@ -69,6 +71,7 @@ def handleDelivery(message): ...@@ -69,6 +71,7 @@ def handleDelivery(message):
manager_type = param["value"] manager_type = param["value"]
elif name == "credential": elif name == "credential":
value = param["value"] value = param["value"]
value = base64.b64decode(value)
ip = param["attributes"]["IP"] ip = param["attributes"]["IP"]
user = param["attributes"]["user"] user = param["attributes"]["user"]
role = param["attributes"]["role"] role = param["attributes"]["role"]
......
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error"> <list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error">
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.sh" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.sh" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/rpc_server.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/rpc_server.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/basic_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/basic_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" />
......
...@@ -20,28 +20,32 @@ import logging ...@@ -20,28 +20,32 @@ import logging
def get_cpu_frequency(): def get_cpu_frequency():
return '2.9 GHz' return '2.9 GHz'
def get_num_cpus(): def get_num_cpus():
return 1 return 1
def get_cloud_domain(): def get_cloud_domain():
return 'UvA (Amsterdam, The Netherlands) XO Rack' return 'UvA (Amsterdam, The Netherlands) XO Rack'
def get_cloud_provider(): def get_cloud_provider():
return 'ExoGeni' return 'ExoGeni'
def get_disk_size(): def get_disk_size():
return '25000 MB' return '25000 MB'
def get_mem_size(): def get_mem_size():
return '3000 MB' return '3000 MB'
def get_os_distribution(): def get_os_distribution():
return 'Ubuntu 14.04' return 'Ubuntu 16.04'
def set_VM_properties(node_template_dict): def set_vm_properties(node_template_dict):
node_template_dict['properties'].pop('host_name') node_template_dict['properties'].pop('host_name')
node_template_dict['properties']['host_name'] = 'vm' node_template_dict['properties']['host_name'] = 'vm'
node_template_dict['properties'].pop('num_cpus') node_template_dict['properties'].pop('num_cpus')
...@@ -56,6 +60,7 @@ def set_VM_properties(node_template_dict): ...@@ -56,6 +60,7 @@ def set_VM_properties(node_template_dict):
node_template_dict['properties']['os'] = get_os_distribution() node_template_dict['properties']['os'] = get_os_distribution()
return node_template_dict return node_template_dict
def set_topology_properties(node_template_dict): def set_topology_properties(node_template_dict):
node_template_dict['properties'].pop('provider') node_template_dict['properties'].pop('provider')
node_template_dict['properties']['provider'] = get_cloud_provider() node_template_dict['properties']['provider'] = get_cloud_provider()
...@@ -71,9 +76,10 @@ def fill_in_properties(nodetemplate_dict): ...@@ -71,9 +76,10 @@ def fill_in_properties(nodetemplate_dict):
if 'type' in nodetemplate_dict and nodetemplate_dict['type'] == 'tosca.nodes.ARTICONF.VM.topology': if 'type' in nodetemplate_dict and nodetemplate_dict['type'] == 'tosca.nodes.ARTICONF.VM.topology':
nodetemplate_dict = set_topology_properties(nodetemplate_dict) nodetemplate_dict = set_topology_properties(nodetemplate_dict)
if 'type' in nodetemplate_dict and nodetemplate_dict['type'] == 'tosca.nodes.ARTICONF.VM.Compute': if 'type' in nodetemplate_dict and nodetemplate_dict['type'] == 'tosca.nodes.ARTICONF.VM.Compute':
nodetemplate_dict = set_VM_properties(nodetemplate_dict) nodetemplate_dict = set_vm_properties(nodetemplate_dict)
return nodetemplate_dict return nodetemplate_dict
def fix_occurrences(node_templates): def fix_occurrences(node_templates):
# Replace 'occurrences': [1, 'UNBOUNDED'] with 'occurrences': 1 # Replace 'occurrences': [1, 'UNBOUNDED'] with 'occurrences': 1
for node in node_templates: for node in node_templates:
...@@ -82,6 +88,7 @@ def fix_occurrences(node_templates): ...@@ -82,6 +88,7 @@ def fix_occurrences(node_templates):
req[next(iter(req))].pop('occurrences') req[next(iter(req))].pop('occurrences')
return node_templates return node_templates
def node_type_2_node_template(node_type): def node_type_2_node_template(node_type):
nodetemplate_dict = {} nodetemplate_dict = {}
type_name = next(iter(node_type)) type_name = next(iter(node_type))
...@@ -121,6 +128,8 @@ def get_requirement_occurrences(req): ...@@ -121,6 +128,8 @@ def get_requirement_occurrences(req):
if 'occurrences' in req: if 'occurrences' in req:
return req['occurrences'] return req['occurrences']
return None return None
def fix_duplicate_vm_names(yaml_str): def fix_duplicate_vm_names(yaml_str):
topology_dict = yaml.load(yaml_str) topology_dict = yaml.load(yaml_str)
node_templates = topology_dict['tosca_template']['node_templates'] node_templates = topology_dict['tosca_template']['node_templates']
...@@ -131,10 +140,10 @@ def fix_duplicate_vm_names(yaml_str): ...@@ -131,10 +140,10 @@ def fix_duplicate_vm_names(yaml_str):
for node_name in node_templates: for node_name in node_templates:
if node_templates[node_name]['type'] == 'tosca.nodes.ARTICONF.VM.topology': if node_templates[node_name]['type'] == 'tosca.nodes.ARTICONF.VM.topology':
i=0 i = 0
for req in node_templates[node_name]['requirements']: for req in node_templates[node_name]['requirements']:
req['vm']['node'] = vm_names[i] req['vm']['node'] = vm_names[i]
i+=1 i += 1
return yaml.dump(topology_dict) return yaml.dump(topology_dict)
...@@ -163,7 +172,7 @@ class BasicPlanner: ...@@ -163,7 +172,7 @@ class BasicPlanner:
yaml_str = yaml_str.replace('tosca_definitions_version: tosca_simple_yaml_1_0', '') yaml_str = yaml_str.replace('tosca_definitions_version: tosca_simple_yaml_1_0', '')
yaml_str = yaml_str.replace('description: TOSCA example', '') yaml_str = yaml_str.replace('description: TOSCA example', '')
yaml_str = yaml_str.replace('tosca_template', 'topology_template') yaml_str = yaml_str.replace('tosca_template', 'topology_template')
self.formatted_yaml_str = 'tosca_definitions_version: tosca_simple_yaml_1_0\nrepositories:\n docker_hub: https://hub.docker.com/\n'+yaml_str self.formatted_yaml_str = 'tosca_definitions_version: tosca_simple_yaml_1_0\nrepositories:\n docker_hub: https://hub.docker.com/\n' + yaml_str
logging.info('TOSCA template: \n' + self.formatted_yaml_str) logging.info('TOSCA template: \n' + self.formatted_yaml_str)
def get_plan(self): def get_plan(self):
...@@ -224,7 +233,8 @@ class BasicPlanner: ...@@ -224,7 +233,8 @@ class BasicPlanner:
# Only return the nodes that have interfaces. This means that they are not "abstract" # Only return the nodes that have interfaces. This means that they are not "abstract"
for candidate_node_name in candidate_nodes: for candidate_node_name in candidate_nodes:
if 'interfaces' in candidate_nodes[candidate_node_name].keys() and 'tosca.nodes.Root' != candidate_node_name: if 'interfaces' in candidate_nodes[
candidate_node_name].keys() and 'tosca.nodes.Root' != candidate_node_name:
capable_nodes[candidate_node_name] = candidate_nodes[candidate_node_name] capable_nodes[candidate_node_name] = candidate_nodes[candidate_node_name]
return capable_nodes return capable_nodes
...@@ -308,4 +318,3 @@ class BasicPlanner: ...@@ -308,4 +318,3 @@ class BasicPlanner:
node_templates.append(node) node_templates.append(node)
return node_templates return node_templates
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment