使用python书写检查ceph组件进程例如rgw和osd和mon等等。要求输出格式如果检查不预期退出并给出退出原因。要求如果rgw和osd混合部署给出混合部署的组件。要求远程链接检查
-- coding:utf-8 --
import subprocess
定义ceph组件列表
ceph_components = ['mon', 'osd', 'rgw', 'mds']
定义ceph节点列表
ceph_nodes = ['ceph-node1', 'ceph-node2', 'ceph-node3']
定义混合部署组件列表
mixed_components = []
定义检查命令
check_cmd = 'sudo systemctl status ceph-{}'
定义远程登录命令
ssh_cmd = 'ssh {} "{}"'
遍历ceph节点和组件进行检查
for node in ceph_nodes: for component in ceph_components: # 执行远程登录并检查命令 cmd = ssh_cmd.format(node, check_cmd.format(component)) try: result = subprocess.check_output(cmd, shell=True) result = result.decode('utf-8') # 如果进程异常退出,则输出原因 if 'exited with' in result: print('{} on {} exited unexpectedly with:'.format(component, node)) print(result) # 如果检查到混合部署组件,则记录 elif component not in mixed_components and 'active (mixed)' in result: mixed_components.append(component) except subprocess.CalledProcessError as e: print('Failed to execute command on {}: {}'.format(node, e))
输出混合部署组件
if mixed_components: mixed_str = ', '.join(mixed_components) print('Mixed components deployed: {}'.format(mixed_str)
原文地址: https://www.cveoy.top/t/topic/cjnt 著作权归作者所有。请勿转载和采集!