[Kimchi-devel] [PATCH] UI: CPU Topology

Christy Perez christy at linux.vnet.ibm.com
Thu Nov 20 21:20:22 UTC 2014


I was able to test this out, and it looks okay, but isn't quite what
we'd discussed. Here are some things that need tweaking:

1. Remove the 'sockets' field completely. It's actually pretty
meaningless in practice. It will still need to be passed in to create a
template -- just not displayed to the user.
2. Make sure the vcpus count becomes a product of threads and cores when
the box is checked. Right now, no matter what I change, it stays '1.'

On 11/20/2014 05:16 AM, huoyuxin at linux.vnet.ibm.com wrote:
> From: Yu Xin Huo <huoyuxin at linux.vnet.ibm.com>
> 
> Signed-off-by: Yu Xin Huo <huoyuxin at linux.vnet.ibm.com>
> ---
>  ui/css/theme-default/template-edit.css |   24 ++++++++++++++++++++++-
>  ui/js/src/kimchi.api.js                |   14 +++++++++++++
>  ui/js/src/kimchi.template_edit_main.js |   33 +++++++++++++++++++++++++++++++-
>  ui/pages/template-edit.html.tmpl       |   17 ++++++++++++---
>  4 files changed, 82 insertions(+), 6 deletions(-)
> 
> diff --git a/ui/css/theme-default/template-edit.css b/ui/css/theme-default/template-edit.css
> index 094e909..2231dc6 100644
> --- a/ui/css/theme-default/template-edit.css
> +++ b/ui/css/theme-default/template-edit.css
> @@ -142,4 +142,26 @@
> 
>  #edit-template-tabs .hide {
>      display: none;
> -}
> \ No newline at end of file
> +}
> +
> +#form-template-processor select,
> +#form-template-processor input[type="text"] {
> +    margin-left: 10px;
> +}
> +
> +#form-template-processor input[type="checkbox"] {
> +    margin-right: 5px;
> +}
> +
> +#form-template-processor .manual {
> +    margin-top: 10px;
> +    margin-left: -3px;
> +}
> +
> +#form-template-processor .topology {
> +    margin: 10px 30px;
> +}
> +
> +#form-template-processor .topology div {
> +    margin-bottom: 10px;
> +}
> diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
> index 78c6d66..7a239c0 100644
> --- a/ui/js/src/kimchi.api.js
> +++ b/ui/js/src/kimchi.api.js
> @@ -1260,5 +1260,19 @@ var kimchi = {
>                  kimchi.message.error(data.responseJSON.reason);
>              }
>          });
> +    },
> +
> +    getCPUInfo : function(suc, err) {
> +        kimchi.requestJSON({
> +            url : kimchi.url + 'host/cpuinfo',
> +            type : 'GET',
> +            contentType : 'application/json',
> +            dataType : 'json',
> +            resend : true,
> +            success : suc,
> +            error : err ? err : function(data) {
> +                kimchi.message.error(data.responseJSON.reason);
> +            }
> +        });
>      }
>  };
> diff --git a/ui/js/src/kimchi.template_edit_main.js b/ui/js/src/kimchi.template_edit_main.js
> index d4e19c2..bba4415 100644
> --- a/ui/js/src/kimchi.template_edit_main.js
> +++ b/ui/js/src/kimchi.template_edit_main.js
> @@ -200,8 +200,33 @@ kimchi.template_edit_main = function() {
>                  });
>              });
>          };
> +        var initProcessor = function(){
> +            $("input:text", "#form-template-processor").on('keyup', function(){
> +                $(this).toggleClass("invalid-field", !$(this).val().match('^[0-9]*$'));
> +            });
> +            $("input:checkbox", "#form-template-processor").click(function(){
> +                $(".topology", "#form-template-processor").toggleClass("hide", !$(this).prop("checked"));
> +                $("#cpu").attr("disabled", $(this).prop("checked"));
> +            });
> +            kimchi.getCPUInfo(function(data){
> +                var options = "";
> +                for(var i=0;Math.pow(2,i)<=data.threads_per_core;i++){
> +                    var lastOne = Math.pow(2,i+1)>data.threads_per_core?" selected":"";
> +                    options += "<option"+lastOne+">"+Math.pow(2,i)+"</option>";
> +                }
> +                $('select', '#form-template-processor').append(options);
> +                if(template.cpus) $("#cpu").val(template.cpus);
> +                if(template.cpu_info.sockets) $("#sockets").val(template.cpu_info.sockets);
> +                if(template.cpu_info.cores) $("#cores").val(template.cpu_info.cores);
> +                if(template.cpu_info.threads){
> +                    $('select', '#form-template-processor').val(template.cpu_info.threads);
> +                    $("input:checkbox", "#form-template-processor").trigger('click');
> +                }
> +            });
> +        };
>          kimchi.listNetworks(initInterface);
>          kimchi.listStoragePools(initStorage);
> +        initProcessor();
>      };
>      kimchi.retrieveTemplate(kimchi.selectedTemplate, initTemplate);
> 
> @@ -241,7 +266,13 @@ kimchi.template_edit_main = function() {
>              }
>          });
>          data['memory'] = Number(data['memory']);
> -        data['cpus']   = Number(data['cpus']);
> +        data['cpus']   = parseInt($('#cpu').val());
> +        if($("input:checkbox", "#form-template-processor").prop("checked"))
> +            data['cpu_info'] = {
> +                sockets: parseInt($("#sockets").val()),
> +                cores: parseInt($("#cores").val()),
> +                threads: parseInt($("#threads").val()),
> +            };
>          var networks = $('.template-tab-body .item', '#form-template-interface');
>          var networkForUpdate = new Array();
>          $.each(networks, function(index, networkEntities) {
> diff --git a/ui/pages/template-edit.html.tmpl b/ui/pages/template-edit.html.tmpl
> index 90a6256..47c3979 100644
> --- a/ui/pages/template-edit.html.tmpl
> +++ b/ui/pages/template-edit.html.tmpl
> @@ -40,6 +40,9 @@
>                  <li>
>                      <a href="#form-template-interface">$_("Interface")</a>
>                  </li>
> +                <li>
> +                    <a href="#form-template-processor">$_("Processor")</a>
> +                </li>
>              </ul>
>              <form id="form-template-general">
>                  <div class="form-template-inline-wrapper">
> @@ -53,9 +56,6 @@
>                          <label for="template-edit-version-textbox">$_("Version")</label>
>                      </div>
>                      <div class="template-edit-wrapper-label">
> -                        <label for="template-edit-cpu-textbox">$_("CPU Number")</label>
> -                    </div>
> -                    <div class="template-edit-wrapper-label">
>                          <label for="template-edit-memory-textbox">$_("Memory (MB)")</label>
>                      </div>
>                      <div class="template-edit-wrapper-label templ-edit-cdrom">
> @@ -120,6 +120,15 @@
>                  </div>
>                  <div class="template-tab-body"></div>
>              </form>
> +            <form id="form-template-processor">
> +                <div>$_("CPU Number"):<input type="text" value="1" id="cpu"></div>
> +                <div class="manual"><input type="checkbox">$_("Manually set CPU topology")</div>
> +                <div class="topology hide">
> +                    <div>$_("Sockets"):<input type="text" value="1"  id="sockets"></div>
> +                    <div>$_("Cores"):<input type="text" value="1"  id="cores"></div>
> +                    <div>$_("Threads"):<select id="threads"></select></div>
> +                </div>
> +            </form>
>          </div>
>      </div>
>      <footer>
> @@ -157,4 +166,4 @@
>              <button class="delete"></button>
>          </span>
>      </div>
> -</script>
> \ No newline at end of file
> +</script>
> 




More information about the Kimchi-devel mailing list