proxmox新版本使用了lxc容器,导致以前的vzlist命令无法使用,于是自己写了一个脚本来获取所有半虚拟化主机的信息状态
#!/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命令无法使用,于是自己写了一个脚本来获取所有半虚拟化主机的信息状态的更多相关文章
- centos7.5误删python2.7之后,导致yum和Pythonm命令无法使用
问题描述 最近想要将服务器上的Python2.7升级成3.x的版本时.使用了如下命令: (1)强制删除已安装python及其关联 # rpm -qa|grep python|xargs rpm -ev ...
- Lxc容器基本用法
你将学到什么 如何安装LXC 如何创建LXC容器 如何管理LXC容器 如何查询进程所属Namespace 如何给LXC容器添加网卡 如何限制LXC容器资源 环境 x64 Ubuntu 14.04.3 ...
- LXC容器
1. LXC简述 Linux container是一种资源隔离机制而非虚拟化技术.VMM(VMM Virtual Machine Monitor)或者叫Hypervisor是标准的虚拟化技术,这 ...
- 如何在Ubuntu上创建及管理LXC容器?
将LXC安装到Ubuntu上 $ sudo apt-get install lxc 安装完毕之后,运行lxc-checkconifg工具,检查当前Linux内核支持LXC的情况.要是一切都已被启用,内 ...
- 在Ubuntu16.04上部署LXC容器管理系统的相关步骤
打算安装一个LXC linux容器管理的软件来分配使用资源并配置不同的编程环境,这样就方便大家的使用,步骤如下(宿主机的环境都搭建好了,对应显卡的驱动等): 参考网站: 简单入门和相关指令总结:htt ...
- lxc 容器基础配置篇
一, 首先配置lxc需要的网卡断 吧eth0复制一份变为br0 配置br0 配置eth0 重启网卡 /etc/init.d/network restart 安装lxc软件 需要epel源--- y ...
- 生成Alpine LXC容器的根文件系统
一个Alpine LXC容器的文件系统内容包括以下内容 根文件系统 应用程序,库文件以及配置文件 根文件系统主要包含alpine linux最小系统所需要的组件.下面主要讲一下制作根文件系统的方法. ...
- Docker容器(四)——常用命令
(1).基本使用方法 查看所有镜像.docker images [root@youxi1 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ...
- 由于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问题.解 ...
随机推荐
- JAVA 算法练习(一)
用java写了几道编程题目,分享给大家 语法和C语言几乎一样,不懂 java 会 c 也可以看明白的. 最大连续数列和 题目说明 对于一个有正有负的整数数组,请找出总和最大的连续数列.给定一个int数 ...
- EditText制作简单的登录界面
EditText与之前的TextView和Button的用法大体相同,用法案例如下: activity_edit_text.xml: <?xml version="1.0" ...
- mysql 5.6 cmake的安装
# cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDI ...
- codeforces 596
C 题意 定义p-binary为2^x+p 现在给你一个数x,和一个p. 问你最少用多少个p-binary能构造出x,如果没有输出-1 题解 转化为: x = 2^x1 + 2^x2 + ... + ...
- ruoyi ShiroUtils
package com.ruoyi.framework.util; import org.apache.shiro.SecurityUtils; import org.apache.shiro.cry ...
- ios avplayer 监控播放进度
var timeObserver = avPlayerVC.player?.addPeriodicTimeObserver(forInterval: CMTime.init(value: , ti ...
- centos快速安装mysql
1. wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2. rpm -ivh mysql-community-r ...
- 上传本地项目到GIT码云
1.下载GIT 下载地址:https://git-scm.com/downloads 我这里下载的64位 2.安装GIT 双击下载的Git-2.18.0-64-bit.exe文件,选择自己的安装目录, ...
- c++语法(2)
#include<iostream> #include<windows.h> using namespace std; class Parents { public: virt ...
- Centos7安装Xrdp远程桌面
Xrdp是Microsoft远程桌面协议RDP的一个开源实现,它允许以图像方式控制远程系统. 测试环境 服务端: CentOS Linux release 7.7.1908 (Core) 客户端: W ...