-
Notifications
You must be signed in to change notification settings - Fork 1
/
nxGetVersions.php
270 lines (221 loc) · 8.27 KB
/
nxGetVersions.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
// =====================================================
// Get Nutanix software version on a list of clusters
// =====================================================
// -----------------------------------------------------
// Includes section
// -----------------------------------------------------
include_once('nxFramework.php');
// -----------------------------------------------------
// Variables definition
// -----------------------------------------------------
// =====================
// Clusters
// =====================
$clusters=array(
0 => array( "username" => "username",
"password" => "password",
"ip" => "192.168.1.1"),
1 => array( "username" => "username",
"password" => "password",
"ip" => "192.168.1.2")
);
// -----------------------------------------------------
// Main entry point
// -----------------------------------------------------
print("\n");
print(" _______ __ .__ \n");
print(" \ \ __ ___/ |______ ____ |__|__ ___\n");
print(" / | \| | \ __\__ \ / \| \ \/ /\n");
print("/ | \ | /| | / __ \| | \ |> < \n");
print("\____|__ /____/ |__| (____ /___| /__/__/\_ \\\n");
print(" \/ \/ \/ \/\n");
print("\t\t\t nxGetVersion v 0.9\n\n");
$ver=array();
print("\nPlease wait while collecting data from ".nxColorBold(count($clusters))." cluster(s)...\n");
// Main loop thru all pre-defined clusters
for($i=0;$i<count($clusters);$i++)
{
$clusterConnect=array(
"username" => $clusters[$i]["username"],
"password" => $clusters[$i]["password"],
"ip" => $clusters[$i]["ip"]
);
// Getting cluster name
$data=json_decode(nxGetClusterDetails($clusterConnect));
// Getting number of nodes
$ver[$i]["nodes"]=$data->num_nodes;
$name=str_replace(".pccwglobal.com", "",$data->name);
$ver[$i]["name"] = $name;
print("\n-> ".nxColorOutput(str_pad($ver[$i]["name"],15,".",STR_PAD_RIGHT)));
// Get all software version from LCM module
// Get PC version
$pc=nxGetSWVersions($clusterConnect,"\"entity_model==PC\"");
if(isset($pc->data->entities[0]->version)) $pc=$pc->data->entities[0]->version;
else $pc="";
$ver[$i]["PC"]=$pc;
// Get LCM version
$lcm=nxGetLCMVersion($clusterConnect);
$ver[$i]["LCM"] = $lcm;
// Get Foundation version
$data=nxGetSWVersions($clusterConnect,"\"entity_model==Foundation Platforms\"");
$data=$data->data->entities;
$ver[$i]["Foundation"]=$data;
// Get unique hypervisor version
$tmp=array();
for($h=0;$h<count($ver[$i]["Foundation"]);$h++)
{
$tmp[$h]=$ver[$i]["Foundation"][$h]->version;
}
$tmp2=array_unique($tmp);
$ver[$i]["Foundation"]=array_values($tmp2);
// Get NCC version
$data=nxGetSWVersions($clusterConnect,"\"entity_model==NCC\"");
$data=$data->data->entities;
$ver[$i]["NCC"]=$data;
// Get AOS version
$data=nxGetSWVersions($clusterConnect,"\"entity_model==AOS\"");
$data=$data->data->entities;
unset($data[0]->available_version_list);
$ver[$i]["AOS"]=$data;
// Get Hypervisor version
$data=nxGetSWVersions($clusterConnect,"\"entity_class==Hypervisor\"");
@$data=$data->data->entities;
// Remove unusable upgrade list from array
for($j=0;$j<count($data);$j++)
{
unset($data[$j]->available_version_list);
}
$ver[$i]["Hypervisor"]=$data;
@sort($ver[$i]["Hypervisor"]);
// Get unique hypervisor version
$tmp=array();
for($h=0;$h<count($ver[$i]["Hypervisor"]);$h++)
{
$tmp[$h]=$ver[$i]["Hypervisor"][$h]->version;
}
$tmp2=array_unique($tmp);
$ver[$i]["Hypervisor"]=array_values($tmp2);
// Get File Server version
$data=nxGetSWVersions($clusterConnect,"\"entity_model==File Server\"");
$data=$data->data->entities;
// Remove unusable upgrade list from array
for($j=0;$j<count($data);$j++)
{
unset($data[$j]->available_version_list);
}
$ver[$i]["FileServer"]=$data;
// Get unique fileserver version
$tmp=array();
for($h=0;$h<count($ver[$i]["FileServer"]);$h++)
{
$tmp[$h]=$ver[$i]["FileServer"][$h]->version;
}
$tmp2=array_unique($tmp);
$ver[$i]["FileServer"]=array_values($tmp2);
print(" Done!");
}
print("\n\nData collected, diplaying results...\n\n");
print("+------------------------\n");
print("| ".nxColorBold("Nutanix Clusters Version Summary")."\n");
// first line top table
print("+".str_pad("",20,"-",STR_PAD_BOTH));
print("+".str_pad("",13,"-",STR_PAD_BOTH));
print("+".str_pad("",62,"-",STR_PAD_BOTH));
print("+".str_pad("",17,"-",STR_PAD_BOTH));
print("+".str_pad("",13,"-",STR_PAD_BOTH));
print("+".str_pad("",27,"-",STR_PAD_BOTH));
print("+".str_pad("",20,"-",STR_PAD_BOTH));
print("+\n");
// second line top table - with labels
print("| ".nxColorBold(str_pad("Cluster Name (#n)",19," ",STR_PAD_RIGHT)));
print("| ".nxColorBold(str_pad("AOS",12," ",STR_PAD_BOTH)));
print("| ".nxColorBold(str_pad("Hypervisor",61," ",STR_PAD_BOTH)));
print("| ".nxColorBold(str_pad("LCM",16," ",STR_PAD_BOTH)));
print("| ".nxColorBold(str_pad("NCC",12," ",STR_PAD_BOTH)));
print("| ".nxColorBold(str_pad("File Server",26," ",STR_PAD_BOTH)));
print("| ".nxColorBold(str_pad("Foundation",19," ",STR_PAD_BOTH)));
print("|\n");
// last line top table - same as first one
print("+".str_pad("",20,"-",STR_PAD_BOTH));
print("+".str_pad("",13,"-",STR_PAD_BOTH));
print("+".str_pad("",62,"-",STR_PAD_BOTH));
print("+".str_pad("",17,"-",STR_PAD_BOTH));
print("+".str_pad("",13,"-",STR_PAD_BOTH));
print("+".str_pad("",27,"-",STR_PAD_BOTH));
print("+".str_pad("",20,"-",STR_PAD_BOTH));
print("+\n");
// =-=-=-=-=-=-=-=-=--=-=
// Display collected data
// =-=-=-=-=-=-=-=-=--=-=
for($i=0;$i<count($ver);$i++)
{
// Cluster Name
if(isset($ver[$i]["nodes"])) print("| ".nxColorOutput(str_pad($ver[$i]["name"]." (".$ver[$i]["nodes"].") ", 19, " ", STR_PAD_RIGHT)));
else print("| ".nxColorOutput(str_pad($ver[$i]["name"]." (n/a) ", 19, " ", STR_PAD_RIGHT)));
// AOS Version
print("| ".nxColorOutput(str_pad($ver[$i]["AOS"][0]->version, 12, " ", STR_PAD_BOTH)));
// Hypervisor(s)
// Loop thru nodes to display hypervisor version on each node
// If Prism Central detected, hypervisor is not displayed but PC version instead
if($ver[$i]["PC"])
{
print("| ".nxColorOutput(str_pad($ver[$i]["PC"],61," ",STR_PAD_BOTH)));
}
else
{
$pHypervisor="";
for($n=0;$n<count($ver[$i]["Hypervisor"]);$n++)
{
if (count($ver[$i]["Hypervisor"]) == 1)
$pHypervisor=$pHypervisor.$ver[$i]["Hypervisor"][$n];
elseif ($n==count($ver[$i]["Hypervisor"])-1)
$pHypervisor=$pHypervisor.$ver[$i]["Hypervisor"][$n];
else
$pHypervisor=$pHypervisor.$ver[$i]["Hypervisor"][$n].", ";
}
if($pHypervisor) print("| ".nxColorOutput(str_pad($pHypervisor,61," ",STR_PAD_BOTH)));
else print("| ".str_pad("n/a",61," ",STR_PAD_BOTH));
}
// LCM
print("| ".nxColorOutput(str_pad($ver[$i]["LCM"], 16, " ", STR_PAD_BOTH)));
// NCC
print("| ".nxColorOutput(str_pad($ver[$i]["NCC"][0]->version, 12, " ", STR_PAD_BOTH)));
// File Server
$pFS="";
for($n=0;$n<count($ver[$i]["FileServer"]);$n++)
{
if (count($ver[$i]["FileServer"]) == 1)
$pFS=$pFS.$ver[$i]["FileServer"][$n];
elseif ($n==count($ver[$i]["FileServer"])-1)
$pFS=$pFS.$ver[$i]["FileServer"][$n];
else
$pFS=$pFS.$ver[$i]["FileServer"][$n].", ";
}
if($pFS) print("| ".nxColorOutput(str_pad($pFS,26," ",STR_PAD_BOTH)));
else print("| ".str_pad("n/a",26," ",STR_PAD_BOTH));
//Foundation
$pFoundation="";
for($n=0;$n<count($ver[$i]["Foundation"]);$n++)
{
if (count($ver[$i]["Foundation"]) == 1)
$pFoundation=$pFoundation.$ver[$i]["Foundation"][$n];
elseif ($n==count($ver[$i]["Foundation"])-1)
$pFouncation=$pFoundation.$ver[$i]["Foundation"][$n];
else
$pFoundation=$pFoundation.$ver[$i]["FileServer"][$n].", ";
}
if($pFoundation) print("| ".nxColorOutput(str_pad($pFoundation,18," ",STR_PAD_BOTH)));
else print("| ".str_pad("n/a",18," ",STR_PAD_BOTH));
print(" |\n");
}
// last line top table - same as first one
print("+".str_pad("",20,"-",STR_PAD_BOTH));
print("+".str_pad("",13,"-",STR_PAD_BOTH));
print("+".str_pad("",62,"-",STR_PAD_BOTH));
print("+".str_pad("",17,"-",STR_PAD_BOTH));
print("+".str_pad("",13,"-",STR_PAD_BOTH));
print("+".str_pad("",27,"-",STR_PAD_BOTH));
print("+".str_pad("",20,"-",STR_PAD_BOTH));
print("+\n");
?>