feature #1664: Add network tab in vms tab

This commit is contained in:
Daniel Molina committed 2013-03-14 16:35:47 +01:00
1 parent ee625402ae
commit 6bf572d77d
4 files changed
+589 -274

No files matched your search

@@ -64,6 +64,8 @@ module OpenNebulaJSON
when "chmod" then self.chmod_octet(action_hash['params'])
when "attachdisk" then self.attachdisk(action_hash['params'])
when "detachdisk" then self.detachdisk(action_hash['params'])
when "attachnic" then self.attachnic(action_hash['params'])
when "detachnic" then self.detachnic(action_hash['params'])
when "update" then self.update(action_hash['params'])
when "rename" then self.rename(action_hash['params'])
else
@@ -111,6 +113,16 @@ module OpenNebulaJSON
super(params['disk_id'].to_i)
end
def attachnic(params=Hash.new)
template_json = params['nic_template']
template = template_to_str(template_json)
super(template)
end
def detachnic(params=Hash.new)
super(params['nic_id'].to_i)
end
def update(params=Hash.new)
super(params['template_raw'])
end
+10
View File
@@ -744,6 +744,16 @@ var OpenNebula = {
OpenNebula.Action.simple_action(params,OpenNebula.VM.resource,
"detachdisk",action_obj);
},
"attachnic" : function(params){
var action_obj = {"nic_template": params.data.extra_param};
OpenNebula.Action.simple_action(params,OpenNebula.VM.resource,
"attachnic",action_obj);
},
"detachnic" : function(params){
var action_obj = {"nic_id": params.data.extra_param};
OpenNebula.Action.simple_action(params,OpenNebula.VM.resource,
"detachnic",action_obj);
},
"rename" : function(params){
var action_obj = params.data.extra_param;
OpenNebula.Action.simple_action(params,
+243 -222
View File
@@ -829,6 +829,242 @@ function setup_disk_tab_content(disk_section, str_disk_tab_id, str_datatable_id)
//$('button',disk_section).button();
}
function generate_nic_tab_content(str_nic_tab_id, str_datatable_id){
var html = '<div class="row">'+
'<div class="five columns push-seven">'+
'<input id="'+str_nic_tab_id+'_search" type="text" placeholder="Search"/>'+
'</div>'+
'</div>'+
'<table id="'+str_datatable_id+'" class="datatable twelve">'+
'<thead>'+
'<tr>'+
'<th class="check"><input type="checkbox" class="check_all" value=""></input></th>'+
'<th>'+tr("ID")+'</th>'+
'<th>'+tr("Owner")+'</th>'+
'<th>'+tr("Group")+'</th>'+
'<th>'+tr("Name")+'</th>'+
'<th>'+tr("Cluster")+'</th>'+
'<th>'+tr("Type")+'</th>'+
'<th>'+tr("Bridge")+'</th>'+
'<th>'+tr("Leases")+'</th>'+
'</tr>'+
'</thead>'+
'<tbody id="tbodynetworks">'+
'</tbody>'+
'</table>'+
'<br>'+
'<div class="vm_param kvm_opt xen_opt vmware_opt">'+
'<span id="select_network" class="radius secondary label">'+tr("Please select an network from the list")+'</span>'+
'<span id="network_selected" class="radius secondary label hidden">You selected the following image: '+
'</span>'+
'<span class="radius label" type="text" id="NETWORK" name="network"></span>'+
'<input type="hidden" id="NETWORK_ID" name="network_id" size="2"/>'+
'</div>'+
'<hr>'+
'<div class="show_hide" id="advanced">'+
'<h4><small><i class=" icon-plus-sign-alt"/> '+tr("Advanced options")+'<a id="add_os_boot_opts" class="icon_left" href="#"></a></small></h4>'+
'</div>'+
'<div class="advanced">'+
'<div class="row">'+
'<div class="six columns">'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="IP">'+tr("IP")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="IP" name="IP" size="3" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("Request an specific IP from the Network")+'</div>'+
'</div>'+
'</div>'+
'</div>'+
'<div class="six columns">'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="MODEL">'+tr("MODEL")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="MODEL" name="MODEL" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'<div class="row">'+
'<div class="six columns">'+
'<fieldset>'+
'<legend>'+tr("TCP Firewall")+'</legend>'+
'<div class="row">'+
'<div class="four columns push-two">'+
'<input type="radio" name="tcp_type" id="tcp_type" value="WHITE_PORTS_TCP"> Whitelist '+
'</div>'+
'<div class="four columns pull-two">'+
'<input type="radio" name="tcp_type" id="tcp_type" value="BLACK_PORTS_TCP"> Blacklist'+
'</div>'+
'</div>'+
'<br>'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="TCP_PORTS">'+tr("PORTS")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="TCP_PORTS" name="ports" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
'</div>'+
'</div>'+
'</fieldset>'+
'</div>'+
'<div class="six columns">'+
'<fieldset>'+
'<legend>'+tr("UDP Firewall")+'</legend>'+
'<div class="row">'+
'<div class="four columns push-two">'+
'<input type="radio" name="udp_type" id="udp_type" value="WHITE_PORTS_UDP"> Whitelist '+
'</div>'+
'<div class="four columns pull-two">'+
'<input type="radio" name="udp_type" id="udp_type" value="BLACK_PORTS_UDP"> Blacklist'+
'</div>'+
'</div>'+
'<br>'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="UDP_PORTS">'+tr("PORTS")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="UDP_PORTS" name="ports" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
'</div>'+
'</div>'+
'</fieldset>'+
'</div>'+
'</div>'+
'<div class="row">'+
'<div class="six columns">'+
'<div class="row">'+
'<div class="four columns">'+
'</div>'+
'<div class="six columns">'+
'<label for="icmp_type"><input type="checkbox" name="icmp_type" value="ICMP" id="icmp_type"> '+ tr("Drop ICMP")+'</label>'+
'</div>'+
'<div class="two columns">'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
return html;
}
function setup_nic_tab_content(nic_section, str_nic_tab_id, str_datatable_id) {
var dataTable_template_networks = $('#'+str_datatable_id, nic_section).dataTable({
"bSortClasses": false,
"bAutoWidth":false,
"iDisplayLength": 4,
"sDom" : '<"H">t<"F"p>',
"oColVis": {
"aiExclude": [ 0 ]
},
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0,6,7,8] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "100px", "aTargets": [2,3,5] },
{ "bVisible": false, "aTargets": [0, 7]}
],
"oLanguage": (datatable_lang != "") ?
{
sUrl: "locale/"+lang+"/"+datatable_lang
} : ""
});
//addElement([spinner,'','','','','','','',''],dataTable_template_networks);
// Retrieve the networks to fill the datatable
OpenNebula.Network.list({
timeout: true,
success: function (request, networks_list){
var network_list_array = [];
$.each(networks_list,function(){
network_list_array.push(vNetworkElementArray(this));
});
updateView(network_list_array, dataTable_template_networks);
},
error: onError
});
$('#'+str_nic_tab_id+'_search', nic_section).keyup(function(){
dataTable_template_networks.fnFilter( $(this).val() );
})
// TBD Add refresh button for the datatable
// When a row is selected the background color is updated. If a previous row
// was selected (previous_row) the background color is removed.
// #IMAGE and #IMAGE_ID inputs are updated using the row information
if (typeof previous_row === 'undefined') {
var previous_row = 0;
}
$('#'+str_datatable_id + ' tbody', nic_section).delegate("tr", "click", function(e){
if ($(e.target).is('input') ||
$(e.target).is('select') ||
$(e.target).is('option')) return true;
var aData = dataTable_template_networks.fnGetData(this);
if (previous_row) {
$("td:first", previous_row).parent().children().each(function(){$(this).removeClass('markrow');});
}
else {
$('#network_selected', nic_section).toggle();
$('#select_network', nic_section).hide();
}
$('.alert-box', nic_section).hide();
previous_row = this;
$("td:first", this).parent().children().each(function(){$(this).addClass('markrow');});
$('#NETWORK', nic_section).text(aData[4]);
$('#NETWORK_ID', nic_section).val(aData[1]);
return false;
});
$('.advanced', nic_section).hide();
$('#advanced', nic_section).click(function(){
$('.advanced', nic_section).toggle();
return false;
});
setupTips(nic_section);
}
// Callback to update the information panel tabs and pop it up
function updateTemplateInfo(request,template){
var template_info = template.VMTEMPLATE;
@@ -1463,234 +1699,19 @@ function setupCreateTemplateDialog(){
var str_datatable_id = 'datatable_template_networks' + number_of_nics;
var html_tab_content = '<li id="'+str_nic_tab_id+'Tab" class="nic wizard_internal_tab">'+
'<div class="row">'+
'<div class="five columns push-seven">'+
'<input id="'+str_nic_tab_id+'_search" type="text" placeholder="Search"/>'+
'</div>'+
'</div>'+
'<table id="'+str_datatable_id+'" class="datatable twelve">'+
'<thead>'+
'<tr>'+
'<th class="check"><input type="checkbox" class="check_all" value=""></input></th>'+
'<th>'+tr("ID")+'</th>'+
'<th>'+tr("Owner")+'</th>'+
'<th>'+tr("Group")+'</th>'+
'<th>'+tr("Name")+'</th>'+
'<th>'+tr("Cluster")+'</th>'+
'<th>'+tr("Type")+'</th>'+
'<th>'+tr("Bridge")+'</th>'+
'<th>'+tr("Leases")+'</th>'+
'</tr>'+
'</thead>'+
'<tbody id="tbodynetworks">'+
'</tbody>'+
'</table>'+
'<br>'+
'<div class="vm_param kvm_opt xen_opt vmware_opt">'+
'<span id="select_network" class="radius secondary label">'+tr("Please select an network from the list")+'</span>'+
'<span id="network_selected" class="radius secondary label hidden">You selected the following image: '+
'</span>'+
'<span class="radius label" type="text" id="NETWORK" name="network"></span>'+
'<input type="hidden" id="NETWORK_ID" name="network_id" size="2"/>'+
'</div>'+
'<hr>'+
'<div class="show_hide" id="advanced">'+
'<h4><small><i class=" icon-plus-sign-alt"/> '+tr("Advanced options")+'<a id="add_os_boot_opts" class="icon_left" href="#"></a></small></h4>'+
'</div>'+
'<div class="advanced">'+
'<div class="row">'+
'<div class="six columns">'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="IP">'+tr("IP")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="IP" name="IP" size="3" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("Request an specific IP from the Network")+'</div>'+
'</div>'+
'</div>'+
'</div>'+
'<div class="six columns">'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="MODEL">'+tr("MODEL")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="MODEL" name="MODEL" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'<div class="row">'+
'<div class="six columns">'+
'<fieldset>'+
'<legend>'+tr("TCP Firewall")+'</legend>'+
'<div class="row">'+
'<div class="four columns push-two">'+
'<input type="radio" name="tcp_type" id="tcp_type" value="WHITE_PORTS_TCP"> Whitelist '+
'</div>'+
'<div class="four columns pull-two">'+
'<input type="radio" name="tcp_type" id="tcp_type" value="BLACK_PORTS_TCP"> Blacklist'+
'</div>'+
'</div>'+
'<br>'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="TCP_PORTS">'+tr("PORTS")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="TCP_PORTS" name="ports" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
'</div>'+
'</div>'+
'</fieldset>'+
'</div>'+
'<div class="six columns">'+
'<fieldset>'+
'<legend>'+tr("UDP Firewall")+'</legend>'+
'<div class="row">'+
'<div class="four columns push-two">'+
'<input type="radio" name="udp_type" id="udp_type" value="WHITE_PORTS_UDP"> Whitelist '+
'</div>'+
'<div class="four columns pull-two">'+
'<input type="radio" name="udp_type" id="udp_type" value="BLACK_PORTS_UDP"> Blacklist'+
'</div>'+
'</div>'+
'<br>'+
'<div class="row">'+
'<div class="four columns">'+
'<label class="right inline" for="UDP_PORTS">'+tr("PORTS")+':</label>'+
'</div>'+
'<div class="six columns">'+
'<input type="text" id="UDP_PORTS" name="ports" />'+
'</div>'+
'<div class="two columns">'+
'<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
'</div>'+
'</div>'+
'</fieldset>'+
'</div>'+
'</div>'+
'<div class="row">'+
'<div class="six columns">'+
'<div class="row">'+
'<div class="four columns">'+
'</div>'+
'<div class="six columns">'+
'<label for="icmp_type"><input type="checkbox" name="icmp_type" value="ICMP" id="icmp_type"> '+ tr("Drop ICMP")+'</label>'+
'</div>'+
'<div class="two columns">'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
generate_nic_tab_content(str_nic_tab_id, str_datatable_id) +
'</li>'
// Append the new div containing the tab and add the tab to the list
var a = $("<dd><a href='#"+str_nic_tab_id+"'>NIC <i class='icon-remove-sign remove-tab'></i></a></dd>").appendTo($("dl#template_create_network_tabs"));
// Append the new div containing the tab and add the tab to the list
var a = $("<dd><a href='#"+str_nic_tab_id+"'>NIC <i class='icon-remove-sign remove-tab'></i></a></dd>").appendTo($("dl#template_create_network_tabs"));
$(html_tab_content).appendTo($("ul#template_create_network_tabs_content"));
$(html_tab_content).appendTo($("ul#template_create_network_tabs_content"));
$(document).foundationTabs("set_tab", a);
$(document).foundationTabs("set_tab", a);
var nic_section = $('li#' + str_nic_tab_id + 'Tab', dialog);
var dataTable_template_networks = $('#'+str_datatable_id, dialog).dataTable({
"bSortClasses": false,
"bAutoWidth":false,
"iDisplayLength": 4,
"sDom" : '<"H">t<"F"p>',
"oColVis": {
"aiExclude": [ 0 ]
},
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0,6,7,8] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "100px", "aTargets": [2,3,5] },
{ "bVisible": false, "aTargets": [0, 7]}
],
"oLanguage": (datatable_lang != "") ?
{
sUrl: "locale/"+lang+"/"+datatable_lang
} : ""
});
//addElement([spinner,'','','','','','','',''],dataTable_template_networks);
// Retrieve the networks to fill the datatable
OpenNebula.Network.list({
timeout: true,
success: function (request, networks_list){
var network_list_array = [];
$.each(networks_list,function(){
network_list_array.push(vNetworkElementArray(this));
});
updateView(network_list_array, dataTable_template_networks);
},
error: onError
});
$('#'+str_nic_tab_id+'_search', nic_section).keyup(function(){
dataTable_template_networks.fnFilter( $(this).val() );
})
// TBD Add refresh button for the datatable
// When a row is selected the background color is updated. If a previous row
// was selected (previous_row) the background color is removed.
// #IMAGE and #IMAGE_ID inputs are updated using the row information
if (typeof previous_row === 'undefined') {
var previous_row = 0;
}
$('#'+str_datatable_id + ' tbody', dialog).delegate("tr", "click", function(e){
if ($(e.target).is('input') ||
$(e.target).is('select') ||
$(e.target).is('option')) return true;
var aData = dataTable_template_networks.fnGetData(this);
if (previous_row) {
$("td:first", previous_row).parent().children().each(function(){$(this).removeClass('markrow');});
}
else {
$('#network_selected', nic_section).toggle();
$('#select_network', nic_section).hide();
}
$('.alert-box', nic_section).hide();
previous_row = this;
$("td:first", this).parent().children().each(function(){$(this).addClass('markrow');});
$('#NETWORK', nic_section).text(aData[4]);
$('#NETWORK_ID', nic_section).val(aData[1]);
return false;
});
$('.advanced', nic_section).hide();
$('#advanced', nic_section).click(function(){
$('.advanced', nic_section).toggle();
return false;
});
setupTips(nic_section);
var nic_section = $('li#' + str_nic_tab_id + 'Tab', dialog);
setup_nic_tab_content(nic_section, str_nic_tab_id, str_datatable_id)
number_of_nics++;
nics_index++;
+324 -52
View File
@@ -203,6 +203,15 @@ var vm_actions = {
error: onError
},
"VM.shownics" : {
type: "single",
call: OpenNebula.VM.show,
callback: function(request, vm){
updateVMachineElement(request, vm);
updateVMNicsInfo(request, vm);
},
error: onError
},
"VM.refresh" : {
type: "custom",
call : function (){
@@ -550,6 +559,24 @@ var vm_actions = {
error: onError,
notify: true
},
"VM.attachnic" : {
type: "single",
call: OpenNebula.VM.attachnic,
callback: function(request) {
Sunstone.runAction("VM.shownics", request.request.data[0]);
},
error: onError,
notify: true
},
"VM.detachnic" : {
type: "single",
call: OpenNebula.VM.detachnic,
callback: function(request) {
Sunstone.runAction("VM.shownics", request.request.data[0]);
},
error: onError,
notify: true
},
"VM.help" : {
type: "custom",
call: function() {
@@ -966,11 +993,6 @@ function updateVMachineElement(request, vm_json){
var id = vm_json.VM.ID;
var element = vMachineElementArray(vm_json);
updateSingleElement(element,dataTable_vMachines,'#vm_'+id)
//we update this too, even if it is not shown.
var $hotplugging_tab = $('div#vm_info_panel div#vm_hotplugging_tab');
$('#hotplugging_form',$hotplugging_tab).replaceWith(printDisks(vm_json.VM));
$('tr.at_volatile',$hotplugging_tab).hide();
}
// Callback to delete a single element from the list
@@ -1217,6 +1239,11 @@ function updateVMInfo(request,vm){
content: printDisks(vm_info)
};
var network_tab = {
title: tr("Network"),
content: printNics(vm_info)
};
var template_tab = {
title: tr("VM Template"),
content:
@@ -1343,6 +1370,7 @@ function updateVMInfo(request,vm){
Sunstone.updateInfoPanelTab("vm_info_panel","vm_info_tab",info_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_hotplugging_tab",hotplugging_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_network_tab",network_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_template_tab",template_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_log_tab",log_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_history_tab",history_tab);
@@ -1378,11 +1406,10 @@ function printDisks(vm_info){
<div id="datatable_cluster_vnets_info_div columns twelve">\
<form id="hotplugging_form" vmid="'+vm_info.ID+'" >\
<div class="twelve columns">\
<div id="refresh_disk" class="button small secondary radius" ><i class="icon-refresh"/></div>\
'
<div id="refresh_disk" class="button small secondary radius" ><i class="icon-refresh"/></div>'
// If VM is not RUNNING, then we forget about the attach disk form.
if (vm_info.STATE == "3"){
if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3"){
html += '\
<div id="attach_disk" class="button small secondary radius" >' + tr("Attach new disk") +'</div>'
}
@@ -1426,23 +1453,64 @@ function printDisks(vm_info){
var disk = disks[i];
var save_as;
if (vm_info.STATE == "3" && vm_info.LCM_STATE == "26") {
// Snapshot deferred
if (
( // ACTIVE
vm_info.STATE == "3") &&
( // HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED
vm_info.LCM_STATE == "26" || vm_info.LCM_STATE == "27" || vm_info.LCM_STATE == "28") &&
( //
disk.SAVE_AS_ACTIVE == "YES")
) {
save_as = "in progress";
} else {
actions = 'deferred snapshot in progress'
}
// Snapshot Hot
else if (
( // ACTIVE
vm_info.STATE == "3") &&
( // HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED
vm_info.LCM_STATE == "26" || vm_info.LCM_STATE == "27" || vm_info.LCM_STATE == "28") &&
( //
disk.HOTPLUG_SAVE_AS_ACTIVE == "YES")
) {
save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
actions = 'hot snapshot in progress'
}
// Attach / Detach
else if (
( // ACTIVE
vm_info.STATE == "3") &&
( // HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED
vm_info.LCM_STATE == "17") &&
( //
disk.ATTACH = "YES")
) {
save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
actions = 'attach/detach in progress'
}
else {
save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
actions = '';
if ((vm_info.STATE == "3" && vm_info.LCM_STATE == "3") || vm_info.STATE == "5" || vm_info.STATE == "8") {
actions += '<a href="VM.saveas" class="saveas" ><i class="icon-save"/>'+tr("Snapshot")+'</a> &emsp;'
}
if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3") {
actions += '<a href="VM.detachdisk" class="detachdisk" ><i class="icon-remove"/>'+tr("Detach")+'</a>'
}
}
html += '\
<tr disk_id="'+(disk.DISK_ID)+'">\
<td>' + disk.DISK_ID + '</td>\
<td>' + disk.TARGET + '</td>\
<td>' + (disk.IMAGE ? disk.IMAGE : (disk.FORMAT ? (disk.FORMAT + ' - ') : + humanize_size_from_mb(disk.SIZE))) + '</td>\
<td>' + (disk.IMAGE ? disk.IMAGE : (humanize_size_from_mb(disk.SIZE) + (disk.FORMAT ? (' - ' + disk.FORMAT) : '') )) + '</td>\
<td>' + ((disk.SAVE && disk.SAVE == 'YES' )? tr('YES') : tr('NO')) + '</td>\
<td>' + save_as + '</td>\
<td>\
<a href="VM.saveas" class="saveas" ><i class="icon-save"/>'+tr("Snapshot")+'</a> &emsp;\
<a href="VM.detachdisk" class="detachdisk" ><i class="icon-remove"/>'+tr("Detach")+'</a>\
</td>\
<td>' + actions + '</td>\
</tr>';
}
}
@@ -1663,49 +1731,253 @@ function hotpluggingOps(){
return false;
});
}
$('select#attach_disk_type').live('change',function(){
var context = $(this).parents('form');
switch ($(this).val()){
case "image":
$('tr.at_volatile',context).hide();
$('tr.at_image',context).show();
break;
case "volatile":
$('tr.at_image',context).hide();
$('tr.at_volatile',context).show();
break;
};
});
$('#hotplugging_form').live('submit',function(){
var vm_id = $(this).attr('vmid');
var disk_obj = {};
switch($('select#attach_disk_type',this).val()){
case "image":
var im_id = $('select[name="IMAGE_ID"]',this).val();
if (!im_id) {
notifyError(tr("Please select an image to attach"));
return false;
function updateVMNicsInfo(request,vm){
$("li#vm_network_tabTab").html(printNics(vm.VM));
}
function printNics(vm_info){
var html ='\
<div class="">\
<div>\
<form id="tab_network_form" vmid="'+vm_info.ID+'" >\
<div class="twelve columns">\
<div id="refresh_nic" class="button small secondary radius" ><i class="icon-refresh"/></div>'
// If VM is not RUNNING, then we forget about the attach nic form.
if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3"){
html += '\
<div id="attach_nic" class="button small secondary radius" >' + tr("Attach new nic") +'</div>'
}
html += '\
</div>\
<br>\
<br>'
html += '\
<div class="twelve columns">\
<table class="info_table twelve extended_table">\
<thead>\
<tr>\
<th>'+tr("ID")+'</th>\
<th>'+tr("Network")+'</th>\
<th>'+tr("VLAN")+'</th>\
<th>'+tr("Bridge")+'</th>\
<th>'+tr("IP")+'</th>\
<th>'+tr("MAC")+'</th>\
<th colspan="">'+tr("Actions")+'</th>\
</tr>\
</thead>\
<tbody>';
var nics = []
if ($.isArray(vm_info.TEMPLATE.NIC))
nics = vm_info.TEMPLATE.NIC
else if (!$.isEmptyObject(vm_info.TEMPLATE.NIC))
nics = [vm_info.TEMPLATE.NIC]
if (!nics.length){
html += '\
<tr id="no_nics_tr">\
<td colspan="6">' + tr("No nics to show") + '</td>\
</tr>';
}
else {
for (var i = 0; i < nics.length; i++){
var nic = nics[i];
var save_as;
// Attach / Detach
if (
( // ACTIVE
vm_info.STATE == "3") &&
( // HOTPLUG_NIC
vm_info.LCM_STATE == "25") &&
( //
nic.ATTACH == "YES")
) {
actions = 'attach/detach in progress'
}
disk_obj.IMAGE_ID = $('select[name="IMAGE_ID"]',this).val();
disk_obj.DEV_PREFIX = $('input[name="DEV_PREFIX"]',this).val();
break;
case "volatile":
disk_obj.SIZE = $('input[name="SIZE"]',this).val();
disk_obj.FORMAT = $('input[name="FORMAT"]',this).val();
disk_obj.TYPE = $('select[name="TYPE"]',this).val();
disk_obj.DEV_PREFIX = $('input[name="DEV_PREFIX"]',this).val();
// disk_obj.READONLY = $('select[name="READONLY"]',this).val();
// disk_obj.SAVE = $('save[name="SAVE"]',this).val();
break;
}
else {
actions = '';
var obj = { DISK : disk_obj };
Sunstone.runAction("VM.attachdisk", vm_id, obj);
if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3") {
actions += '<a href="VM.detachnic" class="detachnic" ><i class="icon-remove"/>'+tr("Detach")+'</a>'
}
}
html += '\
<tr nic_id="'+(nic.NIC_ID)+'">\
<td>' + nic.NIC_ID + '</td>\
<td>' + nic.NETWORK + '</td>\
<td>' + nic.VLAN + '</td>\
<td>' + nic.BRIDGE + '</td>\
<td>' + nic.IP + '</td>\
<td>' + nic.MAC + '</td>\
<td>' + actions + '</td>\
</tr>';
}
}
html += '\
</tbody>\
</table>\
</div>\
</form>';
return html;
}
function setupAttachNicDialog(){
dialogs_context.append('<div id="attach_nic_dialog"></div>');
$attach_nic_dialog = $('#attach_nic_dialog',dialogs_context);
var dialog = $attach_nic_dialog;
dialog.html('<div class="panel">\
<h3>\
<small id="">'+tr("Attach new nic")+'</small>\
</h3>\
</div>\
<form id="attach_nic_form" action="">\
<div class="row centered">\
<div class="four columns">\
<label class="inline right" for="vm_id">'+tr("Virtual Machine ID")+':</label>\
</div>\
<div class="seven columns">\
<input type="text" name="vm_id" id="vm_id" disabled/>\
</div>\
<div class="one columns">\
<div class=""></div>\
</div>\
</div>' +
generate_nic_tab_content("attach_nic", "attach_nic") +
'<hr>\
<div class="form_buttons">\
<button class="button radius right success" id="attach_nic_button" type="submit" value="VM.attachnic">'+tr("Attach")+'</button>\
<button class="close-reveal-modal button secondary radius" type="button" value="close">' + tr("Close") + '</button>\
</div>\
<a class="close-reveal-modal">&#215;</a>\
</form>')
dialog.addClass("reveal-modal large");
setupTips(dialog);
setup_nic_tab_content(dialog, "attach_nic", "attach_nic")
$('#attach_nic_form',dialog).submit(function(){
var vm_id = $('#vm_id', this).val();
var data = {};
addSectionJSON(data, this);
var obj = {NIC: data}
Sunstone.runAction('VM.attachnic', vm_id, obj);
$attach_nic_dialog.trigger("reveal:close")
return false;
});
};
function popUpAttachNicDialog(vm_id){
$('#vm_id',$attach_nic_dialog).val(vm_id);
$attach_nic_dialog.reveal();
}
// Listeners to the nics operations (detach, saveas, attach)
function setup_vm_network_tab(){
//setupSaveAsDialog();
setupAttachNicDialog();
$('a.detachnic').live('click', function(){
var b = $(this);
var vm_id = b.parents('form').attr('vmid');
var nic_id = b.parents('tr').attr('nic_id');
Sunstone.runAction('VM.detachnic', vm_id, nic_id);
//b.html(spinner);
return false;
});
$('#attach_nic').live('click', function(){
var b = $(this);
var vm_id = b.parents('form').attr('vmid');
popUpAttachNicDialog(vm_id);
//b.html(spinner);
return false;
});
$('#refresh_nic').live('click', function(){
var b = $(this);
var vm_id = b.parents('form').attr('vmid');
Sunstone.runAction("VM.shownics", vm_id);
return false;
});
}
// Sets up the create-template dialog and all the processing associated to it,
// which is a lot.
@@ -1946,8 +2218,8 @@ $(document).ready(function(){
setVMAutorefresh();
setupVNC();
hotpluggingOps();
setup_vm_network_tab();
setupSaveAsDialog
initCheckAllBoxes(dataTable_vMachines);
tableCheckboxesListener(dataTable_vMachines);