Skip to content

Commit

Permalink
Merge pull request #4 from maricaantonacci/devel
Browse files Browse the repository at this point in the history
Adding SLAs management
  • Loading branch information
maricaantonacci authored Apr 17, 2019
2 parents 0ff666e + fb7e87c commit dd94ba6
Show file tree
Hide file tree
Showing 19 changed files with 1,270 additions and 31 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Create the `config.json` file (see the [example](app/config-sample.json)):
"IAM_CLIENT_SECRET": "*****",
"IAM_BASE_URL": "https://iam-test.indigo-datacloud.eu",
"ORCHESTRATOR_URL": "https://indigo-paas.cloud.ba.infn.it/orchestrator",
"TOSCA_TEMPLATES_DIR": "/opt/tosca-templates"
"TOSCA_TEMPLATES_DIR": "/opt/tosca-templates",
"SLAM_URL": "https://indigo-slam.cloud.ba.infn.it:8443",
"CMDB_URL": "https://indigo-paas.cloud.ba.infn.it/cmdb"
}
````
Clone the tosca-templates repository to get a set of tosca templates that the dashboard will load, e.g.:
Expand Down Expand Up @@ -124,6 +126,19 @@ cd orchestrator-dashboard
docker build -f docker/Dockerfile -t orchestrator-dashboard .
```

## How to setup a development environment

```
git clone https://github.com/maricaantonacci/orchestrator-dashboard.git
cd orchestrator-dashboard
python3 -m venv venv
source venv/source/activate
pip install -r requirements.txt
```

Start the dashboard app:
```
FLASK_app=orchdashboard flask run --host=0.0.0.0 --cert cert.pem --key privkey.pem --port 443
```


2 changes: 2 additions & 0 deletions app/config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"IAM_CLIENT_SECRET": "my_client_secret",
"IAM_BASE_URL": "https://iam-test.indigo-datacloud.eu",
"ORCHESTRATOR_URL": "https://indigo-paas.cloud.ba.infn.it/orchestrator",
"SLAM_URL": "https://indigo-slam.cloud.ba.infn.it:8443",
"CMDB_URL": "https://indigo-paas.cloud.ba.infn.it/cmdb",
"TOSCA_TEMPLATES_DIR": "/opt/tosca-templates"
}
145 changes: 127 additions & 18 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from app import app, iam_blueprint
from app import app, iam_blueprint, iam_base_url
from flask import json, current_app, render_template, request, redirect, url_for, flash, session
import requests, json
import yaml
Expand Down Expand Up @@ -29,40 +29,111 @@ def avatar(email, size):
toscaTemplates.append( os.path.relpath(os.path.join(path, name), toscaDir ))

orchestratorUrl = app.config.get('ORCHESTRATOR_URL')
slamUrl = app.config.get('SLAM_URL')
cmdbUrl = app.config.get('CMDB_URL')
slam_cert = app.config.get('SLAM_CERT')

@app.route('/settings')
def show_settings():
if not iam_blueprint.session.authorized:
return redirect(url_for('login'))
return render_template('settings.html', orchestrator_url=orchestratorUrl, iam_url=iam_base_url)

#@app.route('/')
@app.route('/login')
def login():
session.clear()
return render_template('home.html')

@app.route('/dashboard')

def get_sla_extra_info(access_token, service_id):
headers = {'Authorization': 'bearer %s' % (access_token)}
url = cmdbUrl + "/service/id/" + service_id
response = requests.get(url, headers=headers, timeout=20)
response.raise_for_status()
app.logger.info(json.dumps(response.json()['data']['service_type']))

service_type=response.json()['data']['service_type']
sitename=response.json()['data']['sitename']
if 'properties' in response.json()['data']:
if 'gpu_support' in response.json()['data']['properties']:
service_type = service_type + " (gpu_support: " + str(response.json()['data']['properties']['gpu_support']) + ")"

return sitename, service_type

def get_slas(access_token):

headers = {'Authorization': 'bearer %s' % (access_token)}

url = slamUrl + "/rest/slam/preferences/" + session['organisation_name']
verify = True
if slam_cert:
verify = slam_cert
response = requests.get(url, headers=headers, timeout=20, verify=verify)
app.logger.info("SLA response status: " + str(response.status_code))

response.raise_for_status()
app.logger.info("SLA response: " + json.dumps(response.json()))
slas = response.json()['sla']

for i in range(len(slas)):
sitename, service_type = get_sla_extra_info(access_token,slas[i]['services'][0]['service_id'])
slas[i]['service_type']=service_type
slas[i]['sitename']=sitename

return slas

@app.route('/slas')
def getslas():

if not iam_blueprint.session.authorized:
return redirect(url_for('login'))

slas={}

try:
access_token = iam_blueprint.token['access_token']
slas = get_slas(access_token)

except Exception as e:
flash("Error retrieving SLAs list: \n" + str(e), 'warning')
return redirect(url_for('home'))

return render_template('sla.html', slas=slas)


@app.route('/dashboard/<page>')
@app.route('/<page>')
@app.route('/')
def home():
def home(page=0):

if not iam_blueprint.session.authorized:
return redirect(url_for('login'))
if not iam_blueprint.session.authorized:
return redirect(url_for('login'))
try:
account_info=iam_blueprint.session.get("/userinfo")

if account_info.ok:
account_info_json = account_info.json()
session['username'] = account_info_json['name']
session['gravatar'] = avatar(account_info_json['email'], 26)
session['organisation_name']=account_info_json['organisation_name']
access_token = iam_blueprint.token['access_token']

headers = {'Authorization': 'bearer %s' % (access_token)}

url = orchestratorUrl + "/deployments?createdBy=me"
url = orchestratorUrl + "/deployments?createdBy=me&page=" + str(page)
response = requests.get(url, headers=headers)

deployments = {}
if not response.ok:
flash("Error retrieving deployment list: \n" + response.text, 'warning')
else:
deployments = response.json()["content"]
return render_template('deployments.html', deployments=deployments)

pages=response.json()['page']['totalPages']
app.logger.debug(pages)
return render_template('deployments.html', deployments=deployments, tot_pages=pages, current_page=page)
except Exception:
app.logger.info("error")
return redirect(url_for('logout'))


@app.route('/template/<depid>')
Expand Down Expand Up @@ -125,7 +196,23 @@ def depcreate():
description = "N/A"
if 'description' in template:
description = template['description']
return render_template('createdep.html', templates=toscaTemplates, selectedTemplate=selected_tosca, description=description, inputs=inputs)

slas = get_slas(access_token)
return render_template('createdep.html', templates=toscaTemplates, selectedTemplate=selected_tosca, description=description, inputs=inputs, slas=slas)

def add_sla_to_template(template, sla_id):
# Add the placement policy

nodes=template['topology_template']['node_templates']
compute_nodes = []
# for key, dict in nodes.items():
# node_type=dict["type"]
# if node_type == "tosca.nodes.indigo.Compute" or node_type == "tosca.nodes.indigo.Container.Application.Docker.Chronos" :
# compute_nodes.append(key)
# template['topology_template']['policies']=[{ "deploy_on_specific_site": { "type": "tosca.policies.Placement", "properties": { "sla_id": sla_id }, "targets": compute_nodes } }]
template['topology_template']['policies']=[{ "deploy_on_specific_site": { "type": "tosca.policies.Placement", "properties": { "sla_id": sla_id } } }]
app.logger.info(yaml.dump(template,default_flow_style=False))
return template
#
#
@app.route('/submit', methods=['POST'])
Expand All @@ -136,23 +223,43 @@ def createdep():

access_token = iam_blueprint.session.token['access_token']

app.logger.debug("Form data: " + json.dumps(request.form.to_dict()))

try:
with io.open( toscaDir + request.args.get('template')) as stream:
payload = { "template" : stream.read(), "parameters": request.form.to_dict() }

body= json.dumps(payload)
with io.open( toscaDir + request.args.get('template')) as stream:
template = yaml.load(stream)

form_data = request.form.to_dict()

params={}
if 'extra_opts.keepLastAttempt' in form_data:
params['keepLastAttempt'] = 'true'
else:
params['keepLastAttempt'] = 'false'

if form_data['extra_opts.schedtype'] == "man":
template = add_sla_to_template(template, form_data['extra_opts.selectedSLA'])

inputs = { k:v for (k,v) in form_data.items() if not k.startswith("extra_opts.") }

app.logger.debug("Parameters: " + json.dumps(inputs))

payload = { "template" : yaml.dump(template,default_flow_style=False), "parameters": inputs }

#body= json.dumps(payload)

url = orchestratorUrl + "/deployments/"
headers = {'Content-Type': 'application/json', 'Authorization': 'bearer %s' % (access_token)}
response = requests.post(url, data=body, headers=headers)
#response = requests.post(url, data=body, headers=headers)
response = requests.post(url, json=payload, params=params, headers=headers)

if not response.ok:
flash("Error submitting deployment: \n" + response.text)

return redirect(url_for('home'))

except Exception as e:
app.logger.error("Error submitting deployment:" + str(e))
flash("Error submitting deployment:" + str(e) + ". Please retry")
return redirect(url_for('home'))


Expand All @@ -162,3 +269,5 @@ def logout():
iam_blueprint.session.get("/logout")
# del iam_blueprint.session.token
return redirect(url_for('login'))


8 changes: 8 additions & 0 deletions app/static/bootstrap/Bootstrap-Confirmation-2/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
4 changes: 4 additions & 0 deletions app/static/bootstrap/Bootstrap-Confirmation-2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.idea
/*.iml
/bower_components
/node_modules
106 changes: 106 additions & 0 deletions app/static/bootstrap/Bootstrap-Confirmation-2/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
module.exports = function(grunt) {
require('jit-grunt')(grunt);

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

banner: '/*!\n' +
' * Bootstrap Confirmation <%= pkg.version %>\n' +
' * Copyright 2013 Nimit Suwannagate <[email protected]>\n' +
' * Copyright 2014-<%= grunt.template.today("yyyy") %> Damien "Mistic" Sorel <[email protected]>\n' +
' * Licensed under the Apache License, Version 2.0\n' +
' */',

// serve folder content
connect: {
dev: {
options: {
port: 9000,
livereload: true
}
}
},

// watchers
watch: {
options: {
livereload: true
},
dev: {
files: ['bootstrap-confirmation.js', 'example/**'],
tasks: []
}
},

// open example
open: {
dev: {
path: 'http://localhost:<%= connect.dev.options.port%>/example/index.html'
}
},

// replace version number
replace: {
dist: {
options: {
patterns: [
{
match: /(Confirmation\.VERSION = ').*(';)/,
replacement: '$1<%= pkg.version %>$2'
}
]
},
files: {
'bootstrap-confirmation.js': [
'bootstrap-confirmation.js'
]
}
}
},

// compress js
uglify: {
options: {
banner: '<%= banner %>\n',
mangle: {
except: ['$']
}
},
dist: {
files: {
'bootstrap-confirmation.min.js': [
'bootstrap-confirmation.js'
]
}
}
},

// jshint tests
jshint: {
lib: {
files: {
src: [
'bootstrap-confirmation.js'
]
}
}
}
}
);

grunt.registerTask('default', [
'replace',
'uglify'
]);

grunt.registerTask('test', [
'jshint'
]);

grunt.registerTask('serve', [
'connect',
'open',
'watch'
]);

};
26 changes: 26 additions & 0 deletions app/static/bootstrap/Bootstrap-Confirmation-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Bootstrap-Confirmation

[![npm version](https://img.shields.io/npm/v/bootstrap-confirmation2.svg?style=flat-square)](https://www.npmjs.com/package/bootstrap-confirmation2)
[![jsDelivr CDN](https://data.jsdelivr.com/v1/package/npm/bootstrap-confirmation2/badge)](https://www.jsdelivr.com/package/npm/bootstrap-confirmation2)
[![Build Status](https://img.shields.io/travis/mistic100/Bootstrap-Confirmation/master.svg?style=flat-square)](https://travis-ci.org/mistic100/Bootstrap-Confirmation)
[![Dependencies Status](https://david-dm.org/mistic100/Bootstrap-Confirmation/status.svg?style=flat-square)](https://david-dm.org/mistic100/Bootstrap-Confirmation)

Bootstrap plugin for on-place confirm boxes using Popover.

## Documentation

[bootstrap-confirmation.js.org](http://bootstrap-confirmation.js.org)

## Installation

#### Bootstrap 4

```
npm install bootstrap-confirmation2
```

#### Bootstrap 3

```
npm install [email protected]
```
Loading

0 comments on commit dd94ba6

Please sign in to comment.