From e0de6912f86ed4cd86289ab4ded2006600b5db11 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 17 Jul 2014 16:31:39 +0200 Subject: [PATCH] this change is designed for illustrative purposes only it shows how the tag in the rspec can be extended with a tag whoe value is derived from a PL tag --- sfa/planetlab/plaggregate.py | 18 ++++++++++++++++++ sfa/rspecs/elements/memory.py | 11 +++++++++++ sfa/rspecs/elements/versions/pgv2Node.py | 5 +++++ 3 files changed, 34 insertions(+) create mode 100644 sfa/rspecs/elements/memory.py diff --git a/sfa/planetlab/plaggregate.py b/sfa/planetlab/plaggregate.py index 28766948..7bf0faa2 100644 --- a/sfa/planetlab/plaggregate.py +++ b/sfa/planetlab/plaggregate.py @@ -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 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 index 00000000..74fda41c --- /dev/null +++ b/sfa/rspecs/elements/memory.py @@ -0,0 +1,11 @@ +# This is a simple illustrative example of how a memory amount could be exposed +# in the rspec like this +# this is not intended for production though + +from sfa.rspecs.elements.element import Element + +class Memory(Element): + + fields = [ + 'Gb', + ] diff --git a/sfa/rspecs/elements/versions/pgv2Node.py b/sfa/rspecs/elements/versions/pgv2Node.py index 60447b03..2784fcfb 100644 --- a/sfa/rspecs/elements/versions/pgv2Node.py +++ b/sfa/rspecs/elements/versions/pgv2Node.py @@ -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: -- 2.43.0