this change is designed for illustrative purposes only memory
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 17 Jul 2014 14:31:39 +0000 (16:31 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 17 Jul 2014 14:31:39 +0000 (16:31 +0200)
it shows how the <node> tag in the rspec can be extended with a <memory> tag whoe value is derived from a PL tag

sfa/planetlab/plaggregate.py
sfa/rspecs/elements/memory.py [new file with mode: 0644]
sfa/rspecs/elements/versions/pgv2Node.py

index 2876694..7bf0faa 100644 (file)
@@ -16,6 +16,7 @@ from sfa.rspecs.elements.services import ServicesElement
 from sfa.rspecs.elements.pltag import PLTag
 from sfa.rspecs.elements.lease import Lease
 from sfa.rspecs.elements.granularity import Granularity
+from sfa.rspecs.elements.memory import Memory
 from sfa.rspecs.version_manager import VersionManager
 
 from sfa.planetlab.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename, slicename_to_hrn, top_auth, hash_loginbase
@@ -222,6 +223,23 @@ class PlAggregate:
         else:
             rspec_node['exclusive'] = 'false'
 
+        # this mostly is a sample code, not designed for production but more for
+        # illustrative purposes, that gives an example of how you can extend the node's
+        # rspec to expose their amount of memory
+        # in this example I chose to always expose a <memory> tag
+        # also by default the exposed amount will be 4 Gb
+        # but this value can be overridden by setting a 'memory' tag on the node
+        memory_in_gb='4'
+        # let's scan the node tags to find for any 'memory' tag
+        for id,node_tag in node_tags.items():
+            if node_tag['tagname']=='memory':
+                memory_in_gb = node_tag['value']
+                # note that in this case it would make sense to delete the node_tag
+                # so that the XML does not contain a duplicate information
+        # always add a 'memory' xml tag
+        # this will be rendered by pgv2node.py
+        rspec_node['memory'] = Memory({'Gb':memory_in_gb})
+        
         rspec_node['hardware_types'] = [HardwareType({'name': 'plab-pc'}),
                                         HardwareType({'name': 'pc'})]
         # only doing this because protogeni rspec needs
diff --git a/sfa/rspecs/elements/memory.py b/sfa/rspecs/elements/memory.py
new file mode 100644 (file)
index 0000000..74fda41
--- /dev/null
@@ -0,0 +1,11 @@
+# This is a simple illustrative example of how a memory amount could be exposed
+# in the rspec like this <memory Gb="4"/>
+# this is not intended for production though
+
+from sfa.rspecs.elements.element import Element
+
+class Memory(Element):
+    
+    fields = [
+        'Gb',
+    ]
index 60447b0..2784fcf 100644 (file)
@@ -15,6 +15,7 @@ from sfa.rspecs.elements.versions.pgv2Interface import PGv2Interface
 from sfa.rspecs.elements.versions.sfav1PLTag import SFAv1PLTag
 from sfa.rspecs.elements.granularity import Granularity
 from sfa.rspecs.elements.attribute import Attribute
+from sfa.rspecs.elements.memory import Memory
 
 
 class PGv2Node:
@@ -67,6 +68,10 @@ class PGv2Node:
                         slivers['tags'].append({'name': 'initscript', 'value': initscript['name']})
             PGv2SliverType.add_slivers(node_elem, slivers)
 
+            # render the memory tag; it will be placed at this point in the xml output
+            if node.get('memory'):
+                node_elem.add_instance('memory',node['memory'],Memory.fields)
+
             # advertise the node tags
             tags = node.get('tags', [])
             if tags: