[Kimchi-devel] [PATCH] [Kimchi 9/9] Edit Guest: block CPU settings when guest is running or paused

dhbarboza82 at gmail.com dhbarboza82 at gmail.com
Thu Nov 24 16:10:14 UTC 2016


From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>

This patch disables all CPU options in the 'Processor'
tab when the guest is running or paused.

Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.guest_edit_main.js | 45 ++++++++++++++++++++++++-------------
 ui/pages/guest-edit.html.tmpl       |  5 ++++-
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
index dbeb5b9..7a0d02f 100644
--- a/ui/js/src/kimchi.guest_edit_main.js
+++ b/ui/js/src/kimchi.guest_edit_main.js
@@ -781,7 +781,18 @@ kimchi.guest_edit_main = function() {
         setupPermission();
         setupPCIDevice();
         setupSnapshot();
+
         kimchi.init_processor_tab(guest.cpu_info, $(saveButton));
+        if ((kimchi.thisVMState === "running") || (kimchi.thisVMState === "paused")) {
+            $('#vcpus').attr("disabled", true);
+            $('#guest-edit-max-processor-textbox').attr("disabled", true);
+            $('#sockets').attr("disabled", true);
+            $('#cores').attr("disabled", true);
+            $('#threads').attr("disabled", true);
+
+            $("#topology-checkbox").hide();
+            $("#settings-readonly-help").removeClass('hidden');
+        }
 
         wok.topic('kimchi/vmCDROMAttached').subscribe(onAttached);
         wok.topic('kimchi/vmCDROMReplaced').subscribe(onReplaced);
@@ -925,22 +936,26 @@ kimchi.guest_edit_main = function() {
             if (maxCpu >= cpu) {
                 maxCpuFinal = maxCpu;
             }
-            if ($("input:checkbox", "#form-edit-processor").prop("checked")) {
-                data['cpu_info'] = {
-                    vcpus: cpu,
-                    maxvcpus: maxCpuFinal,
-                    topology: {
-                        sockets: parseInt($("#sockets").val()),
-                        cores: parseInt($("#cores").val()),
-                        threads: parseInt($("#threads").val())
-                    }
-                };
+            if (kimchi.thisVMState === 'running' || kimchi.thisVMState === 'paused') {
+                data['cpu_info'] = {vcpus: cpu};
             } else {
-                data['cpu_info'] = {
-                    vcpus: cpu,
-                    maxvcpus: maxCpuFinal,
-                    topology: {}
-                };
+                if ($("input:checkbox", "#form-edit-processor").prop("checked")) {
+                    data['cpu_info'] = {
+                        vcpus: cpu,
+                        maxvcpus: maxCpuFinal,
+                        topology: {
+                            sockets: parseInt($("#sockets").val()),
+                            cores: parseInt($("#cores").val()),
+                            threads: parseInt($("#threads").val())
+                        }
+                    };
+                } else {
+                    data['cpu_info'] = {
+                        vcpus: cpu,
+                        maxvcpus: maxCpuFinal,
+                        topology: {}
+                    };
+                }
             }
 
             kimchi.updateVM(kimchi.selectedGuest, data, function() {
diff --git a/ui/pages/guest-edit.html.tmpl b/ui/pages/guest-edit.html.tmpl
index e0e1a5a..61f010f 100644
--- a/ui/pages/guest-edit.html.tmpl
+++ b/ui/pages/guest-edit.html.tmpl
@@ -175,6 +175,9 @@
             </form>
             <form role="tabpanel" class="tab-pane" id="form-edit-processor">
                 <div class="form-group">
+                    <div id="settings-readonly-help" class="hidden">
+                        <b>$_("Unable to edit CPU settings of a running or paused virtual machine.")</b>
+                    </div>
                     <div id="guest-processor">
                         <label for="vcpus">$_("Current CPU Number")</label>
                         <input id="vcpus" class="form-control" name="processor" type="number" min="1" />
@@ -192,7 +195,7 @@
                         </p>
                     </div>
                 </div>
-                <div class="manual form-group">
+                <div class="manual form-group" id="topology-checkbox">
                     <input type="checkbox" class="wok-checkbox" id="cpus-check" />
                     <label for="cpus-check">$_("Manually set CPU topology")</label>
                 </div>
-- 
2.7.4




More information about the Kimchi-devel mailing list