Skip to content

Commit b79b4d5

Browse files
adoom42infrastation
authored andcommitted
r4952 added hostForVm (#517)
1 parent 985921e commit b79b4d5

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

hostForVm/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
It tells the user on which host a vm currently lies and what vms a host currently provides.
2+
3+
The script is available here:
4+
https://github.com/dploeger/hostForVm
5+
6+
Steps to include hostforvm into racktables:
7+
* Install all necessary things for hostforvm, put the hostforvm.py-script into a directory available to the webserver process
8+
* Put the ajax-loader.gif into the pix-subdirectory of the www-root
9+
* Apply the included patch
10+
11+
https://sourceforge.net/apps/mantisbt/racktables/view.php?id=517

hostForVm/ajax-loader.gif

673 Bytes
Loading

hostForVm/hostForVmWrapup.pdf

56.9 KB
Binary file not shown.

hostForVm/hostforvmracktables.patch

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
Index: wwwroot/inc/ajax-interface.php
2+
===================================================================
3+
--- wwwroot/inc/ajax-interface.php (revision 260)
4+
+++ wwwroot/inc/ajax-interface.php (working copy)
5+
@@ -31,6 +31,35 @@
6+
7+
}
8+
9+
+function ajaxvm2host($mode, $name) {
10+
+
11+
+ global $vm2host_server, $vm2host_username, $vm2host_password, $vm2host_python, $vm2host_hostforvmpy;
12+
+
13+
+ if (! in_array($mode, array("v","h"))) {
14+
+
15+
+ echo "Mode must be v or h";
16+
+ return;
17+
+
18+
+ }
19+
+
20+
+ if (!preg_match("/[a-zA-Z0-9-_.]/", $name)) {
21+
+
22+
+ echo "Invalid host";
23+
+ return;
24+
+
25+
+ }
26+
+
27+
+ $command = $vm2host_python . " " . $vm2host_hostforvmpy . " --server ".$vm2host_server.
28+
+ " --username " . $vm2host_username .
29+
+ " --password " . $vm2host_password .
30+
+ " --mode " . $mode .
31+
+ " --name " . $name .
32+
+ " | sort";
33+
+
34+
+ system($command);
35+
+
36+
+}
37+
+
38+
// retrieves ports link status from switch and formats results to dynamic-HTML
39+
// returns array which could be packed into json and passed to client's browser
40+
function formatPortLinkHints ($object_id)
41+
@@ -205,6 +234,9 @@
42+
case 'search':
43+
ajaxSearch($_REQUEST['term']);
44+
break;
45+
+ case 'vm2host':
46+
+ ajaxvm2host($_REQUEST['mode'], $_REQUEST['name']);
47+
+ break;
48+
default:
49+
throw new InvalidRequestArgException ('ac', $_REQUEST['ac']);
50+
}
51+
Index: wwwroot/inc/secret.php
52+
===================================================================
53+
--- wwwroot/inc/secret.php (revision 260)
54+
+++ wwwroot/inc/secret.php (working copy)
55+
@@ -39,4 +39,13 @@
56+
$nagios_attribute_name = "Nagios Hostname";
57+
$nagios_url = "http://linagios3.ic-zedach.de/nagios/cgi-bin/status.cgi?host=%%NAGIOS%%";
58+
59+
+// vm2host configuration
60+
+
61+
+$vm2host_type = 1504;
62+
+$vm2host_python = "/opt/python27/bin/python2.7";
63+
+$vm2host_server = "vcenter-rz.zedach.intern";
64+
+$vm2host_username = "service.esxbackup";
65+
+$vm2host_password = "pEw6vechAK7q";
66+
+$vm2host_hostforvmpy = "../scripts/hostForVm.py";
67+
+
68+
?>
69+
Index: wwwroot/inc/interface.php
70+
===================================================================
71+
--- wwwroot/inc/interface.php (revision 260)
72+
+++ wwwroot/inc/interface.php (working copy)
73+
@@ -669,7 +669,7 @@
74+
75+
function renderRackObject ($object_id)
76+
{
77+
- global $nextorder, $aac, $virtual_obj_types, $nagios_attribute_name, $nagios_url;
78+
+ global $nextorder, $aac, $virtual_obj_types, $nagios_attribute_name, $nagios_url, $vm2host_type;
79+
$info = spotEntity ('object', $object_id);
80+
amplifyCell ($info);
81+
// Main layout starts.
82+
@@ -725,6 +725,8 @@
83+
echo "<tr><td colspan=2 class=msg_error>Has problems</td></tr>\n";
84+
85+
$nagios_hostname = "";
86+
+ $fqdn = "";
87+
+ $isHypervisor = false;
88+
89+
foreach (getAttrValues ($object_id) as $record) {
90+
91+
@@ -738,12 +740,55 @@
92+
$nagios_hostname = $record['value'];
93+
94+
}
95+
+ if ($record['name'] == "FQDN") {
96+
+ $fqdn = $record['value'];
97+
+ }
98+
+ if ($record['name'] == "Hypervisor") {
99+
+
100+
+ if ($record['value'] == "Yes") {
101+
+
102+
+ $isHypervisor = true;
103+
+
104+
+ }
105+
+
106+
+ }
107+
echo "<tr><th width='50%' class=sticker>${record['name']}:</th><td class=sticker>" .
108+
formatAttributeValue ($record) . "</td></tr>";
109+
110+
}
111+
112+
}
113+
+
114+
+ // Add vm2host for VMs
115+
+
116+
+ if (($info['objtype_id'] == $vm2host_type) ||
117+
+ ($isHypervisor)
118+
+ ) {
119+
+
120+
+ echo "<tr><th width='50%' class=sticker>on ESX-Host:</th><td class=sticker>";
121+
+ echo "<div id=\"vm2host_esx\"><img src=\"pix/ajax-loader.gif\"/></div>";
122+
+ echo "</td></tr>";
123+
+ echo "<script type=\"text/javascript\">\n";
124+
+ echo "function getvm2host(dnsname) {\n";
125+
+ echo " jQuery.ajax({\n";
126+
+ echo " url: \"index.php?module=ajax&ac=vm2host&mode=";
127+
+
128+
+ if ($info['objtype_id'] == $vm2host_type) {
129+
+ echo "v";
130+
+ } else {
131+
+ echo "h";
132+
+ }
133+
+
134+
+ echo "&name=\" + dnsname,\n";
135+
+ echo " success: function(data, textStatus, jqXHR) {\n";
136+
+ echo ' $("#vm2host_esx")[0].innerHTML=data.replace(/\n/g,"<br />");' . "\n";
137+
+ echo " }\n";
138+
+ echo " });\n";
139+
+ echo "}\n";
140+
+ echo "window.setTimeout('getvm2host(\"" . $fqdn. "\")', 1000);\n";
141+
+ echo "</script>\n";
142+
+
143+
+ }
144+
145+
printTagTRs
146+
(

0 commit comments

Comments
 (0)