+ 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.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)
+ except:
+ try:
+ # try upgrading from old config format
+ self.upgrade_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)
+
+ errors = 0
+ # Set SliceMgr URL
+ if (self.options.sm is not None):
+ self.sm_url = self.options.sm
+ elif hasattr(config, "SFI_SM"):
+ self.sm_url = config.SFI_SM
+ else:
+ self.logger.error("You need to set e.g. SFI_SM='http://your.slicemanager.url:12347/' in %s" % config_file)
+ errors += 1
+
+ # Set Registry URL
+ if (self.options.registry is not None):
+ self.reg_url = self.options.registry
+ 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)
+ errors += 1
+
+ # Set user HRN
+ if (self.options.user is not None):
+ self.user = self.options.user
+ 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)
+ errors += 1
+
+ # Set authority HRN
+ if (self.options.auth is not None):
+ self.authority = self.options.auth
+ elif hasattr(config, "SFI_AUTH"):
+ self.authority = config.SFI_AUTH
+ else:
+ self.logger.error("You need to set e.g. SFI_AUTH='plc.princeton' in %s" % config_file)
+ errors += 1
+
+ self.config_file=config_file
+ if errors:
+ sys.exit(1)
+
+ def show_config (self):
+ print "From configuration file %s"%self.config_file
+ flags=[
+ ('SFI_USER','user'),
+ ('SFI_AUTH','authority'),
+ ('SFI_SM','sm_url'),
+ ('SFI_REGISTRY','reg_url'),
+ ]
+ for (external_name, internal_name) in flags:
+ print "%s='%s'"%(external_name,getattr(self,internal_name))
+
+ #
+ # Get various credential and spec files
+ #
+ # Establishes limiting conventions
+ # - conflates MAs and SAs
+ # - assumes last token in slice name is unique
+ #
+ # Bootstraps credentials
+ # - bootstrap user credential from self-signed certificate
+ # - bootstrap authority credential from user credential
+ # - bootstrap slice credential from user credential
+ #