Added description of resources on each SLA agreement when they are created
authorJavier García <javier.garcial.external@atos.net>
Wed, 24 Sep 2014 10:02:05 +0000 (12:02 +0200)
committerJavier García <javier.garcial.external@atos.net>
Wed, 24 Sep 2014 10:02:05 +0000 (12:02 +0200)
sla/slaclient/restclient.py
sla/slaclient/service/fed4fire/fed4fireservice.py
sla/slaclient/service/fed4fire/jsonparser.py
sla/slaclient/templates/fed4fire/django/agreement.xml
sla/slaclient/templates/fed4fire/fed4fire.py

index ec5da1d..8091f4e 100755 (executable)
@@ -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
index adec86b..9883098 100755 (executable)
@@ -104,10 +104,13 @@ def createagreement(json_data, context):
 \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
@@ -120,20 +123,23 @@ def createagreementsimplified(template_id, user, expiration_time, resources):
         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
index 04d01a8..d4a2300 100755 (executable)
@@ -109,10 +109,18 @@ def _json_parse_guarantee_terms(d):
     """\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
index 9b4c826..7cf9a66 100755 (executable)
             </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
index c98e43c..572d9b4 100755 (executable)
@@ -106,7 +106,7 @@ Notes about agreements in fed4fire:
 """\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
@@ -196,20 +196,49 @@ class AgreementInput(object):
 \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
@@ -228,7 +257,7 @@ class AgreementInput(object):
         :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
@@ -278,6 +307,11 @@ class AgreementInput(object):
         #\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
@@ -287,7 +321,15 @@ class AgreementInput(object):
             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