</variablelist>
</category>
- <!-- ======================================== -->
- <category id="sfa_sm">
- <name>Slice Manager</name>
- <description>The settings that affect the slice manager that will run
- as part of this SFA instance.</description>
-
- <variablelist>
- <variable id="enabled" type="boolean">
- <name>Enable Slice Manager</name>
- <value>false</value>
- <description>Allows this local SFA instance to run as a
- slice manager. Warning, this feature is not really supported
- any longer.</description>
- </variable>
-
- <variable id="host" type="hostname">
- <name>Hostname</name>
- <value>localhost</value>
- <description>The hostname where the slice manager is expected to
- be found.</description>
- </variable>
-
- <variable id="port" type="int">
- <name>Port number</name>
- <value>12347</value>
- <description>The port where the slice manager is to be found.</description>
- </variable>
-
- <variable id="caching" type="boolean">
- <name>Cache advertisement rspec</name>
- <value>false</value>
- <description>Enable caching of the global advertisement, as
- returned by ListResources without a slice argument. </description>
- </variable>
-
- </variablelist>
- </category>
-
<!-- ======================================== -->
<category id="sfa_aggregate">
<name>Aggregate</name>
all_vars = ['SFA_CONFIG_DIR', 'SFA_DATA_DIR', 'SFA_INTERFACE_HRN',
'SFA_CM_SLICE_PREFIX', 'SFA_REGISTRY_HOST', 'SFA_REGISTRY_PORT',
'SFA_AGGREGATE_HOST', 'SFA_AGGREGATE_PORT',
- 'SFA_SM_HOST', 'SFA_SM_PORT',
'SFA_CM_ENABLED', 'SFA_CM_HOST', 'SFA_CM_PORT', 'SFA_CM_TYPE', 'SFA_CM_SLICE_PREFIX',
'SFA_API_LOGLEVEL']
host_defaults = {
'SFA_REGISTRY_HOST': default_host,
'SFA_AGGREGATE_HOST': default_host,
- 'SFA_SM_HOST': default_host,
}
const_dict = {}
# HRN
# Human readable name for this interface
-SFA_INTERFACE_HRN="plc"
+SFA_INTERFACE_HRN="plc"
# loglevel
# How deep are we logging (0|1|2)
# Registry Configuration
#
# Enabled
-# Enable the registry interface
+# Enable the registry interface
SFA_REGISTRY_ENABLED=0
# Root Auth
# Level1 Auth
# The hrn of the registry's level1 auth (sub authority)
-# The full name of this interface (only secify if this
+# The full name of this interface (only secify if this
# interface is a sub authority)
# xxx could be determined from hrn above
SFA_REGISTRY_LEVEL1_AUTH=""
## SFA aggregate server port
SFA_AGGREGATE_PORT=12346
-## ==============================================================
-# Slice Manager Configuration
-#
-# Enabled
-# Enable the slice manager
-SFA_SM_ENABLED=0
-
-# Host
-## The fully qualified hostname or IP address of the slice manager server
-SFA_SM_HOST="localhost"
-
-# Port
-# SFA slice manager server port
-SFA_SM_PORT=12347
-
## ===============================================================
# Component Manager Configuration
#
# Directory internal data gets stored
SFA_DATA_DIR="/var/lib/sfa"
-
self.api.manager.Delete(self.api, [xrn], [], {})
-class SliceManagerCommands(AggregateCommands):
-
- def __init__(self, *args, **kwds):
- self.api = Generic.the_flavour().make_api(interface='slicemgr')
-
-
class SfaAdmin:
- CATEGORIES = {'certificate': CertCommands,
- 'registry': RegistryCommands,
- 'aggregate': AggregateCommands,
- 'slicemgr': SliceManagerCommands}
+ CATEGORIES = {
+ 'certificate': CertCommands,
+ 'registry': RegistryCommands,
+ 'aggregate': AggregateCommands,
+ }
# returns (name,class) or (None,None)
def find_category(self, input):
# default is for when we can't determine the type of the service
# typically the server is down, or we can't authenticate, or it's too old
# code
- shapes = {"registry": "diamond", "slicemgr": "ellipse",
+ shapes = {"registry": "diamond",
"aggregate": "box", 'default': 'plaintext'}
- abbrevs = {"registry": "REG", "slicemgr": "SA",
+ abbrevs = {"registry": "REG",
"aggregate": "AM", 'default': '[unknown interface]'}
# return a dictionary that translates into the node's attr
shape = Interface.shapes['default']
layout['shape'] = shape
# fill color to outline wrongly configured or unreachable bodies
- # as of sfa-2.0 registry doesn't have 'sfa' not 'geni_api', but have peers
- # slicemgr and aggregate have 'geni_api' and 'sfa'
+ # as of sfa-2.0 registry doesn't have 'sfa' not 'geni_api',
+ # but have peer aggregates have 'geni_api' and 'sfa'
if 'geni_api' not in version and 'peers' not in version:
layout['style'] = 'filled'
layout['fillcolor'] = 'gray'
# a bundle is the combination of
# (*) an api that reacts on the incoming requests to trigger the API methods
# (*) a manager that implements the function of the service,
-# either aggregate, registry, or slicemgr
+# either aggregate or registry
# (*) a driver that controls the underlying testbed
#
#
def registry_class(self): pass
- def slicemgr_class(self): pass
-
def aggregate_class(self): pass
def component_class(self): pass
def make_manager(self, interface):
"""
- interface expected in ['registry', 'aggregate', 'slicemgr', 'component']
+ interface expected in ['registry', 'aggregate', 'component']
flavour is e.g. 'pl' or 'max' or whatever
"""
flavour = self.flavour
. api: this object reacts to an incoming SFA request
. manager: this implements a given interface, either registry,
-aggregate, or slicemgr
+or aggregate
. driver: this object is in charge of actually talking to the
underlying testbed
* a call to make_api will then create the 3 elements with the
following layout:
-api.manager
+api.manager
api.driver
driver.api
------
more in sfa/generic/__init__.py
-
-
import sfa.managers.registry_manager
return sfa.managers.registry_manager.RegistryManager
- def slicemgr_manager_class(self):
- import sfa.managers.slice_manager
- return sfa.managers.slice_manager.SliceManager
-
def aggregate_manager_class(self):
import sfa.managers.aggregate_manager
return sfa.managers.aggregate_manager.AggregateManager
import sfa.managers.registry_manager
return sfa.managers.registry_manager.RegistryManager
- def slicemgr_manager_class(self):
- import sfa.managers.slice_manager
- return sfa.managers.slice_manager.SliceManager
-
def aggregate_manager_class(self):
import sfa.managers.aggregate_manager
return sfa.managers.aggregate_manager.AggregateManager
import sfa.managers.registry_manager
return sfa.managers.registry_manager.RegistryManager
- def slicemgr_manager_class(self):
- import sfa.managers.slice_manager
- return sfa.managers.slice_manager.SliceManager
-
def aggregate_manager_class(self):
import sfa.managers.aggregate_manager
return sfa.managers.aggregate_manager.AggregateManager
import sfa.managers.registry_manager
return sfa.managers.registry_manager.RegistryManager
- def slicemgr_manager_class(self):
- import sfa.managers.slice_manager
- return sfa.managers.slice_manager.SliceManager
-
def aggregate_manager_class(self):
import sfa.managers.aggregate_manager
return sfa.managers.aggregate_manager.AggregateManager
import sfa.managers.registry_manager
return sfa.managers.registry_manager.RegistryManager
- def slicemgr_manager_class(self):
- import sfa.managers.slice_manager
- return sfa.managers.slice_manager.SliceManager
- # most likely you'll want to turn OFF the aggregate in sfa-config-tty
- # SFA_AGGREGATE_ENABLED=false
-
def aggregate_manager_class(self):
import sfa.managers.aggregate_manager
return sfa.managers.aggregate_manager.AggregateManager
self.logger.info(
"SfaImporter: imported authority (parent) %s " % auth_record)
- def create_sm_client_record(self):
- """
- Create a user record for the Slicemanager service.
- """
- hrn = self.interface_hrn + '.slicemanager' # pylint: disable=e1101
- urn = hrn_to_urn(hrn, 'user')
- if not self.auth_hierarchy.auth_exists(urn):
- self.logger.info("SfaImporter: creating Slice Manager user")
- self.auth_hierarchy.create_auth(urn)
-
- if self.record_exists('user', hrn):
- return
- auth_info = self.auth_hierarchy.get_auth_info(hrn)
- user_record = RegUser(hrn=hrn, gid=auth_info.get_gid_object(),
- authority=get_authority(hrn))
- user_record.just_created()
- global_dbsession.add(user_record)
- global_dbsession.commit()
- self.logger.info(
- "SfaImporter: importing user (slicemanager) %s " % user_record)
-
def create_interface_records(self):
"""
Create a record for each SFA interface
+++ /dev/null
-# pylint: disable=c0111, c0103
-
-import sys
-import time
-import traceback
-from copy import copy
-
-from sfa.trust.credential import Credential
-
-from sfa.util.sfalogging import logger
-from sfa.util.xrn import Xrn, urn_to_hrn
-from sfa.util.version import version_core
-from sfa.util.callids import Callids
-from sfa.util.cache import Cache
-
-from sfa.client.multiclient import MultiClient
-
-from sfa.rspecs.version_manager import VersionManager
-from sfa.rspecs.rspec import RSpec
-
-from sfa.client.return_value import ReturnValue
-
-
-class SliceManager:
-
- # the cache instance is a class member so it survives across incoming
- # requests
- cache = None
-
- def __init__(self, config):
- self.cache = None
- if config.SFA_SM_CACHING:
- if SliceManager.cache is None:
- SliceManager.cache = Cache()
- self.cache = SliceManager.cache
-
- def GetVersion(self, api, options):
- # peers explicitly in aggregates.xml
- peers = {peername: interface.get_url()
- for (peername, interface) in api.aggregates.iteritems()
- if peername != api.hrn}
- version_manager = VersionManager()
- ad_rspec_versions = []
- request_rspec_versions = []
- cred_types = [{'geni_type': 'geni_sfa',
- 'geni_version': str(i)} for i in range(4)[-2:]]
- for rspec_version in version_manager.versions:
- if rspec_version.content_type in ['*', 'ad']:
- ad_rspec_versions.append(rspec_version.to_dict())
- if rspec_version.content_type in ['*', 'request']:
- request_rspec_versions.append(rspec_version.to_dict())
- xrn = Xrn(api.hrn, 'authority+sm')
- version_more = {
- 'interface': 'slicemgr',
- 'sfa': 2,
- 'geni_api': 3,
- 'geni_api_versions':
- {'3': 'https://%s:%s'
- % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)},
- 'hrn': xrn.get_hrn(),
- 'urn': xrn.get_urn(),
- 'peers': peers,
- # Accept operations that act on as subset of slivers in a given
- # state.
- 'geni_single_allocation': 0,
- # Multiple slivers can exist and be incrementally added, including
- # those which connect or overlap in some way.
- 'geni_allocate': 'geni_many',
- 'geni_credential_types': cred_types,
- }
- sm_version = version_core(version_more)
- # local aggregate if present needs to have localhost resolved
- if api.hrn in api.aggregates:
- local_am_url = api.aggregates[api.hrn].get_url()
- sm_version['peers'][api.hrn] = local_am_url.replace(
- 'localhost', sm_version['hostname'])
- return sm_version
-
- def drop_slicemgr_stats(self, rspec):
- try:
- stats_elements = rspec.xml.xpath('//statistics')
- for node in stats_elements:
- node.getparent().remove(node)
- except Exception as e:
- logger.warning("drop_slicemgr_stats failed: %s " % (str(e)))
-
- def add_slicemgr_stat(self, rspec, callname, aggname,
- elapsed, status, exc_info=None):
- try:
- stats_tags = rspec.xml.xpath('//statistics[@call="%s"]' % callname)
- if stats_tags:
- stats_tag = stats_tags[0]
- else:
- stats_tag = rspec.xml.root.add_element(
- "statistics", call=callname)
-
- stat_tag = stats_tag.add_element(
- "aggregate", name=str(aggname),
- elapsed=str(elapsed), status=str(status))
-
- if exc_info:
- exc_tag = stat_tag.add_element(
- "exc_info", name=str(exc_info[1]))
-
- # formats the traceback as a set of xml elements
- tb = traceback.extract_tb(exc_info[2])
- for item in tb:
- exc_frame = exc_tag.add_element(
- "tb_frame", filename=str(item[0]),
- line=str(item[1]), func=str(item[2]), code=str(item[3]))
-
- except Exception as e:
- logger.warning("add_slicemgr_stat failed on %s: %s" %
- (aggname, str(e)))
-
- def ListResources(self, api, creds, options):
- call_id = options.get('call_id')
- if Callids().already_handled(call_id):
- return ""
-
- version_manager = VersionManager()
-
- def _ListResources(aggregate, server, credential, options):
- forward_options = copy(options)
- tStart = time.time()
- try:
- version = api.get_cached_server_version(server)
- # force ProtoGENI aggregates to give us a v2 RSpec
- forward_options['geni_rspec_version'] = options.get(
- 'geni_rspec_version')
- result = server.ListResources(credential, forward_options)
- return {"aggregate": aggregate, "result": result,
- "elapsed": time.time() - tStart, "status": "success"}
- except Exception as e:
- logger.log_exc("ListResources failed at %s" % (server.url))
- return {"aggregate": aggregate, "elapsed": time.time() - tStart,
- "status": "exception", "exc_info": sys.exc_info()}
-
- # get slice's hrn from options
- xrn = options.get('geni_slice_urn', '')
- (hrn, type) = urn_to_hrn(xrn)
- if 'geni_compressed' in options:
- del(options['geni_compressed'])
-
- # get the rspec's return format from options
- rspec_version = version_manager.get_version(
- options.get('geni_rspec_version'))
- version_string = "rspec_%s" % (rspec_version)
-
- # look in cache first
- cached_requested = options.get('cached', True)
- if not xrn and self.cache and cached_requested:
- rspec = self.cache.get(version_string)
- if rspec:
- logger.debug(
- "SliceManager.ListResources returns cached advertisement")
- return rspec
-
- # get the callers hrn
- valid_cred = api.auth.checkCredentials(creds, 'listnodes', hrn)[0]
- caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
-
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- # prevent infinite loop. Dont send request back to caller
- # unless the caller is the aggregate's SM
- if caller_hrn == aggregate and aggregate != api.hrn:
- continue
-
- # get the rspec from the aggregate
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- multiclient.run(_ListResources, aggregate, server, [cred], options)
-
- results = multiclient.get_results()
- rspec_version = version_manager.get_version(
- options.get('geni_rspec_version'))
- if xrn:
- result_version = version_manager._get_version(
- rspec_version.type, rspec_version.version, 'manifest')
- else:
- result_version = version_manager._get_version(
- rspec_version.type, rspec_version.version, 'ad')
- rspec = RSpec(version=result_version)
- for result in results:
- self.add_slicemgr_stat(
- rspec, "ListResources", result["aggregate"], result["elapsed"],
- result["status"], result.get("exc_info", None))
- if result["status"] == "success":
- res = result['result']['value']
- try:
- rspec.version.merge(ReturnValue.get_value(res))
- except Exception:
- logger.log_exc(
- "SM.ListResources: Failed to merge aggregate rspec")
-
- # cache the result
- if self.cache and not xrn:
- logger.debug("SliceManager.ListResources caches advertisement")
- self.cache.add(version_string, rspec.toxml())
-
- return rspec.toxml()
-
- def Allocate(self, api, xrn, creds, rspec_str, expiration, options):
- call_id = options.get('call_id')
- if Callids().already_handled(call_id):
- return ""
-
- version_manager = VersionManager()
-
- def _Allocate(aggregate, server, xrn, credential, rspec, options):
- tStart = time.time()
- try:
- # Need to call GetVersion at an aggregate to determine the supported
- # rspec type/format beofre calling CreateSliver at an Aggregate.
- #server_version = api.get_cached_server_version(server)
- # if 'sfa' not in server_version and 'geni_api' in server_version:
- # sfa aggregtes support both sfa and pg rspecs, no need to convert
- # if aggregate supports sfa rspecs. otherwise convert to pg rspec
- #rspec = RSpec(RSpecConverter.to_pg_rspec(rspec, 'request'))
- #filter = {'component_manager_id': server_version['urn']}
- # rspec.filter(filter)
- #rspec = rspec.toxml()
- result = server.Allocate(xrn, credential, rspec, options)
- return {"aggregate": aggregate, "result": result,
- "elapsed": time.time() - tStart, "status": "success"}
- except:
- logger.log_exc(
- 'Something wrong in _Allocate with URL %s' % server.url)
- return {"aggregate": aggregate, "elapsed": time.time() - tStart,
- "status": "exception", "exc_info": sys.exc_info()}
-
- # Validate the RSpec against PlanetLab's schema --disabled for now
- # The schema used here needs to aggregate the PL and VINI schemas
- # schema = "/var/www/html/schemas/pl.rng"
- rspec = RSpec(rspec_str)
- # schema = None
- # if schema:
- # rspec.validate(schema)
-
- # if there is a <statistics> section, the aggregates don't care about it,
- # so delete it.
- self.drop_slicemgr_stats(rspec)
-
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
-
- # get the callers hrn
- hrn, type = urn_to_hrn(xrn)
- valid_cred = api.auth.checkCredentials(creds, 'createsliver', hrn)[0]
- caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- # prevent infinite loop. Dont send request back to caller
- # unless the caller is the aggregate's SM
- if caller_hrn == aggregate and aggregate != api.hrn:
- continue
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- # Just send entire RSpec to each aggregate
- multiclient.run(_Allocate, aggregate, server, xrn,
- [cred], rspec.toxml(), options)
-
- results = multiclient.get_results()
- manifest_version = version_manager._get_version(
- rspec.version.type, rspec.version.version, 'manifest')
- result_rspec = RSpec(version=manifest_version)
- geni_urn = None
- geni_slivers = []
-
- for result in results:
- self.add_slicemgr_stat(
- result_rspec, "Allocate", result["aggregate"], result["elapsed"],
- result["status"], result.get("exc_info", None))
- if result["status"] == "success":
- try:
- res = result['result']['value']
- geni_urn = res['geni_urn']
- result_rspec.version.merge(
- ReturnValue.get_value(res['geni_rspec']))
- geni_slivers.extend(res['geni_slivers'])
- except Exception:
- logger.log_exc(
- "SM.Allocate: Failed to merge aggregate rspec")
- return {
- 'geni_urn': geni_urn,
- 'geni_rspec': result_rspec.toxml(),
- 'geni_slivers': geni_slivers
- }
-
- def Provision(self, api, xrn, creds, options):
- call_id = options.get('call_id')
- if Callids().already_handled(call_id):
- return ""
-
- version_manager = VersionManager()
-
- def _Provision(aggregate, server, xrn, credential, options):
- tStart = time.time()
- try:
- # Need to call GetVersion at an aggregate to determine the supported
- # rspec type/format before calling CreateSliver at an
- # Aggregate.
- server_version = api.get_cached_server_version(server)
- result = server.Provision(xrn, credential, options)
- return {"aggregate": aggregate, "result": result,
- "elapsed": time.time() - tStart, "status": "success"}
- except Exception:
- logger.log_exc(
- 'Something wrong in _Allocate with URL %s' % server.url)
- return {"aggregate": aggregate, "elapsed": time.time() - tStart,
- "status": "exception", "exc_info": sys.exc_info()}
-
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
-
- # get the callers hrn
- valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0]
- caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- # prevent infinite loop. Dont send request back to caller
- # unless the caller is the aggregate's SM
- if caller_hrn == aggregate and aggregate != api.hrn:
- continue
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- # Just send entire RSpec to each aggregate
- multiclient.run(_Provision, aggregate,
- server, xrn, [cred], options)
-
- results = multiclient.get_results()
- manifest_version = version_manager._get_version(
- 'GENI', '3', 'manifest')
- result_rspec = RSpec(version=manifest_version)
- geni_slivers = []
- geni_urn = None
- for result in results:
- self.add_slicemgr_stat(
- result_rspec, "Provision", result["aggregate"], result["elapsed"],
- result["status"], result.get("exc_info", None))
- if result["status"] == "success":
- try:
- res = result['result']['value']
- geni_urn = res['geni_urn']
- result_rspec.version.merge(
- ReturnValue.get_value(res['geni_rspec']))
- geni_slivers.extend(res['geni_slivers'])
- except:
- logger.log_exc(
- "SM.Provision: Failed to merge aggregate rspec")
- return {
- 'geni_urn': geni_urn,
- 'geni_rspec': result_rspec.toxml(),
- 'geni_slivers': geni_slivers
- }
-
- def Renew(self, api, xrn, creds, expiration_time, options):
- call_id = options.get('call_id')
- if Callids().already_handled(call_id):
- return True
-
- def _Renew(aggregate, server, xrn, creds, expiration_time, options):
- try:
- result = server.Renew(xrn, creds, expiration_time, options)
- if type(result) != dict:
- result = {'code': {'geni_code': 0}, 'value': result}
- result['aggregate'] = aggregate
- return result
- except:
- logger.log_exc(
- 'Something wrong in _Renew with URL %s' % server.url)
- return {'aggregate': aggregate, 'exc_info': traceback.format_exc(),
- 'code': {'geni_code': -1},
- 'value': False, 'output': ""}
-
- # get the callers hrn
- valid_cred = api.auth.checkCredentials(creds, 'renewsliver', xrn)[0]
- caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
-
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential(minimumExpiration=31 * 86400)
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- # prevent infinite loop. Dont send request back to caller
- # unless the caller is the aggregate's SM
- if caller_hrn == aggregate and aggregate != api.hrn:
- continue
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- multiclient.run(_Renew, aggregate, server, xrn,
- [cred], expiration_time, options)
-
- results = multiclient.get_results()
-
- geni_code = 0
- geni_output = ",".join([x.get('output', "") for x in results])
- geni_value = reduce(lambda x, y: x and y,
- [result.get('value', False) for result in results],
- True)
- for agg_result in results:
- agg_geni_code = agg_result['code'].get('geni_code', 0)
- if agg_geni_code:
- geni_code = agg_geni_code
-
- results = {'aggregates': results, 'code': {
- 'geni_code': geni_code}, 'value': geni_value, 'output': geni_output}
-
- return results
-
- def Delete(self, api, xrn, creds, options):
- call_id = options.get('call_id')
- if Callids().already_handled(call_id):
- return ""
-
- def _Delete(server, xrn, creds, options):
- return server.Delete(xrn, creds, options)
-
- (hrn, type) = urn_to_hrn(xrn[0])
- # get the callers hrn
- valid_cred = api.auth.checkCredentials(creds, 'deletesliver', hrn)[0]
- caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
-
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- # prevent infinite loop. Dont send request back to caller
- # unless the caller is the aggregate's SM
- if caller_hrn == aggregate and aggregate != api.hrn:
- continue
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- multiclient.run(_Delete, server, xrn, [cred], options)
-
- results = []
- for result in multiclient.get_results():
- results += ReturnValue.get_value(result)
- return results
-
- # first draft at a merging SliverStatus
- def Status(self, api, slice_xrn, creds, options):
- def _Status(server, xrn, creds, options):
- return server.Status(xrn, creds, options)
-
- call_id = options.get('call_id')
- if Callids().already_handled(call_id):
- return {}
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- multiclient.run(_Status, server, slice_xrn, [cred], options)
- results = [ReturnValue.get_value(result)
- for result in multiclient.get_results()]
-
- # get rid of any void result - e.g. when call_id was hit, where by
- # convention we return {}
- results = [
- result for result in results if result and result['geni_slivers']]
-
- # do not try to combine if there's no result
- if not results:
- return {}
-
- # otherwise let's merge stuff
- geni_slivers = []
- geni_urn = None
- for result in results:
- try:
- geni_urn = result['geni_urn']
- geni_slivers.extend(result['geni_slivers'])
- except Exception:
- logger.log_exc(
- "SM.Provision: Failed to merge aggregate rspec")
- return {
- 'geni_urn': geni_urn,
- 'geni_slivers': geni_slivers
- }
-
- def Describe(self, api, creds, xrns, options):
- def _Describe(server, xrn, creds, options):
- return server.Describe(xrn, creds, options)
-
- call_id = options.get('call_id')
- if Callids().already_handled(call_id):
- return {}
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- multiclient.run(_Describe, server, xrns, [cred], options)
- results = [ReturnValue.get_value(result)
- for result in multiclient.get_results()]
-
- # get rid of any void result - e.g. when call_id was hit, where by
- # convention we return {}
- results = [
- result for result in results if result and result.get('geni_urn')]
-
- # do not try to combine if there's no result
- if not results:
- return {}
-
- # otherwise let's merge stuff
- version_manager = VersionManager()
- manifest_version = version_manager._get_version(
- 'GENI', '3', 'manifest')
- result_rspec = RSpec(version=manifest_version)
- geni_slivers = []
- geni_urn = None
- for result in results:
- try:
- geni_urn = result['geni_urn']
- result_rspec.version.merge(
- ReturnValue.get_value(result['geni_rspec']))
- geni_slivers.extend(result['geni_slivers'])
- except Exception:
- logger.log_exc(
- "SM.Provision: Failed to merge aggregate rspec")
- return {
- 'geni_urn': geni_urn,
- 'geni_rspec': result_rspec.toxml(),
- 'geni_slivers': geni_slivers
- }
-
- def PerformOperationalAction(self, api, xrn, creds, action, options):
- # get the callers hrn
- valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0]
- caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
-
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- # prevent infinite loop. Dont send request back to caller
- # unless the caller is the aggregate's SM
- if caller_hrn == aggregate and aggregate != api.hrn:
- continue
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- multiclient.run(server.PerformOperationalAction,
- xrn, [cred], action, options)
- multiclient.get_results()
- return 1
-
- def Shutdown(self, api, xrn, creds, options=None):
- if options is None:
- options = {}
- xrn = Xrn(xrn)
- # get the callers hrn
- valid_cred = api.auth.checkCredentials(creds, 'stopslice', xrn.hrn)[0]
- caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
-
- # attempt to use delegated credential first
- cred = api.getDelegatedCredential(creds)
- if not cred:
- cred = api.getCredential()
- multiclient = MultiClient()
- for aggregate in api.aggregates:
- # prevent infinite loop. Dont send request back to caller
- # unless the caller is the aggregate's SM
- if caller_hrn == aggregate and aggregate != api.hrn:
- continue
- interface = api.aggregates[aggregate]
- server = api.server_proxy(interface, cred)
- multiclient.run(server.Shutdown, xrn.urn, cred)
- multiclient.get_results()
- return 1
See also http://svn.planet-lab.org/wiki/SFASliceTags
"""
- interfaces = ['aggregate', 'slicemgr']
+ interfaces = ['aggregate']
accepts = [
Parameter(str, "Slice URN"),
Parameter(type([dict]), "List of credentials"),
# flter rspec through sfatables
if self.api.interface in ['aggregate']:
chain_name = 'INCOMING'
- elif self.api.interface in ['slicemgr']:
- chain_name = 'FORWARD-INCOMING'
logger.debug("Allocate: sfatables on chain %s" % chain_name)
actual_caller_hrn = the_credential.actual_caller_hrn()
logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
@return 1 is successful, faults otherwise
"""
- interfaces = ['aggregate', 'slicemgr', 'component']
+ interfaces = ['aggregate', 'component']
accepts = [
Parameter(
@param options dictionary
@return dict
"""
- interfaces = ['aggregate', 'slicemgr']
+ interfaces = ['aggregate']
accepts = [
Parameter(type([str]), "List of URNs"),
Mixed(Parameter(str, "Credential string"),
# filter rspec through sfatables
if self.api.interface in ['aggregate']:
chain_name = 'OUTGOING'
- elif self.api.interface in ['slicemgr']:
- chain_name = 'FORWARD-OUTGOING'
logger.debug(
"ListResources: sfatables on chain %s" % chain_name)
desc['geni_rspec'] = run_sfatables(
Returns this GENI Aggregate Manager's Version Information
@return version
"""
- interfaces = ['registry', 'aggregate', 'slicemgr', 'component']
+ interfaces = ['registry', 'aggregate', 'component']
accepts = [
Parameter(dict, "Options")
]
@param options dictionary
@return string
"""
- interfaces = ['aggregate', 'slicemgr']
+ interfaces = ['aggregate']
accepts = [
Mixed(Parameter(str, "Credential string"),
Parameter(type([str]), "List of credentials")),
# filter rspec through sfatables
if self.api.interface in ['aggregate']:
chain_name = 'OUTGOING'
- elif self.api.interface in ['slicemgr']:
- chain_name = 'FORWARD-OUTGOING'
logger.debug(
"ListResources: sfatables on chain %s" % chain_name)
filtered_rspec = run_sfatables(chain_name, '', origin_hrn, rspec)
@param options (dict) options
"""
- interfaces = ['aggregate', 'slicemgr']
+ interfaces = ['aggregate']
accepts = [
Parameter(type([str]), "URNs"),
Parameter(type([dict]), "Credentials"),
@param options (dict) options
"""
- interfaces = ['aggregate', 'slicemgr']
+ interfaces = ['aggregate']
accepts = [
Parameter(type([str]), "URNs"),
Parameter(type([dict]), "Credentials"),
@param expiration_time (string) requested time of expiration
@param options (dict) options
"""
- interfaces = ['aggregate', 'slicemgr']
+ interfaces = ['aggregate']
accepts = [
Parameter(type([str]), "Slice URN"),
Parameter(type([str]), "List of credentials"),
@param slice_urn (string) URN of slice to renew
@param credentials ([string]) of credentials
"""
- interfaces = ['aggregate', 'slicemgr']
+ interfaces = ['aggregate']
accepts = [
Parameter(str, "Slice URN"),
Parameter(type([dict]), "Credentials"),
@param slice_urn (string) URN of slice to allocate to
"""
- interfaces = ['aggregate', 'slicemgr', 'component']
+ interfaces = ['aggregate', 'component']
accepts = [
Parameter(type([str]), "Slice or sliver URNs"),
Parameter(type([dict]), "credentials"),
@return list of gid strings
"""
- interfaces = ['registry', 'aggregate', 'slicemgr']
+ interfaces = ['registry', 'aggregate']
accepts = [
Mixed(Parameter(str, "Credential string"),
parser = OptionParser(usage="sfa-start.py [options]")
parser.add_option("-r", "--registry", dest="registry", action="store_true",
help="run registry server", default=False)
- parser.add_option("-s", "--slicemgr", dest="sm", action="store_true",
- help="run slice manager", default=False)
parser.add_option("-a", "--aggregate", dest="am", action="store_true",
help="run aggregate manager", default=False)
parser.add_option("-c", "--component", dest="cm", action="store_true",
server_key_file, server_cert_file)
a.start()
- # start slice manager
- if (options.sm):
- from sfa.server.slicemgr import SliceMgr
- s = SliceMgr("", config.SFA_SM_PORT, server_key_file, server_cert_file)
- s.start()
-
if (options.cm):
from sfa.server.component import Component
c = Component("", config.component_port,
augmented with the local cryptographic material and hrn
It also has the notion of its own interface (a string describing
- whether we run a registry, aggregate or slicemgr) and has
+ whether we run a registry, or aggregate) and has
the notion of neighbour sfa services as defined
in /etc/sfa/{aggregates,registries}.xml
response
"""
# as of dec 13 2011 we only support API v2
- if self.interface.lower() in ['aggregate', 'slicemgr']:
+ if self.interface.lower() in ['aggregate']:
result = self.prepare_response_am(result)
return XmlrpcApi.prepare_response(self, result, method)
+++ /dev/null
-import os
-import sys
-import datetime
-import time
-from sfa.server.sfaserver import SfaServer
-
-
-class SliceMgr(SfaServer):
-
- ##
- # Create a new slice manager object.
- #
- # @param ip the ip address to listen on
- # @param port the port to listen on
- # @param key_file private key filename of registry
- # @param cert_file certificate filename containing public key (could be a GID file)
-
- def __init__(self, ip, port, key_file, cert_file, config="/etc/sfa/sfa_config"):
- SfaServer.__init__(self, ip, port, key_file, cert_file, 'slicemgr')
key = None
cert = None
credential = None
- type = None
+ type = None
def __init__(self, options):
try: self.config = config = Config(options.config_file)
except:
self.cert.set_pubkey(self.key)
self.cert.set_issuer(self.key, self.config.SFI_USER)
self.cert.sign()
- self.cert.save_to_file(cert_file)
+ self.cert.save_to_file(cert_file)
SFI_AGGREGATE = config.SFI_SM.replace('12347', '12346')
SFI_CM = 'http://' + options.cm_host + ':12346'
self.registry = SfaServerProxy(config.SFI_REGISTRY, key_file, cert_file)
# test from components persepctive
self.type = 'user'
self.credential = self.GetCredential(self.hrn)
-
+
def GetCredential(self, hrn = None, type = 'user'):
- if not hrn: hrn = self.hrn
+ if not hrn: hrn = self.hrn
if hrn == self.hrn:
cert = self.cert.save_to_string(save_parents=True)
request_hash = self.key.compute_hash([cert, 'user', hrn])
else:
if not self.credential:
self.credential = self.GetCredential(self.hrn, 'user')
- return self.registry.GetCredential(self.credential, type, hrn)
+ return self.registry.GetCredential(self.credential, type, hrn)
class BasicTestCase(unittest.TestCase):
def __init__(self, testname, client, test_slice=None):
unittest.TestCase.__init__(self, testname)
self.client = client
self.slice = test_slice
-
+
def setUp(self):
self.registry = self.client.registry
self.aggregate = self.client.aggregate
self.cm = self.client.cm
self.credential = self.client.credential
self.hrn = self.client.hrn
- self.type = self.client.type
-
+ self.type = self.client.type
+
# Registry tests
class RegistryTest(BasicTestCase):
try: self.registry.Remove(auth_cred, record['type'], record['hrn'])
except: pass
-
+
def testRegisterPeerObject(self):
assert True
-
+
def testUpdate(self):
authority = get_authority(self.hrn)
auth_cred = self.client.GetCredential(authority, 'authority')
records = self.registry.Resolve(self.credential, self.hrn)
if not records: assert False
record = records[0]
- self.registry.update(auth_cred, record)
+ self.registry.update(auth_cred, record)
def testResolve(self):
authority = get_authority(self.hrn)
self.registry.Resolve(self.credential, self.hrn)
-
+
def testRemove(self):
authority = get_authority(self.hrn)
auth_cred = self.client.GetCredential(authority, 'authority')
try:
self.registry.Resolve(self.credential, record['hrn'])
assert False
- except:
+ except:
assert True
-
+
def testRemovePeerObject(self):
assert True
def testList(self):
authority = get_authority(self.client.hrn)
self.registry.List(self.credential, authority)
-
+
def testGetRegistries(self):
self.registry.get_registries(self.credential)
-
+
def testGetAggregates(self):
self.registry.get_aggregates(self.credential)
def testGetTrustedCerts(self):
# this should fail unless we are a node
callable = self.registry.get_trusted_certs
- server_exception = False
+ server_exception = False
try:
callable(self.credential)
except ServerException:
finally:
if self.type in ['user'] and not server_exception:
assert False
-
+
class AggregateTest(BasicTestCase):
def setUp(self):
BasicTestCase.setUp(self)
-
+
def testGetSlices(self):
self.aggregate.ListSlices(self.credential)
RSpec(xml=slice_rspec)
def testCreateSlice(self):
- # get availabel resources
+ # get availabel resources
rspec = self.aggregate.get_resources(self.credential)
slice_credential = self.client.GetCredential(self.slice['hrn'], 'slice')
self.aggregate.CreateSliver(slice_credential, self.slice['hrn'], rspec)
rspec = self.aggregate.get_resources(self.credential)
ticket = self.aggregate.GetTicket(slice_credential, self.slice['hrn'], rspec)
# will raise an exception if the ticket inst valid
- SfaTicket(string=ticket)
-
-class SlicemgrTest(AggregateTest):
- def setUp(self):
- AggregateTest.setUp(self)
-
- # force calls to go through slice manager
- self.aggregate = self.sm
-
- # get the slice credential
-
+ SfaTicket(string=ticket)
class ComponentTest(BasicTestCase):
def setUp(self):
'type': 'slice', 'researcher': [client.hrn]}
client.registry.Register(auth_cred, slice_record)
return slice_record
-
+
def DeleteSliver(client, slice):
authority = get_authority(client.hrn)
auth_cred = client.GetCredential(authority, 'authority')
if slice:
client.registry.Remove(auth_cred, 'slice', slice['hrn'])
-
+
if __name__ == '__main__':
args = sys.argv
default=False, help='run registry tests')
parser.add_option('-a', '--aggregate', dest='aggregate', action='store_true',
default=False, help='run aggregate tests')
- parser.add_option('-s', '--slicemgr', dest='slicemgr', action='store_true',
- default=False, help='run slicemgr tests')
parser.add_option('-c', '--component', dest='component', action='store_true',
default=False, help='run component tests')
- parser.add_option('-d', '--cm_host', dest='cm_host', default=default_cm,
+ parser.add_option('-d', '--cm_host', dest='cm_host', default=default_cm,
help='dns name of component to test. default is %s' % default_cm)
parser.add_option('-A', '--all', dest='all', action='store_true',
default=False, help='run component tests')
-
+
options, args = parser.parse_args()
suite = unittest.TestSuite()
client = Client(options)
test_slice = {}
-
+
# create the test slice if necessary
- if options.all or options.slicemgr or options.aggregate \
- or options.component:
+ if options.all or options.aggregate or options.component:
test_slice = CreateSliver(client)
if options.registry or options.all:
for name in test_names(RegistryTest):
suite.addTest(RegistryTest(name, client))
- if options.aggregate or options.all:
+ if options.aggregate or options.all:
for name in test_names(AggregateTest):
suite.addTest(AggregateTest(name, client, test_slice))
- if options.slicemgr or options.all:
- for name in test_names(SlicemgrTest):
- suite.addTest(SlicemgrTest(name, client, test_slice))
-
- if options.component or options.all:
+ if options.component or options.all:
for name in test_names(ComponentTest):
suite.addTest(ComponentTest(name, client, test_slice))
-
- # run tests
+
+ # run tests
unittest.TextTestRunner(verbosity=2).run(suite)
# remove teset slice
self.interface_options = interface_options
def interface_name (self):
- if self.interface_options.aggregate and \
- self.interface_options.slicemgr and \
- self.interface_options.registry:
+ if (self.interface_options.aggregate and
+ self.interface_options.registry):
return "complete"
if self.interface_options.aggregate: return "aggregate"
- elif self.interface_options.slicemgr: return "slicemgr"
elif self.interface_options.registry: return "registry"
elif self.interface_options.component: return "component"
else: return "unknown"
- def filter_argname(self,argname):
+ def filter_argname(self, argname):
if (not self.interface_options.lite or (argname!="cred")):
if (argname.find('(') != -1):
# The name has documentation in it :-/
min_args = 0
else:
min_args = 1
-
+
self.num_types += 1
type_name = "Type%d"%self.num_types
complex_type = types_section.appendChild(self.types.createElement("xsd:complexType"))
elif (isinstance(arg, Parameter)):
return (self.name_simple_type(arg.type))
elif type(arg) in ( ListType , TupleType ):
- inner_type = self.name_complex_type(arg[0])
+ inner_type = self.name_complex_type(arg[0])
self.num_types=self.num_types+1
type_name = "Type%d"%self.num_types
complex_type = types_section.appendChild(self.types.createElement("xsd:complexType"))
type_name = self.filter_argname(type_name)
complex_type.setAttribute("name", type_name)
complex_content = complex_type.appendChild(self.types.createElement("xsd:sequence"))
-
+
for k in arg.fields:
- inner_type = self.name_complex_type(arg.fields[k])
+ inner_type = self.name_complex_type(arg.fields[k])
element=complex_content.appendChild(self.types.createElement("xsd:element"))
element.setAttribute("name",k)
element.setAttribute("type",inner_type)
- return "xsdl:%s"%type_name
+ return "xsdl:%s"%type_name
else:
return (self.name_simple_type(arg))
#print "\n".join(lines)
#print
-
+
in_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("message"))
in_el.setAttribute("name", method + "_in")
arg_part = in_el.appendChild(self.wsdl.createElement("part"))
arg_part.setAttribute("name", argname)
arg_part.setAttribute("type", self.param_type(argtype))
-
- # Return type
+
+ # Return type
return_type = function.returns
out_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("message"))
out_el.setAttribute("name", method + "_out")
port_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("portType"))
port_el.setAttribute("name", method + "_port")
-
+
op_el = port_el.appendChild(self.wsdl.createElement("operation"))
op_el.setAttribute("name", method)
inp_el=self.wsdl.createElement("input")
bind_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("binding"))
bind_el.setAttribute("name", method + "_binding")
bind_el.setAttribute("type", "tns:" + method + "_port")
-
+
soap_bind = bind_el.appendChild(self.wsdl.createElement("soap:binding"))
soap_bind.setAttribute("style", "rpc")
soap_bind.setAttribute("transport","http://schemas.xmlsoap.org/soap/http")
-
+
wsdl_op = bind_el.appendChild(self.wsdl.createElement("operation"))
wsdl_op.setAttribute("name", method)
wsdl_op.appendChild(self.wsdl.createElement("soap:operation")).setAttribute("soapAction",
"urn:" + method)
-
+
wsdl_input = wsdl_op.appendChild(self.wsdl.createElement("input"))
input_soap_body = wsdl_input.appendChild(self.wsdl.createElement("soap:body"))
input_soap_body.setAttribute("use", "encoded")
input_soap_body.setAttribute("namespace", "urn:" + method)
input_soap_body.setAttribute("encodingStyle","http://schemas.xmlsoap.org/soap/encoding/")
-
+
wsdl_output = wsdl_op.appendChild(self.wsdl.createElement("output"))
output_soap_body = wsdl_output.appendChild(self.wsdl.createElement("soap:body"))
output_soap_body.setAttribute("use", "encoded")
output_soap_body.setAttribute("namespace", "urn:" + method)
output_soap_body.setAttribute("encodingStyle","http://schemas.xmlsoap.org/soap/encoding/")
-
+
def add_wsdl_services(self):
for service in self.services.keys():
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
""" % (self.interface_name(),plc_ns,plc_ns,plc_ns)
-
+
self.wsdl = xml.dom.minidom.parseString(wsdl_text_header)
-
+
def compute_wsdl_definitions_and_types(self):
wsdl_text_header = """
</types>
</wsdl:definitions> """ % (self.interface_name(),plc_ns, plc_ns, plc_ns, plc_ns)
self.types = xml.dom.minidom.parseString(wsdl_text_header)
-
+
def add_wsdl_types(self):
wsdl_types = self.wsdl.importNode(self.types.getElementsByTagName("types")[0], True)
def main():
parser = OptionParser()
- parser.add_option("-r", "--registry", dest="registry", action="store_true",
+ parser.add_option("-r", "--registry", dest="registry", action="store_true",
help="Generate registry.wsdl", metavar="FILE")
- parser.add_option("-s", "--slice-manager",
- action="store_true", dest="slicemgr",
- help="Generate sm.wsdl")
parser.add_option("-a", "--aggregate", action="store_true", dest="aggregate",
help="Generate am.wsdl")
parser.add_option("-c", "--component", action="store_true", dest="component",
gen = WSDLGen(interface_options)
gen.generate_wsdl()
gen.pretty_print()
-
+
if __name__ == "__main__":
main()