data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml',
'config/registries.xml',
'config/default_config.xml',
+ 'config/api_versions.xml',
'config/sfi_config',
'config/topology',
'sfa/managers/pl/pl.rng',
+import socket
from sfa.util.version import version_core
from sfa.util.xrn import Xrn
from sfa.util.callids import Callids
+from sfa.server.api_versions import ApiVersions
class AggregateManager:
def GetVersion(self, api, options):
xrn=Xrn(api.hrn)
version = version_core()
+ geni_api_versions = ApiVersions().get_versions()
+ geni_api_versions.append({'2': 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)})
version_generic = {
'interface':'aggregate',
'sfa': 2,
'geni_api': 2,
- 'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)},
+ 'geni_api_versions': geni_api_versions,
'hrn':xrn.get_hrn(),
'urn':xrn.get_urn(),
}
--- /dev/null
+import os
+from sfa.util.xml import XML
+from sfa.util.config import Config
+
+class ApiVersions:
+
+ required_fields = ['version', 'url']
+
+ template = """<api_versions>
+<api_version name="" version="" url="" />
+</api_versions>"""
+
+ def __init__(self, string=None, filename=None, create=False):
+ self.xml = None
+
+ if create:
+ self.create()
+ elif string:
+ self.load(string)
+ elif filename:
+ self.load(filename)
+ else:
+ # load the default file
+ c = Config()
+ api_versions_file = os.path.sep.join([c.config_path, 'api_versions.xml'])
+ self.load(api_versions_file)
+
+ def create(self):
+ self.xml = XML(string=ApiVersions.template)
+
+ def load(self, source):
+ self.xml = XML(source)
+
+ def get_versions(self):
+ versions = []
+ for value in self.xml.todict().values():
+ if not value:
+ continue
+ if isinstance(value, list):
+ for item in value:
+ if isinstance(item, dict) and \
+ set(ApiVersions.required_fields).issubset(item.keys()):
+ api_version = {str(item['version']): item['url']}
+ versions.append(api_version)
+ return versions
+
+