I wrote a python script to export the pve cluster cluster information, but this script can be exported before, but now it can’t be executed, please help me take a look?
python3 list-pool.py
python3 list-pool.py
Code:
Traceback (most recent call last):
File "list-pool-prd.py", line 58, in <module>
conf = proxmox.nodes(node['node']).qemu(vm['vmid']).config.get()
File "/usr/local/lib/python3.5/dist-packages/proxmoxer/core.py", line 105, in get
return self(args)._request("GET", params=params)
File "/usr/local/lib/python3.5/dist-packages/proxmoxer/core.py", line 94, in _request
resp.reason, resp.content))
proxmoxer.core.ResourceException: 400 Bad Request: Result verification failed - b'{"data":null,"errors":{"boot":"value does not match the regex pattern"}}'
Python:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from proxmoxer import ProxmoxAPI
import re
import xlsxwriter
import pandas as pd
workbook = xlsxwriter.Workbook('pve.xlsx')
worksheet = workbook.add_worksheet(u'pve')
head_format = workbook.add_format()
head_format.set_border(1)
head_format.set_bg_color('silver')
head_format.set_bold()
headings = ('NODE','VMID','VMNAME','POOL','STATUS','IP','DESCRIPTION')
worksheet.write_row(0, 0, headings, head_format)
row = 1
rowdata = []
proxmox = ProxmoxAPI('127.0.0.1', user='root@pam', password='XXX', verify_ssl=False)
pooldict = {}
for pool in proxmox.pools.get():
p = proxmox.pools(pool['poolid']).get()
memberlist = p.get("members")
for item in memberlist:
id = item.get("id")
if id.startswith("lxc"):
pooldict[id[4:]] = pool['poolid']
if id.startswith("qemu"):
pooldict[id[5:]] = pool['poolid']
patt = re.compile(r'ip=.*/\d+')
for node in proxmox.nodes.get():
for vm in proxmox.nodes(node['node']).lxc.get():
conf = proxmox.nodes(node['node']).lxc(vm['vmid']).config.get()
des = conf.get("description")
des = des.strip().replace('\n', ' ').replace('\r', ' ') if des is not None else "/"
ip = "/"
net = conf.get("net0")
if net is not None:
m = re.search(patt, net)
ip = m.group(0)[3:] if m is not None else "/"
rowdata.clear()
rowdata.append(node['node'])
rowdata.append(vm['vmid'])
rowdata.append(vm['name'])
if vm['vmid'] in pooldict.keys():
rowdata.append(pooldict[vm['vmid']])
else:
rowdata.append("/")
rowdata.append(vm['status'])
rowdata.append(ip)
rowdata.append(des)
worksheet.write_row(row, 0, rowdata)
row += 1
for vm in proxmox.nodes(node['node']).qemu.get():
conf = proxmox.nodes(node['node']).qemu(vm['vmid']).config.get()
des = conf.get("description")
des = des.strip().replace('\n', ' ').replace('\r', ' ') if des is not None else "/"
ip = "/"
net = conf.get("net0")
if net is not None:
m = re.search(patt, net)
ip = m.group(0)[3:] if m is not None else "/"
rowdata.clear()
rowdata.append(node['node'])
rowdata.append(vm['vmid'])
rowdata.append(vm['name'])
if vm['vmid'] in pooldict.keys():
rowdata.append(pooldict[vm['vmid']])
else:
rowdata.append("/")
rowdata.append(vm['status'])
rowdata.append(ip)
rowdata.append(des)
worksheet.write_row(row, 0, rowdata)
row += 1
workbook.close()
#
df = pd.DataFrame(pd.read_excel('./pve.xlsx'))
df = df.set_index(['NODE','VMID'])
df = df.sort_index()
df.to_excel(r'./pve.xlsx')
#df.to_excel('./pve_sorted.xlsx')