Exemple #1
0
def configure():
    project = 'discovery-scanner'
    version = '1.0.0'

    CONF = cfg.CONF
    log.register_options(CONF)
    log.setup(CONF, project, version)

    cli_opts = [
        cfg.StrOpt('driver', help='Specify scanner driver', required=True),
        cfg.IPOpt('discovery_host_ip',
                  default='0.0.0.0',
                  help='The IP address on which discovery-api listens.'),
        cfg.IntOpt('discovery_port',
                   default=8881,
                   min=1, max=65535,
                   help='The TCP port on which discovry-api listens.')]

    CONF.register_cli_opts(cli_opts)
    available_scanners = BaseScanner.__subclasses__()
    # TODO add subcommands/groups not to load all parameters globally
    for scanner in available_scanners:
        CONF.register_cli_opts(scanner.cli_opts)

    CONF(sys.argv[1:], project=project, version=version)

    return CONF
Exemple #2
0
def main():
    conf = configure()
    scanner_name = conf.driver
    scanner_class = None
    available_scanners = BaseScanner.__subclasses__()
    for s in available_scanners:
        if s.name == scanner_name:
            scanner_class = s

    if scanner_class is None:
        raise ValueError("Invalid scanner name %s, available scanners %s",
                         scanner_name, [s.name for s in available_scanners])

    scanner = scanner_class(conf)
    scanner.run()