ceph-deploy 中使用remoto
来源:互联网 发布:怎样鉴别mac口红真假 编辑:程序博客网 时间:2024/06/14 09:50
在ceph-deploy 中使用remoto 这个第三方库来访问远程host.这个库的源码的路径为https://github.com/alfredodeza/remoto例如在E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\hosts\common.py 中def ceph_version(conn): """ Log the remote ceph-version by calling `ceph --version` """ return remoto.process.run(conn, ['ceph', '--version'])通过remoto.process.run在远程host 上运行ceph --version其源码分析如下:路径为https://github.com/alfredodeza/remoto/blob/222014a3da8bb77cb462bace3a6c0e7200e5ea08/remoto/process.pydef run(conn, command, exit=False, timeout=None, **kw): """ A real-time-logging implementation of a remote subprocess.Popen call where a command is just executed on the remote end and no other handling is done. :param conn: A connection oject :param command: The command to pass in to the remote subprocess.Popen :param exit: If this call should close the connection at the end :param timeout: How many seconds to wait after no remote data is received (defaults to wait for ever) """ stop_on_error = kw.pop('stop_on_error', True) if not kw.get('env'): # get the remote environment's env so we can explicitly add # the path without wiping out everything kw = extend_path(conn, kw) timeout = timeout or conn.global_timeout conn.logger.info('Running command: %s' % ' '.join(admin_command(conn.sudo, command))) result = conn.execute(_remote_run, cmd=command, **kw)可见这里调用_remote_run,def _remote_run(channel, cmd, **kw): import subprocess import sys from select import select stop_on_nonzero = kw.pop('stop_on_nonzero', True) process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, **kw )原来最后还是调用subprocess 这个第三方库来运行命令,可见remoto 只是subprocess的一个包装第二个ceph-deploy的例子def mon_create(distro, args, monitor_keyring): hostname = distro.conn.remote_module.shortname()这里的remote_module定义如下:路径为https://github.com/alfredodeza/remoto/blob/1e4fbd0f1af5e68ef0d824dd8b93139c3b86aa05/remoto/connection.pyclass Connection(object): def __init__(self, hostname, logger=None, sudo=False, threads=1, eager=True, detect_sudo=False, interpreter=None): self.sudo = sudo self.hostname = hostname self.logger = logger or FakeRemoteLogger() self.remote_module = None self.channel = None self.global_timeout = None # wait for ever self.interpreter = interpreter or 'python%s' % sys.version_info[0] def _make_gateway(self, hostname): gateway = execnet.makegateway( self._make_connection_string(hostname) ) def import_module(self, module): self.remote_module = ModuleExecute(self.gateway, module, self.logger) return self.remote_moduleModuleExecute 是一个类,定义如下:class ModuleExecute(object): def __init__(self, gateway, module, logger=None): self.channel = gateway.remote_exec(module) self.module = module self.logger = logger所以ceph-depoly中的remote_module.shortname()其实调用的gateway中的shortname()。而gateway的赋值如下: def _make_gateway(self, hostname): gateway = execnet.makegateway( self._make_connection_string(hostname) )可见是通过execnet 这个第三方库完成的。这里就是调用python解释器去执行_make_connection_string产生的命令execnet的介绍为http://codespeak.net/execnet/execnet provides a share-nothing model with channel-send/receive communication for distributing execution across many Python interpreters across version, platform and network barriers. It has a minimal and fast API targetting the following uses:distribute tasks to (many) local or remote CPUswrite and deploy hybrid multi-process applicationswrite scripts to administer multiple environments
阅读全文
0 0
- ceph-deploy 中使用remoto
- 使用ceph-deploy部署ceph环境
- 使用 Ceph-deploy 快速部署 Ceph 环境
- [CEPH部署]使用ceph-deploy快速部署ceph集群
- ceph 0.87 ubuntu14.04 使用ceph-deploy配置(配置篇)
- 创建ceph集群不使用mkcephfs和ceph-deploy
- ceph-deploy部署ceph集群
- ceph-deploy搭建ceph集群
- 【Ceph】ceph-deploy命令详解
- 使用ceoh-deploy工具快速部署ceph--先决条件准备
- 使用ceoh-deploy工具快速部署ceph--部署
- ceph-deploy install 失败
- ceph-deploy error
- ceph-deploy new
- 不使用ceph-deploy 手动安装两个节点的Ceph集群
- ceph中使用sgdisk
- ceph-deploy的入口函数
- ceph-deploy的set_overrides函数
- Oracle 12c Non CDB 数据库 切换成 CDB 测试
- 流程控制语句
- 应对steamVR 软件报错306的问题
- 图像学习之如何理解方向梯度直方图(Histogram Of Gradient)
- VideoView
- ceph-deploy 中使用remoto
- Gecorator装饰设计模式(Request、Response)
- highChart导出PDF
- 哈夫曼树与哈夫曼编码(前缀编码)理解
- day2-Javascript--流程控制
- Python中的函数
- 如何让数据库支持emoji表情符存储
- 【图文教程】五分钟内搞一个双十一数据大屏_实时看到自己的业务访问情况
- [C#]在.NET调用加了SSL验证的WebService-根据验证过程远程证书无效