launch_switch.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:Playground3 作者: CrimsonVista 项目源码 文件源码
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument("--private", action="store_true", help="Only accept local connections.")
    parser.add_argument("--port", type=int, default=0, help="listening port for switch")
    parser.add_argument("--statusfile", help="file to record status; useful for communications")
    parser.add_argument("--pidfile", help="file to record pid; useful for communciations")
    parser.add_argument("--unreliable", action="store_true", default=False, help="Introduce errors on the wire")
    parser.add_argument("--no-daemon", action="store_true", default=False, help="do not launch switch in a daemon; remain in foreground")
    args = parser.parse_args()

    pidFileName = os.path.expanduser(os.path.expandvars(args.pidfile))
    statusFileName = os.path.expanduser(os.path.expandvars(args.statusfile))
    pidFileDir = os.path.dirname(pidFileName)
    host = None
    if args.private: host = "127.0.0.1"

    if args.no_daemon:
        runSwitch(args.unreliable, host, args.port, statusFileName)

    else:
        with daemon.DaemonContext(
            working_directory=pidFileDir,
            umask=0o002,
            pidfile=pidfile.TimeoutPIDLockFile(pidFileName),
            ) as context:

            runSwitch(args.unreliable, host, args.port, statusFileName)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号