匿名函数
// 动态给下拉框赋值
//获取所有虚拟机
(function (){
jQuery.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getKVM/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var hname=document.getElementById("allK");
hname.innerHTML="";
for(var i in res){
hname.add(new Option(res[i],res[i]));
}
}
});
}());
// 获取开机状态的虚拟机
(function (){
jQuery.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getOnKVM/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var hname=document.getElementById("onK");
hname.innerHTML="";
for(var i in res){
hname.add(new Option(res[i],res[i]));
}
}
});
}());
// 获取运行状态的虚拟机
(function (){
jQuery.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getrunKVM/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var hnam=document.getElementById("suspendk");
hnam.innerHTML="";
for(var i in res){
hnam.add(new Option(res[i],res[i]));
}
}
});
}());
// 获取关机状态的虚拟机
(function (){
jQuery.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getDownKVM/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var hname=document.getElementById("openk");
hname.innerHTML="";
for(var i in res){
hname.add(new Option(res[i],res[i]));
}
}
});
}());
// 获取暂停状态的虚拟机
(function (){
jQuery.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getsusKVM/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var hnam=document.getElementById("resumek");
hnam.innerHTML="";
for(var i in res){
hnam.add(new Option(res[i],res[i]));
}
}
});
}());
// 获取主机资源状况
(function (){
jQuery.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/statusofhost/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var host1=res[0].replace('[','').replace(']','');
document.getElementById("neicun1").value=host1.split(',')[0];
document.getElementById("cpu1").value=host1.split(',')[1];
document.getElementById("disk1").value=host1.split(',')[2];
document.getElementById("neicun2").value=res[1][0];
document.getElementById("cpu2").value=res[1][1];
document.getElementById("disk2").value=res[1][2];
}
});
}());
KVM相关操作
function createKVM()
{
var hname=document.getElementById("hname").value;
var neicun=document.getElementById("neicun").value;
var cpu=document.getElementById("cpu").value;
var disk=document.getElementById("disk").value;
var host="";
var obj = document.getElementsByName("host"); //这个是以标签的name来取控件
for(var i=0;i<2;i++){
if(obj[i].checked){
host=obj[i].value;
}
}
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/create/',
data: {"hname":hname,"neicun":neicun,"cpu":cpu,"disk":disk,"host":host},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
alert(res)
if(res)
alert("创建成功");
else{
alert("创建失败")
}
// var t2=document.getElementById("aqi");
// t2.value=res[1][2]+" / "+res[1][3];
}
});
}
function deleteKVM()
{
var hname=document.getElementById("hostKVM");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/delete/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
hname.removeChild(hname.options[hname.selectedIndex]);
}
});
}
function closeKVM()
{
var hname=document.getElementById("hostKVMon");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/close/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
hname.removeChild(hname.options[hname.selectedIndex]);
}
});
}
function runKVM()
{
var hname=document.getElementById("hostKVMdown");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/start/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
hname.removeChild(hname.options[hname.selectedIndex]);
}
});
}
function restartKVM()
{
var hname=document.getElementById("hostKVMon");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/restart/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
hname.removeChild(hname.options[hname.selectedIndex]);
}
});
}
function getonHostKVM()
{
var hname=document.getElementById("host");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getonHostKVM/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var sname=document.getElementById("hostKVMon");
sname.innerHTML="";
for(var i in res){
sname.add(new Option(res[i],res[i]));
}
}
});
}
function getsusHostKVM()
{
var hname=document.getElementById("host");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getsusHostKVM/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var sname=document.getElementById("hostKVMsus");
sname.innerHTML="";
for(var i in res){
sname.add(new Option(res[i],res[i]));
}
}
});
}
function getdownHostKVM()
{
var hname=document.getElementById("host");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getdownHostKVM/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var sname=document.getElementById("hostKVMdown");
sname.innerHTML="";
for(var i in res){
sname.add(new Option(res[i],res[i]));
}
}
});
}
// ---------------------------------------------Migrate---------------------------------------
function getHostKVM()
{
var hname=document.getElementById("host");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getHostKVM/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var sname=document.getElementById("hostKVM");
sname.innerHTML="";
for(var i in res){
sname.add(new Option(res[i],res[i]));
}
}
});
}
function migrateKVM()
{
var hname=document.getElementById("host");
hname=hname.options[hname.selectedIndex].value;
var hkvm=document.getElementById("hostKVM");
hkvm=hkvm.options[hkvm.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/migrateKVM/',
data: {"hname":hname,"hkvm":hkvm},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
alert(res)
if(res)
alert("创建成功");
else{
alert("创建失败")
}
}
});
}
function cloneKVM()
{
var hname=document.getElementById("host");
hname=hname.options[hname.selectedIndex].value;
var hkvm=document.getElementById("hostKVM");
hkvm=hkvm.options[hkvm.selectedIndex].value;
var chname=document.getElementById("chname").value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/cloneKVM/',
data: {"hname":hname,"hkvm":hkvm,"chname":chname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
alert(res)
if(res)
alert("创建成功");
else{
alert("创建失败")
}
}
});
}
function suspendKVM()
{
var hname=document.getElementById("hostKVMon");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/suspend/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
hname.removeChild(hname.options[hname.selectedIndex]);
}
});
}
function resumeKVM()
{
var hname=document.getElementById("hostKVMsus");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/resume/',
data: {"hname":hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
hname.removeChild(hname.options[hname.selectedIndex]);
}
});
}
// 创建快照
function createSNP()
{
var hname=document.getElementById("allK");
hname=hname.options[hname.selectedIndex].value;
var sname=document.getElementById("snpname").value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/createSNP/',
data: {"hname":hname,"sname":sname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
alert('创建成功');
}
});
}
// 恢复快照
function recoverSNP()
{
var hname=document.getElementById("allK");
hname=hname.options[hname.selectedIndex].value;
var sname=document.getElementById("snprname");
sname=sname.options[sname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/recoverSNP/',
data: {"hname":hname,"sname":sname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
alert('恢复成功');
}
});
}
// 删除快照
function deleteSNP()
{
var hname=document.getElementById("allK");
hname=hname.options[hname.selectedIndex].value;
var sname=document.getElementById("snprname");
sname=sname.options[sname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/deleteSNP/',
data: {"hname":hname,"sname":sname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
sname.removeChild(sname.options[sname.selectedIndex]);
}
});
}
//当选择某个虚拟机时,出现对应快照列表
function getKSNP(){
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/getSNP/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
var hname=document.getElementById("allK");
hname=hname.options[hname.selectedIndex].value;
res=res[hname];
var sname=document.getElementById("snprname");
sname.innerHTML="";
for(var i in res){
sname.add(new Option(res[i],res[i]));
}
}
});
}
//MPI一级并行
function mpione(){
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/mpione/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
}
});
setInterval("forloop()",1000);
}
//MPI二级并行
function mpitwo(){
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/mpitwo/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
}
});
setInterval("forloop()",1000);
}
//MPI动态增加
function mpinode(){
var hname=document.getElementById("mpinew");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/dynamicnode/',
data:{'hname':hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
}
});
setInterval("forloop()",1000);
}
//MPI容错
function mpierror(){
var hname=document.getElementById("mpierror");
hname=hname.options[hname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/mpierror/',
data:{'hname':hname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
}
});
setInterval("forloop()",1000);
}
function forloop(){
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/mpiinfom/',
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
$("#program").text(res)
}
});
}
var maxmem;
function searchKVM(){
var kvmname=document.getElementById("hostKVM");
kvmname=kvmname.options[kvmname.selectedIndex].value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/searchKVM/',
data:{'kvmname':kvmname},
dataType: 'JSON',
error: function () {
alert('请求失败');
},
success: function (res) {
document.getElementById("host").value=res[0];
document.getElementById("neicunmax").value=res[1];
maxmem=res[1];
document.getElementById("neicunnum").value=res[2];
document.getElementById("cpunum").value=res[3];
// document.getElementById("neicun2").value=res[1][0];
// document.getElementById("cpu2").value=res[1][1];
// document.getElementById("disk2").value=res[1][2];
}
});
}
function modifyKVM(){
var kvmname=document.getElementById("hostKVM");
kvmname=kvmname.options[kvmname.selectedIndex].value;
var neicunnum=document.getElementById("neicunnum").value;
var cpunum=document.getElementById("cpunum").value;
var neicunmax=document.getElementById("neicunmax").value;
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:5000/modifyKVM/',
data:{'kvmname':kvmname,'cpunum':cpunum,'neicunnum':neicunnum,'neicunmax':neicunmax,'maxmem':maxmem},
dataType: 'JSON',
error: function () {
alert('修改失败');
},
success: function (res) {
alert('修改成功!')
}
});
}