From: Javier GarcĂ­a Date: Wed, 24 Sep 2014 10:02:05 +0000 (+0200) Subject: Added description of resources on each SLA agreement when they are created X-Git-Tag: myslice-1.1~27^2~1 X-Git-Url: http://git.onelab.eu/?p=unfold.git;a=commitdiff_plain;h=ca92509528a7ba32b74f9835896182fd7a8b22b2 Added description of resources on each SLA agreement when they are created --- diff --git a/sla/slaclient/restclient.py b/sla/slaclient/restclient.py index ec5da1dd..8091f4ee 100755 --- a/sla/slaclient/restclient.py +++ b/sla/slaclient/restclient.py @@ -151,7 +151,7 @@ class Client(object): ) """ url = _buildpath_(self.rooturl, path) - + if "testbed" in kwargs: url = url + "?testbed=" + kwargs["testbed"] @@ -160,7 +160,7 @@ class Client(object): "content-type": "application/xml"} kwargs["auth"] = HTTPBasicAuth(settings.SLA_MANAGER_USER, - settings.SLA_MANAGER_PASSWORD) + settings.SLA_MANAGER_PASSWORD) result = requests.post(url, data, **kwargs) location = result.headers["location"] \ @@ -346,12 +346,12 @@ class Templates(object): """ return self.res.getall() - def getbyid(self, provider_id, testbed): + def getbyid(self, provider_id): """Get a template :rtype: wsag_model.Template """ - return self.res.getbyid(provider_id, {"testbed": testbed}) + return self.res.getbyid(provider_id, {"testbed": provider_id}) def create(self, template): """Create a new template diff --git a/sla/slaclient/service/fed4fire/fed4fireservice.py b/sla/slaclient/service/fed4fire/fed4fireservice.py index adec86bc..98830985 100755 --- a/sla/slaclient/service/fed4fire/fed4fireservice.py +++ b/sla/slaclient/service/fed4fire/fed4fireservice.py @@ -104,10 +104,13 @@ def createagreement(json_data, context): # Builds AgreementInput from json data = jsonparser.agreementinput_from_json(json_data) + # Read template from manager - slatemplate, request = client_templates.getbyid(data.template_id, data.template_id) + # client_templates.getbyid(provider_id, testbed) + slatemplate, request = client_templates.getbyid(data.template_id) # Copy (overriding if necessary) from template to AgreementInput final_data = data.from_template(slatemplate) + slaagreement = fed4fire.render_slaagreement(final_data) client_agreements = context.restfactory.agreements() @@ -120,20 +123,23 @@ def createagreementsimplified(template_id, user, expiration_time, resources): TemplateFactory() ) - print "Expiration time: ", expiration_time - - # time = dateutil.parser.parse(expiration_time) - # print "ISO FORMAT: ", time.strftime('%Y-%m-%dT%H:%M:%S%Z') - print "ISO FORMAT: ", expiration_time.strftime('%Y-%m-%dT%H:%M:%S%Z') - agreement = { "agreement_id": str(uuid.uuid4()), "template_id": template_id, "expiration_time": expiration_time.strftime('%Y-%m-%dT%H:%M:%S%Z'), "consumer": user, + "guarantees": [ + { + "name": "uptime", + "bounds": ["0", "1"], + "scope": { + "service_name": "", + "scope": resources[template_id] + } + } + ] } json_data = json.dumps(agreement) return createagreement(json_data, context) - \ No newline at end of file diff --git a/sla/slaclient/service/fed4fire/jsonparser.py b/sla/slaclient/service/fed4fire/jsonparser.py index 04d01a8e..d4a23008 100755 --- a/sla/slaclient/service/fed4fire/jsonparser.py +++ b/sla/slaclient/service/fed4fire/jsonparser.py @@ -109,10 +109,18 @@ def _json_parse_guarantee_terms(d): """ result = [] for term in d.get("guarantees", None) or (): + gs = AgreementInput.GuaranteeTerm.GuaranteeScope( + term["scope"].get("service_name", ""), + term["scope"].get("scope", "") + ) + print "*******GS****" + print gs result.append( AgreementInput.GuaranteeTerm( metric_name=term["name"], - bounds=tuple(term["bounds"]) + bounds=tuple(term["bounds"]), + guarantee_scopes=gs ) ) - return result \ No newline at end of file + + return result diff --git a/sla/slaclient/templates/fed4fire/django/agreement.xml b/sla/slaclient/templates/fed4fire/django/agreement.xml index 9b4c8262..7cf9a665 100755 --- a/sla/slaclient/templates/fed4fire/django/agreement.xml +++ b/sla/slaclient/templates/fed4fire/django/agreement.xml @@ -27,9 +27,10 @@ {% for term in data.guarantee_terms %} - {# do not need servicescope #} - {% for scope in term.scopes %} - + {% for gs in term.scopes %} + + {{ gs.scope }} + {% endfor %} diff --git a/sla/slaclient/templates/fed4fire/fed4fire.py b/sla/slaclient/templates/fed4fire/fed4fire.py index c98e43c0..572d9b4e 100755 --- a/sla/slaclient/templates/fed4fire/fed4fire.py +++ b/sla/slaclient/templates/fed4fire/fed4fire.py @@ -106,7 +106,7 @@ Notes about agreements in fed4fire: """ from sla.slaclient import wsag_model -import pdb +import json from sla.slaclient.templates.fed4fire.django.factory import Factory factory = Factory() @@ -196,20 +196,49 @@ class AgreementInput(object): class GuaranteeTerm(object): + class GuaranteeScope(object): + + def __init__(self, + servicename="", + scope=""): + + self.servicename = servicename + self.scope = scope + + def __repr__(self): + s = "" + return s.format( + self.servicename, + self.scope + ) + def __init__(self, metric_name="", - bounds=(0, 0)): + bounds=(0, 0), + guarantee_scopes=()): """Creates a GuaranteeTerm. Take into account that the GT's name is based on the metric_name. - :param str metric_name: name of the service property being enforced. - :param bounds: (lower, upper) bounds of the metric values. + :param str metric_name: name of the service property being enforced + :param bounds: (lower, upper) bounds of the metric values :type bounds: (float, float) """ self.name = "GT_{}".format(metric_name) self.metric_name = metric_name self.kpiname = metric_name self.bounds = bounds + self.guarantee_scopes = guarantee_scopes + + def __repr__(self): + s = "" + return s.format( + self.name, + self.metric_name, + self.kpiname, + self.bounds, + repr(self.guarantee_scopes) + ) def __init__(self, agreement_id="", @@ -228,7 +257,7 @@ class AgreementInput(object): :param str agreement_name: optional agreement name :param str service_id: Domain id/name of the service. :param str consumer: Id of the consumer party in the agreement. - :param str provider: Resource Id of the provider party in the agreement. + :param str provider: Resource Id of the provider party in the agreement The provider must exist previously in the SlaManager. :param str template_id: TemplateId of the template this agreement is based on. @@ -278,6 +307,11 @@ class AgreementInput(object): # # NOTE: templateinput does not address guaranteeterms (yet) # + + for _, gt in slatemplate.guaranteeterms.items(): + gt.scopes[0].scope = self.guarantee_terms[0].guarantee_scopes.scope + gt.scopes[0].scope = [x.encode('utf-8') for x in gt.scopes[0].scope] + result = AgreementInput( agreement_id=self.agreement_id, agreement_name=self.agreement_name, @@ -287,7 +321,15 @@ class AgreementInput(object): template_id=slatemplate.template_id, expiration_time=self.expiration_time, service_properties=slatemplate.variables.values(), + #guarantee_terms=self.guarantee_terms guarantee_terms=slatemplate.guaranteeterms.values() ) - print result.guarantee_terms[0] + + #print self.guarantee_terms[0], "\nVVVVVVVVVVVVVVVVV" + #print slatemplate.guaranteeterms['GT_CPULoad'], "\nVVVVVVVVVVVVVVVVV" + #print self.guarantee_terms[0].guarantee_scopes.scope, "\nVVVVVVVVVVVVVVVVV" + #print "TIPO: ", type(self.guarantee_terms[0]) + #print "TIPO 2", type(slatemplate.guaranteeterms['GT_CPULoad']), "\nVVVVVVVVVVVVVVVVV" + #print slatemplate.guaranteeterms['GT_CPULoad'].scopes, "\nVVVVVVVVVVVVVVVVV" + #print result.guarantee_terms[0], "\nVVVVVVVVVVVVVVVVV" return result