[Kimchi-devel] [PATCH] Initial checkin for live migration UI support

Socorro Stoppler socorro at linux.vnet.ibm.com
Wed Nov 25 23:04:04 UTC 2015


Signed-off-by: Socorro Stoppler <socorro at linux.vnet.ibm.com>
---
 src/wok/plugins/ginger                             |  2 +-
 src/wok/plugins/kimchi/ui/js/src/kimchi.api.js     |  3 +-
 .../plugins/kimchi/ui/js/src/kimchi.guest_main.js  | 46 ++++++++++++++-
 .../kimchi/ui/pages/guest-migration.html.tmpl      | 65 ++++++++++++++++++++++
 src/wok/plugins/kimchi/ui/pages/guest.html.tmpl    |  1 +
 5 files changed, 113 insertions(+), 4 deletions(-)
 create mode 100644 src/wok/plugins/kimchi/ui/pages/guest-migration.html.tmpl

diff --git a/src/wok/plugins/ginger b/src/wok/plugins/ginger
index a0cc2a3..84f36db 160000
--- a/src/wok/plugins/ginger
+++ b/src/wok/plugins/ginger
@@ -1 +1 @@
-Subproject commit a0cc2a369abf5ec93068924c3b681957d1c82cb3
+Subproject commit 84f36dbbfe63869fa97cd68e9abdeaffdf1846d9
diff --git a/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js b/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js
index cb6aaab..6cc8714 100644
--- a/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js
+++ b/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js
@@ -1045,12 +1045,13 @@ var kimchi = {
         });
     },
 
-    migrateGuest: function(vm, suc, err) {
+    migrateGuest: function(vm, data, suc, err) {
         wok.requestJSON({
             url : 'plugins/kimchi/vms/' + encodeURIComponent(vm) + "/migrate",
             type : 'POST',
             contentType : 'application/json',
             dataType : 'json',
+            data : JSON.stringify(data),
             success : suc,
             error : err ? err : function(data) {
                 wok.message.error(data.responseJSON.reason);
diff --git a/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_main.js b/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_main.js
index eb563fb..6fb461b 100644
--- a/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_main.js
+++ b/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_main.js
@@ -274,8 +274,24 @@ kimchi.listVmsAuto = function() {
         }, null, true);
         return guests;
     };
+    var getMigratingGuests = function(){
+        var guests = [];
+        kimchi.getTasksByFilter('status=running&target_uri='+encodeURIComponent('^/vms/.+/migrate'), function(tasks) {
+            for(var i=0;i<tasks.length;i++){
+                var guestUri = tasks[i].target_uri;
+                var guestName = guestUri.split('/')[4]
+                guests.push($.extend({}, kimchi.sampleGuestObject, {name: guestName, isMigrating: true}));
+                if(kimchi.trackingTasks.indexOf(tasks[i].id)==-1)
+                    kimchi.trackTask(tasks[i].id, null, function(err){
+                        wok.message.error(err.message);
+                    }, null);
+            }
+        }, null, true);
+        return guests;
+    };
     kimchi.listVMs(function(result, textStatus, jqXHR) {
         if (result && textStatus=="success") {
+            result = getMigratingGuests().concat(result);            
             result = getCloningGuests().concat(result);
             result = getCreatingGuests().concat(result);
             if(result.length) {
@@ -308,7 +324,27 @@ kimchi.listVmsAuto = function() {
 
 kimchi.createGuestLi = function(vmObject, prevScreenImage, openMenu) {
     var result=kimchi.guestElem.clone();
+
+    var initializeMigratePanel = function() {
+        $("#migrateFormOk").on("click", function() {
+            //TODO:  Get values from UI for remote_host, user, password
+            var data = {
+                    "remote_host" : "ltc-hab1.aus.stglabs.ibm.com",
+                    "user" : "root",
+                    "password" : "passw0rd"
+            };
+            //TODO:  Need to get guest to be passed in here               
+            kimchi.migrateGuest(guest, data, function(){
+                kimchi.listVmsAuto();
+                wok.window.close();
+                }, function(err) {
+                    wok.message.error(err.responseJSON.reason);               
+            });    
+        });
+    }
     
+    initializeMigratePanel();
+
     //Setup the VM list entry
     var vmRunningBool=(vmObject.state=="running");
     var vmSuspendedBool = (vmObject.state=="paused");
@@ -342,7 +378,7 @@ kimchi.createGuestLi = function(vmObject, prevScreenImage, openMenu) {
     imgLoad.attr('src',load_src);
 
     //Link the stopped tile to the start action, the running tile to open the console, and the paused tile to resume
-    if(!(vmObject.isCloning || vmObject.isCreating)){
+    if(!(vmObject.isCloning || vmObject.isCreating || vmObject.isMigrating)){
         if (vmPoweredOffBool) {
             liveTile.off("click", kimchi.openVmConsole);
  	    liveTile.off("click", kimchi.vmresume);
@@ -419,7 +455,7 @@ kimchi.createGuestLi = function(vmObject, prevScreenImage, openMenu) {
     }
 
     //Setup action event handlers
-    if(!(vmObject.isCloning || vmObject.isCreating)){
+    if(!(vmObject.isCloning || vmObject.isCreating || vmObject.isMigrating)){
         guestActions.find("[name=vm-start]").on({click : kimchi.vmstart});
         guestActions.find("[name=vm-poweroff]").on({click : kimchi.vmpoweroff});
         if ((vmRunningBool) || (vmSuspendedBool)) {  
@@ -453,6 +489,10 @@ kimchi.createGuestLi = function(vmObject, prevScreenImage, openMenu) {
                 });
             }, null);
         });
+        guestActions.find("[name=vm-migrate]").click(function(){
+            var guest = $(this).closest('li[name=guest]').attr("id");
+            wok.window.open('plugins/kimchi/guest-migration.html');
+        });       
 
         //Maintain menu open state
         var actionMenu=guestActions.find("div[name=actionmenu]");
@@ -468,6 +508,8 @@ kimchi.createGuestLi = function(vmObject, prevScreenImage, openMenu) {
         pendingText = result.find('.guest-pending .text')
         if(vmObject.isCloning)
             pendingText.text(i18n['KCHAPI6009M']);
+        else if(vmObject.isMigrating)
+            pendingText.text("Migrating");
         else
             pendingText.text(i18n['KCHAPI6008M']);
     }
diff --git a/src/wok/plugins/kimchi/ui/pages/guest-migration.html.tmpl b/src/wok/plugins/kimchi/ui/pages/guest-migration.html.tmpl
new file mode 100644
index 0000000..278d22c
--- /dev/null
+++ b/src/wok/plugins/kimchi/ui/pages/guest-migration.html.tmpl
@@ -0,0 +1,65 @@
+#*
+ * Project Kimchi
+ *
+ * Copyright IBM, Corp. 2015
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *#
+#unicode UTF-8
+#import gettext
+#from wok.cachebust import href
+#silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang, fallback=True)
+#silent _ = t.gettext
+#silent _t = t.gettext
+<div id="migrate-guest-window" class="window modal-content">
+    <div class="modal-header">
+        <h4 class="modal-title" id="migrateModalLabel">$_("Migrate a Guest")</h4>
+    </div>
+    <div id="migrateInfo" class="modal-body">
+         <div class="alert alert-warning" role="alert">Disclaimer: This process cannot be stopped after started,
+            can take a long time to complete and will turn off the VM on this Hypervisor when it is successfully
+            migrated to the remote destination.
+        </div>
+         <div class="form-group">
+            <label for="remoteHostName">$_("Remote Server")</label>
+            <input type="text" class="form-control" id="remoteHostName" />
+            <p class="help-block">
+                <i class="fa fa-info-circle"></i> $_("IP Address or Hostname")</p>
+        </div>
+        <div class="alert alert-info" role="alert">The following fields are optional. Fill them if you want Kimchi to
+            setup a password-less ssh session between the localhost and the remote host. The setup process will only 
+            be successful if the user has 'SUDO ALL' permission in the remote machine.
+        </div>
+        <div class="form-group">
+            <label for="user">$_("User")</label>
+            <input type="text" class="form-control" id="user" />
+            <p class="help-block">
+                <i class="fa fa-info-circle"></i> $_("Username of the remote host")</p>
+        </div>
+        <div class="form-group">
+            <label for="password">$_("Password")</label>
+            <input type="password" class="form-control" id="password" />
+            <p class="help-block">
+                <i class="fa fa-info-circle"></i> $_("Password of the user in the remote host")</p>
+        </div>
+        <div class="form-group">
+            <input id="deleteVM" class="wok-checkbox" type="checkbox" value="" />
+            <label for="deleteVM" id="labelDeleteVM">$_("Delete this VM when the migration is completed") </label>
+        </div>
+    </div>
+    <div class="modal-footer">
+        <button type="submit" id="migrateFormOk" class="btn btn-default">$_("Start")</button>
+        <button type="button" id="migrateFormCancel" data-dismiss="modal" class="btn btn-default">$_("Cancel")</button>
+    </div>
+</div>
+
diff --git a/src/wok/plugins/kimchi/ui/pages/guest.html.tmpl b/src/wok/plugins/kimchi/ui/pages/guest.html.tmpl
index 4aba5ad..56145a2 100644
--- a/src/wok/plugins/kimchi/ui/pages/guest.html.tmpl
+++ b/src/wok/plugins/kimchi/ui/pages/guest.html.tmpl
@@ -65,6 +65,7 @@
                         <div class="popover actionsheet right-side" style="width: 250px">
                             <button class="button-big shutoff-disabled" name="vm-console" ><span class="text">$_("Connect")</span></button>
                             <button class="button-big running-disabled" name="vm-clone"><span class="text">$_("Clone")</span></button>
+                            <button class="button-big" name="vm-migrate"><span class="text">$_("Migrate")</span></button>
                             <button class="button-big" name="vm-edit"><span class="text">$_("Edit")</span></button>
                             <button class="button-big shutoff-hidden non-persistent-disabled" name="vm-reset"><span class="text">$_("Reset")</span></button>
 			    <button class="button-big pause-hidden non-persistent-disabled" name="vm-pause"><span class="text">$_("Pause")</span></button>
-- 
1.9.1




More information about the Kimchi-devel mailing list