From c1623056cb0a51c3817425ceee85aec3c62c57f3 Mon Sep 17 00:00:00 2001 From: Panos Date: Wed, 18 May 2011 23:36:27 +0200 Subject: [PATCH] Added the possibility for users to define a set of information fields 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 | 9 ++++++++- sfa/managers/aggregate_manager_pl.py | 15 ++++++++++++--- sfa/managers/slice_manager_pl.py | 6 ++++++ sfa/plc/aggregate.py | 13 ++++++++++--- sfa/rspecs/rspec.py | 4 +++- sfa/rspecs/sfa_rspec.py | 13 +++++++++++-- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index 5a7ec7fc..579d38ee 100755 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -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: diff --git a/sfa/managers/aggregate_manager_pl.py b/sfa/managers/aggregate_manager_pl.py index 081695dd..6b362842 100644 --- a/sfa/managers/aggregate_manager_pl.py +++ b/sfa/managers/aggregate_manager_pl.py @@ -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) diff --git a/sfa/managers/slice_manager_pl.py b/sfa/managers/slice_manager_pl.py index 065687d8..e7f779d0 100644 --- a/sfa/managers/slice_manager_pl.py +++ b/sfa/managers/slice_manager_pl.py @@ -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) diff --git a/sfa/plc/aggregate.py b/sfa/plc/aggregate.py index afc20d4f..2e49dd6e 100644 --- a/sfa/plc/aggregate.py +++ b/sfa/plc/aggregate.py @@ -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()) diff --git a/sfa/rspecs/rspec.py b/sfa/rspecs/rspec.py index de7e250e..8ed637d9 100755 --- a/sfa/rspecs/rspec.py +++ b/sfa/rspecs/rspec.py @@ -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: diff --git a/sfa/rspecs/sfa_rspec.py b/sfa/rspecs/sfa_rspec.py index 830c8535..2c8a0c93 100755 --- a/sfa/rspecs/sfa_rspec.py +++ b/sfa/rspecs/sfa_rspec.py @@ -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: -- 2.43.0