X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sla%2Fslaclient%2Ftemplates%2Ffed4fire%2Ffed4fire.py;h=572d9b4e8c705c082b1f0305c92ddcf604681eff;hb=ca92509528a7ba32b74f9835896182fd7a8b22b2;hp=efb939c7c9274c6c091067eb80c296c91798ad95;hpb=ba476841726dc818c0efd3ed25e42955a39fc504;p=myslice.git diff --git a/sla/slaclient/templates/fed4fire/fed4fire.py b/sla/slaclient/templates/fed4fire/fed4fire.py index efb939c7..572d9b4e 100755 --- a/sla/slaclient/templates/fed4fire/fed4fire.py +++ b/sla/slaclient/templates/fed4fire/fed4fire.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -"""Template system for xifi project. +"""Template system for fed4fire project. The specific template system is configured with the factory module variable. @@ -32,7 +32,7 @@ Usage: data = sla.slaclient.templates.fed4fire.TemplateInput(template_id="template-test") slatemplate_xml = sla.slaclient.templates.fed4fire.render_slatemplate(data) -Notes about agreements in XiFi: +Notes about agreements in fed4fire: The ws-agreement specification does not address where to place the name/id of the service (as known outside SLA) being defined in the agreement/template xml. So, it has been defined an element @@ -43,7 +43,7 @@ Notes about agreements in XiFi: The guarantee terms, service description terms, etc, use the attribute serviceName to reference (internally in the xml) the service. So, there could be more than one serviceName in a xml (as opposed to the former - serviceId). In Xifi, there is only one service per agreement, so we + serviceId). In fed4fire, there is only one service per agreement, so we can give serviceId and serviceName the same value. A ServiceReference defines how a serviceName is known externally: a @@ -68,7 +68,7 @@ Notes about agreements in XiFi: (they are used to describe the service to be instantiated), so we can extrapolate the location as the "abstract location of the metric". - In summary, in XiFi, the service properties will hold the metrics being + In summary, in fed4fire, the service properties will hold the metrics being monitored for a service. And the guarantee terms hold the constraints that are being enforced for @@ -88,11 +88,11 @@ Notes about agreements in XiFi: - * Name is a name for the guarantee term. In Xifi, the name will have the + * Name is a name for the guarantee term. In fed4fire, the name will have the value "GT_" * ServiceName is an internal reference in the agreement to the service being enforced, as an agreement can created for more than one service. - In Xifi, to my knowledge, one service: one agreement, so this service + In fed4fire, to my knowledge, one service: one agreement, so this service name is not really important. * KpiName is a name given to the constraint, and I am using the same name as the service property used in the constraint. This makes more sense @@ -106,7 +106,7 @@ Notes about agreements in XiFi: """ from sla.slaclient import wsag_model -import pdb +import json from sla.slaclient.templates.fed4fire.django.factory import Factory factory = Factory() @@ -133,7 +133,7 @@ def render_slaagreement(data): print "render_slaagreement" template = _getfactory().slaagreement() #pdb.set_trace() - rendered = template.render(data) + rendered = template.render(data) return rendered @@ -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. @@ -248,7 +277,7 @@ class AgreementInput(object): self.template_id = template_id self.expiration_time = expiration_time self.expiration_time_iso = \ - expiration_time.isoformat() if expiration_time else None + expiration_time if expiration_time else None self.service_properties = service_properties self.guarantee_terms = guarantee_terms @@ -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