git://git.onelab.eu
/
sfa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9ba72fe
)
ListResources uses the 'rspec_version' field specified in the 'options' struct to...
author
Tony Mack
<tmack@paris.CS.Princeton.EDU>
Fri, 29 Apr 2011 20:29:03 +0000
(16:29 -0400)
committer
Tony Mack
<tmack@paris.CS.Princeton.EDU>
Fri, 29 Apr 2011 20:29:03 +0000
(16:29 -0400)
sfa/client/sfi.py
patch
|
blob
|
history
sfa/managers/aggregate_manager_pl.py
patch
|
blob
|
history
sfa/managers/slice_manager_pl.py
patch
|
blob
|
history
sfa/plc/aggregate.py
patch
|
blob
|
history
sfa/rspecs/pg_rspec.py
patch
|
blob
|
history
sfa/rspecs/rspec.py
patch
|
blob
|
history
sfa/rspecs/rspec_parser.py
patch
|
blob
|
history
diff --git
a/sfa/client/sfi.py
b/sfa/client/sfi.py
index
bc6cc60
..
50b88bc
100755
(executable)
--- a/
sfa/client/sfi.py
+++ b/
sfa/client/sfi.py
@@
-204,6
+204,8
@@
class Sfi:
default="all")
# display formats
if command in ("resources"):
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"))
parser.add_option("-f", "--format", dest="format", type="choice",
help="display format ([xml]|dns|ip)", default="xml",
choices=("xml", "dns", "ip"))
@@
-818,8
+820,11
@@
class Sfi:
creds = [cred]
if opts.delegate:
delegated_cred = self.delegate_cred(cred, get_authority(self.authority))
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,unique_call_id())
+ #result = server.ListResources(creds, call_options)
format = opts.format
if opts.file is None:
display_rspec(result, format)
format = opts.format
if opts.file is None:
display_rspec(result, format)
diff --git
a/sfa/managers/aggregate_manager_pl.py
b/sfa/managers/aggregate_manager_pl.py
index
d0eabda
..
437dd15
100644
(file)
--- a/
sfa/managers/aggregate_manager_pl.py
+++ b/
sfa/managers/aggregate_manager_pl.py
@@
-22,6
+22,7
@@
from sfa.plc.api import SfaAPI
from sfa.plc.aggregate import Aggregate
from sfa.plc.slices import *
from sfa.util.version import version_core
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
from sfa.util.sfatime import utcparse
from sfa.util.callids import Callids
@@
-306,18
+307,12
@@
def ListResources(api, creds, options,call_id):
(hrn, type) = urn_to_hrn(xrn)
# get the rspec's return format from options
(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:
# 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 rspec:
api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
return rspec
@@
-326,13
+321,13
@@
def ListResources(api, creds, options,call_id):
if xrn:
# get this rspec for the specified slice
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
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:
# cache the result
if caching and api.cache:
- api.cache.add(
format_template % (format, version)
, rspec)
+ api.cache.add(
version_string
, rspec)
return rspec
return rspec
diff --git
a/sfa/managers/slice_manager_pl.py
b/sfa/managers/slice_manager_pl.py
index
dc16a05
..
254c817
100644
(file)
--- a/
sfa/managers/slice_manager_pl.py
+++ b/
sfa/managers/slice_manager_pl.py
@@
-24,6
+24,7
@@
from sfa.util.threadmanager import ThreadManager
import sfa.util.xmlrpcprotocol as xmlrpcprotocol
import sfa.plc.peers as peers
from sfa.util.version import version_core
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
from sfa.util.callids import Callids
# we have specialized xmlrpclib.ServerProxy to remember the input url
@@
-339,6
+340,10
@@
def ListResources(api, creds, options, call_id):
xrn = options.get('geni_slice_urn', '')
(hrn, type) = urn_to_hrn(xrn)
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:
# get hrn of the original caller
origin_hrn = options.get('origin_hrn', None)
if not origin_hrn:
@@
-349,7
+354,7
@@
def ListResources(api, creds, options, call_id):
# look in cache first
if caching and api.cache and not xrn:
# 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
if rspec:
return rspec
@@
-381,7
+386,7
@@
def ListResources(api, creds, options, call_id):
# cache the result
if caching and api.cache and not xrn:
# 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()
return rspec.toxml()
diff --git
a/sfa/plc/aggregate.py
b/sfa/plc/aggregate.py
index
8160024
..
1d123d8
100644
(file)
--- a/
sfa/plc/aggregate.py
+++ b/
sfa/plc/aggregate.py
@@
-61,12
+61,16
@@
class Aggregate:
self.prepared = True
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
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())
rspec = SfaRSpec()
rspec.add_nodes(self.nodes.values())
diff --git
a/sfa/rspecs/pg_rspec.py
b/sfa/rspecs/pg_rspec.py
index
c3bda95
..
569c342
100755
(executable)
--- a/
sfa/rspecs/pg_rspec.py
+++ b/
sfa/rspecs/pg_rspec.py
@@
-6,25
+6,20
@@
from sfa.util.xrn import *
from sfa.util.plxrn import hostname_to_urn
from sfa.util.config import Config
from sfa.util.plxrn import hostname_to_urn
from sfa.util.config import Config
+
class PGRSpec(RSpec):
class PGRSpec(RSpec):
- xml = None
header = '<?xml version="1.0"?>\n'
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'
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 get_network(self):
network = None
@@
-74,6
+69,9
@@
class PGRSpec(RSpec):
def add_slivers(self, slivers, check_for_dupes=False):
pass
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
def add_links(self, links, check_for_dupes=False):
pass
diff --git
a/sfa/rspecs/rspec.py
b/sfa/rspecs/rspec.py
index
cc42a87
..
aeb0281
100755
(executable)
--- a/
sfa/rspecs/rspec.py
+++ b/
sfa/rspecs/rspec.py
@@
-8,10
+8,14
@@
from sfa.util.config import Config
from sfa.util.faults import SfaNotImplemented, InvalidRSpec
class RSpec:
from sfa.util.faults import SfaNotImplemented, InvalidRSpec
class RSpec:
- xml = None
header = '<?xml version="1.0"?>\n'
header = '<?xml version="1.0"?>\n'
+ template = """
+<RSpec>\n
+</RSpec>
+"""
namespaces = {}
config = Config()
namespaces = {}
config = Config()
+ xml = None
def __init__(self, rspec="", namespaces={}):
if rspec:
def __init__(self, rspec="", namespaces={}):
if rspec:
@@
-24,10
+28,10
@@
class RSpec:
date_format = '%Y-%m-%dT%H:%M:%SZ'
now = datetime.utcnow()
generated_ts = now.strftime(date_format)
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)
def parse_rspec(self, rspec, namespaces={}):
parser = etree.XMLParser(remove_blank_text=True)
diff --git
a/sfa/rspecs/rspec_parser.py
b/sfa/rspecs/rspec_parser.py
index
3d96860
..
c3dde65
100755
(executable)
--- a/
sfa/rspecs/rspec_parser.py
+++ b/
sfa/rspecs/rspec_parser.py
@@
-3,7
+3,7
@@
from sfa.rspecs.sfa_rspec import SfaRSpec
from sfa.rspecs.pg_rspec import PGRSpec
from sfa.rspecs.rspec import RSpec
from lxml import etree
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)
def parse_rspec(in_rspec):
rspec = RSpec(rspec=in_rspec)
@@
-20,8
+20,6
@@
def parse_rspec(in_rspec):
out_rspec.xml = rspec.xml
return out_rspec
out_rspec.xml = rspec.xml
return out_rspec
-
-
if __name__ == '__main__':
print "Parsing SFA RSpec:",
if __name__ == '__main__':
print "Parsing SFA RSpec:",