diff --git a/src/sunstone/public/app/opennebula/host.js b/src/sunstone/public/app/opennebula/host.js index 7508e17864..0b2fce090a 100644 --- a/src/sunstone/public/app/opennebula/host.js +++ b/src/sunstone/public/app/opennebula/host.js @@ -1,6 +1,7 @@ define(function(require) { var OpenNebulaAction = require('./action'); var Locale = require('utils/locale'); + var OpenNebulaError = require('./error'); var RESOURCE = "HOST"; @@ -83,6 +84,33 @@ define(function(require) { }, "getName": function(id){ return OpenNebulaAction.getName(id, RESOURCE); + }, + "pciDevices": function(params){ + var callback = params.success; + var callback_error = params.error; + + $.ajax({ + url: "infrastructure", + type: "GET", + dataType: "json", + success: function(response) { + var pcis = response.pci_devices; + + if (pcis == undefined){ + pcis = []; + } + + if (!$.isArray(pcis)){ // If only 1 convert to array + pcis = [pcis]; + } + + return callback ? callback(pcis) : null; + }, + error: function(response) { + return callback_error ? + callback_error(OpenNebulaError(response)) : null; + } + }); } } diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js index 29fdb925c8..6dfb44cf09 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js @@ -9,6 +9,7 @@ define(function(require) { var WizardFields = require('utils/wizard-fields'); var TemplateUtils = require('utils/template-utils'); var CustomTagsTable = require('utils/custom-tags-table'); + var OpenNebulaHost = require('opennebula/host'); /* TEMPLATES @@ -75,10 +76,46 @@ define(function(require) { context.off("click", ".add_pci"); context.on("click", ".add_pci", function(){ - $(".pci_devices tbody", context).append(RowTemplateHTML()); + var tr = $(RowTemplateHTML()).appendTo( $(".pci_devices tbody", context) ); + + OpenNebulaHost.pciDevices({ + data : {}, + timeout: true, + success: function (pciDevices){ + var html = "'; + + $(".device_name", tr).html(html); + }, + error: function(error_json){ + console.error("There was an error requesting the PCI devices: "+ + error_json.error.message); + + $(".device_name", tr).html(""); + } + }); }); - $(".add_pci", context).trigger("click"); + context.on("change", ".pci_devices td.device_name select", function(){ + var tr = $(this).closest('tr'); + + var option = $("option:selected", this); + + $('input[wizard_field="DEVICE"]', tr).val( option.attr("device") ); + $('input[wizard_field="CLASS"]', tr).val( option.attr("class") ); + $('input[wizard_field="VENDOR"]', tr).val( option.attr("vendor") ); + }); context.on("click", ".pci_devices i.remove-tab", function(){ var tr = $(this).closest('tr'); @@ -127,8 +164,20 @@ define(function(require) { $(".pci_devices i.remove-tab", context).trigger("click"); - $.each(templateJSON['PCI'], function(i, pci){ - var tr = $(RowTemplateHTML()).appendTo( $(".pci_devices tbody", context) ); + var pcis = templateJSON['PCI']; + + if (pcis == undefined){ + pcis = []; + } + + if (!$.isArray(pcis)){ // If only 1 convert to array + pcis = [pcis]; + } + + $.each(pcis, function(i, pci){ + $(".add_pci", context).trigger("click"); + var tr = $('.pci_devices tbody tr', context).last(); + WizardFields.fill(tr, pci); }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/html.hbs index 9b17897feb..f749602bc2 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/html.hbs @@ -38,6 +38,7 @@ + @@ -48,7 +49,7 @@ - + diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index dc89c2159b..2325ace73e 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -458,6 +458,38 @@ post '/config' do [204, ""] end +get '/infrastructure' do + serveradmin_client = $cloud_auth.client(nil, session[:active_zone_endpoint]) + + hpool = OpenNebula::HostPool.new(serveradmin_client) + + rc = hpool.info + + if OpenNebula.is_error?(rc) + logger.error { rc.message } + error 500, "" + end + + set = Set.new + + xml = XMLElement.new + xml.initialize_xml(hpool.to_xml, 'HOST_POOL') + xml.each('HOST/HOST_SHARE/PCI_DEVICES/PCI') do |pci| + set.add({ + :device => pci['DEVICE'], + :class => pci['CLASS'], + :vendor => pci['VENDOR'], + :device_name => pci['DEVICE_NAME'] + }) + end + + infrastructure = { + :pci_devices => set.to_a + } + + [200, infrastructure.to_json] +end + get '/vm/:id/log' do @SunstoneServer.get_vm_log(params[:id]) end
{{tr "Device name"}} {{tr "Vendor"}} {{tr "Device"}} {{tr "Class"}}
+ {{tr "Add PCI device"}} diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/pciRow.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/pciRow.hbs index f633fb0faf..edfef7888b 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/pciRow.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other/pciRow.hbs @@ -1,4 +1,7 @@
+ +