from StringIO import StringIO
from optparse import OptionParser
from pprint import PrettyPrinter
+from tempfile import mkstemp
from sfa.trust.certificate import Keypair, Certificate
from sfa.trust.gid import GID
self.read_config ()
self.bootstrap ()
- self.logger.info("Command=%s" % command)
+ self.logger.debug("Command=%s" % command)
try:
self.dispatch(command, command_options, command_args)
return
+ def upgrade_config(self, config_file):
+ """
+ upgrade from shell to ini format
+ """
+ fp, fn = mkstemp(suffix='sfi_config', text=True)
+ try:
+ tmp_config = Config(fn)
+ tmp_config.add_section('sfi')
+ tmp_config.add_section('sface')
+ tmp_config.load(config_file)
+ tmp_config.save(config_file)
+ except:
+ raise
+ finally:
+ os.unlink(fn)
+
+
####################
def read_config(self):
config_file = os.path.join(self.options.sfi_dir,"sfi_config")
try:
- config = Config (config_file)
+ if Config.is_ini(config_file):
+ config = Config (config_file)
+ else:
+ # try upgrading from shell config format
+ self.upgrade_config(config_file)
+ config = Config(config_file)
+
except:
- self.logger.critical("Failed to read configuration file %s"%config_file)
- self.logger.info("Make sure to remove the export clauses and to add quotes")
- if self.options.verbose==0:
- self.logger.info("Re-run with -v for more details")
- else:
- self.logger.log_exc("Could not read config file %s"%config_file)
- sys.exit(1)
+ self.logger.critical("Failed to read configuration file %s"%config_file)
+ self.logger.info("Make sure to remove the export clauses and to add quotes")
+ if self.options.verbose==0:
+ self.logger.info("Re-run with -v for more details")
+ else:
+ self.logger.log_exc("Could not read config file %s"%config_file)
+ sys.exit(1)
errors = 0
# Set SliceMgr URL
elif hasattr(config, "SFI_REGISTRY"):
self.reg_url = config.SFI_REGISTRY
else:
- self.logger.errors("You need to set e.g. SFI_REGISTRY='http://your.registry.url:12345/' in %s" % config_file)
+ self.logger.error("You need to set e.g. SFI_REGISTRY='http://your.registry.url:12345/' in %s" % config_file)
errors += 1
# Set user HRN
elif hasattr(config, "SFI_USER"):
self.user = config.SFI_USER
else:
- self.logger.errors("You need to set e.g. SFI_USER='plc.princeton.username' in %s" % config_file)
+ self.logger.error("You need to set e.g. SFI_USER='plc.princeton.username' in %s" % config_file)
errors += 1
# Set authority HRN
# init self-signed cert, user credentials and gid
def bootstrap (self):
- client_bootstrap = SfaClientBootstrap (self.user, self.reg_url, self.options.sfi_dir)
+ client_bootstrap = SfaClientBootstrap (self.user, self.reg_url, self.options.sfi_dir,
+ logger=self.logger)
# if -k is provided, use this to initialize private key
if self.options.user_private_key:
client_bootstrap.init_private_key_if_missing (self.options.user_private_key)