)
"""
url = _buildpath_(self.rooturl, path)
-
+
if "testbed" in kwargs:
url = url + "?testbed=" + kwargs["testbed"]
"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"] \
"""
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
\r
# Builds AgreementInput from json\r
data = jsonparser.agreementinput_from_json(json_data)\r
+\r
# Read template from manager\r
- slatemplate, request = client_templates.getbyid(data.template_id, data.template_id)\r
+ # client_templates.getbyid(provider_id, testbed)\r
+ slatemplate, request = client_templates.getbyid(data.template_id)\r
# Copy (overriding if necessary) from template to AgreementInput\r
final_data = data.from_template(slatemplate)\r
+\r
slaagreement = fed4fire.render_slaagreement(final_data)\r
\r
client_agreements = context.restfactory.agreements()\r
TemplateFactory()\r
)\r
\r
- print "Expiration time: ", expiration_time\r
-\r
- # time = dateutil.parser.parse(expiration_time)\r
- # print "ISO FORMAT: ", time.strftime('%Y-%m-%dT%H:%M:%S%Z')\r
- print "ISO FORMAT: ", expiration_time.strftime('%Y-%m-%dT%H:%M:%S%Z')\r
-\r
agreement = {\r
"agreement_id": str(uuid.uuid4()),\r
"template_id": template_id,\r
"expiration_time": expiration_time.strftime('%Y-%m-%dT%H:%M:%S%Z'),\r
"consumer": user,\r
+ "guarantees": [\r
+ {\r
+ "name": "uptime",\r
+ "bounds": ["0", "1"],\r
+ "scope": {\r
+ "service_name": "",\r
+ "scope": resources[template_id]\r
+ }\r
+ }\r
+ ]\r
}\r
\r
json_data = json.dumps(agreement)\r
\r
return createagreement(json_data, context)\r
-
\ No newline at end of file
"""\r
result = []\r
for term in d.get("guarantees", None) or ():\r
+ gs = AgreementInput.GuaranteeTerm.GuaranteeScope(\r
+ term["scope"].get("service_name", ""),\r
+ term["scope"].get("scope", "")\r
+ )\r
+ print "*******GS****"\r
+ print gs\r
result.append(\r
AgreementInput.GuaranteeTerm(\r
metric_name=term["name"],\r
- bounds=tuple(term["bounds"])\r
+ bounds=tuple(term["bounds"]),\r
+ guarantee_scopes=gs\r
)\r
)\r
- return result
\ No newline at end of file
+\r
+ return result\r
</wsag:ServiceProperties>\r
{% for term in data.guarantee_terms %}\r
<wsag:GuaranteeTerm wsag:Name="{{term.name}}">\r
- {# do not need servicescope #}\r
- {% for scope in term.scopes %}\r
- <wsag:ServiceScope wsag:ServiceName="{{scope.servicename}}"/>\r
+ {% for gs in term.scopes %}\r
+ <wsag:ServiceScope wsag:ServiceName="{{gs.servicename}}">\r
+ {{ gs.scope }}\r
+ </wsag:ServiceScope>\r
{% endfor %}\r
<wsag:ServiceLevelObjective>\r
<wsag:KPITarget>\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
\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
#\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
+ #print self.guarantee_terms[0], "\nVVVVVVVVVVVVVVVVV"\r
+ #print slatemplate.guaranteeterms['GT_CPULoad'], "\nVVVVVVVVVVVVVVVVV"\r
+ #print self.guarantee_terms[0].guarantee_scopes.scope, "\nVVVVVVVVVVVVVVVVV"\r
+ #print "TIPO: ", type(self.guarantee_terms[0])\r
+ #print "TIPO 2", type(slatemplate.guaranteeterms['GT_CPULoad']), "\nVVVVVVVVVVVVVVVVV"\r
+ #print slatemplate.guaranteeterms['GT_CPULoad'].scopes, "\nVVVVVVVVVVVVVVVVV"\r
+ #print result.guarantee_terms[0], "\nVVVVVVVVVVVVVVVVV"\r
return result\r