[Kimchi-devel] [PATCH][Kimchi] Test if CPU value is higher than Max CPU before request

Socorro Stoppler socorro at linux.vnet.ibm.com
Wed Apr 6 19:21:24 UTC 2016


Reviewed-by: Socorro Stoppler <socorro at linux.vnet.ibm.com>
Tested-by: Socorro Stoppler <socorro at linux.vnet.ibm.com>


On 04/06/2016 11:42 AM, Rodrigo Trujillo wrote:
> This patch does two modifications in Kimchi UI behavior:
> - Change "CPUs" by "Current CPUs" in Guest edit window in order to make
>    it similar to other windows and widgets, like Template edit;
> - Add a CPU checking in the UI before send server request to update the
>    guest. We know that CPU cannot be higher than Max CPU and backend is
>    going to raise an error, so, to avoid waste of resources, warn the user
>    when he/she clicks on Save button and do not perform the request.
>
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
>   ui/js/src/kimchi.guest_edit_main.js | 7 +++++++
>   ui/pages/guest-edit.html.tmpl       | 2 +-
>   ui/pages/i18n.json.tmpl             | 1 +
>   3 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
> index 7a9c754..ef6d650 100644
> --- a/ui/js/src/kimchi.guest_edit_main.js
> +++ b/ui/js/src/kimchi.guest_edit_main.js
> @@ -752,6 +752,13 @@ kimchi.guest_edit_main = function() {
>               return;
>           }
>
> +        // Test CPU values before submit. Avoid requests we know are going to fail
> +        if ($('#guest-edit-cores-textbox').val() > $('#guest-edit-max-processor-textbox').val()) {
> +            wok.message.error(i18n['KCHVM0003E'], '#alert-modal-container');
> +            $(saveButton).prop('disabled', false);
> +            return;
> +        }
> +
>           if (data['vcpus'] !== undefined) {
>               var cpu = Number(data['vcpus']);
>               var maxCpu = Number(data['max-processor']);
> diff --git a/ui/pages/guest-edit.html.tmpl b/ui/pages/guest-edit.html.tmpl
> index 05d0b14..5b7155a 100644
> --- a/ui/pages/guest-edit.html.tmpl
> +++ b/ui/pages/guest-edit.html.tmpl
> @@ -45,7 +45,7 @@
>                       <input id="guest-edit-id-textbox" class="form-control" name="name" type="text" />
>                   </div>
>                   <div class="form-group">
> -                    <label for="guest-edit-cores-textbox">$_("CPUs")</label>
> +                    <label for="guest-edit-cores-textbox">$_("Current CPUs")</label>
>                       <div id="guest-processor">
>                           <input id="guest-edit-cores-textbox" class="form-control" name="vcpus" type="number" min="1" />
>                           <button id="guest-show-max-processor" class="btn btn-primary" type="button"><i class="fa fa-plus-circle"></i> <span class="cputext">$_("More")</span></button>
> diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl
> index 153d7c2..24abeb6 100644
> --- a/ui/pages/i18n.json.tmpl
> +++ b/ui/pages/i18n.json.tmpl
> @@ -67,6 +67,7 @@
>
>       "KCHVM0001E": "$_("Input is not a number")",
>       "KCHVM0002E": "$_("Memory value cannot be higher then Max Memory value")",
> +    "KCHVM0003E": "$_("Current CPUs value cannot be higher then Max CPU value")",
>
>       "KCHVMCD6001M": "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")",
>       "KCHVMCD6003M": "$_("Attaching...")",




More information about the Kimchi-devel mailing list