# -*- coding: utf-8 -*-\r
-"""Template system for xifi project.\r
+"""Template system for fed4fire project.\r
\r
The specific template system is configured with the factory module variable.\r
\r
data = sla.slaclient.templates.fed4fire.TemplateInput(template_id="template-test")\r
slatemplate_xml = sla.slaclient.templates.fed4fire.render_slatemplate(data)\r
\r
-Notes about agreements in XiFi:\r
+Notes about agreements in fed4fire:\r
The ws-agreement specification does not address where to place the name/id\r
of the service (as known outside SLA) being defined in the\r
agreement/template xml. So, it has been defined an element\r
The guarantee terms, service description terms, etc, use the attribute\r
serviceName to reference (internally in the xml) the service. So, there\r
could be more than one serviceName in a xml (as opposed to the former\r
- serviceId). In Xifi, there is only one service per agreement, so we\r
+ serviceId). In fed4fire, there is only one service per agreement, so we\r
can give serviceId and serviceName the same value.\r
\r
A ServiceReference defines how a serviceName is known externally: a\r
(they are used to describe the service to be instantiated), so we can\r
extrapolate the location as the "abstract location of the metric".\r
\r
- In summary, in XiFi, the service properties will hold the metrics being\r
+ In summary, in fed4fire, the service properties will hold the metrics being\r
monitored for a service.\r
\r
And the guarantee terms hold the constraints that are being enforced for\r
</wsag:ServiceLevelObjective>\r
</wsag:GuaranteeTerm>\r
\r
- * Name is a name for the guarantee term. In Xifi, the name will have the\r
+ * Name is a name for the guarantee term. In fed4fire, the name will have the\r
value "GT_<metric_name>"\r
* ServiceName is an internal reference in the agreement to the service\r
being enforced, as an agreement can created for more than one service.\r
- In Xifi, to my knowledge, one service: one agreement, so this service\r
+ In fed4fire, to my knowledge, one service: one agreement, so this service\r
name is not really important.\r
* KpiName is a name given to the constraint, and I am using the same name\r
as the service property used in the constraint. This makes more sense\r
"""\r
\r
from sla.slaclient import wsag_model\r
-import pdb\r
+import json\r
\r
from sla.slaclient.templates.fed4fire.django.factory import Factory\r
factory = Factory()\r
print "render_slaagreement"\r
template = _getfactory().slaagreement()\r
#pdb.set_trace()\r
- rendered = template.render(data) \r
+ rendered = template.render(data)\r
return rendered\r
\r
\r
\r
class GuaranteeTerm(object):\r
\r
+ class GuaranteeScope(object):\r
+\r
+ def __init__(self,\r
+ servicename="",\r
+ scope=""):\r
+\r
+ self.servicename = servicename\r
+ self.scope = scope\r
+\r
+ def __repr__(self):\r
+ s = "<GuaranteeScope(servicename={}, scope={})>"\r
+ return s.format(\r
+ self.servicename,\r
+ self.scope\r
+ )\r
+\r
def __init__(self,\r
metric_name="",\r
- bounds=(0, 0)):\r
+ bounds=(0, 0),\r
+ guarantee_scopes=()):\r
"""Creates a GuaranteeTerm.\r
\r
Take into account that the GT's name is based on the metric_name.\r
- :param str metric_name: name of the service property being enforced.\r
- :param bounds: (lower, upper) bounds of the metric values.\r
+ :param str metric_name: name of the service property being enforced\r
+ :param bounds: (lower, upper) bounds of the metric values\r
:type bounds: (float, float)\r
"""\r
self.name = "GT_{}".format(metric_name)\r
self.metric_name = metric_name\r
self.kpiname = metric_name\r
self.bounds = bounds\r
+ self.guarantee_scopes = guarantee_scopes\r
+\r
+ def __repr__(self):\r
+ s = "<GuaranteeTerm(name={}, metric_name={}, " \\r
+ "kpiname={}, bounds={}, guarantee_scopes={})>"\r
+ return s.format(\r
+ self.name,\r
+ self.metric_name,\r
+ self.kpiname,\r
+ self.bounds,\r
+ repr(self.guarantee_scopes)\r
+ )\r
\r
def __init__(self,\r
agreement_id="",\r
:param str agreement_name: optional agreement name\r
:param str service_id: Domain id/name of the service.\r
:param str consumer: Id of the consumer party in the agreement.\r
- :param str provider: Resource Id of the provider party in the agreement.\r
+ :param str provider: Resource Id of the provider party in the agreement\r
The provider must exist previously in the SlaManager.\r
:param str template_id: TemplateId of the template this agreement is\r
based on.\r
self.template_id = template_id\r
self.expiration_time = expiration_time\r
self.expiration_time_iso = \\r
- expiration_time.isoformat() if expiration_time else None\r
+ expiration_time if expiration_time else None\r
self.service_properties = service_properties\r
self.guarantee_terms = guarantee_terms\r
\r
#\r
# NOTE: templateinput does not address guaranteeterms (yet)\r
#\r
+\r
+ for _, gt in slatemplate.guaranteeterms.items():\r
+ gt.scopes[0].scope = self.guarantee_terms[0].guarantee_scopes.scope\r
+ gt.scopes[0].scope = [x.encode('utf-8') for x in gt.scopes[0].scope]\r
+\r
result = AgreementInput(\r
agreement_id=self.agreement_id,\r
agreement_name=self.agreement_name,\r
template_id=slatemplate.template_id,\r
expiration_time=self.expiration_time,\r
service_properties=slatemplate.variables.values(),\r
+ #guarantee_terms=self.guarantee_terms\r
guarantee_terms=slatemplate.guaranteeterms.values()\r
)\r
- print result.guarantee_terms[0]\r
+\r
return result\r