示例#1
0
def main(options):
    import json
    settings = config.settings
    dst_folder = None
    if options.vis_uuid:
        config.settings['Http Post']['uuid'] = options.vis_uuid

    try:
        # test if can import, if not present will fail and not add to template
        # path
        import autonetkit_cisco
    except ImportError:
        pass
    else:
        import autonetkit_cisco.version
        version_banner = autonetkit_cisco.version.banner()
        log.info("%s" % version_banner)

    log.info("AutoNetkit %s" % ANK_VERSION)

    if options.target == "cisco":
        # output target is Cisco
        log.info("Setting output target as Cisco")
        settings['Graphml']['Node Defaults']['platform'] = "cisco"
        settings['Graphml']['Node Defaults']['host'] = "internal"
        settings['Graphml']['Node Defaults']['syntax'] = options.syntax
        settings['JSON']['Node Defaults']['syntax'] = options.syntax
        settings['Compiler']['Cisco']['to memory'] = 1
        settings['General']['deploy'] = 1
        settings['Deploy Hosts']['internal'] = {'cisco':
                                                {'deploy': 1}}

    if options.debug or settings['General']['debug']:
        # TODO: fix this
        import logging
        logger = logging.getLogger("ANK")
        logger.setLevel(logging.DEBUG)

    if options.quiet or settings['General']['quiet']:
        import logging
        logger = logging.getLogger("ANK")
        logger.setLevel(logging.WARNING)

    build_options = {
        'compile': options.compile or settings['General']['compile'],
        'render': options.render or settings['General']['render'],
        'validate': options.validate or settings['General']['validate'],
        'build': options.build or settings['General']['build'],
        'deploy': options.deploy or settings['General']['deploy'],
        'measure': options.measure or settings['General']['measure'],
        'monitor': options.monitor or settings['General']['monitor'],
        'diff': options.diff or settings['General']['diff'],
        'archive': options.archive or settings['General']['archive'],
        # use and for visualise as no_vis negates
        'visualise': options.visualise and settings['General']['visualise'],
        'syntax': options.syntax,
    }

    if options.webserver:
        log.info("Webserver not yet supported, please run as seperate module")
    if options.file:
         if options.file == 'dictionary':
            input_string = json.dumps(options.dictionary)
         else:
            with open(options.file, "r") as fh:
                input_string = fh.read()
         filename = os.path.join(BASE_DIR, "autonetkit/ank.log")
         timestamp = os.stat(filename).st_mtime
    elif options.stdin:
        input_string = sys.stdin
        now = datetime.now()
        timestamp = now.strftime("%Y%m%d_%H%M%S_%f")
    elif options.grid:
        input_string = ""
        now = datetime.now()
        timestamp = now.strftime("%Y%m%d_%H%M%S_%f")
    else:
        log.info("No input file specified. Exiting")
        return None

    try:
        dst_folder = workflow.manage_network(input_string, timestamp,
                       grid=options.grid, **build_options)
        log.debug("Generated network configurations: %s" % dst_folder)
    except Exception, err:
        log.error("Error generating network configurations: %s" % err)
        log.debug("Error generating network configurations", exc_info=True)
        if settings['General']['stack_trace']:
            print traceback.print_exc()
示例#2
0
def main(options):
    import json
    settings = config.settings
    dst_folder = None
    if options.vis_uuid:
        config.settings['Http Post']['uuid'] = options.vis_uuid

    try:
        # test if can import, if not present will fail and not add to template
        # path
        import autonetkit_cisco
    except ImportError:
        pass
    else:
        import autonetkit_cisco.version
        version_banner = autonetkit_cisco.version.banner()
        log.info("%s" % version_banner)

    log.info("AutoNetkit %s" % ANK_VERSION)

    if options.target == "cisco":
        # output target is Cisco
        log.info("Setting output target as Cisco")
        settings['Graphml']['Node Defaults']['platform'] = "cisco"
        settings['Graphml']['Node Defaults']['host'] = "internal"
        settings['Graphml']['Node Defaults']['syntax'] = options.syntax
        settings['JSON']['Node Defaults']['syntax'] = options.syntax
        settings['Compiler']['Cisco']['to memory'] = 1
        settings['General']['deploy'] = 1
        settings['Deploy Hosts']['internal'] = {'cisco': {'deploy': 1}}

    if options.debug or settings['General']['debug']:
        # TODO: fix this
        import logging
        logger = logging.getLogger("ANK")
        logger.setLevel(logging.DEBUG)

    if options.quiet or settings['General']['quiet']:
        import logging
        logger = logging.getLogger("ANK")
        logger.setLevel(logging.WARNING)

    build_options = {
        'compile': options.compile or settings['General']['compile'],
        'render': options.render or settings['General']['render'],
        'validate': options.validate or settings['General']['validate'],
        'build': options.build or settings['General']['build'],
        'deploy': options.deploy or settings['General']['deploy'],
        'measure': options.measure or settings['General']['measure'],
        'monitor': options.monitor or settings['General']['monitor'],
        'diff': options.diff or settings['General']['diff'],
        'archive': options.archive or settings['General']['archive'],
        # use and for visualise as no_vis negates
        'visualise': options.visualise and settings['General']['visualise'],
        'syntax': options.syntax,
    }

    if options.webserver:
        log.info("Webserver not yet supported, please run as seperate module")
    if options.file:
        if options.file == 'dictionary':
            input_string = json.dumps(options.dictionary)
        else:
            with open(options.file, "r") as fh:
                input_string = fh.read()
        filename = os.path.join(BASE_DIR, "autonetkit/ank.log")
        timestamp = os.stat(filename).st_mtime
    elif options.stdin:
        input_string = sys.stdin
        now = datetime.now()
        timestamp = now.strftime("%Y%m%d_%H%M%S_%f")
    elif options.grid:
        input_string = ""
        now = datetime.now()
        timestamp = now.strftime("%Y%m%d_%H%M%S_%f")
    else:
        log.info("No input file specified. Exiting")
        return None

    try:
        dst_folder = workflow.manage_network(input_string,
                                             timestamp,
                                             grid=options.grid,
                                             **build_options)
        log.debug("Generated network configurations: %s" % dst_folder)
    except Exception, err:
        log.error("Error generating network configurations: %s" % err)
        log.debug("Error generating network configurations", exc_info=True)
        if settings['General']['stack_trace']:
            print traceback.print_exc()
示例#3
0
        try:
            log.info("Monitoring for updates...")
            input_filemonitor = workflow.file_monitor(options.file)
            #build_filemonitor = file_monitor("autonetkit/build_network.py")
            while True:
                time.sleep(1)
                rebuild = False
                if input_filemonitor.next():
                    rebuild = True

                if rebuild:
                    try:
                        log.info("Input graph updated, recompiling network")
                        with open(options.file, "r") as fh:
                            input_string = fh.read()  # read updates
                        dst_folder = workflow.manage_network(input_string,
                                       timestamp, build_options)
                        log.info("Monitoring for updates...")
                    except Exception, e:
                        log.warning("Unable to build network %s" % e)
                        traceback.print_exc()

        except KeyboardInterrupt:
            log.info("Exiting")

    return dst_folder

def console_entry():
    """If come from console entry point"""
    args = parse_options()
    x = main(args)
    print x
示例#4
0
        try:
            log.info("Monitoring for updates...")
            input_filemonitor = workflow.file_monitor(options.file)
            #build_filemonitor = file_monitor("autonetkit/build_network.py")
            while True:
                time.sleep(1)
                rebuild = False
                if input_filemonitor.next():
                    rebuild = True

                if rebuild:
                    try:
                        log.info("Input graph updated, recompiling network")
                        with open(options.file, "r") as fh:
                            input_string = fh.read()  # read updates
                        dst_folder = workflow.manage_network(
                            input_string, timestamp, build_options)
                        log.info("Monitoring for updates...")
                    except Exception, e:
                        log.warning("Unable to build network %s" % e)
                        traceback.print_exc()

        except KeyboardInterrupt:
            log.info("Exiting")

    return dst_folder


def console_entry():
    """If come from console entry point"""
    args = parse_options()
    x = main(args)