vmnames getter
This commit is contained in:
parent
a0342a2ee5
commit
862dc722ec
|
|
@ -1,11 +1,21 @@
|
||||||
from PVEApi import PVEApi
|
from PVEApi import PVEApi
|
||||||
|
import json
|
||||||
|
|
||||||
USERNAME = "zabbix@pve"
|
USERNAME = "zabbix@pve"
|
||||||
PASSWORD = "zabbix"
|
PASSWORD = "zabbix"
|
||||||
HOST = "172.16.3.11:8006"
|
HOST = "172.16.3.11:8006"
|
||||||
|
NODE='h1'
|
||||||
|
|
||||||
conn = PVEApi(HOST, USERNAME, PASSWORD)
|
conn = PVEApi(HOST, USERNAME, PASSWORD)
|
||||||
|
|
||||||
print conn.get_node_list()
|
|
||||||
for vm in conn.get_cluster_vmlist():
|
def get_vmnames(vmlist):
|
||||||
print vm.node, vm.name, vm.vmid, vm.cpus
|
name_vmlist = [{"#VMNAME": vm.name} for vm in vmlist]
|
||||||
|
return name_vmlist
|
||||||
|
|
||||||
|
def listofdicts_to_zabbix_json(list):
|
||||||
|
# TODO wrap in "data:[]"
|
||||||
|
zabbixjson=json.dumps(list)
|
||||||
|
return zabbixjson
|
||||||
|
|
||||||
|
print listofdicts_to_zabbix_json(get_vmnames(conn.get_cluster_vmlist()))
|
||||||
|
|
@ -43,7 +43,6 @@ class PVEApi(object):
|
||||||
url = self.url + '/nodes/' + node + '/qemu'
|
url = self.url + '/nodes/' + node + '/qemu'
|
||||||
response = json.load(urllib2.urlopen(self.get_request(url), context=ssl._create_unverified_context()))
|
response = json.load(urllib2.urlopen(self.get_request(url), context=ssl._create_unverified_context()))
|
||||||
resources = response['data']
|
resources = response['data']
|
||||||
print resources
|
|
||||||
for machine in resources:
|
for machine in resources:
|
||||||
name = machine[u'name']
|
name = machine[u'name']
|
||||||
status = machine[u'status']
|
status = machine[u'status']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue