<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    Hi Peter,<br>
    <br>
    The API to create a new logical pool from existing VG is:<br>
    <br>
    POST /plugins/kimchi/storagepools {type: logical, name:
    &lt;vg-name&gt;, source: {from_vg: true}}<br>
    <br>
    With this patch the 'from_vg' parameter is not aligned with 'source'
    which is raising an error (see below):<br>
    <br>
    <img src="cid:part1.06050205.02080204@linux.vnet.ibm.com" alt=""><br>
    <img src="cid:part2.07070802.01060303@linux.vnet.ibm.com" alt=""><br>
    <div class="moz-cite-prefix"><br>
      Also when no VG is found in the system the message should be
      updated.<br>
      Instead of "No available partitions found." use "No LVM found in
      the system."<br>
      <br>
      <img src="cid:part3.03040100.02020308@linux.vnet.ibm.com" alt=""><br>
      <br>
      <br>
      On 02/15/2016 08:35 AM, <a class="moz-txt-link-abbreviated" href="mailto:peterpnns@gmail.com">peterpnns@gmail.com</a> wrote:<br>
    </div>
    <blockquote
      cite="mid:1455532544-2984-2-git-send-email-peterpnns@gmail.com"
      type="cite">
      <pre wrap="">From: peterpennings <a class="moz-txt-link-rfc2396E" href="mailto:peterpnns@gmail.com">&lt;peterpnns@gmail.com&gt;</a>

Signed-off-by: peterpennings <a class="moz-txt-link-rfc2396E" href="mailto:peterpnns@gmail.com">&lt;peterpnns@gmail.com&gt;</a>
---
 ui/js/src/kimchi.api.js                  |  13 ++++
 ui/js/src/kimchi.storagepool_add_main.js | 103 +++++++++++++++++++++++++++----
 ui/pages/storagepool-add.html.tmpl       |  39 ++++++++----
 3 files changed, 132 insertions(+), 23 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 3519196..b780875 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -711,6 +711,19 @@ var kimchi = {
         });
     },

+    getHostVgs: function(suc, err) {
+        var url = 'plugins/kimchi/host/vgs/';
+        wok.requestJSON({
+            url : url,
+            type : 'GET',
+            contentType : 'application/json',
+            timeout: 2000,
+            dataType : 'json',
+            success : suc,
+            error : err
+        });
+    },
+
     addVMStorage : function(settings, suc, err) {
         var vm = encodeURIComponent(settings['vm']);
         delete settings['vm'];
diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js
index 0e9654a..a1b2aeb 100644
--- a/ui/js/src/kimchi.storagepool_add_main.js
+++ b/ui/js/src/kimchi.storagepool_add_main.js
@@ -18,6 +18,7 @@

 kimchi.storagepool_add_main = function() {
     kimchi.initStorageAddPage();
+    sessionStorage.clear();
     $('#form-pool-add').on('submit', kimchi.addPool);
     $('#pool-doAdd').on('click', kimchi.addPool);
     // 'pool-doAdd' button starts as disabled.
@@ -126,13 +127,15 @@ kimchi.initStorageAddPage = function() {
     kimchi.listHostPartitions(function(data) {
         if (data.length &gt; 0) {
             var deviceHtml = $('#partitionTmpl').html();
-            var listHtml = '';
+            var listHtml = '&lt;table class="table table-hover"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;device&lt;/th&gt;&lt;th&gt;path&lt;/th&gt;&lt;th&gt;size (GiB)&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
             valid_types = ['part', 'disk', 'mpath'];
             $.each(data, function(index, value) {
                 if (valid_types.indexOf(value.type) !== -1) {
+                    value.size = (value.size / 1000000000).toFixed(2);
                     listHtml += wok.substitute(deviceHtml, value);
                 }
             });
+            listHtml += '&lt;/tbody&gt;&lt;/table&gt;';
             $('.host-partition', '#form-pool-add').html(listHtml);
         } else {
             $('.host-partition').html(i18n['KCHPOOL6011M']);
@@ -143,6 +146,26 @@ kimchi.initStorageAddPage = function() {
         $('.host-partition').addClass('text-help');
     });

+    kimchi.getHostVgs(function(data){
+        if (data.length &gt; 0) {
+            var deviceHtml = $('#existingLvmTmpl').html();
+            var listHtml = '&lt;table class="table table-hover"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;device&lt;/th&gt;&lt;th&gt;size (GiB)&lt;/th&gt;&lt;th&gt;free size (GiB)&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
+            $.each(data, function(index, value) {
+                value.size = (value.size / 1000000000).toFixed(2);
+                value.free = (value.free / 1000000000).toFixed(2);
+                listHtml += wok.substitute(deviceHtml, value);
+            });
+            listHtml += '&lt;/tbody&gt;&lt;/table&gt;';
+            $('.lvm-partition').html(listHtml);
+        } else {
+            $('.lvm-partition').html(i18n['KCHPOOL6011M']);
+            $('.lvm-partition').addClass('text-help');
+        }
+    }, function(err) {
+        $('.lvm-partition').html(i18n['KCHPOOL6013M'] + '&lt;br/&gt;(' + err.responseJSON.reason + ')');
+        $('.lvm-partition').addClass('text-help');
+    });
+
     kimchi.getHostFCDevices(function(data){
         $scsiSelect = $('#scsiAdapter');
         if(data.length&gt;0){
@@ -238,6 +261,14 @@ kimchi.initStorageAddPage = function() {
     });

     $('#poolTypeInputId').change(function() {
+
+        kimchi.cleanLogicalForm();
+        $('#poolId').css("background-color", "#ffffff").attr('readonly', false);
+        $('[name="logicalRadioSelection"]')[1].checked = true;
+        $('.lvm-group').addClass('hidden');
+        $('.disk-group').removeClass('hidden');
+        kimchi.setOldStorageName();
+
         var poolObject = {'dir': ".path-section", 'netfs': '.nfs-section',
                           'iscsi': '.iscsi-section', 'scsi': '.scsi-section',
                           'logical': '.logical-section'};
@@ -265,9 +296,50 @@ kimchi.initStorageAddPage = function() {
     }).change(function(event) {
         $(this).toggleClass("invalid-field",!wok.isServer($(this).val().trim()));
     });
+
+    $('[name="logicalRadioSelection"]').change(function(){
+        kimchi.cleanLogicalForm();
+        kimchi.setOldStorageName();
+        var selectedRadio = ($(this).val());
+        var logicalObject = {'existingLvm' : '.lvm-group', 'rawDisk' : '.disk-group'};
+
+        if(selectedRadio === 'existingLvm') {
+            $('[name="lvmTmplRadioSelection"]').change(function(){
+                $('#poolId').css("background-color", "#EEE").val($(this).val()).attr('readonly', true);
+            });
+        } else {
+            $('#poolId').css("background-color", "#ffffff").attr('readonly', false);
+        }
+
+        $.each(logicalObject, function(type, value) {
+            if(selectedRadio === type){
+                $(value).removeClass('hidden');
+            } else {
+                $(value).addClass('hidden');
+            }
+        });
+    });
+
+    $('#poolId').blur(function() {
+        sessionStorage.setItem('oldStorageName', $('#poolId').val());
+    })
+
     kimchi.setupISCSI();
 };

+kimchi.setOldStorageName = function() {
+    if(sessionStorage.getItem('oldStorageName') !== ''){
+        $('#poolId').val(sessionStorage.getItem('oldStorageName'));
+    } else {
+        $('#poolId').val('');
+    }
+}
+
+kimchi.cleanLogicalForm = function() {
+    $("input[name=devices]").attr('checked', false);
+    $("input[name=lvmTmplRadioSelection]").attr('checked', false);
+}
+
 /* Returns 'true' if all form fields were filled, 'false' if
  * any field is left blank. The function takes into account
  * the current poolType selected.
@@ -288,7 +360,7 @@ kimchi.inputsNotBlank = function() {
         if (!$('#iscsiserverId').val()) { return false; }
         if (!$('#iscsiTargetId').val()) { return false; }
     } else if (poolType === "logical") {
-        if ($("input[name=devices]:checked").length === 0){
+        if ($("input[name=devices]:checked").length === 0 &amp;&amp; $("input[name=lvmTmplRadioSelection]:checked").length === 0){
                     return false;
             }
     }
@@ -351,7 +423,7 @@ kimchi.validateServer = function(serverField) {
 };

 kimchi.validateLogicalForm = function () {
-    if ($("input[name=devices]:checked").length === 0) {
+    if ($("input[name=devices]:checked").length === 0 &amp;&amp; $("input[name=lvmTmplRadioSelection]:checked").length === 0) {
         wok.message.error.code('KCHPOOL6006E');
         return false;
     } else {
@@ -363,21 +435,28 @@ kimchi.addPool = function(event) {
     if (kimchi.validateForm()) {
         var formData = $('#form-pool-add').serializeObject();
         delete formData.authname;
+        delete formData.logicalRadioSelection;
+        delete formData.lvmTmplRadioSelection;
         var poolType = $('#poolTypeInputId').val();
         formData.type = poolType;
         if (poolType === 'dir') {
             formData.path = $('#pathId').val();
         } else if (poolType === 'logical') {
-            var source = {};
-            if (!$.isArray(formData.devices)) {
-                var deviceObj = [];
-                deviceObj[0] =  formData.devices;
-                source.devices = deviceObj;
-            } else {
-                source.devices = formData.devices;
+            var logicalrRadioSelected = $("input[name='logicalRadioSelection']:checked").val();
+            if (logicalrRadioSelected === 'rawDisk') {
+                var source = {};
+                if (!$.isArray(formData.devices)) {
+                    var deviceObj = [];
+                    deviceObj[0] =  formData.devices;
+                    source.devices = deviceObj;
+                } else {
+                    source.devices = formData.devices;
+                }
+                delete formData.devices;
+                formData.source = source;
+            } else if (logicalrRadioSelected === 'existingLvm') {
+                formData.from_vg = true;
             }
-            delete formData.devices;
-            formData.source = source;
         } else if (poolType === 'netfs'){
             var source = {};
             source.path = $('#nfspathId').val();
diff --git a/ui/pages/storagepool-add.html.tmpl b/ui/pages/storagepool-add.html.tmpl
index f7f9b29..b3084fd 100644
--- a/ui/pages/storagepool-add.html.tmpl
+++ b/ui/pages/storagepool-add.html.tmpl
@@ -82,8 +82,18 @@
                         &lt;/div&gt;
                 &lt;/div&gt;
                 &lt;div class="logical-section hidden row"&gt;
-                    &lt;div class="form-group storageType"&gt;
-                        &lt;label&gt;$_("Device path")&lt;/label&gt;
+                    &lt;div&gt;
+                        &lt;input type="radio" class="wok-radio" id="existingLvm" name="logicalRadioSelection" value="existingLvm" /&gt;
+                        &lt;label for="existingLvm"&gt;$_("Create from existing LVM")&lt;/label&gt;
+                        &lt;input type="radio" class="wok-radio" id="rawDisk" name="logicalRadioSelection" value="rawDisk" checked /&gt;
+                        &lt;label for="rawDisk"&gt;$_("Create from raw disk")&lt;/label&gt;
+                    &lt;/div&gt;
+                    &lt;div class="lvm-group hidden"&gt;
+                        &lt;div class="lvm-partition"&gt;
+                            &lt;span class="wok-loading-icon"&gt;&lt;/span&gt;&lt;span&gt;$_("Looking for existing lvms ...")&lt;/span&gt;
+                        &lt;/div&gt;
+                    &lt;/div&gt;
+                    &lt;div class="form-group disk-group storageType"&gt;
                         &lt;div class="host-partition"&gt;
                             &lt;span class="wok-loading-icon"&gt;&lt;/span&gt;&lt;span&gt;$_("Looking for available partitions ...")&lt;/span&gt;
                         &lt;/div&gt;
@@ -156,16 +166,23 @@
     &lt;script&gt;
         kimchi.storagepool_add_main();
     &lt;/script&gt;
+
     &lt;script id="partitionTmpl" type="html/text"&gt;
-    &lt;div&gt;
-        &lt;input type="checkbox" class="wok-checkbox" id="{name}" value="{path}" name="devices"&gt;
-        &lt;label for="{name}"&gt;
-            &lt;div&gt;
-                &lt;span class="device-name"&gt;{name}&lt;/span&gt;
-                &lt;span class="device-path"&gt;{path}&lt;/span&gt;
-            &lt;/div&gt;
-        &lt;/label&gt;
-    &lt;/div&gt;
+    &lt;tr&gt;
+        &lt;td&gt;&lt;input type="checkbox" class="wok-checkbox" id="{name}" value="{path}" name="devices"&gt;&lt;label for="{name}"&gt;&lt;/label&gt;&lt;/td&gt;
+        &lt;td&gt;{name}&lt;/td&gt;
+        &lt;td&gt;{path}&lt;/td&gt;
+        &lt;td&gt;{size}&lt;/td&gt;
+    &lt;/tr&gt;
+    &lt;/script&gt;
+
+    &lt;script id="existingLvmTmpl" type="html/text"&gt;
+    &lt;tr&gt;
+        &lt;td&gt;&lt;input type="radio" class="wok-radio" id="{name}" name="lvmTmplRadioSelection" value="{name}" /&gt;&lt;label for="{name}"&gt;&lt;/label&gt;&lt;/td&gt;
+        &lt;td&gt;{name}&lt;/td&gt;
+        &lt;td&gt;{size}&lt;/td&gt;
+        &lt;td&gt;{free}&lt;/td&gt;
+    &lt;/tr&gt;
     &lt;/script&gt;
 &lt;/body&gt;
 &lt;/html&gt;
</pre>
    </blockquote>
    <br>
  </body>
</html>