Added the possibility for users to define a set of information fields rspec_extension
authorPanos <antoniad@akastos.local>
Wed, 18 May 2011 21:36:27 +0000 (23:36 +0200)
committerPanos <antoniad@akastos.local>
Wed, 18 May 2011 21:36:27 +0000 (23:36 +0200)
to be added to the returned Rspec if available as node tags, using a
new -i option for sfi.py resources (e.g., sfi.py resources -i fcdistro).

sfa/client/sfi.py
sfa/managers/aggregate_manager_pl.py
sfa/managers/slice_manager_pl.py
sfa/plc/aggregate.py
sfa/rspecs/rspec.py
sfa/rspecs/sfa_rspec.py

index 5a7ec7f..579d38e 100755 (executable)
@@ -209,6 +209,10 @@ class Sfi:
             parser.add_option("-f", "--format", dest="format", type="choice",
                              help="display format ([xml]|dns|ip)", default="xml",
                              choices=("xml", "dns", "ip"))
+            #panos: a new option to define the type of information about resources a user is interested in
+           parser.add_option("-i", "--info", dest="info",
+                                help="optional component information", default=None)
+
 
         if command in ("resources", "show", "list"):
            parser.add_option("-o", "--output", dest="file",
@@ -831,7 +835,7 @@ class Sfi:
         if args:
             cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
             hrn = args[0]
-            call_options = {'geni_slice_urn': hrn_to_urn(hrn, 'slice')}
+           call_options = {'geni_slice_urn': hrn_to_urn(hrn, 'slice')}
         else:
             cred = user_cred
             hrn = None
@@ -842,6 +846,9 @@ class Sfi:
             creds.append(delegated_cred)
         if opts.rspec_version:
             call_options['rspec_version'] = opts.rspec_version 
+        #panos add info options
+        if opts.info:
+            call_options['info'] = opts.info 
         result = server.ListResources(creds, call_options,unique_call_id())
         format = opts.format
         if opts.file is None:
index 081695d..6b36284 100644 (file)
@@ -283,8 +283,8 @@ def DeleteSliver(api, xrn, creds, call_id):
     return 1
 
 # xxx Thierry : caching at the aggregate level sounds wrong...
-caching=True
-#caching=False
+#caching=True
+caching=False
 def ListSlices(api, creds, call_id):
     if Callids().already_handled(call_id): return []
     # look in cache first
@@ -313,6 +313,12 @@ def ListResources(api, creds, options,call_id):
     # get the rspec's return format from options
     rspec_version = RSpecVersion(options.get('rspec_version'))
     version_string = "rspec_%s" % (rspec_version.get_version_name())
+
+    #panos adding the info option to the caching key (can be improved)
+    if options.get('info'):
+       version_string = version_string + "_"+options.get('info')
+
+    print "[aggregate] version string = ",version_string
     
     # look in cache first
     if caching and api.cache and not xrn:
@@ -321,7 +327,10 @@ def ListResources(api, creds, options,call_id):
             api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
             return rspec 
 
-    aggregate = Aggregate(api)
+    #aggregate = Aggregate(api)
+    #panos: passing user-defined options
+    #print "manager options = ",options
+    aggregate = Aggregate(api, options)
 
     rspec =  aggregate.get_rspec(slice_xrn=xrn, version=rspec_version)
 
index 065687d..e7f779d 100644 (file)
@@ -362,6 +362,12 @@ def ListResources(api, creds, options, call_id):
     rspec_version = RSpecVersion(options.get('rspec_version'))
     version_string = "rspec_%s" % (rspec_version.get_version_name())
 
+    #panos adding the info option to the caching key (can be improved)
+    if options.get('info'):
+       version_string = version_string + "_"+options.get('info')
+   
+    print "version string = ",version_string
+
     # look in cache first
     if caching and api.cache and not xrn:
         rspec =  api.cache.get(version_string)
index afc20d4..2e49dd6 100644 (file)
@@ -14,9 +14,14 @@ class Aggregate:
     links = {}
     node_tags = {}
     prepared=False
+    #panos new user options variable
+    user_options = {}
 
-    def __init__(self, api):
+    def __init__(self, api, user_options={}):
         self.api = api
+       #panos 
+       self.user_options = user_options
+       print "[aggregate] options = ",self.user_options
 
     def prepare_sites(self, force=False):
         if not self.sites or force:  
@@ -71,10 +76,12 @@ class Aggregate:
         rspec_version = RSpecVersion(version)
         if rspec_version['type'].lower() == 'protogeni':
             rspec = PGRSpec()
+       #panos pass user options to SfaRSpec
         elif rspec_version['type'].lower() == 'sfa':
-            rspec = SfaRSpec()
+            rspec = SfaRSpec("",{},self.user_options)
         else:
-            rspec = SfaRSpec()
+            rspec = SfaRSpec("",{},self.user_options)
+
 
         rspec.add_nodes(self.nodes.values())
         rspec.add_interfaces(self.interfaces.values()) 
index de7e250..8ed637d 100755 (executable)
@@ -15,8 +15,10 @@ class RSpec:
     type = None
     version = None
     namespaces = None    
+    user_options = {}
   
-    def __init__(self, rspec="", namespaces={}):
+    def __init__(self, rspec="", namespaces={}, user_options={}):
+       self.user_options = user_options
         if rspec:
             self.parse_rspec(rspec, namespaces)
         else:
index 830c853..2c8a0c9 100755 (executable)
@@ -202,8 +202,17 @@ class SfaRSpec(RSpec):
                         bwlimit = etree.SubElement(node_tag, 'bw_limit', units='kbps').text = str(interface['bwlimit']/1000)
             if 'tags' in node:
                 for tag in node['tags']:
-                   # expose this hard wired list of tags, plus the ones that are marked 'sfa' in their category 
-                   if tag['tagname'] in ['fcdistro', 'arch'] or 'sfa' in tag['category'].split('/'):
+                    #expose this hard wired list of tags, plus the ones that are marked 'sfa' in their category 
+                    #if tag['tagname'] in ['fcdistro', 'arch'] or 'sfa' in tag['category'].split('/'):
+                        #tag_element = etree.SubElement(node_tag, tag['tagname'], value=tag['value'])
+
+                   #panos expose tags only if requested by the user using the -i option
+                   if self.user_options:
+                       #print "[sfa rspec] found tag ",tag," and have info ",self.user_options.get('info')
+                       if self.user_options.get('info') and tag['tagname'] in self.user_options.get('info'):
+                            tag_element = etree.SubElement(node_tag, tag['tagname'], value=tag['value'])
+
+                    if 'sfa' in tag['category'].split('/'):
                         tag_element = etree.SubElement(node_tag, tag['tagname'], value=tag['value'])
 
             if 'site' in node: