-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.php
executable file
·85 lines (72 loc) · 1.78 KB
/
client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env php
<?php
use ProxBoss\API\Cluster\Tasks;
use ProxBoss\API\Node\Qemu;
use ProxBoss\API\Nodes;
require __DIR__ . "/vendor/autoload.php";
$r = (new Tasks())->getRunningTasks('qmmove');
if ($r) {
print "Running tasks, try again later\n";
exit;
}
$srcpool = "pool2-storage";
$destpool = "store2-image";
$n = new Nodes();
$nodes = $n->getAllNodes();
foreach ($nodes as $n) {
/** @var Node $n */
if ($n->getNodeName() == "larry") {
continue;
}
print "Checking node " . $n->getNodeName() . "\n";
$vms = $n->getAllQemuVms();
foreach ($vms['vmid'] as $q) {
/** @var Qemu $q */
$stores = $q->getDatastores();
if (!empty($stores[$srcpool])) {
print $q->getVmName() . " has storage on $srcpool\n";
}
}
}
/*
use ProxBoss\Client;
$client = new Client();
$nodes = getNodes($client);
$node = $nodes['zoidberg'];
$vms = getVMsOnNode($node);
$storage = getVmStorage($vms['vmid'][203]);
function getNodes($client) {
$res = $client->get('nodes');
$data = json_decode($res->getBody(), true);
$retarr = [];
foreach ($data['data'] as $r) {
$r['client'] = $client;
$node = $r['node'];
$retarr[$node] = $r;
}
return $retarr;
}
function getVMsOnNode($node) {
$client = $node['client'];
$name = $node['node'];
$res = $client->get('nodes/'.$name."/qemu");
$j = json_decode((string) $res->getBody(), true);
$retarr = [ "namemap" => [], "vmid" => []];
foreach ($j['data'] as $v) {
$v['node'] = $node;
$name = $v['name'];
$vmid = $v['vmid'];
$retarr["namemap"][$name] = $vmid;
$retarr["vmid"][$vmid] = $v;
}
return $retarr;
}
function getVmStorage($vm) {
$client = $vm['node']['client'];
$name = $vm['node']['node'];
$vmid = $vm['vmid'];
$res = $client->get('nodes/'.$name."/qemu/$vmid/config");
$j = json_decode((string) $res->getBody(), true);
var_dump($j);
}
*/