.PHONY: all install clean uninstall
-VERSIONTAG=0.0-0-should.be-redefined-by-specfile
+##########
+rpmversion:=$(shell rpm -q --specfile sfa.spec --queryformat="%{version}\n" | head -1)
+# somehow %{taglevel} is empty, turns out %{release} has what we want
+rpmtaglevel:=$(shell rpm -q --specfile sfa.spec --queryformat="%{release}\n" 2> /dev/null | head -1)
+VERSIONTAG=$(rpmversion)-$(rpmtaglevel)
SCMURL=should-be-redefined-by-specfile
-##########
python: version
version: sfa/util/version.py
sfiListSlivers.py sfadump.py
BINS = ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
- ./sfa/plc/sfa-import-plc.py ./sfa/plc/sfa-nuke-plc.py ./sfa/server/sfa-start.py \
+ ./sfa/importer/sfa-import-plc.py ./sfa/importer/sfa-nuke-plc.py ./sfa/server/sfa-start.py \
$(foreach client,$(CLIENTS),./sfa/client/$(client))
sync:
bins = [
'config/sfa-config-tty',
'config/gen-sfa-cm-config.py',
- 'sfa/plc/sfa-import-plc.py',
- 'sfa/plc/sfa-nuke-plc.py',
+ 'sfa/importer/sfa-import-plc.py',
+ 'sfa/importer/sfa-nuke-plc.py',
'sfa/server/sfa-ca.py',
'sfa/server/sfa-start.py',
'sfa/server/sfa-clean-peer-records.py',
'sfa/generic',
'sfa/managers',
'sfa/managers/vini',
+ 'sfa/importer',
'sfa/plc',
'sfa/senslab',
'sfa/rspecs',
# recompute the SFA graphs from different locations
+## use -vv for the full story
SFASCAN = ./sfascan.py -v
# AMs, at least MyPLC AMs, are boring
BUNDLES-LR += http://www.emanicslab.org:12345/@auto-elc-reg
BUNDLES-LR += http://www.emanicslab.org:12347/@auto-elc-sa
-#EXTENSIONS := png svg
-EXTENSIONS := png
+EXTENSIONS := png svg
+#EXTENSIONS := png
####################
ALL += $(foreach bundle,$(BUNDLES),$(word 2,$(subst @, ,$(bundle))))
####################
clean:
- rm -f auto-*.{out,version}
+ rm -f .auto*
$(foreach extension,$(EXTENSIONS),rm -rf auto-*.$(extension);)
+ $(SFASCAN) -c
DATE=$(shell date '+%Y-%m-%d')
PUBEXTENSIONS=png
#!/usr/bin/env python
-import sys
+import sys, os.path
+import pickle
+import time
import socket
import traceback
from urlparse import urlparse
from sfa.client.sfi import Sfi
from sfa.util.sfalogging import logger, DEBUG
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol
def url_hostname_port (url):
if url.find("://")<0:
else:
return (url,parts[0],parts[1])
+### a very simple cache mechanism so that successive runs (see make)
+### will go *much* faster
+### assuming everything is sequential, as simple as it gets
+### { url -> (timestamp,version)}
+class VersionCache:
+ def __init__ (self, filename=None, expires=60*60):
+ # default is to store cache in the same dir as argv[0]
+ if filename is None:
+ filename=os.path.join(os.path.dirname(sys.argv[0]),"sfascan-version-cache.pickle")
+ self.filename=filename
+ self.expires=expires
+ self.url2version={}
+ self.load()
+
+ def load (self):
+ try:
+ infile=file(self.filename,'r')
+ self.url2version=pickle.load(infile)
+ infile.close()
+ except:
+ logger.debug("Cannot load version cache, restarting from scratch")
+ self.url2version = {}
+ logger.debug("loaded version cache with %d entries %s"%(len(self.url2version),self.url2version.keys()))
+
+ def save (self):
+ try:
+ outfile=file(self.filename,'w')
+ pickle.dump(self.url2version,outfile)
+ outfile.close()
+ except:
+ logger.log_exc ("Cannot save version cache into %s"%self.filename)
+ def clean (self):
+ try:
+ retcod=os.unlink(self.filename)
+ logger.info("Cleaned up version cache %s, retcod=%d"%(self.filename,retcod))
+ except:
+ logger.info ("Could not unlink version cache %s"%self.filename)
+
+ def show (self):
+ entries=len(self.url2version)
+ print "version cache from file %s has %d entries"%(self.filename,entries)
+ key_values=self.url2version.items()
+ def old_first (kv1,kv2): return int(kv1[1][0]-kv2[1][0])
+ key_values.sort(old_first)
+ for key_value in key_values:
+ (url,tuple) = key_value
+ (timestamp,version) = tuple
+ how_old = time.time()-timestamp
+ if how_old<=self.expires:
+ print url,"-- %d seconds ago"%how_old
+ else:
+ print "OUTDATED",url,"(%d seconds ago, expires=%d)"%(how_old,self.expires)
+
+ # turns out we might have trailing slashes or not
+ def normalize (self, url):
+ return url.strip("/")
+
+ def set (self,url,version):
+ url=self.normalize(url)
+ self.url2version[url]=( time.time(), version)
+ def get (self,url):
+ url=self.normalize(url)
+ try:
+ (timestamp,version)=self.url2version[url]
+ how_old = time.time()-timestamp
+ if how_old<=self.expires: return version
+ else: return None
+ except:
+ return None
+
###
class Interface:
- def __init__ (self,url):
+ def __init__ (self,url,verbose=False):
self._url=url
+ self.verbose=verbose
try:
(self._url,self.hostname,self.port)=url_hostname_port(url)
self.ip=socket.gethostbyname(self.hostname)
# connect to server and trigger GetVersion
def get_version(self):
+ ### if we already know the answer:
if self.probed:
return self._version
+ ### otherwise let's look in the cache file
+ logger.debug("searching in version cache %s"%self.url())
+ cached_version = VersionCache().get(self.url())
+ if cached_version is not None:
+ logger.info("Retrieved version info from cache")
+ return cached_version
+ ### otherwise let's do the hard work
# dummy to meet Sfi's expectations for its 'options' field
class DummyOptions:
pass
options=DummyOptions()
- options.verbose=False
+ options.verbose=self.verbose
options.timeout=10
try:
client=Sfi(options)
key_file = client.get_key_file()
cert_file = client.get_cert_file(key_file)
url=self.url()
- logger.info('issuing get version at %s'%url)
- logger.debug("GetVersion, using timeout=%d"%options.timeout)
- server=xmlrpcprotocol.get_server(url, key_file, cert_file, timeout=options.timeout, verbose=options.verbose)
+ logger.info('issuing GetVersion at %s'%url)
+ # setting timeout here seems to get the call to fail - even though the response time is fast
+ #server=xmlrpcprotocol.server_proxy(url, key_file, cert_file, verbose=self.verbose, timeout=options.timeout)
+ server=xmlrpcprotocol.server_proxy(url, key_file, cert_file, verbose=self.verbose)
self._version=server.GetVersion()
except:
+ logger.log_exc("failed to get version")
self._version={}
+ # so that next run from this process will find out
self.probed=True
+ # store in version cache so next processes will remember for an hour
+ cache=VersionCache()
+ cache.set(self.url(),self._version)
+ cache.save()
+ logger.debug("Saved version for url=%s in version cache"%self.url())
+ # that's our result
return self._version
@staticmethod
while to_scan:
for interface in to_scan:
# performing xmlrpc call
+ logger.info("retrieving/fetching version at interface %s"%interface.url())
version=interface.get_version()
- if self.verbose:
- logger.info("GetVersion at interface %s"%interface.url())
- if not version:
- logger.info("<EMPTY GetVersion(); offline or cannot authenticate>")
- else:
- for (k,v) in version.iteritems():
- if not isinstance(v,dict):
- logger.info("\r\t%s:%s"%(k,v))
- else:
- logger.info(k)
- for (k1,v1) in v.iteritems():
- logger.info("\r\t\t%s:%s"%(k1,v1))
+ if not version:
+ logger.info("<EMPTY GetVersion(); offline or cannot authenticate>")
+ else:
+ for (k,v) in version.iteritems():
+ if not isinstance(v,dict):
+ logger.debug("\r\t%s:%s"%(k,v))
+ else:
+ logger.debug(k)
+ for (k1,v1) in v.iteritems():
+ logger.debug("\r\t\t%s:%s"%(k1,v1))
# 'geni_api' is expected if the call succeeded at all
# 'peers' is needed as well as AMs typically don't have peers
if 'geni_api' in version and 'peers' in version:
help="output filenames (cumulative) - defaults are %r"%default_outfiles)
parser.add_option("-l","--left-to-right",action="store_true",dest="left_to_right",default=False,
help="instead of top-to-bottom")
- parser.add_option("-v","--verbose",action='store_true',dest='verbose',default=False,
- help="verbose")
- parser.add_option("-d","--debug",action='store_true',dest='debug',default=False,
- help="debug")
+ parser.add_option("-v", "--verbose", action="count", dest="verbose", default=0,
+ help="verbose - can be repeated for more verbosity")
+ parser.add_option("-c", "--clean-cache",action='store_true',
+ dest='clean_cache',default=False,
+ help='clean/trash version cache and exit')
+ parser.add_option("-s","--show-cache",action='store_true',
+ dest='show_cache',default=False,
+ help='show/display version cache')
+
(options,args)=parser.parse_args()
+ logger.enable_console()
+ # apply current verbosity to logger
+ logger.setLevelFromOptVerbose(options.verbose)
+ # figure if we need to be verbose for these local classes that only have a bool flag
+ bool_verbose=logger.getBoolVerboseFromOpt(options.verbose)
+
+ if options.show_cache:
+ VersionCache().show()
+ sys.exit(0)
+ if options.clean_cache:
+ VersionCache().clean()
+ sys.exit(0)
if not args:
parser.print_help()
sys.exit(1)
+
if not options.outfiles:
options.outfiles=default_outfiles
- logger.enable_console()
- if options.debug:
- options.verbose=True
- logger.setLevel(DEBUG)
- scanner=SfaScan(left_to_right=options.left_to_right, verbose=options.verbose)
+ scanner=SfaScan(left_to_right=options.left_to_right, verbose=bool_verbose)
entries = [ Interface(entry) for entry in args ]
g=scanner.graph(entries)
logger.info("creating layout")
from sfa.rspecs.rspec import RSpec
from sfa.rspecs.rspec_converter import RSpecConverter
from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol
from sfa.util.config import Config
from sfa.util.version import version_core
from sfa.util.cache import Cache
self.cert_file = cert_file
self.cert = GID(filename=cert_file)
self.logger.info("Contacting Registry at: %s"%self.reg_url)
- self.registry = xmlrpcprotocol.get_server(self.reg_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
+ self.registry = xmlrpcprotocol.server_proxy(self.reg_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
self.logger.info("Contacting Slice Manager at: %s"%self.sm_url)
- self.slicemgr = xmlrpcprotocol.get_server(self.sm_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
+ self.slicemgr = xmlrpcprotocol.server_proxy(self.sm_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
return
def get_cached_server_version(self, server):
self.logger.info("Getting Registry issued cert")
self.read_config()
# *hack. need to set registyr before _get_gid() is called
- self.registry = xmlrpcprotocol.get_server(self.reg_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
+ self.registry = xmlrpcprotocol.server_proxy(self.reg_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
gid = self._get_gid(type='user')
self.registry = None
self.logger.info("Writing certificate to %s"%cert_file)
return key_string
# xxx opts undefined
- def get_component_server_from_hrn(self, hrn):
+ def get_component_proxy_from_hrn(self, hrn):
# direct connection to the nodes component manager interface
user_cred = self.get_user_cred().save_to_string(save_parents=True)
records = self.registry.Resolve(hrn, user_cred)
self.logger.warning("No such component:%r"% opts.component)
record = records[0]
- return self.get_server(record['hostname'], CM_PORT, self.key_file, self.cert_file)
+ return self.server_proxy(record['hostname'], CM_PORT, self.key_file, self.cert_file)
- def get_server(self, host, port, keyfile, certfile):
+ def server_proxy(self, host, port, keyfile, certfile):
"""
Return an instance of an xmlrpc server connection
"""
host_parts = host.split('/')
host_parts[0] = host_parts[0] + ":" + str(port)
url = "http://%s" % "/".join(host_parts)
- return xmlrpcprotocol.get_server(url, keyfile, certfile, timeout=self.options.timeout, verbose=self.options.debug)
+ return xmlrpcprotocol.server_proxy(url, keyfile, certfile, timeout=self.options.timeout, verbose=self.options.debug)
# xxx opts could be retrieved in self.options
- def get_server_from_opts(self, opts):
+ def server_proxy_from_opts(self, opts):
"""
Return instance of an xmlrpc connection to a slice manager, aggregate
or component server depending on the specified opts
server = self.slicemgr
# direct connection to an aggregate
if hasattr(opts, 'aggregate') and opts.aggregate:
- server = self.get_server(opts.aggregate, opts.port, self.key_file, self.cert_file)
+ server = self.server_proxy(opts.aggregate, opts.port, self.key_file, self.cert_file)
# direct connection to the nodes component manager interface
if hasattr(opts, 'component') and opts.component:
- server = self.get_component_server_from_hrn(opts.component)
+ server = self.get_component_proxy_from_hrn(opts.component)
return server
#==========================================================================
if opts.version_registry:
server=self.registry
else:
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
version=server.GetVersion()
for (k,v) in version.iteritems():
print "%-20s: %s"%(k,v)
if opts.delegate:
delegated_cred = self.delegate_cred(user_cred, get_authority(self.authority))
creds.append(delegated_cred)
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
#results = server.ListSlices(creds, unique_call_id())
results = server.ListSlices(creds)
display_list(results)
user_cred = self.get_user_cred().save_to_string(save_parents=True)
server = self.slicemgr
call_options = {}
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
if args:
cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
# created named slice with given rspec
def create(self, opts, args):
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
server_version = self.get_cached_server_version(server)
slice_hrn = args[0]
slice_urn = hrn_to_urn(slice_hrn, 'slice')
creds.append(delegated_cred)
rspec_file = self.get_rspec_file(rspec_path)
rspec = open(rspec_file).read()
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
ticket_string = server.GetTicket(slice_urn, creds, rspec, [])
file = os.path.join(self.options.sfi_dir, get_leaf(slice_hrn) + ".ticket")
self.logger.info("writing ticket to %s"%file)
for hostname in hostnames:
try:
self.logger.info("Calling redeem_ticket at %(hostname)s " % locals())
- server = self.get_server(hostname, CM_PORT, self.key_file, \
+ server = self.server_proxy(hostname, CM_PORT, self.key_file, \
self.cert_file, self.options.debug)
server.RedeemTicket(ticket.save_to_string(save_parents=True), slice_cred)
self.logger.info("Success")
if opts.delegate:
delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
creds.append(delegated_cred)
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
call_args = [slice_urn, creds]
if self.server_supports_call_id_arg(server):
if opts.delegate:
delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
creds.append(delegated_cred)
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
return server.Start(slice_urn, creds)
# stop named slice
if opts.delegate:
delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
creds.append(delegated_cred)
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
return server.Stop(slice_urn, creds)
# reset named slice
def reset(self, opts, args):
slice_hrn = args[0]
slice_urn = hrn_to_urn(slice_hrn, 'slice')
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
slice_cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
creds = [slice_cred]
if opts.delegate:
def renew(self, opts, args):
slice_hrn = args[0]
slice_urn = hrn_to_urn(slice_hrn, 'slice')
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
slice_cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
creds = [slice_cred]
if opts.delegate:
if opts.delegate:
delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
creds.append(delegated_cred)
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
call_args = [slice_urn, creds]
if self.server_supports_call_id_arg(server):
call_args.append(unique_call_id())
if opts.delegate:
delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
creds.append(delegated_cred)
- server = self.get_server_from_opts(opts)
+ server = self.server_proxy_from_opts(opts)
return server.Shutdown(slice_urn, creds)
def print_help (self):
logger.debug ("xml-rpc %s method:%s"%(self.url,attr))
return xmlrpclib.ServerProxy.__getattr__(self, attr)
-def get_server(url, key_file, cert_file, timeout=None, verbose=False):
+def server_proxy(url, key_file, cert_file, timeout=None, verbose=False):
transport = XMLRPCTransport(key_file, cert_file, timeout)
return XMLRPCServerProxy(url, transport, allow_none=True, verbose=verbose)
def make_api (self, *args, **kwargs):
# interface is a required arg
if not 'interface' in kwargs:
- logger.fatal("Generic.make_api: no interface found")
+ logger.critical("Generic.make_api: no interface found")
api = self.api_class()(*args, **kwargs)
- interface=kwargs['interface']
- # or simpler, interface=api.interface
- manager = self.make_manager(interface)
- api.manager = ManagerWrapper(manager,interface)
+ manager = self.make_manager(api.interface)
+ driver = self.make_driver (api.config, api.interface)
+ ### arrange stuff together
+ # add a manager wrapper
+ manager = ManagerWrapper(manager,api.interface)
+ api.manager=manager
+ # insert driver in manager
+ manager.driver=driver
+ # add it in api as well for convenience
+ api.driver=driver
return api
def make_manager (self, interface):
flavour = self.flavour
message="Generic.make_manager for interface=%s and flavour=%s"%(interface,flavour)
- classname = "%s_class"%interface
+ classname = "%s_manager_class"%interface
try:
module = getattr(self,classname)()
logger.info("%s : %s"%(message,module))
return module
except:
- logger.log_exc(message)
- logger.fatal("Aborting")
+ logger.log_exc_critical(message)
+
+ # need interface to select the right driver
+ def make_driver (self, config, interface):
+ flavour = self.flavour
+ message="Generic.make_driver for flavour=%s and interface=%s"%(flavour,interface)
+
+ if interface == "component":
+ classname = "component_driver_class"
+ else:
+ classname = "driver_class"
+ try:
+ class_obj = getattr(self,classname)()
+ logger.info("%s : %s"%(message,class_obj))
+ return class_obj(config)
+ except:
+ logger.log_exc_critical(message)
-# former logic was
-# basepath = 'sfa.managers'
-# qualified = "%s.%s_manager_%s"%(basepath,interface,flavour)
-# generic = "%s.%s_manager"%(basepath,interface)
-#
-# try:
-# manager = __import__(qualified, fromlist=[basepath])
-# logger.info ("%s: loaded %s"%(message,qualified))
-# except:
-# try:
-# manager = __import__ (generic, fromlist=[basepath])
-# if flavour != 'pl' :
-# logger.warn ("%s: using generic with flavour!='pl'"%(message))
-# logger.info("%s: loaded %s"%(message,generic))
-# except:
-# logger.log_exc("%s: unable to import either %s or %s"%(message,qualified,generic))
-# logger.fatal("Aborted")
-# return manager
--- /dev/null
+We identify 3 layers in the server-side aspects:
+
+. api: this object reacts to an incoming SFA request
+
+. manager: this implements a given interface, either registry,
+aggregate, or slicemgr
+
+. driver: this object is in charge of actually talking to the
+underlying testbed
+
+-----
+
+the generic layer is in charge of instantiating these and to link them
+as follows:
+* the classes actually used for creating the 3 elements are
+configurable in a flavour (e.g. sfa.generic.pl.py)
+* which is then configured from sfa-config-tty as SFA_GENERIC_FLAVOUR
+
+* a call to make_api will then create the 3 elements with the
+ following layout:
+
+api.manager
+manager.driver
+api.driver (for convenience)
+
+------
+example
+
+from sfa.generic import Generic
+generic=Generic.the_flavour()
+-> returns an instance of a Generic object with a flavour from the
+ config; by default it would thus be an instance of sfa.generic.pl
+
+api = generic.make_api (...) returns an instance of the given class
+with the arguments passed as arguments to the constructor
+
+------
+more in sfa/generic/__init__.py
+
+
from sfa.generic import Generic
-import sfa.plc.plcsfaapi
+
+import sfa.server.sfaapi
+import sfa.plc.pldriver
import sfa.managers.registry_manager
import sfa.managers.slice_manager
import sfa.managers.aggregate_manager
class pl (Generic):
+ # use the standard api class
def api_class (self):
- return sfa.plc.plcsfaapi.PlcSfaApi
+ return sfa.server.sfaapi.SfaApi
- def registry_class (self) :
+ # the manager classes for the server-side services
+ def registry_manager_class (self) :
return sfa.managers.registry_manager
- def slicemgr_class (self) :
+ def slicemgr_manager_class (self) :
return sfa.managers.slice_manager
- def aggregate_class (self) :
+ def aggregate_manager_class (self) :
return sfa.managers.aggregate_manager
+ # driver class for server-side services, talk to the whole testbed
+ def driver_class (self):
+ return sfa.plc.pldriver.PlDriver
+
+ # for the component mode, to be run on board planetlab nodes
+ # manager class
+ def component_manager_class (self):
+ return sfa.managers.component_manager_pl
+ # driver_class
+ def component_driver_class (self):
+ return sfa.plc.plcomponentdriver.PlComponentDriver
+
+++ /dev/null
-from sfa.generic.pl import pl
-import sfa.plc.plccomponentapi
-import sfa.managers.component_manager_pl
-
-class plcm (pl):
-
- def api_class (self):
- return sfa.plc.plccomponentapi.PlcComponentApi
-
- def component_class (self):
- return sfa.managers.component_manager_pl
from sfa.util.config import Config
from sfa.util.xrn import Xrn
-from sfa.plc.sfaImport import sfaImport
+from sfa.importer.sfaImport import sfaImport
def process_options():
from sfa.rspecs.version_manager import VersionManager
from sfa.rspecs.rspec import RSpec
+from sfa.server.sfaapi import SfaApi
+
import sfa.plc.peers as peers
-from sfa.plc.plcsfaapi import PlcSfaApi
from sfa.plc.aggregate import Aggregate
from sfa.plc.slices import Slices
# find out where this slice is currently running
slicename = hrn_to_pl_slicename(hrn)
- slices = api.plshell.GetSlices(api.plauth, [slicename], ['slice_id', 'node_ids','person_ids','name','expires'])
+ slices = api.driver.GetSlices([slicename], ['slice_id', 'node_ids','person_ids','name','expires'])
if len(slices) == 0:
raise Exception("Slice %s not found (used %s as slicename internally)" % (slice_xrn, slicename))
slice = slices[0]
# report about the local nodes only
- nodes = api.plshell.GetNodes(api.plauth, {'node_id':slice['node_ids'],'peer_id':None},
+ nodes = api.driver.GetNodes({'node_id':slice['node_ids'],'peer_id':None},
['node_id', 'hostname', 'site_id', 'boot_state', 'last_contact'])
site_ids = [node['site_id'] for node in nodes]
if Callids().already_handled(call_id): return True
(hrn, _) = urn_to_hrn(xrn)
slicename = hrn_to_pl_slicename(hrn)
- slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
+ slices = api.driver.GetSlices({'name': slicename}, ['slice_id'])
if not slices:
raise RecordNotFound(hrn)
slice = slices[0]
requested_time = utcparse(expiration_time)
record = {'expires': int(time.mktime(requested_time.timetuple()))}
try:
- api.plshell.UpdateSlice(api.plauth, slice['slice_id'], record)
+ api.driver.UpdateSlice(slice['slice_id'], record)
return True
except:
return False
def start_slice(api, xrn, creds):
(hrn, _) = urn_to_hrn(xrn)
slicename = hrn_to_pl_slicename(hrn)
- slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
+ slices = api.driver.GetSlices({'name': slicename}, ['slice_id'])
if not slices:
raise RecordNotFound(hrn)
slice_id = slices[0]['slice_id']
- slice_tags = api.plshell.GetSliceTags(api.plauth, {'slice_id': slice_id, 'tagname': 'enabled'}, ['slice_tag_id'])
+ slice_tags = api.driver.GetSliceTags({'slice_id': slice_id, 'tagname': 'enabled'}, ['slice_tag_id'])
# just remove the tag if it exists
if slice_tags:
- api.plshell.DeleteSliceTag(api.plauth, slice_tags[0]['slice_tag_id'])
+ api.driver.DeleteSliceTag(slice_tags[0]['slice_tag_id'])
return 1
def stop_slice(api, xrn, creds):
hrn, _ = urn_to_hrn(xrn)
slicename = hrn_to_pl_slicename(hrn)
- slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
+ slices = api.driver.GetSlices({'name': slicename}, ['slice_id'])
if not slices:
raise RecordNotFound(hrn)
slice_id = slices[0]['slice_id']
- slice_tags = api.plshell.GetSliceTags(api.plauth, {'slice_id': slice_id, 'tagname': 'enabled'})
+ slice_tags = api.driver.GetSliceTags({'slice_id': slice_id, 'tagname': 'enabled'})
if not slice_tags:
- api.plshell.AddSliceTag(api.plauth, slice_id, 'enabled', '0')
+ api.driver.AddSliceTag(slice_id, 'enabled', '0')
elif slice_tags[0]['value'] != "0":
tag_id = slice_tags[0]['slice_tag_id']
- api.plshell.UpdateSliceTag(api.plauth, tag_id, '0')
+ api.driver.UpdateSliceTag(tag_id, '0')
return 1
def reset_slice(api, xrn):
if Callids().already_handled(call_id): return ""
(hrn, _) = urn_to_hrn(xrn)
slicename = hrn_to_pl_slicename(hrn)
- slices = api.plshell.GetSlices(api.plauth, {'name': slicename})
+ slices = api.driver.GetSlices({'name': slicename})
if not slices:
return 1
slice = slices[0]
peer = peers.get_peer(api, hrn)
try:
if peer:
- api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice['slice_id'], peer)
- api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
+ api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer)
+ api.driver.DeleteSliceFromNodes(slicename, slice['node_ids'])
finally:
if peer:
- api.plshell.BindObjectToPeer(api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id'])
+ api.driver.BindObjectToPeer('slice', slice['slice_id'], peer, slice['peer_slice_id'])
return 1
# xxx Thierry : caching at the aggregate level sounds wrong...
return slices
# get data from db
- slices = api.plshell.GetSlices(api.plauth, {'peer_id': None}, ['name'])
+ slices = api.driver.GetSlices({'peer_id': None}, ['name'])
slice_hrns = [slicename_to_hrn(api.hrn, slice['name']) for slice in slices]
slice_urns = [hrn_to_urn(slice_hrn, 'slice') for slice_hrn in slice_hrns]
# get the slice record
credential = api.getCredential()
interface = api.registries[api.hrn]
- registry = api.get_server(interface, credential)
+ registry = api.server_proxy(interface, credential)
records = registry.Resolve(xrn, credential)
# make sure we get a local slice record
-def main():
- """
- rspec = ListResources(api, "plc.princeton.sapan", None, 'pl_test_sapan')
- #rspec = ListResources(api, "plc.princeton.coblitz", None, 'pl_test_coblitz')
- #rspec = ListResources(api, "plc.pl.sirius", None, 'pl_test_sirius')
- print rspec
- """
- api = PlcSfaApi()
- f = open(sys.argv[1])
- xml = f.read()
- f.close()
-#Error (E1120, main): No value passed for parameter 'users' in function call
-#Error (E1120, main): No value passed for parameter 'call_id' in function call
- CreateSliver(api, "plc.princeton.sapan", xml, 'CreateSliver_sapan')
-
-if __name__ == "__main__":
- main()
+#def main():
+# """
+# rspec = ListResources(api, "plc.princeton.sapan", None, 'pl_test_sapan')
+# #rspec = ListResources(api, "plc.princeton.coblitz", None, 'pl_test_coblitz')
+# #rspec = ListResources(api, "plc.pl.sirius", None, 'pl_test_sirius')
+# print rspec
+# """
+# api = PlcSfaApi()
+# f = open(sys.argv[1])
+# xml = f.read()
+# f.close()
+##Error (E1120, main): No value passed for parameter 'users' in function call
+##Error (E1120, main): No value passed for parameter 'call_id' in function call
+# CreateSliver(api, "plc.princeton.sapan", xml, 'CreateSliver_sapan')
+#
+#if __name__ == "__main__":
+# main()
import os, errno
import logging
import datetime
+from multiprocessing import Process
+from time import sleep
import boto
from boto.ec2.regioninfo import RegionInfo
from sfa.util.faults import *
from sfa.util.xrn import urn_to_hrn, Xrn
-from sfa.server.registry import Registries
-from sfa.trust.credential import Credential
-from sfa.plc.plcsfaapi import PlcSfaApi
-from sfa.plc.aggregate import Aggregate
-from sfa.plc.slices import *
from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn
from sfa.util.callids import Callids
from sfa.util.sfalogging import logger
-from sfa.rspecs.sfa_rspec import sfa_rspec_version
from sfa.util.version import version_core
-from multiprocessing import Process
-from time import sleep
+from sfa.trust.credential import Credential
+
+from sfa.server.sfaapi import SfaApi
+
+from sfa.plc.aggregate import Aggregate
+from sfa.plc.slices import *
+from sfa.rspecs.sfa_rspec import sfa_rspec_version
+
##
# The data structure used to represent a cloud.
#
EUCALYPTUS_RSPEC_SCHEMA='/etc/sfa/eucalyptus.rng'
-api = PlcSfaApi()
-
##
# Meta data of an instance.
#
}
return version_core(version_more)
-def main():
- init_server()
-
- #theRSpec = None
- #with open(sys.argv[1]) as xml:
- # theRSpec = xml.read()
- #CreateSliver(None, 'planetcloud.pc.test', theRSpec, 'call-id-cloudtest')
-
- #rspec = ListResources('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy', 'test_euca')
- #print rspec
-
- server_key_file = '/var/lib/sfa/authorities/server.key'
- server_cert_file = '/var/lib/sfa/authorities/server.cert'
- api = PlcSfaApi(key_file = server_key_file, cert_file = server_cert_file, interface='aggregate')
- print getKeysForSlice(api, 'gc.gc.test1')
-
-if __name__ == "__main__":
- main()
+#def main():
+# init_server()
+#
+# #theRSpec = None
+# #with open(sys.argv[1]) as xml:
+# # theRSpec = xml.read()
+# #CreateSliver(None, 'planetcloud.pc.test', theRSpec, 'call-id-cloudtest')
+#
+# #rspec = ListResources('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy', 'test_euca')
+# #print rspec
+#
+# server_key_file = '/var/lib/sfa/authorities/server.key'
+# server_cert_file = '/var/lib/sfa/authorities/server.cert'
+# api = PlcSfaApi(key_file = server_key_file, cert_file = server_cert_file, interface='aggregate')
+# print getKeysForSlice(api, 'gc.gc.test1')
+#
+#if __name__ == "__main__":
+# main()
-from sfa.plc.slices import Slices\r
-from sfa.server.registry import Registries\r
-from sfa.util.xrn import urn_to_hrn, hrn_to_urn, get_authority, Xrn\r
-from sfa.util.plxrn import hrn_to_pl_slicename\r
-from sfa.util.sfalogging import logger\r
+import os\r
+import time\r
+import re\r
+\r
from sfa.util.faults import *\r
+from sfa.util.sfalogging import logger\r
from sfa.util.config import Config\r
from sfa.util.sfatime import utcparse\r
from sfa.util.callids import Callids\r
from sfa.util.version import version_core\r
+from sfa.util.xrn import urn_to_hrn, hrn_to_urn, get_authority, Xrn\r
+from sfa.util.plxrn import hrn_to_pl_slicename\r
+\r
+from sfa.server.sfaapi import SfaApi\r
+from sfa.server.registry import Registries\r
from sfa.rspecs.rspec_version import RSpecVersion\r
from sfa.rspecs.sfa_rspec import sfa_rspec_version\r
from sfa.rspecs.rspec_parser import parse_rspec\r
-from sfa.managers.aggregate_manager_pl import __get_registry_objects, ListSlices\r
-import os\r
-import time\r
-import re\r
+\r
+from sfa.managers.aggregate_manager import __get_registry_objects, ListSlices\r
+\r
+from sfa.plc.slices import Slices\r
+\r
\r
RSPEC_TMP_FILE_PREFIX = "/tmp/max_rspec"\r
\r
slice_urn = options.get('geni_slice_urn')\r
return get_rspec(api, creds, slice_urn)\r
\r
-"""\r
-Returns the request context required by sfatables. At some point, this mechanism should be changed\r
-to refer to "contexts", which is the information that sfatables is requesting. But for now, we just\r
-return the basic information needed in a dict.\r
-"""\r
def fetch_context(slice_hrn, user_hrn, contexts):\r
+ """\r
+ Returns the request context required by sfatables. At some point, this mechanism should be changed\r
+ to refer to "contexts", which is the information that sfatables is requesting. But for now, we just\r
+ return the basic information needed in a dict.\r
+ """\r
base_context = {'sfa':{'user':{'hrn':user_hrn}}}\r
return base_context\r
- api = PlcSfaApi()\r
+ api = SfaApi()\r
create_slice(api, "plc.maxpl.test000", None, rspec_xml, None)\r
\r
def start_slice(api, xrn, creds):
slicename = PlXrn(xrn, type='slice').pl_slicename()
- api.nodemanger.Start(slicename)
+ api.driver.nodemanager.Start(slicename)
def stop_slice(api, xrn, creds):
slicename = PlXrn(xrn, type='slice').pl_slicename()
- api.nodemanager.Stop(slicename)
+ api.driver.nodemanager.Stop(slicename)
def DeleteSliver(api, xrn, creds, call_id):
slicename = PlXrn(xrn, type='slice').pl_slicename()
- api.nodemanager.Destroy(slicename)
+ api.driver.nodemanager.Destroy(slicename)
def reset_slice(api, xrn):
slicename = PlXrn(xrn, type='slice').pl_slicename()
if not api.sliver_exists(slicename):
raise SliverDoesNotExist(slicename)
- api.nodemanager.ReCreate(slicename)
+ api.driver.nodemanager.ReCreate(slicename)
# xxx outdated - this should accept a credential & call_id
def ListSlices(api):
# this returns a tuple, the data we want is at index 1
- xids = api.nodemanager.GetXIDs()
+ xids = api.driver.nodemanager.GetXIDs()
# unfortunately the data we want is given to us as
# a string but we really want it as a dict
# lets eval it
# convert ticket to format nm is used to
nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
- api.nodemanager.AdminTicket(nm_ticket)
+ api.driver.nodemanager.AdminTicket(nm_ticket)
# verify_cancreate_credential requires that the member lists
# (researchers, pis, etc) be filled in
- api.fill_record_info(record)
+ api.driver.fill_record_info(record, api.aggregates)
if record['type']=='user':
if not record['enabled']:
raise AccountNotEnabled(": PlanetLab account %s is not enabled. Please contact your site PI" %(record['email']))
if registry_hrn != api.hrn:
credential = api.getCredential()
interface = api.registries[registry_hrn]
- server = api.get_server(interface, credential)
+ server = api.server_proxy(interface, credential)
peer_records = server.Resolve(xrns, credential)
records.extend([SfaRecord(dict=record).as_dict() for record in peer_records])
table = SfaTable()
local_records = table.findObjects({'hrn': remaining_hrns})
if full:
- api.fill_record_info(local_records)
+ api.driver.fill_record_info(local_records, api.aggregates)
# convert local record objects to dicts
records.extend([dict(record) for record in local_records])
if registry_hrn != api.hrn:
credential = api.getCredential()
interface = api.registries[registry_hrn]
- server = api.get_server(interface, credential)
+ server = api.server_proxy(interface, credential)
record_list = server.List(xrn, credential)
records = [SfaRecord(dict=record).as_dict() for record in record_list]
# get the GID from the newly created authority
gid = auth_info.get_gid_object()
record.set_gid(gid.save_to_string(save_parents=True))
- pl_record = api.sfa_fields_to_pl_fields(type, hrn, record)
- sites = api.plshell.GetSites(api.plauth, [pl_record['login_base']])
+ pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
+ sites = api.driver.GetSites([pl_record['login_base']])
if not sites:
- pointer = api.plshell.AddSite(api.plauth, pl_record)
+ pointer = api.driver.AddSite(pl_record)
else:
pointer = sites[0]['site_id']
elif (type == "slice"):
acceptable_fields=['url', 'instantiation', 'name', 'description']
- pl_record = api.sfa_fields_to_pl_fields(type, hrn, record)
+ pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
for key in pl_record.keys():
if key not in acceptable_fields:
pl_record.pop(key)
- slices = api.plshell.GetSlices(api.plauth, [pl_record['name']])
+ slices = api.driver.GetSlices([pl_record['name']])
if not slices:
- pointer = api.plshell.AddSlice(api.plauth, pl_record)
+ pointer = api.driver.AddSlice(pl_record)
else:
pointer = slices[0]['slice_id']
record.set_pointer(pointer)
record['pointer'] = pointer
elif (type == "user"):
- persons = api.plshell.GetPersons(api.plauth, [record['email']])
+ persons = api.driver.GetPersons([record['email']])
if not persons:
- pointer = api.plshell.AddPerson(api.plauth, dict(record))
+ pointer = api.driver.AddPerson(dict(record))
else:
pointer = persons[0]['person_id']
if 'enabled' in record and record['enabled']:
- api.plshell.UpdatePerson(api.plauth, pointer, {'enabled': record['enabled']})
+ api.driver.UpdatePerson(pointer, {'enabled': record['enabled']})
# add this persons to the site only if he is being added for the first
# time by sfa and doesont already exist in plc
if not persons or not persons[0]['site_ids']:
login_base = get_leaf(record['authority'])
- api.plshell.AddPersonToSite(api.plauth, pointer, login_base)
+ api.driver.AddPersonToSite(pointer, login_base)
# What roles should this user have?
- api.plshell.AddRoleToPerson(api.plauth, 'user', pointer)
+ api.driver.AddRoleToPerson('user', pointer)
# Add the user's key
if pub_key:
- api.plshell.AddPersonKey(api.plauth, pointer, {'key_type' : 'ssh', 'key' : pub_key})
+ api.driver.AddPersonKey(pointer, {'key_type' : 'ssh', 'key' : pub_key})
elif (type == "node"):
- pl_record = api.sfa_fields_to_pl_fields(type, hrn, record)
+ pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
login_base = hrn_to_pl_login_base(record['authority'])
- nodes = api.plshell.GetNodes(api.plauth, [pl_record['hostname']])
+ nodes = api.driver.GetNodes([pl_record['hostname']])
if not nodes:
- pointer = api.plshell.AddNode(api.plauth, login_base, pl_record)
+ pointer = api.driver.AddNode(login_base, pl_record)
else:
pointer = nodes[0]['node_id']
record['record_id'] = record_id
# update membership for researchers, pis, owners, operators
- api.update_membership(None, record)
+ api.driver.update_membership(None, record)
return record.get_gid_object().save_to_string(save_parents=True)
# Update_membership needs the membership lists in the existing record
# filled in, so it can see if members were added or removed
- api.fill_record_info(record)
+ api.driver.fill_record_info(record, api.aggregates)
# Use the pointer from the existing record, not the one that the user
# gave us. This prevents the user from inserting a forged pointer
# update the PLC information that was specified with the record
if (type == "authority"):
- api.plshell.UpdateSite(api.plauth, pointer, new_record)
+ api.driver.UpdateSite(pointer, new_record)
elif type == "slice":
- pl_record=api.sfa_fields_to_pl_fields(type, hrn, new_record)
+ pl_record=api.driver.sfa_fields_to_pl_fields(type, hrn, new_record)
if 'name' in pl_record:
pl_record.pop('name')
- api.plshell.UpdateSlice(api.plauth, pointer, pl_record)
+ api.driver.UpdateSlice(pointer, pl_record)
elif type == "user":
# SMBAKER: UpdatePerson only allows a limited set of fields to be
'password', 'phone', 'url', 'bio', 'accepted_aup',
'enabled']:
update_fields[key] = all_fields[key]
- api.plshell.UpdatePerson(api.plauth, pointer, update_fields)
+ api.driver.UpdatePerson(pointer, update_fields)
if 'key' in new_record and new_record['key']:
# must check this key against the previous one if it exists
- persons = api.plshell.GetPersons(api.plauth, [pointer], ['key_ids'])
+ persons = api.driver.GetPersons([pointer], ['key_ids'])
person = persons[0]
keys = person['key_ids']
- keys = api.plshell.GetKeys(api.plauth, person['key_ids'])
+ keys = api.driver.GetKeys(person['key_ids'])
key_exists = False
if isinstance(new_record['key'], types.ListType):
new_key = new_record['key'][0]
# Delete all stale keys
for key in keys:
if new_record['key'] != key['key']:
- api.plshell.DeleteKey(api.plauth, key['key_id'])
+ api.driver.DeleteKey(key['key_id'])
else:
key_exists = True
if not key_exists:
- api.plshell.AddPersonKey(api.plauth, pointer, {'key_type': 'ssh', 'key': new_key})
+ api.driver.AddPersonKey(pointer, {'key_type': 'ssh', 'key': new_key})
# update the openssl key and gid
pkey = convert_public_key(new_key)
table.update(record)
elif type == "node":
- api.plshell.UpdateNode(api.plauth, pointer, new_record)
+ api.driver.UpdateNode(pointer, new_record)
else:
raise UnknownSfaType(type)
# update membership for researchers, pis, owners, operators
- api.update_membership(record, new_record)
+ api.driver.update_membership(record, new_record)
return 1
except:
pass
if type == "user":
- persons = api.plshell.GetPersons(api.plauth, record['pointer'])
+ persons = api.driver.GetPersons(record['pointer'])
# only delete this person if he has site ids. if he doesnt, it probably means
# he was just removed from a site, not actually deleted
if persons and persons[0]['site_ids']:
- api.plshell.DeletePerson(api.plauth, record['pointer'])
+ api.driver.DeletePerson(record['pointer'])
elif type == "slice":
- if api.plshell.GetSlices(api.plauth, record['pointer']):
- api.plshell.DeleteSlice(api.plauth, record['pointer'])
+ if api.driver.GetSlices(record['pointer']):
+ api.driver.DeleteSlice(record['pointer'])
elif type == "node":
- if api.plshell.GetNodes(api.plauth, record['pointer']):
- api.plshell.DeleteNode(api.plauth, record['pointer'])
+ if api.driver.GetNodes(record['pointer']):
+ api.driver.DeleteNode(record['pointer'])
elif type == "authority":
- if api.plshell.GetSites(api.plauth, record['pointer']):
- api.plshell.DeleteSite(api.plauth, record['pointer'])
+ if api.driver.GetSites(record['pointer']):
+ api.driver.DeleteSite(record['pointer'])
else:
raise UnknownSfaType(type)
from sfa.util.sfalogging import logger
from sfa.util.xrn import Xrn, urn_to_hrn
-from sfa.util.threadmanager import ThreadManager
from sfa.util.version import version_core
from sfa.util.callids import Callids
+from sfa.server.threadmanager import ThreadManager
+
from sfa.rspecs.rspec_converter import RSpecConverter
from sfa.rspecs.version_manager import VersionManager
from sfa.rspecs.rspec import RSpec
# get the rspec from the aggregate
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run(_ListResources, aggregate, server, [cred], options, call_id)
if caller_hrn == aggregate and aggregate != api.hrn:
continue
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
# Just send entire RSpec to each aggregate
threads.run(_CreateSliver, aggregate, server, xrn, [cred], rspec.toxml(), users, call_id)
if caller_hrn == aggregate and aggregate != api.hrn:
continue
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run(_RenewSliver, server, xrn, [cred], expiration_time, call_id)
# 'and' the results
return reduce (lambda x,y: x and y, threads.get_results() , True)
if caller_hrn == aggregate and aggregate != api.hrn:
continue
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run(_DeleteSliver, server, xrn, [cred], call_id)
threads.get_results()
return 1
threads = ThreadManager()
for aggregate in api.aggregates:
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run (_SliverStatus, server, slice_xrn, [cred], call_id)
results = threads.get_results()
if caller_hrn == aggregate and aggregate != api.hrn:
continue
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run(_ListSlices, server, [cred], call_id)
# combime results
continue
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run(server.GetTicket, xrn, [cred], aggregate_rspec, users)
results = threads.get_results()
if caller_hrn == aggregate and aggregate != api.hrn:
continue
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run(server.Start, xrn, cred)
threads.get_results()
return 1
if caller_hrn == aggregate and aggregate != api.hrn:
continue
interface = api.aggregates[aggregate]
- server = api.get_server(interface, cred)
+ server = api.server_proxy(interface, cred)
threads.run(server.Stop, xrn, cred)
threads.get_results()
return 1
def write(self, api):
if self.changed:
if int(self.id) > 0:
- api.plshell.UpdateSliceTag(api.plauth, self.id, self.value)
+ api.driver.UpdateSliceTag(self.id, self.value)
else:
- api.plshell.AddSliceTag(api.plauth, self.slice_id,
- self.tagname, self.value, self.node_id)
+ api.driver.AddSliceTag(self.slice_id, self.tagname, self.value, self.node_id)
elif self.deleted and int(self.id) > 0:
- api.plshell.DeleteSliceTag(api.plauth, self.id)
+ api.driver.DeleteSliceTag(self.id)
"""
"""
def get_sites(api):
tmp = []
- for site in api.plshell.GetSites(api.plauth):
+ for site in api.driver.GetSites():
t = site['site_id'], Site(site)
tmp.append(t)
return dict(tmp)
"""
def get_nodes(api):
tmp = []
- for node in api.plshell.GetNodes(api.plauth):
+ for node in api.driver.GetNodes():
t = node['node_id'], Node(node)
tmp.append(t)
return dict(tmp)
Create a dictionary of slice objects keyed by slice ID
"""
def get_slice(api, slicename):
- slice = api.plshell.GetSlices(api.plauth, [slicename])
+ slice = api.driver.GetSlices([slicename])
if slice:
return Slice(slice[0])
else:
"""
def get_slice_tags(api):
tmp = []
- for tag in api.plshell.GetSliceTags(api.plauth):
+ for tag in api.driver.GetSliceTags():
t = tag['slice_tag_id'], Slicetag(tag)
tmp.append(t)
return dict(tmp)
"""
def get_sites(self, api):
tmp = []
- for site in api.plshell.GetSites(api.plauth, {'peer_id': None}):
+ for site in api.driver.GetSites({'peer_id': None}):
t = site['site_id'], ViniSite(self, site)
tmp.append(t)
return dict(tmp)
"""
def get_nodes(self, api):
tmp = []
- for node in api.plshell.GetNodes(api.plauth, {'peer_id': None}):
+ for node in api.driver.GetNodes({'peer_id': None}):
t = node['node_id'], ViniNode(self, node)
tmp.append(t)
return dict(tmp)
"""
def get_slice(self, api, hrn):
slicename = hrn_to_pl_slicename(hrn)
- slice = api.plshell.GetSlices(api.plauth, [slicename])
+ slice = api.driver.GetSlices([slicename])
if slice:
self.slice = ViniSlice(self, slicename, slice[0])
return self.slice
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrn, self.name))
- manager = self.api.get_interface_manager()
-
- return manager.create_gid(self.api, xrn, cert)
+ return self.api.manager.create_gid(self.api, xrn, cert)
msg = "'users' musst be specified and cannot be null. You may need to update your client."
raise SfaInvalidArgument(name='users', extra=msg)
- manager = self.api.get_interface_manager()
-
# flter rspec through sfatables
if self.api.interface in ['aggregate']:
chain_name = 'INCOMING'
rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
slivers = RSpec(rspec).version.get_nodes_with_slivers()
if slivers:
- result = manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, call_id)
+ result = self.api.manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, call_id)
else:
result = rspec
return result
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
- manager.DeleteSliver(self.api, xrn, creds, call_id)
+ self.api.manager.DeleteSliver(self.api, xrn, creds, call_id)
return 1
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
-
- return manager.get_credential(self.api, xrn, type)
+ return self.api.manager.get_credential(self.api, xrn, type)
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
# resolve the record
- manager = self.api.get_interface_manager()
- records = manager.resolve(self.api, xrns, full = False)
+ records = self.api.manager.resolve(self.api, xrns, full = False)
if not records:
raise RecordNotFound(xrns)
origin_hrn = Certificate(string=cert).get_subject()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
# authenticate the gid
- records = manager.resolve(self.api, xrn, type)
+ records = self.api.manager.resolve(self.api, xrn, type)
if not records:
raise RecordNotFound(hrn)
record = SfaRecord(dict=records[0])
self.api.logger.debug("ConnectionKeyGIDMismatch, %s filename: %s"%(name,obj.filename))
raise ConnectionKeyGIDMismatch(gid.get_subject())
- return manager.get_credential(self.api, xrn, type, is_self=True)
+ return self.api.manager.get_credential(self.api, xrn, type, is_self=True)
#log the call
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
-
# filter rspec through sfatables
if self.api.interface in ['aggregate']:
chain_name = 'OUTGOING'
rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
# remove nodes that are not available at this interface from the rspec
- ticket = manager.get_ticket(self.api, xrn, creds, rspec, users)
-
- return ticket
+ return self.api.manager.get_ticket(self.api, xrn, creds, rspec, users)
def call(self):
self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
- manager = self.api.get_interface_manager()
- return manager.GetVersion(self.api)
+ return self.api.manager.GetVersion(self.api)
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
- return manager.list(self.api, xrn)
+ return self.api.manager.list(self.api, xrn)
origin_hrn = options.get('origin_hrn', None)
if not origin_hrn:
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
- # get manager for this interface
- manager = self.api.get_interface_manager()
- rspec = manager.ListResources(self.api, creds, options, call_id)
+ rspec = self.api.manager.ListResources(self.api, creds, options, call_id)
# filter rspec through sfatables
if self.api.interface in ['aggregate']:
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, self.name))
- manager = self.api.get_interface_manager()
- return manager.ListSlices(self.api, creds, call_id)
+ return self.api.manager.ListSlices(self.api, creds, call_id)
valid_creds = self.api.auth.checkCredentials(cred, 'redeemticket')
self.api.auth.check_ticket(ticket)
-
# send the call to the right manager
- manager = self.api.get_interface_manager()
- manager.redeem_ticket(self.api, ticket)
+ self.api.manager.redeem_ticket(self.api, ticket)
return 1
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
-
- return manager.register(self.api, record)
+ return self.api.manager.register(self.api, record)
self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s"%(
self.api.interface, self.name, origin_hrn, xrn.get_urn()))
- manager = self.api.get_interface_manager()
-
- return manager.remove(self.api, xrn)
+ return self.api.manager.remove(self.api, xrn)
def remove_plc_record(self, record):
type = record['type']
if type == "user":
- persons = self.api.plshell.GetPersons(self.api.plauth, {'person_id' : record['pointer']})
+ persons = self.api.driver.GetPersons({'person_id' : record['pointer']})
if not persons:
return 1
person = persons[0]
if person['peer_id']:
peer = self.get_peer_name(person['peer_id'])
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'person', person['person_id'], peer)
- self.api.plshell.DeletePerson(self.api.plauth, person['person_id'])
+ self.api.driver.UnBindObjectFromPeer('person', person['person_id'], peer)
+ self.api.driver.DeletePerson(person['person_id'])
elif type == "slice":
- slices=self.api.plshell.GetSlices(self.api.plauth, {'slice_id' : record['pointer']})
+ slices=self.api.driver.GetSlices({'slice_id' : record['pointer']})
if not slices:
return 1
slice=slices[0]
if slice['peer_id']:
peer = self.get_peer_name(slice['peer_id'])
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'slice', slice['slice_id'], peer)
- self.api.plshell.DeleteSlice(self.api.plauth, slice['slice_id'])
+ self.api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer)
+ self.api.driver.DeleteSlice(slice['slice_id'])
elif type == "authority":
- sites=self.api.plshell.GetSites(self.api.plauth, {'site_id' : record['pointer']})
+ sites=self.api.driver.GetSites({'site_id' : record['pointer']})
if not sites:
return 1
site=sites[0]
if site['peer_id']:
peer = self.get_peer_name(site['peer_id'])
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'site', site['site_id'], peer)
- self.api.plshell.DeleteSite(self.api.plauth, site['site_id'])
+ self.api.driver.UnBindObjectFromPeer('site', site['site_id'], peer)
+ self.api.driver.DeleteSite(site['site_id'])
else:
raise UnknownSfaType(type)
return 1
def get_peer_name(self, peer_id):
- peers = self.api.plshell.GetPeers(self.api.plauth, [peer_id], ['peername', 'shortname', 'hrn_root'])
+ peers = self.api.driver.GetPeers([peer_id], ['peername', 'shortname', 'hrn_root'])
if not peers:
raise SfaInvalidArgument, "No such peer"
peer = peers[0]
raise InsufficientRights('Renewsliver: Credential expires before requested expiration time')
if requested_time > datetime.datetime.utcnow() + datetime.timedelta(days=max_renew_days):
raise Exception('Cannot renew > %s days from now' % max_renew_days)
- manager = self.api.get_interface_manager()
- return manager.RenewSliver(self.api, slice_xrn, valid_creds, expiration_time, call_id)
+ return self.api.manager.RenewSliver(self.api, slice_xrn, valid_creds, expiration_time, call_id)
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrns, self.name))
# send the call to the right manager
- manager = self.api.get_interface_manager()
- return manager.resolve(self.api, xrns, type)
+ return self.api.manager.resolve(self.api, xrns, type)
self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, hrn, self.name))
- manager = self.api.get_interface_manager()
- status = manager.SliverStatus(self.api, hrn, valid_creds, call_id)
+ status = self.api.manager.SliverStatus(self.api, hrn, valid_creds, call_id)
return status
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
- manager.start_slice(self.api, xrn, creds)
+ self.api.manager.start_slice(self.api, xrn, creds)
return 1
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
- manager.stop_slice(self.api, xrn, creds)
+ self.api.manager.stop_slice(self.api, xrn, creds)
return 1
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- manager = self.api.get_interface_manager()
-
- return manager.update(self.api, record_dict)
+ return self.api.manager.update(self.api, record_dict)
# verify that the callers's ip address exist in the db and is an inteface
# for a node in the db
(ip, port) = self.api.remote_addr
- interfaces = self.api.plshell.GetInterfaces(self.api.plauth, {'ip': ip}, ['node_id'])
+ interfaces = self.api.driver.GetInterfaces({'ip': ip}, ['node_id'])
if not interfaces:
raise NonExistingRecord("no such ip %(ip)s" % locals())
- nodes = self.api.plshell.GetNodes(self.api.plauth, [interfaces[0]['node_id']], ['node_id', 'hostname'])
+ nodes = self.api.driver.GetNodes([interfaces[0]['node_id']], ['node_id', 'hostname'])
if not nodes:
raise NonExistingRecord("no such node using ip %(ip)s" % locals())
node = nodes[0]
def remove_plc_record(self, record):
type = record['type']
if type == "user":
- persons = self.api.plshell.GetPersons(self.api.plauth, {'person_id' : record['pointer']})
+ persons = self.api.driver.GetPersons({'person_id' : record['pointer']})
if not persons:
return 1
person = persons[0]
if person['peer_id']:
peer = self.get_peer_name(person['peer_id'])
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'person', person['person_id'], peer)
- self.api.plshell.DeletePerson(self.api.plauth, person['person_id'])
+ self.api.driver.UnBindObjectFromPeer('person', person['person_id'], peer)
+ self.api.driver.DeletePerson(person['person_id'])
elif type == "slice":
- slices=self.api.plshell.GetSlices(self.api.plauth, {'slice_id' : record['pointer']})
+ slices=self.api.driver.GetSlices({'slice_id' : record['pointer']})
if not slices:
return 1
slice=slices[0]
if slice['peer_id']:
peer = self.get_peer_name(slice['peer_id'])
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'slice', slice['slice_id'], peer)
- self.api.plshell.DeleteSlice(self.api.plauth, slice['slice_id'])
+ self.api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer)
+ self.api.driver.DeleteSlice(slice['slice_id'])
elif type == "authority":
- sites=self.api.plshell.GetSites(self.api.plauth, {'site_id' : record['pointer']})
+ sites=self.api.driver.GetSites({'site_id' : record['pointer']})
if not sites:
return 1
site=sites[0]
if site['peer_id']:
peer = self.get_peer_name(site['peer_id'])
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'site', site['site_id'], peer)
- self.api.plshell.DeleteSite(self.api.plauth, site['site_id'])
+ self.api.driver.UnBindObjectFromPeer('site', site['site_id'], peer)
+ self.api.driver.DeleteSite(site['site_id'])
else:
raise UnknownSfaType(type)
return 1
def get_peer_name(self, peer_id):
- peers = self.api.plshell.GetPeers(self.api.plauth, [peer_id], ['peername', 'shortname', 'hrn_root'])
+ peers = self.api.driver.GetPeers([peer_id], ['peername', 'shortname', 'hrn_root'])
if not peers:
raise SfaInvalidArgument, "No such peer"
peer = peers[0]
def call(self, cred, xrn, origin_hrn=None):
hrn, type = urn_to_hrn(xrn)
self.api.auth.check(cred, 'resetslice', hrn)
- # send the call to the right manager
- manager_base = 'sfa.managers'
- if self.api.interface in ['component']:
- mgr_type = self.api.config.SFA_CM_TYPE
- manager_module = manager_base + ".component_manager_%s" % mgr_type
- manager = __import__(manager_module, fromlist=[manager_base])
- manager.reset_slice(self.api, xrn)
- elif self.api.interface in ['aggregate']:
- mgr_type = self.api.config.SFA_AGGREGATE_TYPE
- manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
- manager = __import__(manager_module, fromlist=[manager_base])
- manager.reset_slice(self.api, xrn)
- elif self.api.interface in ['slicemgr']:
- mgr_type = self.api.config.SFA_SM_TYPE
- manager_module = manager_base + ".slice_manager_%s" % mgr_type
- manager = __import__(manager_module, fromlist=[manager_base])
- manager.reset_slice(self.api, xrn)
-
+ self.api.manager.reset_slice (self.api, xrn)
return 1
def prepare_sites(self, filter={}, force=False):
if not self.sites or force:
- for site in self.api.plshell.GetSites(self.api.plauth, filter):
+ for site in self.api.driver.GetSites(filter):
self.sites[site['site_id']] = site
def prepare_nodes(self, filter={}, force=False):
if not self.nodes or force:
filter.update({'peer_id': None})
- nodes = self.api.plshell.GetNodes(self.api.plauth, filter)
+ nodes = self.api.driver.GetNodes(filter)
site_ids = []
interface_ids = []
tag_ids = []
def prepare_interfaces(self, filter={}, force=False):
if not self.interfaces or force:
- for interface in self.api.plshell.GetInterfaces(self.api.plauth, filter):
+ for interface in self.api.driver.GetInterfaces(filter):
self.interfaces[interface['interface_id']] = interface
def prepare_links(self, filter={}, force=False):
+ # we're aobut to deprecate sfa_aggregate_type, need to get this right
+ # with the generic framework
if not self.links or force:
if not self.api.config.SFA_AGGREGATE_TYPE.lower() == 'vini':
return
def prepare_node_tags(self, filter={}, force=False):
if not self.node_tags or force:
- for node_tag in self.api.plshell.GetNodeTags(self.api.plauth, filter):
+ for node_tag in self.api.driver.GetNodeTags(filter):
self.node_tags[node_tag['node_tag_id']] = node_tag
def prepare_pl_initscripts(self, filter={}, force=False):
if not self.pl_initscripts or force:
filter.update({'enabled': True})
- for initscript in self.api.plshell.GetInitScripts(self.api.plauth, filter):
+ for initscript in self.api.driver.GetInitScripts(filter):
self.pl_initscripts[initscript['initscript_id']] = initscript
def prepare(self, slice = None, force=False):
if slice_xrn:
slice_hrn, _ = urn_to_hrn(slice_xrn)
slice_name = hrn_to_pl_slicename(slice_hrn)
- slices = self.api.plshell.GetSlices(self.api.plauth, slice_name)
+ slices = self.api.driver.GetSlices(slice_name)
if slices:
slice = slices[0]
self.prepare(slice=slice)
# add slivers
if slice_xrn and slice:
slivers = []
- tags = self.api.plshell.GetSliceTags(self.api.plauth, slice['slice_tag_ids'])
+ tags = self.api.driver.GetSliceTags(slice['slice_tag_ids'])
# add default tags
for tag in tags:
def write(self, api):
if self.was_added():
- api.plshell.AddSliceTag(api.plauth, self.slice_id,
- self.tagname, self.value, self.node_id)
+ api.driver.AddSliceTag(self.slice_id, self.tagname, self.value, self.node_id)
elif self.was_changed():
- api.plshell.UpdateSliceTag(api.plauth, self.id, self.value)
+ api.driver.UpdateSliceTag(self.id, self.value)
elif self.was_deleted():
- api.plshell.DeleteSliceTag(api.plauth, self.id)
+ api.driver.DeleteSliceTag(self.id)
class TagType:
Create a dictionary of site objects keyed by site ID
"""
tmp = []
- for site in api.plshell.GetSites(api.plauth, {'peer_id': None}):
+ for site in api.driver.GetSites({'peer_id': None}):
t = site['site_id'], Site(self, site)
tmp.append(t)
return dict(tmp)
Create a dictionary of node objects keyed by node ID
"""
tmp = []
- for node in api.plshell.GetNodes(api.plauth, {'peer_id': None}):
+ for node in api.driver.GetNodes({'peer_id': None}):
try:
t = node['node_id'], Node(self, node)
tmp.append(t)
Create a dictionary of node objects keyed by node ID
"""
tmp = []
- for iface in api.plshell.GetInterfaces(api.plauth):
+ for iface in api.driver.GetInterfaces():
t = iface['interface_id'], Iface(self, iface)
tmp.append(t)
return dict(tmp)
Create a dictionary of slicetag objects keyed by slice tag ID
"""
tmp = []
- for tag in api.plshell.GetSliceTags(api.plauth, {'~tagname':Slicetag.ignore_tags}, Slicetag.filter_fields):
+ for tag in api.driver.GetSliceTags({'~tagname':Slicetag.ignore_tags}, Slicetag.filter_fields):
t = tag['slice_tag_id'], Slicetag(tag)
tmp.append(t)
return dict(tmp)
Create a list of tagtype obects keyed by tag name
"""
tmp = []
- for tag in api.plshell.GetTagTypes(api.plauth, {'~tagname':TagType.ignore_tags}):
+ for tag in api.driver.GetTagTypes({'~tagname':TagType.ignore_tags}):
t = tag['tagname'], TagType(tag)
tmp.append(t)
return dict(tmp)
Return a Slice object for a single slice
"""
slicename = hrn_to_pl_slicename(hrn)
- slice = api.plshell.GetSlices(api.plauth, [slicename])
+ slice = api.driver.GetSlices([slicename])
if len(slice):
self.slice = Slice(self, slicename, slice[0])
return self.slice
# get this site's authority (sfa root authority or sub authority)
site_authority = get_authority(slice_authority).lower()
# check if we are already peered with this site_authority, if so
- peers = api.plshell.GetPeers(api.plauth, {}, \
- ['peer_id', 'peername', 'shortname', 'hrn_root'])
+ peers = api.driver.GetPeers( {}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
for peer_record in peers:
names = [name.lower() for name in peer_record.values() if isinstance(name, StringTypes)]
if site_authority in names:
import os
import tempfile
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
-from sfa.util.nodemanager import NodeManager
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol
+from sfa.plc.nodemanager import NodeManager
from sfa.trust.credential import Credential
from sfa.trust.certificate import Certificate, Keypair
from sfa.trust.gid import GID
-from sfa.server.sfaapi import SfaApi
-
####################
-class PlcComponentApi(SfaApi):
+class PlComponentDriver:
"""
This class is the type for the toplevel 'api' object
when running the component manager inside a planetlab node.
some tweaks as compared with a service running in the infrastructure.
"""
- def __init__ (self, encoding="utf-8", methods='sfa.methods',
- config = "/etc/sfa/sfa_config.py",
- peer_cert = None, interface = None,
- key_file = None, cert_file = None, cache = None):
- SfaApi.__init__(self, encoding=encoding, methods=methods,
- config=config,
- peer_cert=peer_cert, interface=interface,
- key_file=key_file,
- cert_file=cert_file, cache=cache)
-
- self.nodemanager = NodeManager(self.config)
+ def __init__ (self, config):
+ self.nodemanager = NodeManager(config)
def sliver_exists(self):
sliver_dict = self.nodemanager.GetXIDs()
def get_registry(self):
addr, port = self.config.SFA_REGISTRY_HOST, self.config.SFA_REGISTRY_PORT
url = "http://%(addr)s:%(port)s" % locals()
- server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file)
+ ### xxx this would require access to the api...
+ server = xmlrpcprotocol.server_proxy(url, self.key_file, self.cert_file)
return server
def get_node_key(self):
-import xmlrpclib
#
from sfa.util.faults import MissingSfaInfo
from sfa.util.sfalogging import logger
from sfa.util.xrn import hrn_to_urn
from sfa.util.plxrn import slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, hrn_to_pl_login_base
-from sfa.server.sfaapi import SfaApi
+from sfa.plc.plshell import PlShell
def list_to_dict(recs, key):
"""
keys = [rec[key] for rec in recs]
return dict(zip(keys, recs))
-class PlcSfaApi(SfaApi):
-
- def __init__ (self, encoding="utf-8", methods='sfa.methods',
- config = "/etc/sfa/sfa_config.py",
- peer_cert = None, interface = None,
- key_file = None, cert_file = None, cache = None):
- SfaApi.__init__(self, encoding=encoding, methods=methods,
- config=config,
- peer_cert=peer_cert, interface=interface,
- key_file=key_file,
- cert_file=cert_file, cache=cache)
+class PlDriver (PlShell):
+
+ def __init__ (self, config):
+ PlShell.__init__ (self, config)
- self.SfaTable = SfaTable
+ self.hrn = config.SFA_INTERFACE_HRN
+ # xxx thgen fixme - use SfaTable hardwired for now
+ # will need to extend generic to support multiple storage systems
+ #self.SfaTable = SfaTable
# Initialize the PLC shell only if SFA wraps a myPLC
- rspec_type = self.config.get_aggregate_type()
- if (rspec_type == 'pl' or rspec_type == 'vini' or \
- rspec_type == 'eucalyptus' or rspec_type == 'max'):
- self.plshell = self.getPLCShell()
- self.plshell_version = "4.3"
-
- def getPLCShell(self):
- self.plauth = {'Username': self.config.SFA_PLC_USER,
- 'AuthMethod': 'password',
- 'AuthString': self.config.SFA_PLC_PASSWORD}
-
- # The native shell (PLC.Shell.Shell) is more efficient than xmlrpc,
- # but it leaves idle db connections open. use xmlrpc until we can figure
- # out why PLC.Shell.Shell doesn't close db connection properly
- #try:
- # sys.path.append(os.path.dirname(os.path.realpath("/usr/bin/plcsh")))
- # self.plshell_type = 'direct'
- # import PLC.Shell
- # shell = PLC.Shell.Shell(globals = globals())
- #except:
-
- self.plshell_type = 'xmlrpc'
- url = self.config.SFA_PLC_URL
- shell = xmlrpclib.Server(url, verbose = 0, allow_none = True)
- return shell
+ rspec_type = config.get_aggregate_type()
+ assert (rspec_type == 'pl' or rspec_type == 'vini' or \
+ rspec_type == 'eucalyptus' or rspec_type == 'max')
##
# Convert SFA fields to PLC fields for use when registering up updating
# get pl records
nodes, sites, slices, persons, keys = {}, {}, {}, {}, {}
if node_ids:
- node_list = self.plshell.GetNodes(self.plauth, node_ids)
+ node_list = self.GetNodes(node_ids)
nodes = list_to_dict(node_list, 'node_id')
if site_ids:
- site_list = self.plshell.GetSites(self.plauth, site_ids)
+ site_list = self.GetSites(site_ids)
sites = list_to_dict(site_list, 'site_id')
if slice_ids:
- slice_list = self.plshell.GetSlices(self.plauth, slice_ids)
+ slice_list = self.GetSlices(slice_ids)
slices = list_to_dict(slice_list, 'slice_id')
if person_ids:
- person_list = self.plshell.GetPersons(self.plauth, person_ids)
+ person_list = self.GetPersons(person_ids)
persons = list_to_dict(person_list, 'person_id')
for person in persons:
key_ids.extend(persons[person]['key_ids'])
'slice': slices, 'user': persons}
if key_ids:
- key_list = self.plshell.GetKeys(self.plauth, key_ids)
+ key_list = self.GetKeys(key_ids)
keys = list_to_dict(key_list, 'key_id')
# fill record info
# get pl records
slices, persons, sites, nodes = {}, {}, {}, {}
if site_ids:
- site_list = self.plshell.GetSites(self.plauth, site_ids, ['site_id', 'login_base'])
+ site_list = self.GetSites(site_ids, ['site_id', 'login_base'])
sites = list_to_dict(site_list, 'site_id')
if person_ids:
- person_list = self.plshell.GetPersons(self.plauth, person_ids, ['person_id', 'email'])
+ person_list = self.GetPersons(person_ids, ['person_id', 'email'])
persons = list_to_dict(person_list, 'person_id')
if slice_ids:
- slice_list = self.plshell.GetSlices(self.plauth, slice_ids, ['slice_id', 'name'])
+ slice_list = self.GetSlices(slice_ids, ['slice_id', 'name'])
slices = list_to_dict(slice_list, 'slice_id')
if node_ids:
- node_list = self.plshell.GetNodes(self.plauth, node_ids, ['node_id', 'hostname'])
+ node_list = self.GetNodes(node_ids, ['node_id', 'hostname'])
nodes = list_to_dict(node_list, 'node_id')
# convert ids to hrns
return records
- def fill_record_sfa_info(self, records):
+ # aggregates is basically api.aggregates
+ def fill_record_sfa_info(self, records, aggregates):
def startswith(prefix, values):
return [value for value in values if value.startswith(prefix)]
site_pis = {}
if site_ids:
pi_filter = {'|roles': ['pi'], '|site_ids': site_ids}
- pi_list = self.plshell.GetPersons(self.plauth, pi_filter, ['person_id', 'site_ids'])
+ pi_list = self.GetPersons(pi_filter, ['person_id', 'site_ids'])
for pi in pi_list:
# we will need the pi's hrns also
person_ids.append(pi['person_id'])
# we obtain
# get the sfa records
- table = self.SfaTable()
+ # xxx thgen fixme - use SfaTable hardwired for now
+ # table = self.SfaTable()
+ table = SfaTable()
person_list, persons = [], {}
person_list = table.find({'type': 'user', 'pointer': person_ids})
# create a hrns keyed on the sfa record's pointer.
# get the pl records
pl_person_list, pl_persons = [], {}
- pl_person_list = self.plshell.GetPersons(self.plauth, person_ids, ['person_id', 'roles'])
+ pl_person_list = self.GetPersons(person_ids, ['person_id', 'roles'])
pl_persons = list_to_dict(pl_person_list, 'person_id')
# fill sfa info
elif (type.startswith("authority")):
record['url'] = None
- if record['hrn'] in self.aggregates:
+ if record['hrn'] in aggregates:
- record['url'] = self.aggregates[record['hrn']].get_url()
+ record['url'] = aggregates[record['hrn']].get_url()
if record['pointer'] != -1:
record['PI'] = []
# xxx TODO: PostalAddress, Phone
record.update(sfa_info)
- def fill_record_info(self, records):
+ def fill_record_info(self, records, aggregates):
"""
Given a SFA record, fill in the PLC specific and SFA specific
fields in the record.
records = [records]
self.fill_record_pl_info(records)
- self.fill_record_sfa_info(records)
+ self.fill_record_sfa_info(records, aggregates)
def update_membership_list(self, oldRecord, record, listName, addFunc, delFunc):
# get a list of the HRNs that are members of the old and new records
# build a list of the new person ids, by looking up each person to get
# their pointer
newIdList = []
- table = self.SfaTable()
+ # xxx thgen fixme - use SfaTable hardwired for now
+ #table = self.SfaTable()
+ table = SfaTable()
records = table.find({'type': 'user', 'hrn': newList})
for rec in records:
newIdList.append(rec['pointer'])
# add people who are in the new list, but not the oldList
for personId in newIdList:
if not (personId in oldIdList):
- addFunc(self.plauth, personId, containerId)
+ addFunc(personId, containerId)
# remove people who are in the old list, but not the new list
for personId in oldIdList:
if not (personId in newIdList):
- delFunc(self.plauth, personId, containerId)
+ delFunc(personId, containerId)
def update_membership(self, oldRecord, record):
if record.type == "slice":
self.update_membership_list(oldRecord, record, 'researcher',
- self.plshell.AddPersonToSlice,
- self.plshell.DeletePersonFromSlice)
+ self.AddPersonToSlice,
+ self.DeletePersonFromSlice)
elif record.type == "authority":
# xxx TODO
pass
--- /dev/null
+import xmlrpclib
+
+class PlShell:
+ """
+ A simple xmlrpc shell to a myplc instance
+ This class can receive all PLCAPI calls to the underlying testbed
+ For safety this is limited to a set of hard-coded calls
+ """
+
+ direct_calls = ['AddNode', 'AddPerson', 'AddPersonKey', 'AddPersonToSite',
+ 'AddPersonToSlice', 'AddRoleToPerson', 'AddSite', 'AddSiteTag', 'AddSlice',
+ 'AddSliceTag', 'AddSliceToNodes', 'BindObjectToPeer', 'DeleteKey',
+ 'DeleteNode', 'DeletePerson', 'DeletePersonFromSlice', 'DeleteSite',
+ 'DeleteSlice', 'DeleteSliceFromNodes', 'DeleteSliceTag', 'GetInitScripts',
+ 'GetInterfaces', 'GetKeys', 'GetNodeTags', 'GetPeers',
+ 'GetPersons', 'GetSlices', 'GetSliceTags', 'GetTagTypes',
+ 'UnBindObjectFromPeer', 'UpdateNode', 'UpdatePerson', 'UpdateSite',
+ 'UpdateSlice', 'UpdateSliceTag',
+ # also used as-is in importer
+ 'GetSites','GetNodes',
+ ]
+ # support for other names - this is experimental
+ alias_calls = { 'get_authorities':'GetSites',
+ 'get_nodes':'GetNodes',
+ }
+
+ def __init__ ( self, config ) :
+ self.plauth = {'Username': config.SFA_PLC_USER,
+ 'AuthMethod': 'password',
+ 'AuthString': config.SFA_PLC_PASSWORD}
+
+ self.url = config.SFA_PLC_URL
+ self.plauth = {'Username': 'root@test.onelab.eu',
+ 'AuthMethod': 'password',
+ 'AuthString': 'test++'}
+ self.proxy_server = xmlrpclib.Server(self.url, verbose = 0, allow_none = True)
+
+ def __getattr__(self, name):
+ def func(*args, **kwds):
+ actual_name=None
+ if name in PlShell.direct_calls: actual_name=name
+ if name in PlShell.alias_calls: actual_name=PlShell.alias_calls[name]
+ if not actual_name:
+ raise Exception, "Illegal method call %s for PL driver"%(name)
+ return getattr(self.proxy_server, actual_name)(self.plauth, *args, **kwds)
+ return func
slice_name = hrn_to_pl_slicename(hrn)
# XX Should we just call PLCAPI.GetSliceTicket(slice_name) instead
# of doing all of this?
- #return self.api.GetSliceTicket(self.auth, slice_name)
+ #return self.api.driver.GetSliceTicket(self.auth, slice_name)
# from PLCAPI.GetSlivers.get_slivers()
slice_fields = ['slice_id', 'name', 'instantiation', 'expires', 'person_ids', 'slice_tag_ids']
- slices = self.api.plshell.GetSlices(self.api.plauth, slice_name, slice_fields)
+ slices = self.api.driver.GetSlices(slice_name, slice_fields)
# Build up list of users and slice attributes
person_ids = set()
all_slice_tag_ids = set()
person_ids = list(person_ids)
all_slice_tag_ids = list(all_slice_tag_ids)
# Get user information
- all_persons_list = self.api.plshell.GetPersons(self.api.plauth, {'person_id':person_ids,'enabled':True}, ['person_id', 'enabled', 'key_ids'])
+ all_persons_list = self.api.driver.GetPersons({'person_id':person_ids,'enabled':True}, ['person_id', 'enabled', 'key_ids'])
all_persons = {}
for person in all_persons_list:
all_persons[person['person_id']] = person
key_ids.update(person['key_ids'])
key_ids = list(key_ids)
# Get user account keys
- all_keys_list = self.api.plshell.GetKeys(self.api.plauth, key_ids, ['key_id', 'key', 'key_type'])
+ all_keys_list = self.api.driver.GetKeys(key_ids, ['key_id', 'key', 'key_type'])
all_keys = {}
for key in all_keys_list:
all_keys[key['key_id']] = key
# Get slice attributes
- all_slice_tags_list = self.api.plshell.GetSliceTags(self.api.plauth, all_slice_tag_ids)
+ all_slice_tags_list = self.api.driver.GetSliceTags(all_slice_tag_ids)
all_slice_tags = {}
for slice_tag in all_slice_tags_list:
all_slice_tags[slice_tag['slice_tag_id']] = slice_tag
site_authority = get_authority(slice_authority).lower()
# check if we are already peered with this site_authority, if so
- peers = self.api.plshell.GetPeers(self.api.plauth, {}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
+ peers = self.api.driver.GetPeers({}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
for peer_record in peers:
names = [name.lower() for name in peer_record.values() if isinstance(name, StringTypes)]
if site_authority in names:
def verify_slice_nodes(self, slice, requested_slivers, peer):
- nodes = self.api.plshell.GetNodes(self.api.plauth, slice['node_ids'], ['hostname'])
+ nodes = self.api.driver.GetNodes(slice['node_ids'], ['hostname'])
current_slivers = [node['hostname'] for node in nodes]
# remove nodes not in rspec
try:
if peer:
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'slice', slice['slice_id'], peer['shortname'])
- self.api.plshell.AddSliceToNodes(self.api.plauth, slice['name'], added_nodes)
- self.api.plshell.DeleteSliceFromNodes(self.api.plauth, slice['name'], deleted_nodes)
+ self.api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer['shortname'])
+ self.api.driver.AddSliceToNodes(slice['name'], added_nodes)
+ self.api.driver.DeleteSliceFromNodes(slice['name'], deleted_nodes)
except:
self.api.logger.log_exc('Failed to add/remove slice from nodes')
if1 = aggregate.interfaces[node['interface_ids'][0]]
ipaddr = if1['ip']
topo_rspec = VLink.get_topo_rspec(link, ipaddr)
- self.api.plshell.AddSliceTag(self.api.plauth, slice['name'], 'topo_rspec', str([topo_rspec]), node_id)
+ self.api.driver.AddSliceTag(slice['name'], 'topo_rspec', str([topo_rspec]), node_id)
# bind site
try:
if site:
- self.api.plshell.BindObjectToPeer(self.api.plauth, 'site', \
- site['site_id'], peer['shortname'], slice['site_id'])
+ self.api.driver.BindObjectToPeer('site', site['site_id'], peer['shortname'], slice['site_id'])
except Exception,e:
- self.api.plshell.DeleteSite(self.api.plauth, site['site_id'])
+ self.api.driver.DeleteSite(site['site_id'])
raise e
# bind slice
try:
if slice:
- self.api.plshell.BindObjectToPeer(self.api.plauth, 'slice', \
- slice['slice_id'], peer['shortname'], slice['slice_id'])
+ self.api.driver.BindObjectToPeer('slice', slice['slice_id'], peer['shortname'], slice['slice_id'])
except Exception,e:
- self.api.plshell.DeleteSlice(self.api.plauth, slice['slice_id'])
+ self.api.driver.DeleteSlice(slice['slice_id'])
raise e
# bind persons
for person in persons:
try:
- self.api.plshell.BindObjectToPeer(self.api.plauth, 'person', \
- person['person_id'], peer['shortname'], person['peer_person_id'])
+ self.api.driver.BindObjectToPeer('person',
+ person['person_id'], peer['shortname'], person['peer_person_id'])
for (key, remote_key_id) in zip(person['keys'], person['key_ids']):
try:
- self.api.plshell.BindObjectToPeer(self.api.plauth, 'key',\
- key['key_id'], peer['shortname'], remote_key_id)
+ self.api.driver.BindObjectToPeer( 'key', key['key_id'], peer['shortname'], remote_key_id)
except:
- self.api.plshell.DeleteKey(self.api.plauth, key['key_id'])
+ self.api.driver.DeleteKey(key['key_id'])
self.api.logger("failed to bind key: %s to peer: %s " % (key['key_id'], peer['shortname']))
except Exception,e:
- self.api.plshell.DeletePerson(self.api.plauth, person['person_id'])
+ self.api.driver.DeletePerson(person['person_id'])
raise e
return slice
slicename = hrn_to_pl_slicename(slice_hrn)
authority_name = slicename.split('_')[0]
login_base = authority_name[:20]
- sites = self.api.plshell.GetSites(self.api.plauth, login_base)
+ sites = self.api.driver.GetSites(login_base)
if not sites:
# create new site record
site = {'name': 'geni.%s' % authority_name,
'peer_site_id': None}
if peer:
site['peer_site_id'] = slice_record.get('site_id', None)
- site['site_id'] = self.api.plshell.AddSite(self.api.plauth, site)
+ site['site_id'] = self.api.driver.AddSite(site)
# exempt federated sites from monitor policies
- self.api.plshell.AddSiteTag(self.api.plauth, site['site_id'], 'exempt_site_until', "20200101")
+ self.api.driver.AddSiteTag(site['site_id'], 'exempt_site_until', "20200101")
# is this still necessary?
# add record to the local registry
site = sites[0]
if peer:
# unbind from peer so we can modify if necessary. Will bind back later
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'site', site['site_id'], peer['shortname'])
+ self.api.driver.UnBindObjectFromPeer('site', site['site_id'], peer['shortname'])
return site
slicename = hrn_to_pl_slicename(slice_hrn)
parts = slicename.split("_")
login_base = parts[0]
- slices = self.api.plshell.GetSlices(self.api.plauth, [slicename])
+ slices = self.api.driver.GetSlices([slicename])
if not slices:
slice = {'name': slicename,
'url': slice_record.get('url', slice_hrn),
'description': slice_record.get('description', slice_hrn)}
# add the slice
- slice['slice_id'] = self.api.plshell.AddSlice(self.api.plauth, slice)
+ slice['slice_id'] = self.api.driver.AddSlice(slice)
slice['node_ids'] = []
slice['person_ids'] = []
if peer:
if peer:
slice['peer_slice_id'] = slice_record.get('slice_id', None)
# unbind from peer so we can modify if necessary. Will bind back later
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'slice',\
- slice['slice_id'], peer['shortname'])
+ self.api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer['shortname'])
#Update existing record (e.g. expires field) it with the latest info.
if slice_record and slice['expires'] != slice_record['expires']:
- self.api.plshell.UpdateSlice(self.api.plauth, slice['slice_id'],\
- {'expires' : slice_record['expires']})
+ self.api.driver.UpdateSlice( slice['slice_id'], {'expires' : slice_record['expires']})
return slice
existing_user_ids = []
if users_by_email:
# get existing users by email
- existing_users = self.api.plshell.GetPersons(self.api.plauth, \
- {'email': users_by_email.keys()}, ['person_id', 'key_ids', 'email'])
+ existing_users = self.api.driver.GetPersons({'email': users_by_email.keys()},
+ ['person_id', 'key_ids', 'email'])
existing_user_ids.extend([user['email'] for user in existing_users])
if users_by_site:
# get a list of user sites (based on requeste user urns
- site_list = self.api.plshell.GetSites(self.api.plauth, users_by_site.keys(), \
+ site_list = self.api.driver.GetSites(users_by_site.keys(), \
['site_id', 'login_base', 'person_ids'])
sites = {}
site_user_ids = []
sites[site['site_id']] = site
site_user_ids.extend(site['person_ids'])
- existing_site_persons_list = self.api.plshell.GetPersons(self.api.plauth, \
- site_user_ids, ['person_id', 'key_ids', 'email', 'site_ids'])
+ existing_site_persons_list = self.api.driver.GetPersons(site_user_ids,
+ ['person_id', 'key_ids', 'email', 'site_ids'])
# all requested users are either existing users or new (added) users
for login_base in users_by_site:
requested_user_ids = users_dict.keys()
# existing slice users
existing_slice_users_filter = {'person_id': slice_record.get('person_ids', [])}
- existing_slice_users = self.api.plshell.GetPersons(self.api.plauth, \
- existing_slice_users_filter, ['person_id', 'key_ids', 'email'])
+ existing_slice_users = self.api.driver.GetPersons(existing_slice_users_filter,
+ ['person_id', 'key_ids', 'email'])
existing_slice_user_ids = [user['email'] for user in existing_slice_users]
# users to be added, removed or updated
# Remove stale users (only if we are not appending).
if append == False:
for removed_user_id in removed_user_ids:
- self.api.plshell.DeletePersonFromSlice(self.api.plauth, removed_user_id, slice_record['name'])
+ self.api.driver.DeletePersonFromSlice(removed_user_id, slice_record['name'])
# update_existing users
updated_users_list = [user for user in existing_slice_users if user['email'] in \
updated_user_ids]
'keys': [],
'key_ids': added_user.get('key_ids', []),
}
- person['person_id'] = self.api.plshell.AddPerson(self.api.plauth, person)
+ person['person_id'] = self.api.driver.AddPerson(person)
if peer:
person['peer_person_id'] = added_user['person_id']
added_persons.append(person)
# enable the account
- self.api.plshell.UpdatePerson(self.api.plauth, person['person_id'], {'enabled': True})
+ self.api.driver.UpdatePerson(person['person_id'], {'enabled': True})
# add person to site
- self.api.plshell.AddPersonToSite(self.api.plauth, added_user_id, login_base)
+ self.api.driver.AddPersonToSite(added_user_id, login_base)
for key_string in added_user.get('keys', []):
key = {'key':key_string, 'key_type':'ssh'}
- key['key_id'] = self.api.plshell.AddPersonKey(self.api.plauth, person['person_id'], key)
+ key['key_id'] = self.api.driver.AddPersonKey(person['person_id'], key)
person['keys'].append(key)
# add the registry record
for added_slice_user_id in added_slice_user_ids.union(added_user_ids):
# add person to the slice
- self.api.plshell.AddPersonToSlice(self.api.plauth, added_slice_user_id, slice_record['name'])
+ self.api.driver.AddPersonToSlice(added_slice_user_id, slice_record['name'])
# if this is a peer record then it should already be bound to a peer.
# no need to return worry about it getting bound later
key_ids = []
for person in persons:
key_ids.extend(person['key_ids'])
- keylist = self.api.plshell.GetKeys(self.api.plauth, key_ids, ['key_id', 'key'])
+ keylist = self.api.driver.GetKeys(key_ids, ['key_id', 'key'])
keydict = {}
for key in keylist:
keydict[key['key']] = key['key_id']
try:
if peer:
person = persondict[user['email']]
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'person', person['person_id'], peer['shortname'])
- key['key_id'] = self.api.plshell.AddPersonKey(self.api.plauth, user['email'], key)
+ self.api.driver.UnBindObjectFromPeer('person', person['person_id'], peer['shortname'])
+ key['key_id'] = self.api.driver.AddPersonKey(user['email'], key)
if peer:
key_index = user_keys.index(key['key'])
remote_key_id = user['key_ids'][key_index]
- self.api.plshell.BindObjectToPeer(self.api.plauth, 'key', key['key_id'], peer['shortname'], remote_key_id)
+ self.api.driver.BindObjectToPeer('key', key['key_id'], peer['shortname'], remote_key_id)
finally:
if peer:
- self.api.plshell.BindObjectToPeer(self.api.plauth, 'person', person['person_id'], peer['shortname'], user['person_id'])
+ self.api.driver.BindObjectToPeer('person', person['person_id'], peer['shortname'], user['person_id'])
# remove old keys (only if we are not appending)
if append == False:
if keydict[existing_key_id] in removed_keys:
try:
if peer:
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'key', existing_key_id, peer['shortname'])
- self.api.plshell.DeleteKey(self.api.plauth, existing_key_id)
+ self.api.driver.UnBindObjectFromPeer('key', existing_key_id, peer['shortname'])
+ self.api.driver.DeleteKey(existing_key_id)
except:
pass
def verify_slice_attributes(self, slice, requested_slice_attributes):
# get list of attributes users ar able to manage
- slice_attributes = self.api.plshell.GetTagTypes(self.api.plauth, {'category': '*slice*', '|roles': ['user']})
+ slice_attributes = self.api.driver.GetTagTypes({'category': '*slice*', '|roles': ['user']})
valid_slice_attribute_names = [attribute['tagname'] for attribute in slice_attributes]
# get sliver attributes
added_slice_attributes = []
removed_slice_attributes = []
ignored_slice_attribute_names = []
- existing_slice_attributes = self.api.plshell.GetSliceTags(self.api.plauth, {'slice_id': slice['slice_id']})
+ existing_slice_attributes = self.api.driver.GetSliceTags({'slice_id': slice['slice_id']})
# get attributes that should be removed
for slice_tag in existing_slice_attributes:
# remove stale attributes
for attribute in removed_slice_attributes:
try:
- self.api.plshell.DeleteSliceTag(self.api.plauth, attribute['slice_tag_id'])
+ self.api.driver.DeleteSliceTag(attribute['slice_tag_id'])
except Exception, e:
self.api.logger.warn('Failed to remove sliver attribute. name: %s, value: %s, node_id: %s\nCause:%s'\
% (name, value, node_id, str(e)))
# add requested_attributes
for attribute in added_slice_attributes:
try:
- self.api.plshell.AddSliceTag(self.api.plauth, slice['name'], attribute['name'], attribute['value'], attribute.get('node_id', None))
+ self.api.driver.AddSliceTag(slice['name'], attribute['name'], attribute['value'], attribute.get('node_id', None))
except Exception, e:
self.api.logger.warn('Failed to add sliver attribute. name: %s, value: %s, node_id: %s\nCause:%s'\
% (name, value, node_id, str(e)))
slice = self.verify_slice(registry, credential, hrn, site_id, remote_site_id, peer, sfa_peer)
# find out where this slice is currently running
- nodelist = self.api.plshell.GetNodes(self.api.plauth, slice['node_ids'], ['hostname'])
+ nodelist = self.api.driver.GetNodes(slice['node_ids'], ['hostname'])
hostnames = [node['hostname'] for node in nodelist]
# get netspec details
try:
if peer:
- self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'slice', slice['slice_id'], peer)
+ self.api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer)
- self.api.plshell.AddSliceToNodes(self.api.plauth, slicename, added_nodes)
+ self.api.driver.AddSliceToNodes(slicename, added_nodes)
# Add recognized slice tags
for node_name in node_names:
if (isinstance(value, list)):
value = value[0]
- self.api.plshell.AddSliceTag(self.api.plauth, slicename, slice_tag, value, node_name)
+ self.api.driver.AddSliceTag(slicename, slice_tag, value, node_name)
- self.api.plshell.DeleteSliceFromNodes(self.api.plauth, slicename, deleted_nodes)
+ self.api.driver.DeleteSliceFromNodes(slicename, deleted_nodes)
finally:
if peer:
- self.api.plshell.BindObjectToPeer(self.api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id'])
+ self.api.driver.BindObjectToPeer('slice', slice['slice_id'], peer, slice['peer_slice_id'])
return 1
def add_element(self, name, attrs={}, parent=None, text=""):
"""
- Generic wrapper around etree.SubElement(). Adds an element to
+ Wrapper around etree.SubElement(). Adds an element to
specified parent node. Adds element to root node is parent is
not specified.
"""
##
# Component is a SfaServer that serves component operations.
-# set SFA_GENERIC_FLAVOUR=plcm to get a PlcComponentApi instance in the request handler
class Component(SfaServer):
##
# Create a new registry object.
# @param cert_file certificate filename containing public key (could be a GID file)
def __init__(self, ip, port, key_file, cert_file):
- SfaServer.__init__(self, ip, port, key_file, cert_file)
- self.server.interface = 'component'
+ SfaServer.__init__(self, ip, port, key_file, cert_file, interface='component')
#from sfa.util.faults import *
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol
from sfa.util.xml import XML
# GeniLight client support is optional
url = "http://%s" % "/".join(address_parts)
return url
- def get_server(self, key_file, cert_file, timeout=30):
+ def server_proxy(self, key_file, cert_file, timeout=30):
server = None
if self.client_type == 'geniclientlight' and GeniClientLight:
# xxx url and self.api are undefined
server = GeniClientLight(url, self.api.key_file, self.api.cert_file)
else:
- server = xmlrpcprotocol.get_server(self.get_url(), key_file, cert_file, timeout)
+ server = xmlrpcprotocol.server_proxy(self.get_url(), key_file, cert_file, timeout)
return server
##
interface = Interface(hrn, address, port)
self[hrn] = interface
- def get_server(self, hrn, key_file, cert_file, timeout=30):
- return self[hrn].get_server(key_file, cert_file, timeout)
+ def server_proxy(self, hrn, key_file, cert_file, timeout=30):
+ return self[hrn].server_proxy(key_file, cert_file, timeout)
import xmlrpclib
from mod_python import apache
-from sfa.plc.plcsfaapi import PlcSfaApi
from sfa.util.sfalogging import logger
+from sfa.plc.server import SfaApi
-api = PlcSfaApi(interface='aggregate')
+api = SfaApi(interface='aggregate')
def handler(req):
try:
import xmlrpclib
from mod_python import apache
-from sfa.plc.plcsfaapi import PlcSfaApi
from sfa.util.sfalogging import logger
+from sfa.plc.server import SfaApi
-api = PlcSfaApi(interface='registry')
+api = SfaApi(interface='registry')
def handler(req):
try:
import xmlrpclib
from mod_python import apache
-from sfa.plc.plcsfaapi import PlcSfaApi
from sfa.util.sfalogging import logger
+from sfa.plc.server import SfaApi
-api = PlcSfaApi(interface='slicemgr')
+api = SfaApi(interface='slicemgr')
def handler(req):
try:
import sys
import os
import traceback
+import socket
+
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol
from sfa.util.table import SfaTable
from sfa.util.prefixTree import prefixTree
-from sfa.plc.plcsfaapi import PlcSfaApi
from sfa.util.config import Config
+
+from sfa.generic import Generic
+
from sfa.trust.certificate import Keypair
from sfa.trust.hierarchy import Hierarchy
from sfa.server.registry import Registries
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
-import socket
def main():
config = Config()
# and a valid credential
authority = config.SFA_INTERFACE_HRN
url = 'http://%s:%s/' %(config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT)
- registry = xmlrpcprotocol.get_server(url, key_file, cert_file)
- sfa_api = PlcSfaApi(key_file = key_file, cert_file = cert_file, interface='registry')
+ registry = xmlrpcprotocol.server_proxy(url, key_file, cert_file)
+ sfa_api = Generic.the_flavour()
credential = sfa_api.getCredential()
# get peer registries
import os, os.path
import traceback
import sys
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
from optparse import OptionParser
from sfa.util.sfalogging import logger
+from sfa.util.xrn import get_authority, hrn_to_urn
+from sfa.util.config import Config
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol
+
from sfa.trust.certificate import Keypair, Certificate
from sfa.trust.hierarchy import Hierarchy
from sfa.trust.gid import GID
-from sfa.util.config import Config
-from sfa.plc.plcsfaapi import PlcSfaApi
+
+from sfa.server.sfaapi import SfaApi
+
from sfa.server.registry import Registries
from sfa.server.aggregate import Aggregates
-from sfa.util.xrn import get_authority, hrn_to_urn
-from sfa.util.sfalogging import logger
# after http://www.erlenstar.demon.co.uk/unix/faq_2.html
def daemon():
# There should be a gid file in /etc/sfa/trusted_roots for every
# peer registry found in in the registries.xml config file. If there
# are any missing gids, request a new one from the peer registry.
- api = PlcSfaApi(key_file = server_key_file, cert_file = server_cert_file)
+ api = SfaApi(key_file = server_key_file, cert_file = server_cert_file)
registries = Registries()
aggregates = Aggregates()
interfaces = dict(registries.items() + aggregates.items())
try:
# get gid from the registry
url = interfaces[new_hrn].get_url()
- interface = interfaces[new_hrn].get_server(server_key_file, server_cert_file, timeout=30)
+ interface = interfaces[new_hrn].server_proxy(server_key_file, server_cert_file, timeout=30)
# skip non sfa aggregates
server_version = api.get_cached_server_version(interface)
if 'sfa' not in server_version:
from sfa.util.faults import ConnectionKeyGIDMismatch
from sfa.util.config import Config
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol
from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn
from sfa.trust.certificate import Keypair, Certificate
return wrapper
-def get_server(url=None, port=None, keyfile=None, certfile=None,verbose=False):
+def server_proxy(url=None, port=None, keyfile=None, certfile=None,verbose=False):
"""
returns an xmlrpc connection to the service a the specified
address
if verbose:
print "Contacting registry at: %(url)s" % locals()
- server = xmlrpcprotocol.get_server(url, keyfile, certfile)
+ server = xmlrpcprotocol.server_proxy(url, keyfile, certfile)
return server
cert.sign()
cert.save_to_file(certfile)
- registry = get_server(url = registry, keyfile=keyfile, certfile=certfile)
+ registry = server_proxy(url = registry, keyfile=keyfile, certfile=certfile)
registry.get_key()
def create_server_keypair(keyfile=None, certfile=None, hrn="component", verbose=False):
create_server_keypair(keyfile, certfile, hrn, verbose)
# get credential from registry
- registry = get_server(url=registry, keyfile=keyfile, certfile=certfile)
+ registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
cert = Certificate(filename=certfile)
cert_str = cert.save_to_string(save_parents=True)
cred = registry.GetSelfCredential(cert_str, 'node', hrn)
cred = get_credential(registry=registry, verbose=verbose)
# make sure server key cert pair exists
create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
- registry = get_server(url=registry, keyfile=keyfile, certfile=certfile)
+ registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
# get the trusted certs and save them in the right place
if verbose:
print "Getting trusted certs from registry"
cred = get_credential(registry=registry, verbose=verbose)
# make sure server key cert pair exists
create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
- registry = get_server(url=registry, keyfile=keyfile, certfile=certfile)
+ registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
if verbose:
print "Getting current slices on this node"
# get a list of slices on this node
- from sfa.plc.plcsfaapi import PlcComponentApi
- api = PlcComponentApi()
- xids_tuple = api.nodemanager.GetXIDs()
+ from sfa.generic import Generic
+ generic=Generic.the_flavour()
+ api = generic.make_api(interface='component')
+ xids_tuple = api.driver.nodemanager.GetXIDs()
slices = eval(xids_tuple[1])
slicenames = slices.keys()
-import os.path
+import os, os.path
import datetime
from sfa.util.faults import SfaAPIError
from sfa.trust.credential import Credential
from sfa.trust.rights import determine_rights
-# this is wrong all right, but temporary, will use generic
from sfa.server.xmlrpcapi import XmlrpcApi
-import os
-import datetime
+
+# thgen xxx fixme this is wrong all right, but temporary, will use generic
+from sfa.util.table import SfaTable
####################
class SfaApi (XmlrpcApi):
# filled later on by generic/Generic
self.manager=None
- # tmp
- def get_interface_manager(self, manager_base = 'sfa.managers'):
- return self.manager
-
- def get_server(self, interface, cred, timeout=30):
+ def server_proxy(self, interface, cred, timeout=30):
"""
Returns a connection to the specified interface. Use the specified
credential to determine the caller and look for the caller's key/cert
auth_info = hierarchy.get_auth_info(caller_gid.get_hrn())
key_file = auth_info.get_privkey_filename()
cert_file = auth_info.get_gid_filename()
- server = interface.get_server(key_file, cert_file, timeout)
+ server = interface.server_proxy(key_file, cert_file, timeout)
return server
"""
from sfa.server.registry import Registries
registries = Registries()
- registry = registries.get_server(self.hrn, self.key_file, self.cert_file)
+ registry = registries.server_proxy(self.hrn, self.key_file, self.cert_file)
cert_string=self.cert.save_to_string(save_parents=True)
# get self credential
self_cred = registry.GetSelfCredential(cert_string, self.hrn, 'authority')
if not auth_hrn or hrn == self.config.SFA_INTERFACE_HRN:
auth_hrn = hrn
auth_info = self.auth.get_auth_info(auth_hrn)
- table = self.SfaTable()
+ # xxx thgen fixme - use SfaTable hardwired for now
+ #table = self.SfaTable()
+ table = SfaTable()
records = table.findObjects({'hrn': hrn, 'type': 'authority+sa'})
if not records:
raise RecordNotFound
+++ /dev/null
-#! /usr/bin/env python
-
-import sys
-
-from copy import deepcopy
-from lxml import etree
-from StringIO import StringIO
-from optparse import OptionParser
-
-from sfa.util.faults import InvalidRSpec
-from sfa.util.sfalogging import logger
-
-def merge_rspecs(rspecs):
- """
- Merge merge a list of RSpecs into 1 RSpec, and return the result.
- rspecs must be a valid RSpec string or list of RSpec strings.
- """
- if not rspecs or not isinstance(rspecs, list):
- return rspecs
-
- # ugly hack to avoid sending the same info twice, when the call graph has dags
- known_networks={}
- def register_network (network):
- try:
- known_networks[network.get('name')]=True
- except:
- logger.error("merge_rspecs: cannot register network with no name in rspec")
- pass
- def is_registered_network (network):
- try:
- return network.get('name') in known_networks
- except:
- logger.error("merge_rspecs: cannot retrieve network with no name in rspec")
- return False
-
- # the resulting tree
- rspec = None
- for input_rspec in rspecs:
- # ignore empty strings as returned with used call_ids
- if not input_rspec: continue
- try:
- tree = etree.parse(StringIO(input_rspec))
- except etree.XMLSyntaxError:
- # consider failing silently here
- logger.log_exc("merge_rspecs, parse error")
- message = str(sys.exc_info()[1]) + ' with ' + input_rspec
- raise InvalidRSpec(message)
-
- root = tree.getroot()
- if not root.get("type") in ["SFA"]:
- logger.error("merge_rspecs: unexpected type for rspec root, %s"%root.get('type'))
- continue
- if rspec == None:
- # we scan the first input, register all networks
- # in addition we remove duplicates - needed until everyone runs 1.0-10
- rspec = root
- for network in root.iterfind("./network"):
- if not is_registered_network(network):
- register_network(network)
- else:
- # duplicate in the first input - trash it
- root.remove(network)
- else:
- for network in root.iterfind("./network"):
- if not is_registered_network(network):
- rspec.append(deepcopy(network))
- register_network(network)
- for request in root.iterfind("./request"):
- rspec.append(deepcopy(request))
- return etree.tostring(rspec, xml_declaration=True, pretty_print=True)
-
-class RSpec:
- def __init__(self, xml):
- parser = etree.XMLParser(remove_blank_text=True)
- tree = etree.parse(StringIO(xml), parser)
- self.rspec = tree.getroot()
-
- # If there is only one network in the rspec, make it the default
- self.network = None
- networks = self.get_network_list()
- if len(networks) == 1:
- self.network = networks[0]
-
- # Thierry : need this to locate hostname even if several networks
- def get_node_element(self, hostname, network=None):
- if network == None and self.network:
- network = self.network
- if network != None:
- names = self.rspec.iterfind("./network[@name='%s']/site/node/hostname" % network)
- else:
- names = self.rspec.iterfind("./network/site/node/hostname")
- for name in names:
- if name.text == hostname:
- return name.getparent()
- return None
-
- # Thierry : need this to return all nodes in all networks
- def get_node_list(self, network=None):
- if network == None and self.network:
- network = self.network
- if network != None:
- return self.rspec.xpath("./network[@name='%s']/site/node/hostname/text()" % network)
- else:
- return self.rspec.xpath("./network/site/node/hostname/text()")
-
- def get_network_list(self):
- return self.rspec.xpath("./network[@name]/@name")
-
- def get_sliver_list(self, network=None):
- if network == None:
- network = self.network
- result = self.rspec.xpath("./network[@name='%s']/site/node[sliver]/hostname/text()" % network)
- return result
-
- def get_available_node_list(self, network=None):
- if network == None:
- network = self.network
- result = self.rspec.xpath("./network[@name='%s']/site/node[not(sliver)]/hostname/text()" % network)
- return result
-
- def add_sliver(self, hostname, network=None):
- if network == None:
- network = self.network
- node = self.get_node_element(hostname, network)
- etree.SubElement(node, "sliver")
-
- def remove_sliver(self, hostname, network=None):
- if network == None:
- network = self.network
- node = self.get_node_element(hostname, network)
- node.remove(node.find("sliver"))
-
- def attributes_list(self, elem):
- opts = []
- if elem is not None:
- for e in elem:
- opts.append((e.tag, e.text))
- return opts
-
- def get_default_sliver_attributes(self, network=None):
- if network == None:
- network = self.network
- defaults = self.rspec.find("./network[@name='%s']/sliver_defaults" % network)
- return self.attributes_list(defaults)
-
- def get_sliver_attributes(self, hostname, network=None):
- if network == None:
- network = self.network
- node = self.get_node_element(hostname, network)
- sliver = node.find("sliver")
- return self.attributes_list(sliver)
-
- def add_attribute(self, elem, name, value):
- opt = etree.SubElement(elem, name)
- opt.text = value
-
- def add_default_sliver_attribute(self, name, value, network=None):
- if network == None:
- network = self.network
- defaults = self.rspec.find("./network[@name='%s']/sliver_defaults" % network)
- if defaults is None:
- defaults = etree.Element("sliver_defaults")
- network = self.rspec.find("./network[@name='%s']" % network)
- network.insert(0, defaults)
- self.add_attribute(defaults, name, value)
-
- def add_sliver_attribute(self, hostname, name, value, network=None):
- if network == None:
- network = self.network
- node = self.get_node_element(hostname, network)
- sliver = node.find("sliver")
- self.add_attribute(sliver, name, value)
-
- def remove_attribute(self, elem, name, value):
- if elem is not None:
- opts = elem.iterfind(name)
- if opts is not None:
- for opt in opts:
- if opt.text == value:
- elem.remove(opt)
-
- def remove_default_sliver_attribute(self, name, value, network=None):
- if network == None:
- network = self.network
- defaults = self.rspec.find("./network[@name='%s']/sliver_defaults" % network)
- self.remove_attribute(defaults, name, value)
-
- def remove_sliver_attribute(self, hostname, name, value, network=None):
- if network == None:
- network = self.network
- node = self.get_node_element(hostname, network)
- sliver = node.find("sliver")
- self.remove_attribute(sliver, name, value)
-
- def get_site_nodes(self, siteid, network=None):
- if network == None:
- network = self.network
- query = './network[@name="%s"]/site[@id="%s"]/node/hostname/text()' % (network, siteid)
- result = self.rspec.xpath(query)
- return result
-
- def get_link_list(self, network=None):
- if network == None:
- network = self.network
- linklist = []
- links = self.rspec.iterfind("./network[@name='%s']/link" % network)
- for link in links:
- (end1, end2) = link.get("endpoints").split()
- name = link.find("description")
- linklist.append((name.text,
- self.get_site_nodes(end1, network),
- self.get_site_nodes(end2, network)))
- return linklist
-
- def get_vlink_list(self, network=None):
- if network == None:
- network = self.network
- vlinklist = []
- vlinks = self.rspec.iterfind("./network[@name='%s']//vlink" % network)
- for vlink in vlinks:
- endpoints = vlink.get("endpoints")
- (end1, end2) = endpoints.split()
- query = './network[@name="%s"]//node[@id="%s"]/hostname/text()' % network
- node1 = self.rspec.xpath(query % end1)[0]
- node2 = self.rspec.xpath(query % end2)[0]
- desc = "%s <--> %s" % (node1, node2)
- kbps = vlink.find("kbps")
- vlinklist.append((endpoints, desc, kbps.text))
- return vlinklist
-
- def query_links(self, fromnode, tonode, network=None):
- if network == None:
- network = self.network
- fromsite = fromnode.getparent()
- tosite = tonode.getparent()
- fromid = fromsite.get("id")
- toid = tosite.get("id")
-
- query = "./network[@name='%s']/link[@endpoints = '%s %s']" % (network, fromid, toid)
- results = self.rspec.xpath(query)
- if results == None:
- query = "./network[@name='%s']/link[@endpoints = '%s %s']" % (network, toid, fromid)
- results = self.rspec.xpath(query)
- return results
-
- def query_vlinks(self, endpoints, network=None):
- if network == None:
- network = self.network
- query = "./network[@name='%s']//vlink[@endpoints = '%s']" % (network, endpoints)
- results = self.rspec.xpath(query)
- return results
-
-
- def add_vlink(self, fromhost, tohost, kbps, network=None):
- if network == None:
- network = self.network
- fromnode = self.get_node_element(fromhost, network)
- tonode = self.get_node_element(tohost, network)
- links = self.query_links(fromnode, tonode, network)
-
- for link in links:
- vlink = etree.SubElement(link, "vlink")
- fromid = fromnode.get("id")
- toid = tonode.get("id")
- vlink.set("endpoints", "%s %s" % (fromid, toid))
- self.add_attribute(vlink, "kbps", kbps)
-
-
- def remove_vlink(self, endpoints, network=None):
- if network == None:
- network = self.network
- vlinks = self.query_vlinks(endpoints, network)
- for vlink in vlinks:
- vlink.getparent().remove(vlink)
-
- def toxml(self):
- return etree.tostring(self.rspec, pretty_print=True,
- xml_declaration=True)
-
- def __str__(self):
- return self.toxml()
-
- def save(self, filename):
- f = open(filename, "w")
- f.write(self.toxml())
- f.close()
-
-
-class Commands:
- def __init__(self, usage, description, epilog=None):
- self.parser = OptionParser(usage=usage, description=description,
- epilog=epilog)
- self.parser.add_option("-i", "", dest="infile", metavar="FILE",
- help="read RSpec from FILE (default is stdin)")
- self.parser.add_option("-o", "", dest="outfile", metavar="FILE",
- help="write output to FILE (default is stdout)")
- self.nodefile = False
- self.attributes = {}
-
- def add_nodefile_option(self):
- self.nodefile = True
- self.parser.add_option("-n", "", dest="nodefile",
- metavar="FILE",
- help="read node list from FILE"),
-
- def add_show_attributes_option(self):
- self.parser.add_option("-s", "--show-attributes", action="store_true",
- dest="showatt", default=False,
- help="show sliver attributes")
-
- def add_attribute_options(self):
- self.parser.add_option("", "--capabilities", action="append",
- metavar="<cap1,cap2,...>",
- help="Vserver bcapabilities")
- self.parser.add_option("", "--codemux", action="append",
- metavar="<host,local-port>",
- help="Demux HTTP between slices using " +
- "localhost ports")
- self.parser.add_option("", "--cpu-pct", action="append",
- metavar="<num>",
- help="Reserved CPU percent (e.g., 25)")
- self.parser.add_option("", "--cpu-share", action="append",
- metavar="<num>",
- help="Number of CPU shares (e.g., 5)")
- self.parser.add_option("", "--delegations",
- metavar="<slice1,slice2,...>", action="append",
- help="List of slices with delegation authority")
- self.parser.add_option("", "--disk-max",
- metavar="<num>", action="append",
- help="Disk quota (1k disk blocks)")
- self.parser.add_option("", "--initscript",
- metavar="<name>", action="append",
- help="Slice initialization script (e.g., stork)")
- self.parser.add_option("", "--ip-addresses", action="append",
- metavar="<IP addr>",
- help="Add an IP address to a sliver")
- self.parser.add_option("", "--net-i2-max-kbyte",
- metavar="<KBytes>", action="append",
- help="Maximum daily network Tx limit " +
- "to I2 hosts.")
- self.parser.add_option("", "--net-i2-max-rate",
- metavar="<Kbps>", action="append",
- help="Maximum bandwidth over I2 routes")
- self.parser.add_option("", "--net-i2-min-rate",
- metavar="<Kbps>", action="append",
- help="Minimum bandwidth over I2 routes")
- self.parser.add_option("", "--net-i2-share",
- metavar="<num>", action="append",
- help="Number of bandwidth shares over I2 routes")
- self.parser.add_option("", "--net-i2-thresh-kbyte",
- metavar="<KBytes>", action="append",
- help="Limit sent to I2 hosts before warning, " +
- "throttling")
- self.parser.add_option("", "--net-max-kbyte",
- metavar="<KBytes>", action="append",
- help="Maximum daily network Tx limit " +
- "to non-I2 hosts.")
- self.parser.add_option("", "--net-max-rate",
- metavar="<Kbps>", action="append",
- help="Maximum bandwidth over non-I2 routes")
- self.parser.add_option("", "--net-min-rate",
- metavar="<Kbps>", action="append",
- help="Minimum bandwidth over non-I2 routes")
- self.parser.add_option("", "--net-share",
- metavar="<num>", action="append",
- help="Number of bandwidth shares over non-I2 " +
- "routes")
- self.parser.add_option("", "--net-thresh-kbyte",
- metavar="<KBytes>", action="append",
- help="Limit sent to non-I2 hosts before " +
- "warning, throttling")
- self.parser.add_option("", "--vsys",
- metavar="<name>", action="append",
- help="Vsys script (e.g., fd_fusemount)")
- self.parser.add_option("", "--vsys-vnet",
- metavar="<IP network>", action="append",
- help="Allocate a virtual private network")
-
- def get_attribute_dict(self):
- attrlist = ['capabilities','codemux','cpu_pct','cpu_share',
- 'delegations','disk_max','initscript','ip_addresses',
- 'net_i2_max_kbyte','net_i2_max_rate','net_i2_min_rate',
- 'net_i2_share','net_i2_thresh_kbyte',
- 'net_max_kbyte','net_max_rate','net_min_rate',
- 'net_share','net_thresh_kbyte',
- 'vsys','vsys_vnet']
- attrdict = {}
- for attr in attrlist:
- value = getattr(self.opts, attr, None)
- if value is not None:
- attrdict[attr] = value
- return attrdict
-
- def prep(self):
- (self.opts, self.args) = self.parser.parse_args()
-
- if self.opts.infile:
- sys.stdin = open(self.opts.infile, "r")
- xml = sys.stdin.read()
- self.rspec = RSpec(xml)
-
- if self.nodefile:
- if self.opts.nodefile:
- f = open(self.opts.nodefile, "r")
- self.nodes = f.read().split()
- f.close()
- else:
- self.nodes = self.args
-
- if self.opts.outfile:
- sys.stdout = open(self.opts.outfile, "w")
-
-
-
-
-
-
-
self.logger.setLevel(logging.WARNING)
elif verbose==1:
self.logger.setLevel(logging.INFO)
- elif verbose==2:
+ elif verbose>=2:
self.logger.setLevel(logging.DEBUG)
+ # in case some other code needs a boolean
+ def getBoolVerboseFromOpt(self,verbose):
+ return verbose>=1
####################
def info(self, msg):
+++ /dev/null
-# SOAP-specific code for SFA Client
-
-from httplib import HTTPSConnection
-from ZSI.client import Binding
-
-def xmlrpc_like_callable (soap_callable, *x):
- soap_result = soap_callable(*x)
- xmlrpc_result = soap_result['Result']
- return xmlrpc_result
-
-class SFACallable:
- def __init__(self, soap_callable):
- self.soap_callable = soap_callable
-
- def __call__(self, *args):
- outer_result = self.soap_callable(*args)
- return outer_result['Result']
-
-
-class SFASoapBinding(Binding):
- def __getattr__(self, attr):
- soap_callable = Binding.__getattr__(self, attr)
- return SFACallable(soap_callable)
-
-
-def get_server(url, key_file, cert_file):
- auth = {
- 'transport' : HTTPSConnection,
- 'transdict' : {'cert_file' : cert_file,
- 'key_file' : key_file
- },
- }
-
- return SFASoapBinding(url=url, **auth)
-
+++ /dev/null
-from ssl import SSLSocket
-
-import textwrap
-
-import _ssl # if we can't import it, let the error propagate
-
-from _ssl import SSLError
-from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
-from _ssl import PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
-from _ssl import RAND_status, RAND_egd, RAND_add
-from _ssl import \
- SSL_ERROR_ZERO_RETURN, \
- SSL_ERROR_WANT_READ, \
- SSL_ERROR_WANT_WRITE, \
- SSL_ERROR_WANT_X509_LOOKUP, \
- SSL_ERROR_SYSCALL, \
- SSL_ERROR_SSL, \
- SSL_ERROR_WANT_CONNECT, \
- SSL_ERROR_EOF, \
- SSL_ERROR_INVALID_ERROR_CODE
-
-from socket import socket, _fileobject
-from socket import getnameinfo as _getnameinfo
-import base64 # for DER-to-PEM translation
-
-class SSLSocket(SSLSocket, socket):
-
- """This class implements a subtype of socket.socket that wraps
- the underlying OS socket in an SSL context when necessary, and
- provides read and write methods over that channel."""
-
- def __init__(self, sock, keyfile=None, certfile=None,
- server_side=False, cert_reqs=CERT_NONE,
- ssl_version=PROTOCOL_SSLv23, ca_certs=None,
- do_handshake_on_connect=True,
- suppress_ragged_eofs=True):
- socket.__init__(self, _sock=sock._sock)
- # the initializer for socket trashes the methods (tsk, tsk), so...
- self.send = lambda data, flags=0: SSLSocket.send(self, data, flags)
- self.sendto = lambda data, addr, flags=0: SSLSocket.sendto(self, data, addr, flags)
- self.recv = lambda buflen=1024, flags=0: SSLSocket.recv(self, buflen, flags)
- self.recvfrom = lambda addr, buflen=1024, flags=0: SSLSocket.recvfrom(self, addr, buflen, flags)
- self.recv_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recv_into(self, buffer, nbytes, flags)
- self.recvfrom_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recvfrom_into(self, buffer, nbytes, flags)
-
- if certfile and not keyfile:
- keyfile = certfile
- # see if it's connected
- try:
- socket.getpeername(self)
- except:
- # no, no connection yet
- self._sslobj = None
- else:
- # yes, create the SSL object
- self._sslobj = _ssl.sslwrap(self._sock, server_side,
- keyfile, certfile,
- cert_reqs, ssl_version, ca_certs)
- if do_handshake_on_connect:
- timeout = self.gettimeout()
- try:
- if timeout == 0:
- self.settimeout(None)
- self.do_handshake()
- finally:
- self.settimeout(timeout)
- self.keyfile = keyfile
- self.certfile = certfile
- self.cert_reqs = cert_reqs
- self.ssl_version = ssl_version
- self.ca_certs = ca_certs
- self.do_handshake_on_connect = do_handshake_on_connect
- self.suppress_ragged_eofs = suppress_ragged_eofs
- self._makefile_refs = 0
-
-
# element.attrib.update will explode if DateTimes are in the
# dcitionary.
d=d.copy()
- for (k,v) in d.iteritems():
- if not isinstance(v,StringTypes): del d[k]
+ # looks like iteritems won't stand side-effects
for k in d.keys():
- if (type(d[k]) != str) and (type(d[k]) != unicode):
+ if not isinstance(d[k],StringTypes):
del d[k]
element.attrib.update(d)
def add_element(self, name, attrs={}, parent=None, text=""):
"""
- Generic wrapper around etree.SubElement(). Adds an element to
+ Wrapper around etree.SubElement(). Adds an element to
specified parent node. Adds element to root node is parent is
not specified.
"""
import random
import string
import unittest
-import sfa.util.xmlrpcprotocol as xmlrpc
+import sfa.util.xmlrpcprotocol as xmlrpcprotocol
from unittest import TestCase
from optparse import OptionParser
-from sfa.util.xmlrpcprotocol import ServerException
from sfa.util.xrn import get_authority
from sfa.util.config import *
from sfa.trust.certificate import *
self.cert.save_to_file(cert_file)
SFI_AGGREGATE = config.SFI_SM.replace('12347', '12346')
SFI_CM = 'http://' + options.cm_host + ':12346'
- self.registry = xmlrpc.get_server(config.SFI_REGISTRY, key_file, cert_file)
- self.aggregate = xmlrpc.get_server(SFI_AGGREGATE, key_file, cert_file)
- self.sm = xmlrpc.get_server(config.SFI_SM, key_file, cert_file)
- self.cm = xmlrpc.get_server(SFI_CM, key_file, cert_file)
+ self.registry = xmlrpcprotocol.server_proxy(config.SFI_REGISTRY, key_file, cert_file)
+ self.aggregate = xmlrpcprotocol.server_proxy(SFI_AGGREGATE, key_file, cert_file)
+ self.sm = xmlrpcprotocol.server_proxy(config.SFI_SM, key_file, cert_file)
+ self.cm = xmlrpcprotocol.server_proxy(SFI_CM, key_file, cert_file)
self.hrn = config.SFI_USER
# XX defaulting to user, but this should be configurable so we can
# test from components persepctive
server_exception = False
try:
callable(self.credential)
- except ServerException:
+ except xmlrpcprotocol.ServerException:
server_exception = True
finally:
if self.type in ['user'] and not server_exception: