1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

Feature #3963: Show PCI device names in template wizard

This commit is contained in:
Carlos Martín 2015-09-03 18:57:38 +02:00
parent c5f614b43c
commit 9a4ea9caeb
5 changed files with 118 additions and 5 deletions

View File

@ -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;
}
});
}
}

View File

@ -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 = "<select>";
html += '<option device="" class="" vendor="">'+Locale.tr("Please select")+'</option>';
$.each(pciDevices, function(i,pci){
html += '<option device="'+pci['device']+'" '+
'class="'+pci['class']+'" '+
'vendor="'+pci['vendor']+'">'+
pci.device_name+
'</option>';
});
html += '</select>';
$(".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);
});

View File

@ -38,6 +38,7 @@
<table class="dataTable pci_devices">
<thead>
<tr>
<th style="width:50%">{{tr "Device name"}}</th>
<th>{{tr "Vendor"}}</th>
<th>{{tr "Device"}}</th>
<th>{{tr "Class"}}</th>
@ -48,7 +49,7 @@
</tbody>
<tfoot>
<tr>
<td colspan="4">
<td colspan="5">
<a type="button" class="add_pci button small small-12 secondary radius">
<i class="fa fa-plus"></i> {{tr "Add PCI device"}}
</a>

View File

@ -1,4 +1,7 @@
<tr>
<td class="device_name">
<i class="fa fa-spinner fa-spin"></i>
</td>
<td>
<input type="text" maxlength="4" wizard_field="VENDOR" value="{{vendor}}">
</td>

View File

@ -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