xcpweb

changeset 9:a8a680105b67

Some changes and bug fixes
author Nikola Nikov <nikolanikov@webconnect.bg>
date Mon Jul 19 03:28:11 2010 +0300 (2010-07-19)
parents dff069dff4b7
children 0803fe338c81
files interface/img/menu_arrow.png interface/img/menu_resume.png interface/img/menu_start.png interface/templates/cloud_pool.js libxen/callbacks.js libxen/core.js libxen/db_callbacks.js libxen/libxen.js libxen/libxen_host.js libxen/libxen_init.js libxen/libxen_vm.js xcpweb_screenshot_migration.png
line diff
     1.1 Binary file interface/img/menu_arrow.png has changed
     2.1 Binary file interface/img/menu_resume.png has changed
     3.1 Binary file interface/img/menu_start.png has changed
     4.1 --- a/interface/templates/cloud_pool.js	Tue Jul 13 01:15:04 2010 +0300
     4.2 +++ b/interface/templates/cloud_pool.js	Mon Jul 19 03:28:11 2010 +0300
     4.3 @@ -48,6 +48,7 @@ var is_hidden = 0;
     4.4  	var tempcell;
     4.5  	x.className="pool_server_tr";
     4.6  	x.id=id;
     4.7 +	x.onclick = function(e) {cp_submenus.host(id,e);}
     4.8  	tempcell=x.insertCell(0);
     4.9  	tempcell.className="img";
    4.10  	tempcell.innerHTML='<img src="/interface/img/server.png" />';
    4.11 @@ -57,8 +58,8 @@ var is_hidden = 0;
    4.12  	tempcell.innerHTML=params['name_label'];
    4.13  	
    4.14  	tempcell=x.insertCell(2);
    4.15 -	tempcell.className="name_description";
    4.16 -	tempcell.innerHTML=params['server_description'];
    4.17 +	tempcell.className="server_description";
    4.18 +	tempcell.innerHTML=params['name_description'];
    4.19  	
    4.20  	tempcell=x.insertCell(3);
    4.21  	tempcell.className="memory_usage";
    4.22 @@ -207,7 +208,7 @@ var is_hidden = 0;
    4.23  		{
    4.24  		var current_vm=xen_get_vm_list_vm(vm_pool[server_id]['resident_VMs'][vm_id]);
    4.25  		current_vm['max_memory']=vm_pool[server_id]['memory_total'];
    4.26 -		self.addVM(vm_id,current_vm,vm_pool[server_id]['table_id']);
    4.27 +		self.addVM(vm_pool[server_id]['resident_VMs'][vm_id],current_vm,vm_pool[server_id]['table_id']);
    4.28  		}
    4.29  	
    4.30  	}
    4.31 @@ -226,16 +227,69 @@ function Cloud_Pool_submenus()
    4.32  this.vm = function(param,e)
    4.33  	{
    4.34  	if (xcp_menu.getMenu(param)) { xcp_menu.dropMenu(param); }
    4.35 +	var allowed_operations=xen_vm_get_allowed_operations(param);
    4.36 +	var power_state=xen_vm_get_power_state(param);
    4.37 +	var possible_hosts=xen_vm_get_possible_hosts(param);
    4.38 +	var possible_hosts_label=new Array();
    4.39 +	var possible_hosts_num = 0;
    4.40 +	
    4.41 +	possible_hosts=new Array();
    4.42 +	possible_hosts[0]='OpaqueRef:bba544aa-e038-b9f8-b50a-07a6a833a568';
    4.43 +	for (var i in possible_hosts) {
    4.44 +	possible_hosts_num++;
    4.45 +	possible_hosts_label[i]=xen_host_get_name_label(possible_hosts[i]);
    4.46 +	}
    4.47 +	//for now 
    4.48 +	power_state="Running";
    4.49 +	
    4.50  	var currentMenu = xcp_menu.createMenu(param);
    4.51  	if (typeof(currentMenu) == 'object') {
    4.52  		xcp_menu.appendInMenu(currentMenu,'console','Console',"",'/interface/img/menu_terminal.png');
    4.53  		var subcurrent = xcp_menu.appendSubInMenu(currentMenu,'oprations','Operations','/interface/img/menu_operations.png');
    4.54  		if (typeof(subcurrent) == 'object') {
    4.55 -			xcp_menu.appendInMenu(subcurrent,'shutdown','Shutdown',"",'/interface/img/menu_shutdown.png');
    4.56 -			xcp_menu.appendInMenu(subcurrent,'hard_shutdown','Force Shutdown',"",'/interface/img/menu_shutdown.png');
    4.57 -			xcp_menu.appendInMenu(subcurrent,'reboot','Reboot',"",'/interface/img/menu_reboot.png');
    4.58 -			xcp_menu.appendInMenu(subcurrent,'hard_reboot','Force Reboot',"",'/interface/img/menu_reboot.png');
    4.59 -			xcp_menu.appendInMenu(subcurrent,'pause','Pause',"",'/interface/img/menu_pause.png');
    4.60 +			if(power_state=='Running' && possible_hosts_num)
    4.61 +				{
    4.62 +				var submigrate = xcp_menu.appendSubInMenu(subcurrent,'migrate_on','Migrate On','/interface/img/menu_arrow.png');
    4.63 +					if (typeof(submigrate) == 'object') {
    4.64 +						for(var host in possible_hosts)
    4.65 +						{
    4.66 +						xcp_menu.appendInMenu(submigrate,possible_hosts[host],possible_hosts_label[host],"xen_vm_pool_migrate('"+param+"','"+possible_hosts[host]+"');",'/interface/img/server.png');
    4.67 +						}
    4.68 +					}
    4.69 +				}
    4.70 +			if(power_state=='Halted' && possible_hosts_num)
    4.71 +				{
    4.72 +				var substart = xcp_menu.appendSubInMenu(subcurrent,'start_on','Start On','/interface/img/menu_start.png');
    4.73 +					if (typeof(substart) == 'object') {
    4.74 +						for(var host in possible_hosts)
    4.75 +						{
    4.76 +						xcp_menu.appendInMenu(substart,possible_hosts[host],possible_hosts_label[host],"xen_vm_start_on('"+param+"','"+possible_hosts[host]+"');",'/interface/img/server.png');
    4.77 +						}
    4.78 +					}
    4.79 +				}
    4.80 +			if(power_state=='Suspended' && possible_hosts_num)
    4.81 +				{
    4.82 +				var subresume = xcp_menu.appendSubInMenu(subcurrent,'resume_on','Resume On','/interface/img/menu_start.png');
    4.83 +					if (typeof(subresume) == 'object') {
    4.84 +						for(var host in possible_hosts)
    4.85 +						{
    4.86 +						xcp_menu.appendInMenu(subresume,possible_hosts[host],possible_hosts_label[host],"xen_vm_resume_on('"+param+"','"+possible_hosts[host]+"');",'/interface/img/server.png');
    4.87 +						}
    4.88 +					}
    4.89 +				}
    4.90 +			
    4.91 +			for(var op_id in allowed_operations)
    4.92 +			{
    4.93 +			if(allowed_operations[op_id]=='clean_shutdown')xcp_menu.appendInMenu(subcurrent,'clean_shutdown','Shutdown',"xen_vm_clean_shutdown('"+param+"');",'/interface/img/menu_shutdown.png');
    4.94 +			if(allowed_operations[op_id]=='hard_shutdown')xcp_menu.appendInMenu(subcurrent,'hard_shutdown','Force Shutdown',"xen_vm_hard_shutdown('"+param+"');",'/interface/img/menu_shutdown.png');
    4.95 +			if(allowed_operations[op_id]=='clean_reboot')xcp_menu.appendInMenu(subcurrent,'clean_reboot','Reboot',"xen_vm_clean_reboot('"+param+"');",'/interface/img/menu_reboot.png');
    4.96 +			if(allowed_operations[op_id]=='hard_reboot')xcp_menu.appendInMenu(subcurrent,'hard_reboot','Force Reboot',"xen_vm_hard_reboot('"+param+"');",'/interface/img/menu_reboot.png');
    4.97 +			if(allowed_operations[op_id]=='pause')xcp_menu.appendInMenu(subcurrent,'pause','Pause',"xen_vm_pause('"+param+"');",'/interface/img/menu_pause.png');
    4.98 +			if(allowed_operations[op_id]=='unpause')xcp_menu.appendInMenu(subcurrent,'pause','UnPause',"xen_vm_unpause('"+param+"');",'/interface/img/menu_pause.png');
    4.99 +			if(allowed_operations[op_id]=='resume')xcp_menu.appendInMenu(subcurrent,'resume','Resume',"xen_vm_resume('"+param+"');",'/interface/img/menu_resume.png');
   4.100 +			if(allowed_operations[op_id]=='suspend')xcp_menu.appendInMenu(subcurrent,'suspend','Suspend',"xen_vm_suspend('"+param+"');",'/interface/img/menu_shutdown.png');
   4.101 +			if(allowed_operations[op_id]=='start')xcp_menu.appendInMenu(subcurrent,'start','Start',"xen_vm_start('"+param+"');",'/interface/img/menu_start.png');
   4.102 +			}
   4.103  		}
   4.104  		xcp_menu.appendInMenu(currentMenu,'graphics','Statistics',"",'/interface/img/menu_stats.png');
   4.105  		xcp_menu.appendInMenu(currentMenu,'settings','Settings',"",'/interface/img/menu_settings.png');
   4.106 @@ -245,6 +299,30 @@ this.vm = function(param,e)
   4.107  	
   4.108  this.host = function(param,e)
   4.109  	{
   4.110 +	//the param is the host ref
   4.111 +	var allowed_operations=xen_host_get_allowed_operations(param);
   4.112 +	
   4.113 +	
   4.114 +	if (xcp_menu.getMenu(param)) { xcp_menu.dropMenu(param); }
   4.115 +	var currentMenu = xcp_menu.createMenu(param);
   4.116 +	if (typeof(currentMenu) == 'object') {
   4.117 +		//test
   4.118 +		/*
   4.119 +		allowed_operations.push('evacuate');
   4.120 +		allowed_operations.push('shutdown');
   4.121 +		allowed_operations.push('reboot');
   4.122 +		*/
   4.123 +		for(var op_id in allowed_operations)
   4.124 +		{
   4.125 +		if(allowed_operations[op_id]=='evacuate')xcp_menu.appendInMenu(currentMenu,'evacuate','Evacuate',"xen_host_evacuate('"+param+"');",'/interface/img/menu_arrow.png');
   4.126 +		if(allowed_operations[op_id]=='shutdown')xcp_menu.appendInMenu(currentMenu,'shutdown','Shutdown',"xen_host_shutdown('"+param+"');",'/interface/img/menu_shutdown.png');
   4.127 +		if(allowed_operations[op_id]=='reboot')xcp_menu.appendInMenu(currentMenu,'reboot','Reboot',"xen_host_reboot('"+param+"');",'/interface/img/menu_reboot.png');
   4.128 +		}
   4.129 +		xcp_menu.appendInMenu(currentMenu,'disable','Disable',"xen_host_disable('"+param+"');",'/interface/img/menu_disable.png');
   4.130 +		xcp_menu.appendInMenu(currentMenu,'enable','Enable',"xen_host_enable'("+param+"');",'/interface/img/menu_enable.png');
   4.131 +		xcp_menu.appendInMenu(currentMenu,'settings','Settings',"alert('Settings');",'/interface/img/menu_settings.png');
   4.132 +		xcp_menu.openRightMenu('menu_'+param,e);
   4.133 +		}
   4.134  	}
   4.135  	
   4.136  }
     5.1 --- a/libxen/callbacks.js	Tue Jul 13 01:15:04 2010 +0300
     5.2 +++ b/libxen/callbacks.js	Mon Jul 19 03:28:11 2010 +0300
     5.3 @@ -1,1 +1,1 @@
     5.4 -function xen_callback_proceed_init(result,xmldoc,param_pass)
{
var params=new Array();
var event_params=new Array();
params[0]=xen_db['session_id'];
event_params[0]=xen_db['session_id'];
event_params[1]=new Array('*');

ApiCall('event.register',event_params,true,0,xen_callback_get_next_event,0,0); //TODO callback error
var initCalls=new Array('VM.get_all_records','task.get_all_records','VBD.get_all_records','VBD_metrics.get_all_records','VDI.get_all_records','network.get_all_records','PIF.get_all_records','PIF_metrics.get_all_records','PBD.get_all_records','VIF.get_all_records','VIF_metrics.get_all_records','VM_guest_metrics.get_all_records','VM_metrics.get_all_records','host_metrics.get_all_records','host_cpu.get_all_records','Bond.get_all_records','pool_patch.get_all_records','host_patch.get_all_records','console.get_all_records','host.get_all_records','pool.get_all_records','SR.get_all_records','message.get_all_records');
for (call_id in initCalls)ApiCall(initCalls[call_id],params,false,1,0,0,0); //TODO callback error
param_pass();
return ;
}

function xen_callback_get_next_event(result,xmldoc,param_pass)
{
//this calls the next event function
var params=new Array();
params[0]=xen_db['session_id'];

ApiCall('event.next',params,true,1,xen_callback_get_next_event,0,0); //TODO callback error
}
     5.5 \ No newline at end of file
     5.6 +function xen_callback_proceed_init(result,xmldoc,param_pass)
{
var params=new Array();
var event_params=new Array();
params[0]=xen_db['session_id'];
event_params[0]=xen_db['session_id'];
event_params[1]=new Array('*');

var initCalls=new Array('VM.get_all_records','task.get_all_records','VBD.get_all_records','VBD_metrics.get_all_records','VDI.get_all_records','network.get_all_records','PIF.get_all_records','PIF_metrics.get_all_records','PBD.get_all_records','VIF.get_all_records','VIF_metrics.get_all_records','VM_guest_metrics.get_all_records','VM_metrics.get_all_records','host_metrics.get_all_records','host_cpu.get_all_records','Bond.get_all_records','pool_patch.get_all_records','host_patch.get_all_records','console.get_all_records','host.get_all_records','pool.get_all_records','SR.get_all_records','message.get_all_records');
for (call_id in initCalls)ApiCall(initCalls[call_id],params,false,1,0,0,0); //TODO callback error
ApiCall('event.register',event_params,true,0,xen_callback_get_next_event,0,0); //TODO callback error and to make it sync after the xen_db structure is inicialized to call the event.register
param_pass();
return ;
}

function xen_callback_get_next_event(result,xmldoc,param_pass)
{
//this calls the next event function
var params=new Array();
params[0]=xen_db['session_id'];

ApiCall('event.next',params,true,1,xen_callback_get_next_event,0,0); //TODO callback error
}
     5.7 \ No newline at end of file
     6.1 --- a/libxen/core.js	Tue Jul 13 01:15:04 2010 +0300
     6.2 +++ b/libxen/core.js	Mon Jul 19 03:28:11 2010 +0300
     6.3 @@ -42,7 +42,7 @@ function CreateHttpRequestObject()
     6.4  ApiCall=function(method,params,async,doupdate,callback,error_callback,param_pass)
     6.5  {
     6.6  var data=xmlRpc(method, params);
     6.7 -makeRequest(url,method,data,async,doupdate,callback,error_callback,param_pass);
     6.8 +return makeRequest(url,method,data,async,doupdate,callback,error_callback,param_pass);
     6.9  }
    6.10  
    6.11  
    6.12 @@ -102,6 +102,8 @@ url+='&'+rand;
    6.13  					
    6.14  					if(callback)callback(result,xmldoc,param_pass);
    6.15  					
    6.16 +					if(!callback && !async)return result;
    6.17 +					
    6.18  				}
    6.19  			 	else
    6.20  				{
    6.21 @@ -134,9 +136,12 @@ url+='&'+rand;
    6.22  		//debug
    6.23  		//document.write('<br><textarea style="width:1200px;height:100px">==DATA TO SERVER== '+data+'</textarea>');
    6.24  		httpRequest.send(data);
    6.25 -		if(async==false)parse_request();
    6.26 -		
    6.27 -    }
    6.28 +		if(async==false)
    6.29 +		{
    6.30 +		return parse_request();
    6.31 +		}
    6.32 +    
    6.33 +	}
    6.34  
    6.35  
    6.36  	
     7.1 --- a/libxen/db_callbacks.js	Tue Jul 13 01:15:04 2010 +0300
     7.2 +++ b/libxen/db_callbacks.js	Mon Jul 19 03:28:11 2010 +0300
     7.3 @@ -1,1 +1,1 @@
     7.4 -function invoke_event(array_name){if(typeof(xen_db_events[array_name])!='undefined'){xen_db_events[array_name]();}if(typeof(xen_db_events['*'])!='undefined'){xen_db_events['*']();}}
var db_callbacks=new Array();

db_callbacks['session.login_with_password']=function(result)
{
xen_db['session_id']=result;
xen_db['is_logged']=1;
xen_db['logged']=1;
return ;
}

db_callbacks['VM.get_all_records']=function(result){xen_db['VM']=result;invoke_event('VM');return;} 
db_callbacks['task.get_all_records']=function(result){xen_db['task']=result;invoke_event('task');return;} 
db_callbacks['VBD.get_all_records']=function(result){xen_db['VBD']=result;invoke_event('VBD');return;} 
db_callbacks['VBD_metrics.get_all_records']=function(result){xen_db['VBD_metrics']=result;invoke_event('VBD_metrics');return;} 
db_callbacks['VDI.get_all_records']=function(result){xen_db['VDI']=result;invoke_event('VDI');return;} 
db_callbacks['network.get_all_records']=function(result){xen_db['network']=result;invoke_event('network');return;} 
db_callbacks['PIF.get_all_records']=function(result){xen_db['PIF']=result;invoke_event('PIF');return;} 
db_callbacks['PIF_metrics.get_all_records']=function(result){xen_db['PIF_metrics']=result;invoke_event('PIF_metrics');return;} 
db_callbacks['PBD.get_all_records']=function(result){xen_db['PBD']=result;invoke_event('PBD');return;} 
db_callbacks['VIF.get_all_records']=function(result){xen_db['VIF']=result;invoke_event('VIF');return;} 
db_callbacks['VIF_metrics.get_all_records']=function(result){xen_db['VIF_metrics']=result;invoke_event('VIF_metrics');return;} 
db_callbacks['VM_guest_metrics.get_all_records']=function(result){xen_db['VM_guest_metrics']=result;invoke_event('VM_guest_metrics');return;} 
db_callbacks['VM_metrics.get_all_records']=function(result){xen_db['VM_metrics']=result;invoke_event('VM_metrics');return;} 
db_callbacks['host_metrics.get_all_records']=function(result){xen_db['host_metrics']=result;invoke_event('host_metrics');return;} 
db_callbacks['host_cpu.get_all_records']=function(result){xen_db['host_cpu']=result;invoke_event('host_cpu');return;} 
db_callbacks['Bond.get_all_records']=function(result){xen_db['Bond']=result;invoke_event('Bond');return;} 
db_callbacks['pool_patch.get_all_records']=function(result){xen_db['pool_patch']=result;invoke_event('pool_patch');return;} 
db_callbacks['host_patch.get_all_records']=function(result){xen_db['host_patch']=result;invoke_event('host_patch');return;} 
db_callbacks['console.get_all_records']=function(result){xen_db['console']=result;invoke_event('console');return;} 
db_callbacks['host.get_all_records']=function(result){xen_db['host']=result;invoke_event('host');return;} 
db_callbacks['pool.get_all_records']=function(result){xen_db['pool']=result;invoke_event('pool');return;} 
db_callbacks['SR.get_all_records']=function(result){xen_db['SR']=result;invoke_event('SR');return;} 
db_callbacks['message.get_all_records']=function(result){xen_db['message']=result;invoke_event('message');return;}

db_callbacks['event.next']=function(result)
{
	for ( var i in result )
	{
		if(result[i].operation=='mod' || result[i].operation=='add')
		{
		if(typeof(xen_db[result[i].class][result[i].ref])!='undefined') //TODO: some errors happen when there are no result[i].class, because it may load before xen_db
			{
			xen_db[result[i].class][result[i].ref]=result[i].snapshot;
			invoke_event(result[i].class);
			}
		else
			{
			alert("non existing class in xen_db class name:"+result[i].class+" reference:"+result[i].ref);
			}
		}
		if(result[i].operation=='del')
		{
		delete xen_db[result[i].class][result[i].ref];
		invoke_event('del');
		}
	}
	
	return;
}
     7.5 \ No newline at end of file
     7.6 +function invoke_event(array_name){if(typeof(xen_db_events[array_name])!='undefined'){xen_db_events[array_name]();}if(typeof(xen_db_events['*'])!='undefined'){xen_db_events['*']();}}
var db_callbacks=new Array();

db_callbacks['session.login_with_password']=function(result)
{
xen_db['session_id']=result;
xen_db['is_logged']=1;
xen_db['logged']=1;
return ;
}

db_callbacks['VM.get_all_records']=function(result){xen_db['VM']=result;invoke_event('VM');return;} 
db_callbacks['task.get_all_records']=function(result){xen_db['task']=result;invoke_event('task');return;} 
db_callbacks['VBD.get_all_records']=function(result){xen_db['VBD']=result;invoke_event('VBD');return;} 
db_callbacks['VBD_metrics.get_all_records']=function(result){xen_db['VBD_metrics']=result;invoke_event('VBD_metrics');return;} 
db_callbacks['VDI.get_all_records']=function(result){xen_db['VDI']=result;invoke_event('VDI');return;} 
db_callbacks['network.get_all_records']=function(result){xen_db['network']=result;invoke_event('network');return;} 
db_callbacks['PIF.get_all_records']=function(result){xen_db['PIF']=result;invoke_event('PIF');return;} 
db_callbacks['PIF_metrics.get_all_records']=function(result){xen_db['PIF_metrics']=result;invoke_event('PIF_metrics');return;} 
db_callbacks['PBD.get_all_records']=function(result){xen_db['PBD']=result;invoke_event('PBD');return;} 
db_callbacks['VIF.get_all_records']=function(result){xen_db['VIF']=result;invoke_event('VIF');return;} 
db_callbacks['VIF_metrics.get_all_records']=function(result){xen_db['VIF_metrics']=result;invoke_event('VIF_metrics');return;} 
db_callbacks['VM_guest_metrics.get_all_records']=function(result){xen_db['VM_guest_metrics']=result;invoke_event('VM_guest_metrics');return;} 
db_callbacks['VM_metrics.get_all_records']=function(result){xen_db['VM_metrics']=result;invoke_event('VM_metrics');return;} 
db_callbacks['host_metrics.get_all_records']=function(result){xen_db['host_metrics']=result;invoke_event('host_metrics');return;} 
db_callbacks['host_cpu.get_all_records']=function(result){xen_db['host_cpu']=result;invoke_event('host_cpu');return;} 
db_callbacks['Bond.get_all_records']=function(result){xen_db['Bond']=result;invoke_event('Bond');return;} 
db_callbacks['pool_patch.get_all_records']=function(result){xen_db['pool_patch']=result;invoke_event('pool_patch');return;} 
db_callbacks['host_patch.get_all_records']=function(result){xen_db['host_patch']=result;invoke_event('host_patch');return;} 
db_callbacks['console.get_all_records']=function(result){xen_db['console']=result;invoke_event('console');return;} 
db_callbacks['host.get_all_records']=function(result){xen_db['host']=result;invoke_event('host');return;} 
db_callbacks['pool.get_all_records']=function(result){xen_db['pool']=result;invoke_event('pool');return;} 
db_callbacks['SR.get_all_records']=function(result){xen_db['SR']=result;invoke_event('SR');return;} 
db_callbacks['message.get_all_records']=function(result){xen_db['message']=result;invoke_event('message');return;}

db_callbacks['event.next']=function(result)
{
	for ( var i in result )
	{
		if(result[i].operation=='mod' || result[i].operation=='add')
		{

		if(typeof(xen_db[result[i].class])!='undefined') //TODO: some error happens when there are no result[i].class, because it may load before xen_db
			{
			xen_db[result[i].class][result[i].ref]=result[i].snapshot;
			}
		else
			{
			xen_db[result[i].class]=new Object();
			xen_db[result[i].class][result[i].ref]=result[i].snapshot;
			}
			invoke_event(result[i].class);
			
		
		}
		if(result[i].operation=='del')
		{ 
		delete xen_db[result[i].class][result[i].ref];
		invoke_event(result[i].class);
		}
	}
	
	return;
}
     7.7 \ No newline at end of file
     8.1 --- a/libxen/libxen.js	Tue Jul 13 01:15:04 2010 +0300
     8.2 +++ b/libxen/libxen.js	Mon Jul 19 03:28:11 2010 +0300
     8.3 @@ -22,63 +22,3 @@ function xen_register_db_event(db_array,
     8.4  {
     8.5  xen_db_events[db_array]=function_call;
     8.6  }
     8.7 -
     8.8 -
     8.9 -//for the vm list box
    8.10 -
    8.11 -function xen_get_vm_list_hosts()
    8.12 -{
    8.13 -
    8.14 -var vm_pool=new Array();
    8.15 -
    8.16 - for ( var host_id in xen_db['host'] )
    8.17 - {
    8.18 -	vm_pool[host_id] = new Array();
    8.19 -	vm_pool[host_id]['name_label']=xen_db['host'][host_id]['name_label'];
    8.20 -	vm_pool[host_id]['name_description']=xen_db['host'][host_id]['name_description'];
    8.21 -	
    8.22 -	//to get other things from the metrics 
    8.23 -	//get the cpu_usage
    8.24 -	var cpu_usage=0;
    8.25 -	var cpus=0
    8.26 -		for (var cpu_id in xen_db['host'][host_id]['host_CPUs'])
    8.27 -			{
    8.28 -			cpu_usage=parseInt(cpu_usage)+parseInt(xen_db['host_cpu'][xen_db['host'][host_id]['host_CPUs'][cpu_id]]['utilisation']);
    8.29 -			cpus++;
    8.30 -			}
    8.31 -		cpu_usage=cpu_usage/cpus;
    8.32 -	
    8.33 -	vm_pool[host_id]['cpu_usage']=cpu_usage;
    8.34 -
    8.35 -	vm_pool[host_id]['memory_free']=Math.floor(parseInt(xen_db['host_metrics'][xen_db['host'][host_id]['metrics']]['memory_free']) / (1024*1024));
    8.36 -	vm_pool[host_id]['memory_total']=Math.floor(parseInt(xen_db['host_metrics'][xen_db['host'][host_id]['metrics']]['memory_total']) / (1024*1024));
    8.37 -	
    8.38 -	vm_pool[host_id]['resident_VMs']=new Array();
    8.39 -	for(var id in xen_db['host'][host_id]['resident_VMs'])
    8.40 -	{
    8.41 -	var vm_id=xen_db['host'][host_id]['resident_VMs'][id];
    8.42 -	if(!xen_db['VM'][vm_id]['is_a_snapshot'] && !xen_db['VM'][vm_id]['is_a_template'] && !xen_db['VM'][vm_id]['is_control_domain'])vm_pool[host_id]['resident_VMs'].push(vm_id);
    8.43 -	}
    8.44 -	
    8.45 - }
    8.46 -
    8.47 - return vm_pool;
    8.48 -}
    8.49 -
    8.50 -function xen_get_vm_list_vm(vm_id)
    8.51 -{
    8.52 -var vm_pool = new Array();
    8.53 -	
    8.54 -	vm_pool['name_label']=xen_db['VM'][vm_id]['name_label'];
    8.55 -	vm_pool['name_description']=xen_db['VM'][vm_id]['name_description'];
    8.56 -	if(vm_pool['name_description']=='')vm_pool['name_description']=xen_db['VM_guest_metrics'][xen_db['VM'][vm_id]['guest_metrics']]['os_version']['name'];
    8.57 -	
    8.58 -	vm_pool['memory_total']=Math.floor(parseInt(xen_db['VM'][vm_id]['memory_target']) / (1024*1024));
    8.59 -	vm_pool['power_state']=xen_db['VM'][vm_id]['power_state'];
    8.60 -	vm_pool['vm_cpus_count']=xen_db['VM'][vm_id]['VCPUs_max'];
    8.61 -	vm_pool['vm_cpus_weight']='';// TODO
    8.62 -	vm_pool['vm_cpus_cap']='';// TODO
    8.63 -return vm_pool;
    8.64 -}
    8.65 -
    8.66 -//end of vm list box
    8.67 \ No newline at end of file
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/libxen/libxen_host.js	Mon Jul 19 03:28:11 2010 +0300
     9.3 @@ -0,0 +1,95 @@
     9.4 +// functions to deal with Host part of the xen_db
     9.5 +
     9.6 +function xen_get_vm_list_hosts()
     9.7 +{
     9.8 +
     9.9 +var vm_pool=new Array();
    9.10 +
    9.11 + for ( var host_id in xen_db['host'] )
    9.12 + {
    9.13 +	vm_pool[host_id] = new Array();
    9.14 +	vm_pool[host_id]['name_label']=xen_db['host'][host_id]['name_label'];
    9.15 +	vm_pool[host_id]['name_description']=xen_db['host'][host_id]['name_description'];
    9.16 +	
    9.17 +	//to get other things from the metrics 
    9.18 +	//get the cpu_usage
    9.19 +	var cpu_usage=0;
    9.20 +	var cpus=0
    9.21 +		for (var cpu_id in xen_db['host'][host_id]['host_CPUs'])
    9.22 +			{
    9.23 +			cpu_usage=parseInt(cpu_usage)+parseInt(xen_db['host_cpu'][xen_db['host'][host_id]['host_CPUs'][cpu_id]]['utilisation']);
    9.24 +			cpus++;
    9.25 +			}
    9.26 +		cpu_usage=cpu_usage/cpus;
    9.27 +	
    9.28 +	vm_pool[host_id]['cpu_usage']=cpu_usage;
    9.29 +
    9.30 +	vm_pool[host_id]['memory_free']=Math.floor(parseInt(xen_db['host_metrics'][xen_db['host'][host_id]['metrics']]['memory_free']) / (1024*1024));
    9.31 +	vm_pool[host_id]['memory_total']=Math.floor(parseInt(xen_db['host_metrics'][xen_db['host'][host_id]['metrics']]['memory_total']) / (1024*1024));
    9.32 +	
    9.33 +	vm_pool[host_id]['resident_VMs']=new Array();
    9.34 +	for(var id in xen_db['host'][host_id]['resident_VMs'])
    9.35 +	{
    9.36 +	var vm_id=xen_db['host'][host_id]['resident_VMs'][id];
    9.37 +	if(!xen_db['VM'][vm_id]['is_a_template'] && !xen_db['VM'][vm_id]['is_control_domain'])vm_pool[host_id]['resident_VMs'].push(vm_id);
    9.38 +	}
    9.39 +	
    9.40 + }
    9.41 +
    9.42 + return vm_pool;
    9.43 +}
    9.44 +
    9.45 +function xen_host_get_allowed_operations(ref)
    9.46 +{
    9.47 +return xen_db['host'][ref]['allowed_operations'];
    9.48 +}
    9.49 +
    9.50 +function xen_host_get_name_label(ref)
    9.51 +{
    9.52 +return xen_db['host'][ref]['name_label'];
    9.53 +}
    9.54 +
    9.55 +function xen_host_shutdown(ref)
    9.56 +{
    9.57 +var params=new Array();
    9.58 +params[0]=xen_db['session_id'];
    9.59 +params[1]=ref;
    9.60 +ApiCall('host.shutdown',params,true,0,0,0,0);
    9.61 +return ;
    9.62 +}
    9.63 +
    9.64 +function xen_host_reboot(ref)
    9.65 +{
    9.66 +var params=new Array();
    9.67 +params[0]=xen_db['session_id'];
    9.68 +params[1]=ref;
    9.69 +ApiCall('host.reboot',params,true,0,0,0,0);
    9.70 +return ;
    9.71 +}
    9.72 +
    9.73 +function xen_host_enable(ref)
    9.74 +{
    9.75 +var params=new Array();
    9.76 +params[0]=xen_db['session_id'];
    9.77 +params[1]=ref;
    9.78 +ApiCall('host.enable',params,true,0,0,0,0);
    9.79 +return ;
    9.80 +}
    9.81 +
    9.82 +function xen_host_disable(ref)
    9.83 +{
    9.84 +var params=new Array();
    9.85 +params[0]=xen_db['session_id'];
    9.86 +params[1]=ref;
    9.87 +ApiCall('host.disable',params,true,0,0,0,0);
    9.88 +return ;
    9.89 +}
    9.90 +
    9.91 +function xen_host_evacuate(ref)
    9.92 +{
    9.93 +var params=new Array();
    9.94 +params[0]=xen_db['session_id'];
    9.95 +params[1]=ref;
    9.96 +ApiCall('host.evacuate',params,true,0,0,0,0);
    9.97 +return ;
    9.98 +}
    10.1 --- a/libxen/libxen_init.js	Tue Jul 13 01:15:04 2010 +0300
    10.2 +++ b/libxen/libxen_init.js	Mon Jul 19 03:28:11 2010 +0300
    10.3 @@ -10,3 +10,5 @@ loadjs(libxen_path+'/callbacks.js');
    10.4  loadjs(libxen_path+'/db_callbacks.js');
    10.5  loadjs(libxen_path+'/core.js');
    10.6  loadjs(libxen_path+'/libxen.js');
    10.7 +loadjs(libxen_path+'/libxen_host.js');
    10.8 +loadjs(libxen_path+'/libxen_vm.js');
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/libxen/libxen_vm.js	Mon Jul 19 03:28:11 2010 +0300
    11.3 @@ -0,0 +1,146 @@
    11.4 +// functions to deal with VM part of the xen_db
    11.5 +
    11.6 +function xen_get_vm_list_vm(vm_id)
    11.7 +{
    11.8 +var vm_pool = new Array();
    11.9 +	
   11.10 +	vm_pool['name_label']=xen_db['VM'][vm_id]['name_label'];
   11.11 +	vm_pool['name_description']=xen_db['VM'][vm_id]['name_description'];
   11.12 +	if(vm_pool['name_description']=='' && typeof(xen_db['VM_guest_metrics'][xen_db['VM'][vm_id]['guest_metrics']])!='undefined')vm_pool['name_description']=xen_db['VM_guest_metrics'][xen_db['VM'][vm_id]['guest_metrics']]['os_version']['name'];
   11.13 +	
   11.14 +	vm_pool['memory_total']=Math.floor(parseInt(xen_db['VM'][vm_id]['memory_target']) / (1024*1024));
   11.15 +	vm_pool['power_state']=xen_db['VM'][vm_id]['power_state'];
   11.16 +	vm_pool['vm_cpus_count']=xen_db['VM'][vm_id]['VCPUs_max'];
   11.17 +	vm_pool['vm_cpus_weight']='';// TODO
   11.18 +	vm_pool['vm_cpus_cap']='';// TODO
   11.19 +return vm_pool;
   11.20 +}
   11.21 +
   11.22 +function xen_vm_get_allowed_operations(ref)
   11.23 +{
   11.24 +return xen_db['VM'][ref]['allowed_operations'];
   11.25 +}
   11.26 +
   11.27 +function xen_vm_get_power_state(ref)
   11.28 +{
   11.29 +return xen_db['VM'][ref]['power_state'];
   11.30 +}
   11.31 +
   11.32 +function xen_vm_get_possible_hosts(ref)
   11.33 +{
   11.34 +var params=new Array();
   11.35 +params[0]=xen_db['session_id'];
   11.36 +params[1]=ref;
   11.37 +return ApiCall('VM.get_possible_hosts',params,false,0,0,0,0);;
   11.38 +}
   11.39 +
   11.40 +function xen_vm_clean_shutdown(ref)
   11.41 +{
   11.42 +var params=new Array();
   11.43 +params[0]=xen_db['session_id'];
   11.44 +params[1]=ref;
   11.45 +ApiCall('VM.clean_shutdown',params,true,0,0,0,0);
   11.46 +return ;
   11.47 +}
   11.48 +
   11.49 +function xen_vm_clean_reboot(ref)
   11.50 +{
   11.51 +var params=new Array();
   11.52 +params[0]=xen_db['session_id'];
   11.53 +params[1]=ref;
   11.54 +ApiCall('VM.clean_reboot',params,true,0,0,0,0);
   11.55 +return ;
   11.56 +}
   11.57 +
   11.58 +function xen_vm_hard_shutdown(ref)
   11.59 +{
   11.60 +var params=new Array();
   11.61 +params[0]=xen_db['session_id'];
   11.62 +params[1]=ref;
   11.63 +ApiCall('VM.hard_shutdown',params,true,0,0,0,0);
   11.64 +return ;
   11.65 +}
   11.66 +
   11.67 +function xen_vm_hard_reboot(ref)
   11.68 +{
   11.69 +var params=new Array();
   11.70 +params[0]=xen_db['session_id'];
   11.71 +params[1]=ref;
   11.72 +ApiCall('VM.hard_reboot',params,true,0,0,0,0);
   11.73 +return ;
   11.74 +}
   11.75 +
   11.76 +function xen_vm_pause(ref)
   11.77 +{
   11.78 +var params=new Array();
   11.79 +params[0]=xen_db['session_id'];
   11.80 +params[1]=ref;
   11.81 +ApiCall('VM.pause',params,true,0,0,0,0);
   11.82 +return ;
   11.83 +}
   11.84 +
   11.85 +function xen_vm_unpause(ref)
   11.86 +{
   11.87 +var params=new Array();
   11.88 +params[0]=xen_db['session_id'];
   11.89 +params[1]=ref;
   11.90 +ApiCall('VM.unpause',params,true,0,0,0,0);
   11.91 +return ;
   11.92 +}
   11.93 +
   11.94 +function xen_vm_suspend(ref)
   11.95 +{
   11.96 +var params=new Array();
   11.97 +params[0]=xen_db['session_id'];
   11.98 +params[1]=ref;
   11.99 +ApiCall('VM.suspend',params,true,0,0,0,0);
  11.100 +return ;
  11.101 +}
  11.102 +
  11.103 +function xen_vm_resume(ref)
  11.104 +{
  11.105 +var params=new Array();
  11.106 +params[0]=xen_db['session_id'];
  11.107 +params[1]=ref;
  11.108 +ApiCall('VM.resume',params,true,0,0,0,0);
  11.109 +return ;
  11.110 +}
  11.111 +
  11.112 +function xen_vm_start(ref)
  11.113 +{
  11.114 +var params=new Array();
  11.115 +params[0]=xen_db['session_id'];
  11.116 +params[1]=ref;
  11.117 +ApiCall('VM.start',params,true,0,0,0,0);
  11.118 +return ;
  11.119 +}
  11.120 +
  11.121 +function xen_vm_start_on(vm_ref,host_ref)
  11.122 +{
  11.123 +var params=new Array();
  11.124 +params[0]=xen_db['session_id'];
  11.125 +params[1]=vm_ref;
  11.126 +params[2]=host_ref;
  11.127 +ApiCall('VM.start_on',params,true,0,0,0,0);
  11.128 +return ;
  11.129 +}
  11.130 +
  11.131 +function xen_vm_resume_on(vm_ref,host_ref)
  11.132 +{
  11.133 +var params=new Array();
  11.134 +params[0]=xen_db['session_id'];
  11.135 +params[1]=vm_ref;
  11.136 +params[2]=host_ref;
  11.137 +ApiCall('VM.resume_on',params,true,0,0,0,0);
  11.138 +return ;
  11.139 +}
  11.140 +
  11.141 +function xen_vm_pool_migrate(vm_ref,host_ref)
  11.142 +{
  11.143 +var params=new Array();
  11.144 +params[0]=xen_db['session_id'];
  11.145 +params[1]=vm_ref;
  11.146 +params[2]=host_ref;
  11.147 +ApiCall('VM.pool_migrate',params,true,0,0,0,0);
  11.148 +return ;
  11.149 +}
    12.1 Binary file xcpweb_screenshot_migration.png has changed