Commit 9bd8d5fa authored by Spiros Koulouzis's avatar Spiros Koulouzis

generate ansible k8s

parent 8ed128bc
...@@ -76,10 +76,10 @@ def handle_delivery(message): ...@@ -76,10 +76,10 @@ def handle_delivery(message):
paths = ansible_service.write_playbooks_from_tosca_interface(interfaces, tmp_path) paths = ansible_service.write_playbooks_from_tosca_interface(interfaces, tmp_path)
for playbook_path in paths: for playbook_path in paths:
out,err = ansible_service.run(inventory_path,playbook_path) out,err = ansible_service.run(inventory_path,playbook_path)
api_key, join_token, discovery_token_ca_cert_hash = ansible_service.parse_tokens(out) api_key, join_token, discovery_token_ca_cert_hash = ansible_service.parse_tokens(out.decode("utf-8"))
ansible_playbook_path = k8s_service.write_ansible_k8s_files(tosca_template_json, tmp_path) ansible_playbook_path = k8s_service.write_ansible_k8s_files(tosca_template_json, tmp_path)
out, err = ansible_service.run(inventory_path, playbook_path) out, err = ansible_service.run(inventory_path, ansible_playbook_path)
template_dict = {} template_dict = {}
......
...@@ -71,7 +71,7 @@ def write_inventory_file(tmp_path, vms): ...@@ -71,7 +71,7 @@ def write_inventory_file(tmp_path, vms):
def write_playbooks(tmp_path, interface): def write_playbooks(tmp_path, interface):
playbook_paths = [] playbook_paths = []
interface_stage_list = ['install','create'] interface_stage_list = ['install', 'create']
# for interface_stage in interface: # for interface_stage in interface:
for interface_stage in interface_stage_list: for interface_stage in interface_stage_list:
playbook_url = interface[interface_stage]['inputs']['playbook'] playbook_url = interface[interface_stage]['inputs']['playbook']
...@@ -101,6 +101,10 @@ def run(inventory_path, playbook_path): ...@@ -101,6 +101,10 @@ def run(inventory_path, playbook_path):
def parse_tokens(out): def parse_tokens(out):
api_key = None
join_token = None
discovery_token_ca_cert_hash = None
if 'Join command is kubeadm join' in out:
api_key = re.search("^msg.*", out) api_key = re.search("^msg.*", out)
join_token = re.search("^\"stdout\": \"$", out) join_token = re.search("^\"stdout\": \"$", out)
......
...@@ -69,24 +69,26 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path): ...@@ -69,24 +69,26 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
i = 0 i = 0
tasks = [] tasks = []
for services_def in services: for services_def in services:
task = {'name': 'Create a Service object' + str(i)}
k8s = {'state': 'present', 'definition': services_def} k8s = {'state': 'present', 'definition': services_def}
task = {'name': 'Create a Service object' + str(i), 'become': 'yes', 'k8s': k8s} task['k8s'] = k8s
i += 1 i += 1
tasks.append(task) tasks.append(task)
i = 0 i = 0
tasks = []
for deployments_def in deployments: for deployments_def in deployments:
k8s = {'state': 'present', 'definition': services_def} task = {'name': 'Create a deployment object' + str(i)}
task = {'name': 'Create a Service object' + str(i), 'become': 'yes', 'k8s': k8s} k8s = {'state': 'present', 'definition': deployments_def}
task['k8s'] = k8s
i += 1 i += 1
tasks.append(task) tasks.append(task)
ansible_playbook = {'hosts': 'k8-master', 'tasks': tasks} ansible_playbook = []
plays = {'hosts': 'k8-master', 'tasks': tasks}
ansible_playbook.append(plays)
print(yaml.safe_dump(ansible_playbook)) print(yaml.safe_dump(ansible_playbook))
ansible_playbook_path = tmp_path+'/'+'k8s_playbook.yml' ansible_playbook_path = tmp_path + '/' + 'k8s_playbook.yml'
f = open(ansible_playbook_path, "w")
yaml.dump(yaml.safe_dump(ansible_playbook), f)
f.close()
with open(ansible_playbook_path, 'w') as file:
documents = yaml.dump(ansible_playbook, file)
return ansible_playbook_path return ansible_playbook_path
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/drip-deployer.iml" filepath="$PROJECT_DIR$/.idea/drip-deployer.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="350a2cb3-d21f-4a78-bd8c-7614f85494cc" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../deployer/__main__.py" beforeDir="false" afterPath="$PROJECT_DIR$/../deployer/__main__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../deployer/service/ansible_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../deployer/service/ansible_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../deployer/service/k8s_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../deployer/service/k8s_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../provisioner/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../provisioner/pom.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectId" id="1XDOwMpLrjLoOX7wa6ziawR8wDT" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../deployer" />
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="350a2cb3-d21f-4a78-bd8c-7614f85494cc" name="Default Changelist" comment="" />
<created>1580577435383</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1580577435383</updated>
</task>
<servers />
</component>
<component name="WindowStateProjectService">
<state x="1043" y="437" width="530" height="598" key="FileChooserDialogImpl" timestamp="1580577475090">
<screen x="67" y="34" width="2493" height="1406" />
</state>
<state x="1043" y="437" width="530" height="598" key="FileChooserDialogImpl/67.34.2493.1406@67.34.2493.1406" timestamp="1580577475090" />
</component>
</project>
\ No newline at end of file
...@@ -15,4 +15,18 @@ ...@@ -15,4 +15,18 @@
<jpda.listen>true</jpda.listen> <jpda.listen>true</jpda.listen>
</properties> </properties>
</action> </action>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath nl.uva.sne.drip.provisioner.RPCServer</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions> </actions>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>nl.uva.sne.drip</groupId> <groupId>nl.uva.sne.drip</groupId>
<artifactId>drip</artifactId> <artifactId>conf</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
</parent> </parent>
......
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