#!/usr/bin/python
+import os
import sys
import copy
from pprint import pformat
def import_registry(self):
- pass
-
+ from sfa.importer import Importer
+ importer = Importer()
+ importer.run()
@args('-a', '--all', dest='all', metavar='<all>', action='store_true', default=False,
help='Remove all registry records and all files in %s area' % Hierarchy().basedir)
@args('-c', '--certs', dest='certs', metavar='<certs>', action='store_true', default=False,
help='Remove all cached certs/gids found in %s' % Hierarchy().basedir )
@args('-0', '--no-reinit', dest='reinit', metavar='<reinit>', action='store_false', default=True,
- help='By default a new DB schema is installed after the cleanup; this option prevents that')
+ help='Prevents new DB schema from being installed after cleanup')
def nuke(self, all=False, certs=False, reinit=True):
from sfa.storage.dbschema import DBSchema
from sfa.util.sfalogging import _SfaLogger
# for convenience we re-create the schema here, so there's no need for an explicit
# service sfa restart
# however in some (upgrade) scenarios this might be wrong
- if options.reinit:
+ if reinit:
logger.info("re-creating empty schema")
dbschema.init_or_upgrade()
# remove the server certificate and all gids found in /var/lib/sfa/authorities
- if options.clean_certs:
+ if certs:
logger.info("Purging cached certificates")
for (dir, _, files) in os.walk('/var/lib/sfa/authorities'):
for file in files:
os.unlink(path)
# just remove all files that do not match 'server.key' or 'server.cert'
- if options.all:
+ if all:
logger.info("Purging registry filesystem cache")
preserved_files = [ 'server.key', 'server.cert']
for (dir,_,files) in os.walk(Hierarchy().basedir):
os.unlink(path)
-class CerficiateCommands(Commands):
+class CertCommands(Commands):
def import_gid(self, xrn):
pass
@args('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
@args('-o', '--outfile', dest='outfile', metavar='<outfile>', help='output file', default=None)
def export(self, xrn, type=None, outfile=None):
+ from sfa.storage.alchemy import dbsession
+ from sfa.storage.model import RegRecord
+ hrn = Xrn(xrn).get_hrn()
request=dbsession.query(RegRecord).filter_by(hrn=hrn)
if type: request = request.filter_by(type=type)
record=request.first()
self.api= Generic.the_flavour().make_api(interface='slicemgr')
-CATEGORIES = {'registry': RegistryCommands,
+CATEGORIES = {'cert': CertCommands,
+ 'registry': RegistryCommands,
'aggregate': AggregateCommands,
'slicemgr': SliceManagerCommands}
+def category_usage():
+ print "Available categories:"
+ for k in CATEGORIES:
+ print "\t%s" % k
+
def main():
argv = copy.deepcopy(sys.argv)
script_name = argv.pop(0)
+ # ensure category is specified
if len(argv) < 1:
print script_name + " category action [<args>]"
- print "Available categories:"
- for k in CATEGORIES:
- print "\t%s" % k
+ category_usage()
sys.exit(2)
+ # ensure category is valid
category = argv.pop(0)
usage = "%%prog %s action <args> [options]" % (category)
parser = OptionParser(usage=usage)
- command_class = CATEGORIES[category]
+ command_class = CATEGORIES.get(category, None)
+ if not command_class:
+ print "no such category %s " % category
+ category_usage()
+ sys.exit(2)
+
+ # ensure command is valid
command_instance = command_class()
actions = command_instance._get_commands()
if len(argv) < 1:
- if hasattr(command_instance, '__call__'):
- action = ''
- command = command_instance.__call__
- else:
- print script_name + " category action [<args>]"
- print "Available actions for %s category:" % category
- for k in actions:
- print "\t%s" % k
- sys.exit(2)
+ action = '__call__'
else:
action = argv.pop(0)
+
+ if hasattr(command_instance, action):
command = getattr(command_instance, action)
+ else:
+ print script_name + " category action [<args>]"
+ print "Available actions for %s category:" % category
+ for k in actions:
+ print "\t%s" % k
+ sys.exit(2)
+ # ensure options are valid
options = getattr(command, 'options', [])
usage = "%%prog %s %s <args> [options]" % (category, action)
parser = OptionParser(usage=usage)
if v is None:
del cmd_kwds[k]
+ # execute commadn
try:
command(*cmd_args, **cmd_kwds)
sys.exit(0)