From: Thierry Parmentelat Date: Tue, 6 Dec 2011 14:21:19 +0000 (+0100) Subject: Merge branch 'master' of ssh://git.onelab.eu/git/sfa X-Git-Tag: sfa-2.0-3~37 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=196db84cd78fb47e19188ab976def62523a2de9b;hp=2ea09d2555ea338090535c8ba139293ceb825b6e Merge branch 'master' of ssh://git.onelab.eu/git/sfa --- diff --git a/Makefile b/Makefile index d6ecaad2..1ee9e996 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ RSYNC_EXCLUDES := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $ RSYNC_COND_DRY_RUN := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,) RSYNC := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES) -CLIENTS = sfi.py getNodes.py getRecord.py setRecord.py \ +CLIENTS = sfi.py sfascan.py getNodes.py getRecord.py setRecord.py \ sfiAddAttribute.py sfiAddSliver.py sfiDeleteAttribute.py sfiDeleteSliver.py sfiListNodes.py \ sfiListSlivers.py sfadump.py diff --git a/setup.py b/setup.py index 9f68e18e..5408817a 100755 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ bins = [ 'sfa/server/sfa-clean-peer-records.py', 'sfa/server/sfa_component_setup.py', 'sfa/client/sfi.py', + 'sfa/client/sfascan.py', 'sfa/client/getNodes.py', 'sfa/client/getRecord.py', 'sfa/client/setRecord.py', diff --git a/sfa.spec b/sfa.spec index a43d9c95..b10e9698 100644 --- a/sfa.spec +++ b/sfa.spec @@ -127,6 +127,8 @@ make VERSIONTAG="%{version}-%{taglevel}" SCMURL="%{SCMURL}" install DESTDIR="$RP rm -rf $RPM_BUILD_ROOT/%{python_sitelib}/*egg-info # this gets duplicated rm -rf $RPM_BUILD_ROOT/%{python_sitelib}/sfa/storage/sfa.sql +# create symlinks +(cd $RPM_BUILD_ROOT/%{_bindir}; ln -s sfi.py sfi; ln -s sfascan.py sfascan) %clean rm -rf $RPM_BUILD_ROOT @@ -163,6 +165,7 @@ rm -rf $RPM_BUILD_ROOT %files client %config (noreplace) /etc/sfa/sfi_config %{_bindir}/sfi* +%{_bindir}/sfascan* %{_bindir}/getNodes.py* %{_bindir}/getRecord.py* %{_bindir}/setRecord.py* diff --git a/sfa/client/sfascan.py b/sfa/client/sfascan.py index 6a7e79ab..3a285b03 100755 --- a/sfa/client/sfascan.py +++ b/sfa/client/sfascan.py @@ -7,7 +7,10 @@ import socket import traceback from urlparse import urlparse -import pygraphviz +try: + import pygraphviz +except: + print 'Warning, could not import pygraphviz, test mode only' from optparse import OptionParser @@ -148,6 +151,7 @@ class Interface: client.read_config() key_file = client.get_key_file() cert_file = client.get_cert_file(key_file) + logger.debug("using key %s & cert %s"%(key_file,cert_file)) url=self.url() logger.info('issuing GetVersion at %s'%url) # setting timeout here seems to get the call to fail - even though the response time is fast @@ -291,6 +295,9 @@ default_outfiles=['sfa.png','sfa.svg','sfa.dot'] def main(): usage="%prog [options] url-entry-point(s)" parser=OptionParser(usage=usage) + parser.add_option("-d", "--dir", dest="sfi_dir", + help="config & working directory - default is " + Sfi.default_sfi_dir(), + metavar="PATH", default=Sfi.default_sfi_dir()) parser.add_option("-o","--output",action='append',dest='outfiles',default=[], 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, @@ -325,13 +332,18 @@ def main(): options.outfiles=default_outfiles 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") - g.layout(prog='dot') - for outfile in options.outfiles: - logger.info("drawing in %s"%outfile) - g.draw(outfile) - logger.info("done") + try: + g=scanner.graph(entries) + logger.info("creating layout") + g.layout(prog='dot') + for outfile in options.outfiles: + logger.info("drawing in %s"%outfile) + g.draw(outfile) + logger.info("done") + # test mode when pygraphviz is not available + except: + entry=entries[0] + print "GetVersion at %s returned %s"%(entry.url(),entry.get_version()) if __name__ == '__main__': main() diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index 3b610c74..29149bde 100755 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -8,7 +8,7 @@ import sys sys.path.append('.') import os, os.path -import tempfile +#import tempfile import socket import datetime import codecs @@ -167,6 +167,13 @@ class Sfi: required_options=['verbose', 'debug', 'registry', 'sm', 'auth', 'user'] + @staticmethod + def default_sfi_dir (): + if os.path.isfile("./sfi_config"): + return os.getcwd() + else: + return os.path.expanduser("~/.sfi/") + # dummy to meet Sfi's expectations for its 'options' field # i.e. s/t we can do setattr on class DummyOptions: @@ -176,10 +183,7 @@ class Sfi: if options is None: options=Sfi.DummyOptions() for opt in Sfi.required_options: if not hasattr(options,opt): setattr(options,opt,None) - if not hasattr(options,'sfi_dir'): options.sfi_dir=os.path.expanduser("~/.sfi/") - # xxx oops, this is dangerous, sounds like ww sometimes have discrepency - # would be safer to remove self.sfi_dir altogether - self.sfi_dir = options.sfi_dir + if not hasattr(options,'sfi_dir'): options.sfi_dir=Sfi.default_sfi_dir() self.options = options self.slicemgr = None self.registry = None @@ -189,14 +193,12 @@ class Sfi: self.logger = sfi_logger self.logger.enable_console() - def create_cmd_parser(self, command, additional_cmdargs=None): + def create_cmd_parser(self, command): cmdargs = {"list": "authority", "show": "name", "remove": "name", "add": "record", "update": "record", - "aggregates": "[name]", - "registries": "[name]", "create_gid": "[name]", "get_gid": [], "get_trusted_certs": "cred", @@ -216,9 +218,6 @@ class Sfi: "version": "", } - if additional_cmdargs: - cmdargs.update(additional_cmdargs) - if command not in cmdargs: msg="Invalid command\n" msg+="Commands: " @@ -313,10 +312,9 @@ class Sfi: help="root registry", metavar="URL", default=None) parser.add_option("-s", "--slicemgr", dest="sm", help="slice manager", metavar="URL", default=None) - default_sfi_dir = os.path.expanduser("~/.sfi/") parser.add_option("-d", "--dir", dest="sfi_dir", - help="config & working directory - default is " + default_sfi_dir, - metavar="PATH", default=default_sfi_dir) + help="config & working directory - default is " + Sfi.default_sfi_dir(), + metavar="PATH", default=Sfi.default_sfi_dir()) parser.add_option("-u", "--user", dest="user", help="user name", metavar="HRN", default=None) parser.add_option("-a", "--auth", dest="auth", @@ -639,21 +637,6 @@ class Sfi: self.logger.critical("No such registry record file %s"%record) sys.exit(1) - def load_publickey_string(self, fn): - f = file(fn, "r") - key_string = f.read() - - # if the filename is a private key file, then extract the public key - if "PRIVATE KEY" in key_string: - outfn = tempfile.mktemp() - cmd = "openssl rsa -in " + fn + " -pubout -outform PEM -out " + outfn - os.system(cmd) - f = file(outfn, "r") - key_string = f.read() - os.remove(outfn) - - return key_string - # xxx opts undefined def get_component_proxy_from_hrn(self, hrn): # direct connection to the nodes component manager interface @@ -699,9 +682,6 @@ class Sfi: # Registry-related commands #========================================================================== - def dispatch(self, command, cmd_opts, cmd_args): - return getattr(self, command)(cmd_opts, cmd_args) - def create_gid(self, opts, args): if len(args) < 1: self.print_help() @@ -712,7 +692,7 @@ class Sfi: if opts.file: filename = opts.file else: - filename = os.sep.join([self.sfi_dir, '%s.gid' % target_hrn]) + filename = os.sep.join([self.options.sfi_dir, '%s.gid' % target_hrn]) self.logger.info("writing %s gid to %s" % (target_hrn, filename)) GID(string=gid).save_to_file(filename) @@ -884,32 +864,6 @@ class Sfi: self.logger.debug('Sfi.get_trusted_certs -> %r'%cert.get_subject()) return - def aggregates(self, opts, args): - """ - return a list of details about known aggregates - """ - user_cred = self.get_user_cred().save_to_string(save_parents=True) - hrn = None - if args: - hrn = args[0] - - result = self.registry.get_aggregates(user_cred, hrn) - display_list(result) - return - - def registries(self, opts, args): - """ - return a list of details about known registries - """ - user_cred = self.get_user_cred().save_to_string(save_parents=True) - hrn = None - if args: - hrn = args[0] - result = self.registry.get_registries(user_cred, hrn) - display_list(result) - return - - # ================================================================== # Slice-related commands # ================================================================== @@ -1212,6 +1166,9 @@ class Sfi: # # Main: parse arguments and dispatch to command # + def dispatch(self, command, cmd_opts, cmd_args): + return getattr(self, command)(cmd_opts, cmd_args) + def main(self): self.sfi_parser = self.create_parser() (options, args) = self.sfi_parser.parse_args()