ceph-deploy的pkg命令

来源:互联网 发布:iphone无缝拼图软件 编辑:程序博客网 时间:2024/06/05 02:48
ceph-deploy的pkg命令用于在远程在host上安装package,这个host可以是远程的,也可以是本地的。其入口函数在:E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\pkg.py 中的makedef make(parser):    """    Manage packages on remote hosts.    """    action = parser.add_mutually_exclusive_group()    action.add_argument(        '--install',        metavar='PKG(s)',        help='Comma-separated package(s) to install',    )    action.add_argument(        '--remove',        metavar='PKG(s)',        help='Comma-separated package(s) to remove',    )    parser.add_argument(        'hosts',        nargs='+',    )    parser.set_defaults(        func=pkg,    )可见pkg命令提供了位置参数hosts 用于指定在哪个host上安装package,还有两个可选册数install和remove分别表示是安装和删除package。pkg这个命令的默认处理函数是pkgdef pkg(args):    if args.install:        install(args)    elif args.remove:        remove(args)可以很明显看到pkg这个命令主要做安装和删除package这两件事情首先看安装def install(args):#得到需要安装的package    packages = args.install.split(',')#遍历需要安装package的host,这里用for循环的意思是hosts 可能不止一个    for hostname in args.hosts:        distro = hosts.get(hostname, username=args.username)#打印得到的发行版的name,方便debug        LOG.info(            'Distro info: %s %s %s',            distro.name,            distro.release,            distro.codename        )        rlogger = logging.getLogger(hostname)        rlogger.info('installing packages on %s' % hostname)#调用发新版自己的install函数来安装package。需要注意的是在前面得到发行版distro后,#最终要调用distro.conn.exit() 来释放资源.        distro.conn.global_timeout = None        distro.packager.install(packages)        distro.conn.exit()删除host中的package的remove函数如下所示:其和install函数实现完全类似,不同的是这里调用发行版的remove函数来删除packagedef remove(args):    packages = args.remove.split(',')    for hostname in args.hosts:        distro = hosts.get(hostname, username=args.username)        LOG.info(            'Distro info: %s %s %s',            distro.name,            distro.release,            distro.codename        )        rlogger = logging.getLogger(hostname)        rlogger.info('removing packages from %s' % hostname)        # Do not timeout on package removal. If we use this command to remove        # e.g. ceph-selinux or some other package with long post script we can        # easily timeout in the 5 minutes that we use as a default timeout,        # turning off the timeout completely for the time we run the command        # should make this much more safe.        distro.conn.global_timeout = None        distro.packager.remove(packages)        distro.conn.exit()

原创粉丝点击