forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaplan.js
More file actions
117 lines (99 loc) · 3.36 KB
/
Copy pathhaplan.js
File metadata and controls
117 lines (99 loc) · 3.36 KB
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
/*
* Copyright (C) 2006-2009 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
/* Example of how to add functionality to devweb */
$(document).ready(function() {$('#topbar').append($($.create("button",{ns:xhtmlns,id:"searchbutton","class":"topbutton"},["HA Plan"])).click(createhaplan));});
function docontent(win,placedvms,disabledhosts) {
var height;
var vms=[];
var hosts=[];
var c;
var content=$('.content',win);
var resident;
var vm;
var i;
var x;
var mem;
globalvms=placedvms;
var errors="";
for(vm in placedvms) {
if(placedvms[vm].error_code) {
alert("Cant place VM: "+$xapi.xo.vm[vm].name_label);
}
}
function isdisabled(host) {
for(x=0; x<disabledhosts.length; x++)
if(disabledhosts[x]==host)
return true;
return false;
}
$.each($xapi.xo.host,function(i,val) {
vms=[];
if(!isdisabled(i)) {
$.each(val.resident_VMs,function(j,vm) {
if($xapi.xo.vm_metrics[$xapi.xo.vm[vm].metrics]) {
mem=$xapi.xo.vm_metrics[$xapi.xo.vm[vm].metrics].memory_actual;
} else {
mem=$xapi.xo.vm[$xapi.xo.vm[vm].memory_dynamic_max];
}
height=mem / (8*1024*1024);
vms=vms.concat(["div",{ns:xhtmlns,"class":"HAVM",style:"height:"+height+"px"},
[$xapi.xo.vm[vm].name_label]]);
});
$.each(placedvms,function(key,val) {
if(val.host==i) {
height=$xapi.xo.vm_metrics[$xapi.xo.vm[key].metrics].memory_actual / (8*1024*1024);
vms=vms.concat(["div",{ns:xhtmlns,"class":"HAVMNEW",style:"height:"+height+"px"},
[$xapi.xo.vm[key].name_label]]);
}
});
}
c=(isdisabled(i))?"HAHOSTDISABLED":"HAHOST";
if($xapi.xo.host_metrics[val.metrics].live) {
height=$xapi.xo.host_metrics[val.metrics].memory_total/(8*1024*1024);
hosts=hosts.concat(["div",{ns:xhtmlns,"class":c,id:'ha'+i,style:"height:"+height+"px"},["Host: "+val.name_label].concat(vms)]);
}
});
content.empty().append($($.create("div",{ns:xhtmlns},hosts)));
$('.HAHOST',win).click(function(evt) {
resident=[];
vms=[];
var tgt=$(evt.target);
host=tgt.attr("id").slice(2);
disabledhosts=disabledhosts.concat(host);
for(xx=0; xx<disabledhosts.length; xx++) {
host=disabledhosts[xx];
for(i=0; i<$xapi.xo.host[host].resident_VMs.length; i++) {
vm=$xapi.xo.host[host].resident_VMs[i];
if(! $xapi.xo.vm[vm].is_control_domain) {
vms=vms.concat(vm);
}
}
}
if (typeof netscape != "undefined") {
//netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserRead");
}
$xapi.xapi.pool.ha_compute_vm_failover_plan(
(function(host,win,disabledhosts) {
return function(vms) {
docontent(win,$xapi.check(vms),disabledhosts);
}
})(host,win,disabledhosts),
$xapi.session,disabledhosts,vms);
});
}
function createhaplan() {
var win=$dw.createWindow("haplan","HA plan");
var host;
docontent(win,{},[]);
}