diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb index 8c682c4f3c..50795da235 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb @@ -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 diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 3491eccccb..0ddb5eb957 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -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, diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 371bfe495e..2b61650fbc 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -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 = '
'+ + '
'+ + ''+ + '
'+ + '
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Cluster")+''+tr("Type")+''+tr("Bridge")+''+tr("Leases")+'
'+ + '
'+ + '
'+ + ''+tr("Please select an network from the list")+''+ + ''+ + ''+ + ''+ + '
'+ + '
'+ + '
'+ + '

'+tr("Advanced options")+'

'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+tr("Request an specific IP from the Network")+'
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+tr("TCP Firewall")+''+ + '
'+ + '
'+ + ' Whitelist '+ + '
'+ + '
'+ + ' Blacklist'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+tr("UDP Firewall")+''+ + '
'+ + '
'+ + ' Whitelist '+ + '
'+ + '
'+ + ' Blacklist'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'; + + 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 = '
  • '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Cluster")+''+tr("Type")+''+tr("Bridge")+''+tr("Leases")+'
    '+ - '
    '+ - '
    '+ - ''+tr("Please select an network from the list")+''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - '
    '+ - '

    '+tr("Advanced options")+'

    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '
    '+tr("Request an specific IP from the Network")+'
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '
    '+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+tr("TCP Firewall")+''+ - '
    '+ - '
    '+ - ' Whitelist '+ - '
    '+ - '
    '+ - ' Blacklist'+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '
    '+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+tr("UDP Firewall")+''+ - '
    '+ - '
    '+ - ' Whitelist '+ - '
    '+ - '
    '+ - ' Blacklist'+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '
    '+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ - '
    '+ + generate_nic_tab_content(str_nic_tab_id, str_datatable_id) + '
  • ' - // Append the new div containing the tab and add the tab to the list - var a = $("
    NIC
    ").appendTo($("dl#template_create_network_tabs")); + // Append the new div containing the tab and add the tab to the list + var a = $("
    NIC
    ").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++; diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 031c6ccc80..1d435c02d8 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -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){
    \
    \
    \ -
    \ - ' +
    ' // 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 += '\
    ' + tr("Attach new disk") +'
    ' } @@ -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 += ''+tr("Snapshot")+'  ' + } + + if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3") { + actions += ''+tr("Detach")+'' + } } html += '\ \ ' + disk.DISK_ID + '\ ' + disk.TARGET + '\ - ' + (disk.IMAGE ? disk.IMAGE : (disk.FORMAT ? (disk.FORMAT + ' - ') : + humanize_size_from_mb(disk.SIZE))) + '\ + ' + (disk.IMAGE ? disk.IMAGE : (humanize_size_from_mb(disk.SIZE) + (disk.FORMAT ? (' - ' + disk.FORMAT) : '') )) + '\ ' + ((disk.SAVE && disk.SAVE == 'YES' )? tr('YES') : tr('NO')) + '\ ' + save_as + '\ - \ - '+tr("Snapshot")+'  \ - '+tr("Detach")+'\ - \ + ' + actions + '\ '; } } @@ -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 ='\ +
    \ +
    \ + \ +
    \ +
    ' + + // If VM is not RUNNING, then we forget about the attach nic form. + if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3"){ + html += '\ +
    ' + tr("Attach new nic") +'
    ' + } + + html += '\ +
    \ +
    \ +
    ' + + html += '\ +
    \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + + + 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 += '\ + \ + \ + '; + } + 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 += ''+tr("Detach")+'' + } + } + + html += '\ + \ + \ + \ + \ + \ + \ + \ + \ + '; + } + } + + html += '\ + \ +
    '+tr("ID")+''+tr("Network")+''+tr("VLAN")+''+tr("Bridge")+''+tr("IP")+''+tr("MAC")+''+tr("Actions")+'
    ' + tr("No nics to show") + '
    ' + nic.NIC_ID + '' + nic.NETWORK + '' + nic.VLAN + '' + nic.BRIDGE + '' + nic.IP + '' + nic.MAC + '' + actions + '
    \ +
    \ + '; + + return html; +} + +function setupAttachNicDialog(){ + dialogs_context.append('
    '); + $attach_nic_dialog = $('#attach_nic_dialog',dialogs_context); + var dialog = $attach_nic_dialog; + + dialog.html('
    \ +

    \ + '+tr("Attach new nic")+'\ +

    \ +
    \ +
    \ +
    \ +
    \ + \ +
    \ +
    \ + \ +
    \ +
    \ +
    \ +
    \ +
    ' + + generate_nic_tab_content("attach_nic", "attach_nic") + + '
    \ +
    \ + \ + \ +
    \ + ×\ +
    ') + + 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);