#!/usr/bin/env python
#encoding:utf-8
# desc:用来描述各个主机信息 import os #CTID NPROC STATUS IP_ADDR HOSTNAME configDir = '/etc/pve/lxc' #获取所有的配置文件
def fileListFunc(filePathList):
fileList = []
for filePath in filePathList:
for top, dirs, nondirs in os.walk(filePath):
for item in nondirs:
#fileList.append(os.path.join(top, item))
fileList.append(item)
return fileList #根据配置文件获取ID号
def getAllID():
idList = []
for id in fileListFunc([configDir]):
idList.append(id.split('.')[0])
return sorted(idList) #根据ID号获取主机状态
def getStat(id):
statInfo = os.popen('lxc-info -n ' + str(id)).read()
if 'RUNNING' in statInfo:
return 'running'
else:
return 'stoping' #根据ID号获取主机IP地址
def getIP(id):
ip = '-'
statInfo = os.popen('lxc-info -n ' + str(id)).read()
for line in statInfo.split('\n'):
if 'IP' in line:
ip = line.split(':')[1].strip()
return ip #根据ID号获取主机名
def getHostName(id):
hostname = '-'
statInfo = os.popen('cat /etc/pve/lxc/' + str(id) + '.conf').read()
for line in statInfo.split('\n'):
if line.startswith('hostname'):
hostname = line.split(':')[1].strip()
return hostname def pnull(n,str):
sn = len(str)
pn = n - sn
if pn <=0:
pn = 1
return ' ' * pn def main():
print 'CTID STATUS IP_ADDR HOSTNAME'
for id in getAllID():
stat = getStat(id)
ip = getIP(id)
hostname = getHostName(id)
print id + pnull(10,id) + stat + pnull(10,stat) + ip + pnull(16,ip) + hostname + pnull(10,hostname) if __name__ == '__main__':
main()

文件命令为vzlist

cat /usr/bin/vzlist

赋予执行权限,在任何地方都可以执行

proxmox新版本使用了lxc容器,导致以前的vzlist命令无法使用,于是自己写了一个脚本来获取所有半虚拟化主机的信息状态的更多相关文章

  1. centos7.5误删python2.7之后,导致yum和Pythonm命令无法使用

    问题描述 最近想要将服务器上的Python2.7升级成3.x的版本时.使用了如下命令: (1)强制删除已安装python及其关联 # rpm -qa|grep python|xargs rpm -ev ...

  2. Lxc容器基本用法

    你将学到什么 如何安装LXC 如何创建LXC容器 如何管理LXC容器 如何查询进程所属Namespace 如何给LXC容器添加网卡 如何限制LXC容器资源 环境 x64 Ubuntu 14.04.3 ...

  3. LXC容器

    1.    LXC简述 Linux container是一种资源隔离机制而非虚拟化技术.VMM(VMM Virtual Machine Monitor)或者叫Hypervisor是标准的虚拟化技术,这 ...

  4. 如何在Ubuntu上创建及管理LXC容器?

    将LXC安装到Ubuntu上 $ sudo apt-get install lxc 安装完毕之后,运行lxc-checkconifg工具,检查当前Linux内核支持LXC的情况.要是一切都已被启用,内 ...

  5. 在Ubuntu16.04上部署LXC容器管理系统的相关步骤

    打算安装一个LXC linux容器管理的软件来分配使用资源并配置不同的编程环境,这样就方便大家的使用,步骤如下(宿主机的环境都搭建好了,对应显卡的驱动等): 参考网站: 简单入门和相关指令总结:htt ...

  6. lxc 容器基础配置篇

    一, 首先配置lxc需要的网卡断 吧eth0复制一份变为br0 配置br0 配置eth0 重启网卡   /etc/init.d/network restart 安装lxc软件 需要epel源--- y ...

  7. 生成Alpine LXC容器的根文件系统

    一个Alpine LXC容器的文件系统内容包括以下内容 根文件系统 应用程序,库文件以及配置文件 根文件系统主要包含alpine linux最小系统所需要的组件.下面主要讲一下制作根文件系统的方法. ...

  8. Docker容器(四)——常用命令

    (1).基本使用方法 查看所有镜像.docker images [root@youxi1 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ...

  9. 由于CentOS的系统安装了epel-release-latest-7.noarch.rpm 导致在使用yum命令时出现Error: xz compression not available问题

    由于CentOS6的系统安装了epel-release-latest-7.noarch.rpm 导致在使用yum命令时出现Error: xz compression not available问题.解 ...

随机推荐

  1. D11 列表 list 元祖 字典dict

    取值 name = "alexdfg" print(name[3:5]) 取出 ex name = "alexdfg" print(name[3]) 取出e 列 ...

  2. 16. docker 网络 端口映射

    一.本地操作 1.如何将 nginx 暴露给外界 创建 nginx 服务器 docker run  --name web -d nginx 查看 nginx 的 ip地址 docker network ...

  3. Linux 系统查看服务器SN序列号以及服务器型号

    1.单独查看服务器的序列号 [root@localhost ~]# dmidecode -t system | grep 'Serial Number' Serial Number: 2102310Y ...

  4. UML-类图-如何画引用类和集合?

    1.画引用类 引用到了类时,需要画关联线,否则其他基本类型(int.string.date等)不画. 2.画集合 当然,方法1中可加入箭头.对应java代码: public class Sale { ...

  5. java 用阻塞队列实现生产者消费者

    package com.lb; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.Blocking ...

  6. DataStructuresAndAlgorithm--字谜游戏

    参考:http://tieba.baidu.com/p/2071585293 输入是由一些字母构成的一个二维数组以及一些单词组成.目标是要找出字谜中的单词,这些单词可能是水平.垂直或沿对角线上任何方向 ...

  7. PAT甲级——1035 Password (20分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  8. HDU-4614 Vases and Flowers(线段树区间更新+二分查找)

    http://acm.hdu.edu.cn/showproblem.php?pid=4614 Time Limit: 4000/2000 MS (Java/Others)    Memory Limi ...

  9. centos设置上网代理

    假设我们要设置代理为 IP:PORT 1.网页上网网页上网设置代理很简单,在firefox浏览器下 Edit-->>Preferences-->>Advanced-->& ...

  10. getopt|sys|open|print文件|main()|if __name__ == "__main__"|getline()

    #!/usr/bin/python import sys import getopt import re def compare(f1,f2,o1,o2,si_line): lines_count=0 ...