default="all")
# display formats
if command in ("resources"):
+ parser.add_option("-r", "--rspec-version", dest="rspec_version", default="sfa 1",
+ help="schema type and version of resulting RSpec")
parser.add_option("-f", "--format", dest="format", type="choice",
help="display format ([xml]|dns|ip)", default="xml",
choices=("xml", "dns", "ip"))
creds = [cred]
if opts.delegate:
delegated_cred = self.delegate_cred(cred, get_authority(self.authority))
- creds.append(delegated_cred)
+ creds.append(delegated_cred)
+ if opts.rspec_version:
+ call_options['rspec_version'] = opts.rspec_version
result = server.ListResources(creds, call_options,unique_call_id())
+ #result = server.ListResources(creds, call_options)
format = opts.format
if opts.file is None:
display_rspec(result, format)
from sfa.plc.aggregate import Aggregate
from sfa.plc.slices import *
from sfa.util.version import version_core
+from sfa.rspecs.rspec_version import RSpecVersion
from sfa.util.sfatime import utcparse
from sfa.util.callids import Callids
(hrn, type) = urn_to_hrn(xrn)
# get the rspec's return format from options
- try:
- format_raw = options.get('rspec_version', 'SFA 1')
- format_split = format_raw.split(' ')
- format, version = format_split[0].lower(), format_split[1]
- except:
- # invalid format. Just continue
- format, version = 'sfa', '1'
- format_template = "rsepc_%s_%s"
-
+ rspec_version = RSpecVersion(options.get('rspec_version', 'SFA 1'))
+ version_string = "rspec_%s_%s" % (rspec_version.format, rspec_version.version)
+
# look in cache first
if caching and api.cache and not xrn:
- rspec = api.cache.get(format_template % (format, version))
+ rspec = api.cache.get(version_string)
if rspec:
api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
return rspec
if xrn:
# get this rspec for the specified slice
- rspec = aggregate.get_rspec(slice_xrn=hrn, format=format)
+ rspec = aggregate.get_rspec(slice_xrn=hrn, version=rspec_version)
else:
# generate rspec in both pg and sfa formats
- rspec = aggregate.get_rspec(format=format)
+ rspec = aggregate.get_rspec(version=rspec_version)
# cache the result
if caching and api.cache:
- api.cache.add(format_template % (format, version), rspec)
+ api.cache.add(version_string, rspec)
return rspec
import sfa.util.xmlrpcprotocol as xmlrpcprotocol
import sfa.plc.peers as peers
from sfa.util.version import version_core
+from sfa.rspecs.rspec_version import RSpecVersion
from sfa.util.callids import Callids
# we have specialized xmlrpclib.ServerProxy to remember the input url
xrn = options.get('geni_slice_urn', '')
(hrn, type) = urn_to_hrn(xrn)
+ # get the rspec's return format from options
+ rspec_version = RSpecVersion(options.get('rspec_version', 'SFA 1'))
+ version_string = "rspec_%s_%s" % (rspec_version.format, rspec_version.version)
+
# get hrn of the original caller
origin_hrn = options.get('origin_hrn', None)
if not origin_hrn:
# look in cache first
if caching and api.cache and not xrn:
- rspec = api.cache.get('nodes')
+ rspec = api.cache.get(version_string)
if rspec:
return rspec
# cache the result
if caching and api.cache and not xrn:
- api.cache.add('nodes', rspec)
+ api.cache.add(version_string, rspec)
return rspec.toxml()
self.prepared = True
- def get_rspec(self, slice_xrn=None, format='sfa'):
+ def get_rspec(self, slice_xrn=None, version = None):
self.prepare()
rspec = None
- if format == ['pg']:
- rspec = PGRSpec()
- else:
+ if version:
+ format = version.format
+ if format == 'pg':
+ rspec = PGRSpec()
+ else:
+ rspec = SfaRSpec()
+ else:
rspec = SfaRSpec()
rspec.add_nodes(self.nodes.values())
from sfa.util.plxrn import hostname_to_urn
from sfa.util.config import Config
+
class PGRSpec(RSpec):
- xml = None
header = '<?xml version="1.0"?>\n'
+ template = """
+<rspec xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.protogeni.net/resources/rspec/0.2" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/0.2 http://www.protogeni.net/resources/rspec/0.2/ad.xsd">\n
+</rspec>
+"""
namespaces = {'rspecv2':'http://www.protogeni.net/resources/rspec/0.2',
'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
}
schemas = {'xsi': 'http://www.protogeni.net/resources/rspec/0.2 http://www.protogeni.net/resources/rspec/0.2/ad.xsd'
}
format = 'pg'
-
- def create(self, type="advertisement"):
- RSpec.create(self)
- for namespace in self.namespaces:
- xmlns = "xmlns"
- if namespace not in 'rspecv2':
- xmlns = xmlns + ":" + namespace
- self.xml.set(xmlns, self.namespaces[namespace])
- for schema in self.schemas:
- self.xml.set(schema+":schemaLocation", self.schemas[schema])
+ xml = None
def get_network(self):
network = None
def add_slivers(self, slivers, check_for_dupes=False):
pass
+ def add_interfaces(self, interfaces, check_for_dupes=False):
+ pass
+
def add_links(self, links, check_for_dupes=False):
pass
from sfa.util.faults import SfaNotImplemented, InvalidRSpec
class RSpec:
- xml = None
header = '<?xml version="1.0"?>\n'
+ template = """
+<RSpec>\n
+</RSpec>
+"""
namespaces = {}
config = Config()
+ xml = None
def __init__(self, rspec="", namespaces={}):
if rspec:
date_format = '%Y-%m-%dT%H:%M:%SZ'
now = datetime.utcnow()
generated_ts = now.strftime(date_format)
- expires_ts = (now + timedelta(minutes=30)).strftime(date_format)
- self.xml = etree.Element("rspec", type = type,
- valid_until=expires_ts,
- generated=generated_ts)
+ expires_ts = (now + timedelta(hours=1)).strftime(date_format)
+ self.parse_rspec(self.template, self.namespaces)
+ self.xml.set('valid_until', expires_ts)
+ self.xml.set('generated', generated_ts)
def parse_rspec(self, rspec, namespaces={}):
parser = etree.XMLParser(remove_blank_text=True)
from sfa.rspecs.pg_rspec import PGRSpec
from sfa.rspecs.rspec import RSpec
from lxml import etree
-
+from
def parse_rspec(in_rspec):
rspec = RSpec(rspec=in_rspec)
out_rspec.xml = rspec.xml
return out_rspec
-
-
if __name__ == '__main__':
print "Parsing SFA RSpec:",