- Instead of checking the companion for each device (with performance
penalties when opening the Edit Guest window) we now check for
companions before plugging a device to a guest. Then, we popup
a confirmation window showing devices affected by such action and
asks for user confirmation.
Signed-off-by: Jose Ricardo Ziviani <joserz(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.guest_edit_main.js | 74 ++++++++++++++++++++++---------------
ui/pages/i18n.json.tmpl | 1 +
2 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
index cabd497..9099f39 100644
--- a/ui/js/src/kimchi.guest_edit_main.js
+++ b/ui/js/src/kimchi.guest_edit_main.js
@@ -467,30 +467,6 @@ kimchi.guest_edit_main = function() {
if (kimchi.thisVMState === "running" && device.vga3d) {
$('button', deviceHtml).prop("disabled", true);
}
- kimchi.getPCIDeviceCompanions(device.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);
- }
- });
device = deviceHtml[0].outerHTML;
$('.body', '#form-guest-edit-pci').append(device);
});
@@ -565,12 +541,50 @@ kimchi.guest_edit_main = function() {
wok.message.error(err.responseJSON.reason,
'#alert-modal-container');
});
} else {
- kimchi.addVMPCIDevice(kimchi.selectedGuest, {
- name: id
- }, function(task) {
- getOngoingAttachingDevices(task);
- }, function(err) {
- wok.message.error(err.responseJSON.reason,
'#alert-modal-container');
+ kimchi.getPCIDeviceCompanions(id, 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';
+ }
+ }
+ var settings = {
+ title: i18n['KCHVMED6012M'],
+ content: pciTitle,
+ confirm: i18n['KCHAPI6002M'],
+ cancel: i18n['KCHAPI6003M']
+ };
+
+ if (haveCompanions) {
+ wok.confirm(settings, function() {
+ kimchi.addVMPCIDevice(kimchi.selectedGuest, {
+ name: id
+ }, function(task) {
+ getOngoingAttachingDevices(task);
+ }, function(err) {
+ wok.message.error(err.responseJSON.reason,
'#alert-modal-container');
+ });
+ });
+ } else {
+ kimchi.addVMPCIDevice(kimchi.selectedGuest, {
+ name: id
+ }, function(task) {
+ getOngoingAttachingDevices(task);
+ }, function(err) {
+ wok.message.error(err.responseJSON.reason,
'#alert-modal-container');
+ });
+ }
});
}
});
diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl
index 610debc..a5185b1 100644
--- a/ui/pages/i18n.json.tmpl
+++ b/ui/pages/i18n.json.tmpl
@@ -86,6 +86,7 @@
"KCHVMED6009M": "$_("Less")",
"KCHVMED6010M": "$_("Successfully attached device to
VM")",
"KCHVMED6011M": "$_("Successfully detached device from
VM")",
+ "KCHVMED6012M": "$_("Following devices will be affected,
confirm?")",
"KCHNET6001M": "$_("unavailable")",
"KCHNET6002M": "$_("This action will interrupt network
connectivity for any virtual machine that depend on this network.")",
--
2.7.4