Ejemplo n.º 1
0
def run(comment, configurations, validate, pid=0):
    env = getenv()

    log.notice('Thank you for using ExaBGP', 'welcome')
    log.notice('%s' % version, 'version')
    log.notice('%s' % sys.version.replace('\n', ' '), 'interpreter')
    log.notice('%s' % ' '.join(platform.uname()[:5]), 'os')
    log.notice('%s' % ROOT, 'installation')

    if comment:
        log.notice(comment, 'advice')

    warning = warn()
    if warning:
        log.warning(warning, 'advice')

    if env.api.cli:
        pipename = 'exabgp' if env.api.pipename is None else env.api.pipename
        pipes = named_pipe(ROOT, pipename)
        if len(pipes) != 1:
            env.api.cli = False
            log.error(
                'could not find the named pipes (%s.in and %s.out) required for the cli' % (pipename, pipename), 'cli'
            )
            log.error('we scanned the following folders (the number is your PID):', 'cli')
            for location in pipes:
                log.error(' - %s' % location, 'cli control')
            log.error('please make them in one of the folder with the following commands:', 'cli control')
            log.error('> mkfifo %s/run/%s.{in,out}' % (os.getcwd(), pipename), 'cli control')
            log.error('> chmod 600 %s/run/%s.{in,out}' % (os.getcwd(), pipename), 'cli control')
            if os.getuid() != 0:
                log.error(
                    '> chown %d:%d %s/run/%s.{in,out}' % (os.getuid(), os.getgid(), os.getcwd(), pipename),
                    'cli control',
                )
        else:
            pipe = pipes[0]
            os.environ['exabgp_cli_pipe'] = pipe
            os.environ['exabgp_api_pipename'] = pipename

            log.info('named pipes for the cli are:', 'cli control')
            log.info('to send commands  %s%s.in' % (pipe, pipename), 'cli control')
            log.info('to read responses %s%s.out' % (pipe, pipename), 'cli control')

    if not env.profile.enable:
        exit_code = Reactor(configurations).run(validate, ROOT)
        __exit(env.debug.memory, exit_code)

    try:
        import cProfile as profile
    except ImportError:
        import profile

    if env.profile.file == 'stdout':
        profiled = 'Reactor(%s).run(%s,"%s")' % (str(configurations), str(validate), str(ROOT))
        exit_code = profile.run(profiled)
        __exit(env.debug.memory, exit_code)

    if pid:
        profile_name = "%s-pid-%d" % (env.profile.file, pid)
    else:
        profile_name = env.profile.file

    notice = ''
    if os.path.isdir(profile_name):
        notice = 'profile can not use this filename as output, it is not a directory (%s)' % profile_name
    if os.path.exists(profile_name):
        notice = 'profile can not use this filename as output, it already exists (%s)' % profile_name

    if not notice:
        cwd = os.getcwd()
        log.debug('profiling ....', 'reactor')
        profiler = profile.Profile()
        profiler.enable()
        try:
            exit_code = Reactor(configurations).run(validate, ROOT)
        except Exception:
            exit_code = Reactor.Exit.unknown
            raise
        finally:
            from exabgp.vendoring import lsprofcalltree

            profiler.disable()
            kprofile = lsprofcalltree.KCacheGrind(profiler)
            try:
                destination = profile_name if profile_name.startswith('/') else os.path.join(cwd, profile_name)
                with open(destination, 'w+') as write:
                    kprofile.output(write)
            except IOError:
                notice = 'could not save profiling in formation at: ' + destination
                log.debug("-" * len(notice), 'reactor')
                log.debug(notice, 'reactor')
                log.debug("-" * len(notice), 'reactor')
            __exit(env.debug.memory, exit_code)
    else:
        log.debug("-" * len(notice), 'reactor')
        log.debug(notice, 'reactor')
        log.debug("-" * len(notice), 'reactor')
        Reactor(configurations).run(validate, ROOT)
        __exit(env.debug.memory, 1)
Ejemplo n.º 2
0
Archivo: bgp.py Proyecto: aabdnn/exabgp
def run (env, comment, configurations, root, validate, pid=0):
	logger = Logger()

	logger.notice('Thank you for using ExaBGP','welcome')
	logger.notice('%s' % version,'version')
	logger.notice('%s' % sys.version.replace('\n',' '),'interpreter')
	logger.notice('%s' % ' '.join(platform.uname()[:5]),'os')
	logger.notice('%s' % root,'installation')

	if comment:
		logger.notice(comment,'advice')

	warning = warn()
	if warning:
		logger.warning(warning,'advice')

	if env.api.cli:
		pipes = named_pipe(root)
		if len(pipes) != 1:
			env.api.cli = False
			logger.error('could not find the named pipes (exabgp.in and exabgp.out) required for the cli','cli')
			logger.error('we scanned the following folders (the number is your PID):','cli')
			for location in pipes:
				logger.error(' - %s' % location,'cli control')
			logger.error('please make them in one of the folder with the following commands:','cli control')
			logger.error('> mkfifo %s/run/exabgp.{in,out}' % os.getcwd(),'cli control')
			logger.error('> chmod 600 %s/run/exabgp.{in,out}' % os.getcwd(),'cli control')
			if os.getuid() != 0:
				logger.error('> chown %d:%d %s/run/exabgp.{in,out}' % (os.getuid(),os.getgid(),os.getcwd()),'cli control')
		else:
			pipe = pipes[0]
			os.environ['exabgp_cli_pipe'] = pipe

			logger.info('named pipes for the cli are:','cli control')
			logger.info('to send commands  %sexabgp.in' % pipe,'cli control')
			logger.info('to read responses %sexabgp.out' % pipe,'cli control')

	if not env.profile.enable:
		was_ok = Reactor(configurations).run(validate,root)
		__exit(env.debug.memory,0 if was_ok else 1)

	try:
		import cProfile as profile
	except ImportError:
		import profile

	if env.profile.file == 'stdout':
		profiled = 'Reactor(%s).run(%s,"%s")' % (str(configurations),str(validate),str(root))
		was_ok = profile.run(profiled)
		__exit(env.debug.memory,0 if was_ok else 1)

	if pid:
		profile_name = "%s-pid-%d" % (env.profile.file,pid)
	else:
		profile_name = env.profile.file

	notice = ''
	if os.path.isdir(profile_name):
		notice = 'profile can not use this filename as output, it is not a directory (%s)' % profile_name
	if os.path.exists(profile_name):
		notice = 'profile can not use this filename as output, it already exists (%s)' % profile_name

	if not notice:
		cwd = os.getcwd()
		logger.debug('profiling ....','reactor')
		profiler = profile.Profile()
		profiler.enable()
		try:
			was_ok = Reactor(configurations).run(validate,root)
		except Exception:
			was_ok = False
			raise
		finally:
			profiler.disable()
			kprofile = lsprofcalltree.KCacheGrind(profiler)
			try:
				destination = profile_name if profile_name.startswith('/') else os.path.join(cwd,profile_name)
				with open(destination, 'w+') as write:
					kprofile.output(write)
			except IOError:
				notice = 'could not save profiling in formation at: ' + destination
				logger.debug("-"*len(notice),'reactor')
				logger.debug(notice,'reactor')
				logger.debug("-"*len(notice),'reactor')
			__exit(env.debug.memory,0 if was_ok else 1)
	else:
		logger.debug("-"*len(notice),'reactor')
		logger.debug(notice,'reactor')
		logger.debug("-"*len(notice),'reactor')
		Reactor(configurations).run(validate,root)
		__exit(env.debug.memory,1)
Ejemplo n.º 3
0
def run(env, comment, configurations, root, validate, pid=0):
    logger = Logger()

    logger.info('Thank you for using ExaBGP', source='welcome')
    logger.info('%s' % version, source='version')
    logger.info('%s' % sys.version.replace('\n', ' '), source='interpreter')
    logger.info('%s' % ' '.join(platform.uname()[:5]), source='os')
    logger.info('%s' % root, source='installation')

    if comment:
        logger.info(comment, source='advice')

    warning = warn()
    if warning:
        logger.info(warning, source='advice')

    if env.api.cli:
        pipes = named_pipe(root)
        if len(pipes) != 1:
            env.api.cli = False
            logger.error(
                'Could not find the named pipes (exabgp.in and exabgp.out) required for the cli',
                source='cli')
            logger.error(
                'We scanned the following folders (the number is your PID):',
                source='cli')
            for location in pipes:
                logger.error(' - %s' % location, source='cli control')
            logger.error(
                'please make them in one of the folder with the following commands:',
                source='cli control')
            logger.error('> mkfifo %s/run/exabgp.{in,out}' % os.getcwd(),
                         source='cli control')
            logger.error('> chmod 600 %s/run/exabgp.{in,out}' % os.getcwd(),
                         source='cli control')
            if os.getuid() != 0:
                logger.error('> chown %d:%d %s/run/exabgp.{in,out}' %
                             (os.getuid(), os.getgid(), os.getcwd()),
                             source='cli control')
        else:
            pipe = pipes[0]
            os.environ['exabgp_cli_pipe'] = pipe

            logger.info('named pipes for the cli are:', source='cli control')
            logger.info('to send commands  %sexabgp.in' % pipe,
                        source='cli control')
            logger.info('to read responses %sexabgp.out' % pipe,
                        source='cli control')

    if not env.profile.enable:
        was_ok = Reactor(configurations).run(validate, root)
        __exit(env.debug.memory, 0 if was_ok else 1)

    try:
        import cProfile as profile
    except ImportError:
        import profile

    if env.profile.file == 'stdout':
        profiled = 'Reactor(%s).run(%s,"%s")' % (str(configurations),
                                                 str(validate), str(root))
        was_ok = profile.run(profiled)
        __exit(env.debug.memory, 0 if was_ok else 1)

    if pid:
        profile_name = "%s-pid-%d" % (env.profile.file, pid)
    else:
        profile_name = env.profile.file

    notice = ''
    if os.path.isdir(profile_name):
        notice = 'profile can not use this filename as output, it is not a directory (%s)' % profile_name
    if os.path.exists(profile_name):
        notice = 'profile can not use this filename as output, it already exists (%s)' % profile_name

    if not notice:
        cwd = os.getcwd()
        logger.reactor('profiling ....')
        profiler = profile.Profile()
        profiler.enable()
        try:
            was_ok = Reactor(configurations).run(validate, root)
        except Exception:
            was_ok = False
            raise
        finally:
            profiler.disable()
            kprofile = lsprofcalltree.KCacheGrind(profiler)
            try:
                destination = profile_name if profile_name.startswith(
                    '/') else os.path.join(cwd, profile_name)
                with open(destination, 'w+') as write:
                    kprofile.output(write)
            except IOError:
                notice = 'could not save profiling in formation at: ' + destination
                logger.reactor("-" * len(notice))
                logger.reactor(notice)
                logger.reactor("-" * len(notice))
            __exit(env.debug.memory, 0 if was_ok else 1)
    else:
        logger.reactor("-" * len(notice))
        logger.reactor(notice)
        logger.reactor("-" * len(notice))
        Reactor(configurations).run(validate, root)
        __exit(env.debug.memory, 1)
Ejemplo n.º 4
0
def run(env, comment, configurations, validate, pid=0):
    logger = Logger()

    logger.error('', source='ExaBGP')
    logger.error('%s' % version, source='version')
    logger.error('%s' % sys.version.replace('\n', ' '), source='interpreter')
    logger.error('%s' % ' '.join(platform.uname()[:5]), source='os')
    logger.error('', source='ExaBGP')

    if comment:
        logger.configuration(comment)

    warning = warn()
    if warning:
        logger.configuration(warning)

    if not env.profile.enable:
        ok = Reactor(configurations).run(validate)
        __exit(env.debug.memory, 0 if ok else 1)

    try:
        import cProfile as profile
    except ImportError:
        import profile

    if not env.profile.file or env.profile.file == 'stdout':
        ok = profile.run('Reactor(configurations).run(validate)')
        __exit(env.debug.memory, 0 if ok else 1)

    if pid:
        profile_name = "%s-pid-%d" % (env.profile.file, pid)
    else:
        profile_name = env.profile.file

    notice = ''
    if os.path.isdir(profile_name):
        notice = 'profile can not use this filename as output, it is not a directory (%s)' % profile_name
    if os.path.exists(profile_name):
        notice = 'profile can not use this filename as output, it already exists (%s)' % profile_name

    if not notice:
        logger.reactor('profiling ....')
        profiler = profile.Profile()
        profiler.enable()
        try:
            ok = Reactor(configurations).run()
        except Exception:
            raise
        finally:
            profiler.disable()
            kprofile = lsprofcalltree.KCacheGrind(profiler)

            with open(profile_name, 'w+') as write:
                kprofile.output(write)

            __exit(env.debug.memory, 0 if ok else 1)
    else:
        logger.reactor("-" * len(notice))
        logger.reactor(notice)
        logger.reactor("-" * len(notice))
        Reactor(configurations).run()
        __exit(env.debug.memory, 1)