Commit 41ce522b authored by Spiros Koulouzis's avatar Spiros Koulouzis

added jupyter notebook for demo

parent e7a287a9
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Upload ExoGeni Credentials from ~/.ssl/user.jks\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create ExoGeni Credentials "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import base64\n",
"with open(\"user.jks\", \"rb\") as image_file:\n",
" exoGENI_keystore_as_base64 = base64.b64encode(image_file.read()).decode(\"utf-8\") \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import getpass\n",
"exoGENI_credential_user = getpass.getpass('Enter your ExoGENI_credential_user')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"exoGENI_credential_token = getpass.getpass(\"Enter your ExoGENI_credential_token \" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create EC2 Credentials "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"aws_access_key_id = getpass.getpass('Enter your aws_access_key_id')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"aws_secret_access_key = getpass.getpass('Enter your aws_secret_access_key')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Enter API URL"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"base_url = input(\"Enter host base_url \" )\n",
"# http://manager:8080\n",
"# http://localhost:30000\n",
"print(base_url)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Upload Credentials"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"path = \"/credential\"\n",
"payload = '{\"cloud_provider_name\": \"ExoGENI\",\"keys\": {\"keystore\": \"'+exoGENI_keystore_as_base64+'\"}, \"token\": \"'+exoGENI_credential_token+'\", \"token_type\": \"password\", \"user\": \"'+exoGENI_credential_user+'\"}'\n",
"headers = {\n",
" 'Content-Type': 'application/json',\n",
" 'accept': 'application/json'\n",
"}\n",
"response = requests.post(base_url+path, data=payload,headers=headers)\n",
"credential_id = response.text\n",
"print(credential_id)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"path = \"/credential\"\n",
"payload = '{ \"cloud_provider_name\": \"EC2\",\"keys\": {\"aws_access_key_id\": \"'+aws_access_key_id+'\"}, \"token_type\": \"access_key\", \"token\": \"'+aws_secret_access_key+'\"}' \n",
"headers = {\n",
" 'Content-Type': 'application/json',\n",
" 'accept': 'application/json'\n",
"}\n",
"response = requests.post(base_url+path, data=payload,headers=headers)\n",
"credential_id = response.text\n",
"print(credential_id)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Upload TOSCA"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"path = \"/tosca_template\"\n",
"payload = {}\n",
"filename = 'lifeWatch_vre1.yaml'\n",
"fin = open(filename, 'rb')\n",
"files = {'file': fin}\n",
"\n",
"headers = {}\n",
"\n",
"response = requests.request(\"POST\", base_url+path, headers=headers, files = files)\n",
"tosca_id = response.text\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get TOSCA"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import yaml\n",
"\n",
"path = \"/tosca_template/\"+tosca_id\n",
"payload = {}\n",
"headers= {'accept':'text/plain'}\n",
"\n",
"response = requests.request(\"GET\", base_url+path, headers=headers, data = payload)\n",
"tosca = response.text\n",
"print(tosca)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Show Topology"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import networkx as nx\n",
"import matplotlib\n",
"import plotly.graph_objects as go\n",
"\n",
"\n",
"def build_graph(node_templates):\n",
" graph = nx.DiGraph()\n",
" for node_name in node_templates:\n",
" graph.add_node(node_name, attr_dict=node_templates[node_name])\n",
" if 'requirements' in node_templates[node_name]:\n",
" for req in node_templates[node_name]['requirements']:\n",
" req_name = next(iter(req))\n",
" req_node_name = req[req_name]['node']\n",
" if 'relationship' in req[req_name] and 'type' in req[req_name]['relationship']:\n",
" relationship_type = req[req_name]['relationship']['type']\n",
" else:\n",
" if 'relationship' not in req[req_name]:\n",
" relationship_type = 'tosca.relationships.DependsOn'\n",
" else:\n",
" relationship_type = req[req_name]['relationship']\n",
" graph.add_edge(node_name, req_node_name, relationship=relationship_type)\n",
"\n",
" # nx.draw(graph, with_labels=True)\n",
" # plt.savefig(\"/tmp/graph.png\")\n",
" # plt.show()\n",
" return graph\n",
"\n",
"def get_tosca(tosca_id):\n",
" path = \"/tosca_template/\"+tosca_id\n",
" payload = {}\n",
" headers= {'accept':'text/plain'}\n",
" response = requests.request(\"GET\", base_url+path, headers=headers, data = payload)\n",
" return response.text\n",
"\n",
"tosca = get_tosca(tosca_id)\n",
"tosca_dict = yaml.safe_load(tosca)\n",
"graph = build_graph(tosca_dict['topology_template']['node_templates'])\n",
"nx.draw(graph, with_labels=True)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Make Plan"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"path = \"/planner/plan/\"+tosca_id\n",
"payload = {}\n",
"headers= {'accept':'text/plain'}\n",
"\n",
"response = requests.request(\"GET\", base_url+path, headers=headers, data = payload)\n",
"planed_tosca_id = response.text"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tosca = get_tosca(planed_tosca_id)\n",
"\n",
"tosca_dict = yaml.safe_load(tosca)\n",
"graph = build_graph(tosca_dict['topology_template']['node_templates'])\n",
"nx.draw(graph, with_labels=True)\n",
"\n",
"for node_name in tosca_dict['topology_template']['node_templates']:\n",
" if 'properties' in tosca_dict['topology_template']['node_templates'][node_name]:\n",
" print(node_name+': '+str(tosca_dict['topology_template']['node_templates'][node_name]['properties']))\n",
" print('---------------------------------------------------------------------------------------------------------------------')\n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Provision Plan"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"path = \"/provisioner/provision/\"+planed_tosca_id\n",
"payload = {}\n",
"headers= {'accept':'text/plain'}\n",
"\n",
"response = requests.request(\"GET\", base_url+path, headers=headers, data = payload)\n",
"provisioned_tosca_id = response.text"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tosca = get_tosca(provisioned_tosca_id)\n",
"\n",
"tosca_dict = yaml.safe_load(tosca)\n",
"graph = build_graph(tosca_dict['topology_template']['node_templates'])\n",
"nx.draw(graph, with_labels=True)\n",
"\n",
"\n",
"for node_name in tosca_dict['topology_template']['node_templates']:\n",
" if tosca_dict['topology_template']['node_templates'][node_name]['type'] == 'tosca.nodes.ARTICONF.VM.Compute':\n",
" print(node_name+': '+tosca_dict['topology_template']['node_templates'][node_name]['attributes']['public_ip'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deploy K8s And WS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"path = \"/deployer/deploy/\"+provisioned_tosca_id\n",
"payload = {}\n",
"headers= {'accept':'text/plain'}\n",
"\n",
"response = requests.request(\"GET\", base_url+path, headers=headers, data = payload)\n",
"deployed_tosca_id = response.text"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tosca = get_tosca(deployed_tosca_id)\n",
"\n",
"tosca_dict = yaml.safe_load(tosca)\n",
"graph = build_graph(tosca_dict['topology_template']['node_templates'])\n",
"nx.draw(graph, with_labels=True)\n",
"\n",
"for node_name in tosca_dict['topology_template']['node_templates']:\n",
" if tosca_dict['topology_template']['node_templates'][node_name]['type'] == 'tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes':\n",
" for token in tosca_dict['topology_template']['node_templates'][node_name]['attributes']['tokens']:\n",
" if token['user'] == 'dashboard_token':\n",
" print(node_name+': '+' dashboard_token: '+token['token'])\n",
" print(node_name+': '+str(tosca_dict['topology_template']['node_templates'][node_name]['attributes']['dashboard_url']))\n",
" if tosca_dict['topology_template']['node_templates'][node_name]['type'] == 'tosca.nodes.ARTICONF.Container.Application.Docker':\n",
" print(node_name+': '+str(tosca_dict['topology_template']['node_templates'][node_name]['attributes']['service_url']))\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
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