[Kimchi-devel] [PATCH] UI: Use capabilities cached values on 'Host PCI Device' tab

Royce Lv lvroyce at linux.vnet.ibm.com
Fri Dec 5 08:38:57 UTC 2014


Reviewed-by: Royce Lv<lvroyce at linux.vnet.ibm.com>
On 2014年11月04日 20:38, Aline Manera wrote:
> Kimchi capabilities are cached on UI to avoid multiples request to it as
> those values does not change with high frequency.
> So use the cached values to check host has kernel_vfio capability.
>
> Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> ---
>   ui/js/src/kimchi.guest_edit_main.js | 132 ++++++++++++++++++------------------
>   1 file changed, 65 insertions(+), 67 deletions(-)
>
> diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
> index 9d87a73..359add8 100644
> --- a/ui/js/src/kimchi.guest_edit_main.js
> +++ b/ui/js/src/kimchi.guest_edit_main.js
> @@ -360,77 +360,75 @@ kimchi.guest_edit_main = function() {
>       var setupPCIDevice = function(){
>           kimchi.getHostPCIDevices(function(hostPCIs){
>               kimchi.getVMPCIDevices(kimchi.selectedGuest, function(vmPCIs){
> -                kimchi.getCapabilities(function(result) {
> -                    var pciEnabled = result.kernel_vfio;
> -                    for(var i=0; i<hostPCIs.length; i++){
> -                        var itemNode = $.parseHTML(kimchi.substitute($('#pci-tmpl').html(),{
> -                            name: hostPCIs[i].name,
> -                            product: hostPCIs[i].product.description,
> -                            vendor: hostPCIs[i].vendor.description
> -                        }));
> -                        $(".body", "#form-guest-edit-pci").append(itemNode);
> -                        var iconClass = "ui-icon-plus";
> -                        for(var j=0; j<vmPCIs.length; j++){
> -                            if(hostPCIs[i].name==vmPCIs[j].name){
> -                                iconClass = "ui-icon-minus";
> -                                break;
> -                            }
> +                var pciEnabled = kimchi.capabilities.kernel_vfio;
> +                for(var i=0; i<hostPCIs.length; i++){
> +                    var itemNode = $.parseHTML(kimchi.substitute($('#pci-tmpl').html(),{
> +                        name: hostPCIs[i].name,
> +                        product: hostPCIs[i].product.description,
> +                        vendor: hostPCIs[i].vendor.description
> +                    }));
> +                    $(".body", "#form-guest-edit-pci").append(itemNode);
> +                    var iconClass = "ui-icon-plus";
> +                    for(var j=0; j<vmPCIs.length; j++){
> +                        if(hostPCIs[i].name==vmPCIs[j].name){
> +                            iconClass = "ui-icon-minus";
> +                            break;
>                           }
> -                        pciEnabled || $("button", itemNode).remove();
> -                        $("button", itemNode).button({
> -                            icons: { primary: iconClass },
> -                            text: false
> -                        }).click(function(){
> -                            var obj = $(this);
> -                            if(obj.button("option", "icons").primary == "ui-icon-minus"){
> -                                kimchi.removeVMPCIDevice(kimchi.selectedGuest, obj.parent().prop("id"), function(){
> -                                    kimchi.getVMPCIDevices(kimchi.selectedGuest, function(vmPCIs1){
> -                                        for(var k=0; k<hostPCIs.length; k++) {
> -                                            $("button", "#" + hostPCIs[k].name).button("option", "icons", {primary: "ui-icon-plus"});
> -                                        }
> -                                        for(var k=0; k<vmPCIs1.length; k++) {
> -                                            $("button", "#" + vmPCIs1[k].name).button("option", "icons", {primary: "ui-icon-minus"});
> -                                        }
> -                                    });
> -                                    filterNodes($("select", "#form-guest-edit-pci").val(), $("input", "#form-guest-edit-pci").val());
> +                    }
> +                    pciEnabled || $("button", itemNode).remove();
> +                    $("button", itemNode).button({
> +                        icons: { primary: iconClass },
> +                        text: false
> +                    }).click(function(){
> +                        var obj = $(this);
> +                        if(obj.button("option", "icons").primary == "ui-icon-minus"){
> +                            kimchi.removeVMPCIDevice(kimchi.selectedGuest, obj.parent().prop("id"), function(){
> +                                kimchi.getVMPCIDevices(kimchi.selectedGuest, function(vmPCIs1){
> +                                    for(var k=0; k<hostPCIs.length; k++) {
> +                                        $("button", "#" + hostPCIs[k].name).button("option", "icons", {primary: "ui-icon-plus"});
> +                                    }
> +                                    for(var k=0; k<vmPCIs1.length; k++) {
> +                                        $("button", "#" + vmPCIs1[k].name).button("option", "icons", {primary: "ui-icon-minus"});
> +                                    }
>                                   });
> -                            }else{
> -                                kimchi.addVMPCIDevice(kimchi.selectedGuest, { name: obj.parent().prop("id") }, function(){
> -                                    kimchi.getVMPCIDevices(kimchi.selectedGuest, function(vmPCIs1){
> -                                        for(var k=0; k<vmPCIs1.length; k++) {
> -                                            $("button", "#" + vmPCIs1[k].name).button("option", "icons", {primary: "ui-icon-minus"});
> -                                        }
> -                                    });
> -                                    filterNodes($("select", "#form-guest-edit-pci").val(), $("input", "#form-guest-edit-pci").val());
> +                                filterNodes($("select", "#form-guest-edit-pci").val(), $("input", "#form-guest-edit-pci").val());
> +                            });
> +                        } else {
> +                            kimchi.addVMPCIDevice(kimchi.selectedGuest, { name: obj.parent().prop("id") }, function(){
> +                                kimchi.getVMPCIDevices(kimchi.selectedGuest, function(vmPCIs1){
> +                                    for(var k=0; k<vmPCIs1.length; k++) {
> +                                        $("button", "#" + vmPCIs1[k].name).button("option", "icons", {primary: "ui-icon-minus"});
> +                                    }
>                                   });
> +                                filterNodes($("select", "#form-guest-edit-pci").val(), $("input", "#form-guest-edit-pci").val());
> +                            });
> +                        }
> +                    });
> +                    kimchi.getPCIDeviceCompanions(hostPCIs[i].name, function(infoData) {
> +                        var pciTitle = i18n["KCHVMED6007M"] + "\n";
> +                        var haveCompanions = false;
> +                        for(var p=0; p<infoData.length; p++) {
> +                            if(infoData[p].device_type === "net") {
> +                                haveCompanions = true;
> +                                pciTitle += "   " + infoData[p].name + "\n";
> +                                pciTitle += "      " + i18n["KCHVMED6001M"] + " " + infoData[p].interface;
> +                                pciTitle += ", " + i18n["KCHVMED6002M"] + " " + infoData[p].address;
> +                                pciTitle += ", " + i18n["KCHVMED6003M"] + " " + infoData[p].link_type + "\n";
> +                            } else if(infoData[p].device_type === "storage") {
> +                                haveCompanions = true;
> +                                pciTitle += "   " + infoData[p].name + "\n";
> +                                pciTitle += "      " + i18n["KCHVMED6004M"] + " " + infoData[p].block;
> +                                pciTitle += ", " + i18n["KCHVMED6005M"] + " " + infoData[p].drive_type;
> +                                pciTitle += ", " + i18n["KCHVMED6006M"] + " " + infoData[p].model + "\n";
>                               }
> -                        });
> -                        kimchi.getPCIDeviceCompanions(hostPCIs[i].name, function(infoData) {
> -                            var pciTitle = i18n["KCHVMED6007M"] + "\n";
> -                            var haveCompanions = false;
> -                            for(var p=0; p<infoData.length; p++) {
> -                                if(infoData[p].device_type === "net") {
> -                                    haveCompanions = true;
> -                                    pciTitle += "   " + infoData[p].name + "\n";
> -                                    pciTitle += "      " + i18n["KCHVMED6001M"] + " " + infoData[p].interface;
> -                                    pciTitle += ", " + i18n["KCHVMED6002M"] + " " + infoData[p].address;
> -                                    pciTitle += ", " + i18n["KCHVMED6003M"] + " " + infoData[p].link_type + "\n";
> -                                } else if(infoData[p].device_type === "storage") {
> -                                    haveCompanions = true;
> -                                    pciTitle += "   " + infoData[p].name + "\n";
> -                                    pciTitle += "      " + i18n["KCHVMED6004M"] + " " + infoData[p].block;
> -                                    pciTitle += ", " + i18n["KCHVMED6005M"] + " " + infoData[p].drive_type;
> -                                    pciTitle += ", " + i18n["KCHVMED6006M"] + " " + infoData[p].model + "\n";
> -                                }
> -                            }
> -                            for(var q=0; q<infoData.length; q++) {
> -                                haveCompanions && $(".name", "#" + infoData[q].parent).attr("title", pciTitle);
> -                                haveCompanions && $(".product", "#" + infoData[q].parent).attr("title", pciTitle);
> -                                haveCompanions && $(".vendor", "#" + infoData[q].parent).attr("title", pciTitle);
> -                            }
> -                        });
> -                    }
> -                });
> +                        }
> +                        for(var q=0; q<infoData.length; q++) {
> +                            haveCompanions && $(".name", "#" + infoData[q].parent).attr("title", pciTitle);
> +                            haveCompanions && $(".product", "#" + infoData[q].parent).attr("title", pciTitle);
> +                            haveCompanions && $(".vendor", "#" + infoData[q].parent).attr("title", pciTitle);
> +                        }
> +                    });
> +                }
>               });
>           });
>           var filterNodes = function(group, text){




More information about the Kimchi-devel mailing list