From abbfa178525f71435d52e4b8dce8bd91d9c2dff6 Mon Sep 17 00:00:00 2001 From: Marica Antonacci Date: Mon, 9 Mar 2020 11:57:44 +0100 Subject: [PATCH] Add sla filter on deployment type (#23) * Remove outdated help text for timeout * Added sla filter on deployment type --- app/routes.py | 2 +- app/sla.py | 40 ++++++++++++++++++++++++------ app/templates/advanced_config.html | 1 - app/utils.py | 22 ++++++++++++++++ 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/app/routes.py b/app/routes.py index b942d44b4..78a3b9557 100644 --- a/app/routes.py +++ b/app/routes.py @@ -188,7 +188,7 @@ def configure(): selected_tosca = request.args['selected_tosca'] - slas = sla.get_slas(access_token, settings.orchestratorConf['slam_url'], settings.orchestratorConf['cmdb_url']) + slas = sla.get_slas(access_token, settings.orchestratorConf['slam_url'], settings.orchestratorConf['cmdb_url'], toscaInfo[selected_tosca]["deployment_type"]) app.logger.debug("Template: " + json.dumps(toscaInfo[selected_tosca])) diff --git a/app/sla.py b/app/sla.py index d39b339ae..51c78be57 100644 --- a/app/sla.py +++ b/app/sla.py @@ -20,9 +20,26 @@ def get_sla_extra_info(access_token, service_id, cmdb_url): return sitename, endpoint, service_type, iam_enabled -def get_slas(access_token, slam_url, cmdb_url): +def is_enabling_services(deployment_type, service_type): - headers = {'Authorization': 'bearer %s' % (access_token)} + if deployment_type == "": + return True + + if deployment_type == "CLOUD": + return True if service_type in [ "org.openstack.nova", "com.amazonaws.ec2" ] else False + elif deployment_type == "MARATHON": + return True if "eu.indigo-datacloud.marathon" in service_type else False + elif deployment_type == "CHRONOS": + return True if "eu.indigo-datacloud.chronos" in service_type else False + elif deployment_type == "QCG": + return True if service_type == "eu.deep.qcg" else False + else: + return True + +def get_slas(access_token, slam_url, cmdb_url, deployment_type=""): + + + headers = {'Authorization': 'bearer %s' % access_token} url = slam_url + "/preferences/" + session['organisation_name'] @@ -31,12 +48,19 @@ def get_slas(access_token, slam_url, cmdb_url): response.raise_for_status() slas = response.json()['sla'] + filtered_slas = [] for i in range(len(slas)): sitename, endpoint, service_type, iam_enabled = get_sla_extra_info(access_token,slas[i]['services'][0]['service_id'], cmdb_url) - slas[i]['service_id']=slas[i]['services'][0]['service_id'] - slas[i]['service_type']=service_type - slas[i]['sitename']=sitename - slas[i]['endpoint']=endpoint - slas[i]['iam_enabled']=iam_enabled - return slas + if is_enabling_services(deployment_type, service_type): + slas[i]['service_id']=slas[i]['services'][0]['service_id'] + slas[i]['service_type']=service_type + slas[i]['sitename']=sitename + slas[i]['endpoint']=endpoint + slas[i]['iam_enabled']=iam_enabled + + filtered_slas.append(slas[i]) + + + return filtered_slas + diff --git a/app/templates/advanced_config.html b/app/templates/advanced_config.html index 1a8b492d1..aa752fc6f 100644 --- a/app/templates/advanced_config.html +++ b/app/templates/advanced_config.html @@ -4,7 +4,6 @@ - Supported only for managed long-running service deployments
diff --git a/app/utils.py b/app/utils.py index ac7dd47d6..82e76092d 100644 --- a/app/utils.py +++ b/app/utils.py @@ -46,6 +46,25 @@ def loadToscaTemplates(directory): return toscaTemplates +def getdeploymenttype(nodes): + deployment_type = "" + for (j, u) in nodes.items(): + if deployment_type == "": + for (k, v) in u.items(): + if k == "type" and v == "tosca.nodes.indigo.Compute": + deployment_type = "CLOUD" + break + if k == "type" and v == "tosca.nodes.indigo.Container.Application.Docker.Marathon": + deployment_type = "MARATHON" + break + if k == "type" and v == "tosca.nodes.indigo.Container.Application.Docker.Chronos": + deployment_type = "CHRONOS" + break + if k == "type" and v == "tosca.nodes.indigo.Qcg.Job": + deployment_type = "QCG" + break + return deployment_type + def extractToscaInfo(toscaDir, tosca_pars_dir, toscaTemplates): toscaInfo = {} for tosca in toscaTemplates: @@ -78,6 +97,9 @@ def extractToscaInfo(toscaDir, tosca_pars_dir, toscaTemplates): if 'inputs' in template['topology_template']: toscaInfo[tosca]['inputs'] = template['topology_template']['inputs'] + + if 'node_templates' in template['topology_template']: + toscaInfo[tosca]['deployment_type'] = getdeploymenttype(template['topology_template']['node_templates']) ## add parameters code here tabs = {}