]> git.proxmox.com Git - novnc-pve.git/blobdiff - pveui.js
detect vm migration and reconnect
[novnc-pve.git] / pveui.js
index 2837f93d3448b58127dff4f1d358aa5e5371daf3..9a689f277eab5083d8323f0cf93521ea9abdc99a 100644 (file)
--- a/pveui.js
+++ b/pveui.js
@@ -22,6 +22,7 @@ Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
 var UI = {
 
 rfb_state : 'loaded',
+pveAllowMigratedVMTest: false, // set to true after a succesful conection 
 pveCommandsOpen: false,
 settingsOpen : false,
 connSettingsOpen : false,
@@ -145,6 +146,36 @@ pve_show_msg: function(klass, msg, permanant) {
     }, 5000);
 },
 
+pve_detect_migrated_vm: function() {
+    if (!(UI.consoletype === 'kvm' || UI.consoletype === 'openvz')) {
+       return;
+    }
+
+    // try to detect migrated VM
+    UI.API2Request({
+       url: '/cluster/resources',
+       method: 'GET',
+       success: function(result) {
+           var list = result.data;
+           list.every(function(item) {
+               if ((item.type === 'qemu' || item.type === 'openvz') && 
+                   (item.vmid == UI.vmid)) {
+                   var url = "?" + UI.urlEncode({
+                       console: UI.consoletype,
+                       novnc: 1,
+                       vmid: UI.vmid,
+                       vmname: UI.vmname,
+                       node: item.node
+                   });
+                   location.href = url;        
+                   return false; // break
+               }
+               return true;
+           });
+       }
+    });
+},
 pve_vm_command: function(cmd, params, reload) {
     var baseUrl;
 
@@ -327,7 +358,6 @@ pve_start: function(callback) {
            el.style.width = "100%";
            el.style.minWidth = "150px";
            cmdpanel.appendChild(el);
-           console.log("ADD: " + btn.text);
        }
     });
 
@@ -1147,10 +1177,15 @@ updateState: function(rfb, state, oldstate, msg) {
             break;
         case 'normal':
             klass = "noVNC_status_normal";
+           UI.pveAllowMigratedVMTest = true;
             break;
         case 'disconnected':
             $D('noVNC_logo').style.display = "block";
-            // Fall through
+           if (UI.pveAllowMigratedVMTest) {
+               UI.pveAllowMigratedVMTest = false;
+               UI.pve_detect_migrated_vm();
+           }
+           // Fall through
         case 'loaded':
             klass = "noVNC_status_normal";
             break;