]> git.proxmox.com Git - novnc-pve.git/blobdiff - pveui.js
replace s/openvz/lxc/
[novnc-pve.git] / pveui.js
index 7890cf008b38664d427b5f46f625fe0af1c17177..b4bae6277dd759a2bffb71049c607a114aca1697 100644 (file)
--- a/pveui.js
+++ b/pveui.js
@@ -4,7 +4,8 @@
  * Copyright (C) 2013 Samuel Mannehed for Cendio AB
  * Licensed under MPL 2.0 (see LICENSE.txt)
  *
- * See README.md for usage and integration instructions.
+ * This is a modified version of the original 'ui.js' file, used
+ * for the proxmox console.
  */
 
 "use strict";
@@ -21,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,
@@ -144,13 +146,43 @@ pve_show_msg: function(klass, msg, permanant) {
     }, 5000);
 },
 
+pve_detect_migrated_vm: function() {
+    if (!(UI.consoletype === 'kvm' || UI.consoletype === 'lxc')) {
+       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 === 'lxc') && 
+                   (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;
 
     if (UI.consoletype === 'kvm') {
        baseUrl = '/nodes/' + UI.nodename + '/qemu/' + UI.vmid;
-    } else if (UI.consoletype === 'openvz') {
-       baseUrl = '/nodes/' + UI.nodename + '/openvz/' + UI.vmid;
+    } else if (UI.consoletype === 'lxc') {
+       baseUrl = '/nodes/' + UI.nodename + '/lxc/' + UI.vmid;
     } else {
        throw "unknown VM type";
     }
@@ -283,17 +315,17 @@ pve_start: function(callback) {
        {
            text: gettext('Start'), 
            handler: UI.pveCmdStart,
-           enable: { kvm: 1, openvz: 1 }
+           enable: { kvm: 1, lxc: 1 }
        },
        {
            text: gettext('Shutdown'), 
            handler: UI.pveCmdShutdown,
-           enable: { kvm: 1, openvz: 1 }
+           enable: { kvm: 1, lxc: 1 }
        },
        {
            text: gettext('Stop'),
            handler: UI.pveCmdStop,
-           enable: { kvm: 1, openvz: 1 }
+           enable: { kvm: 1, lxc: 1 }
        },
        {
            text: gettext('Reset'),
@@ -326,7 +358,6 @@ pve_start: function(callback) {
            el.style.width = "100%";
            el.style.minWidth = "150px";
            cmdpanel.appendChild(el);
-           console.log("ADD: " + btn.text);
        }
     });
 
@@ -440,8 +471,8 @@ pve_start: function(callback) {
        if (UI.vmname) {
            title += " ('" + UI.vmname + "')";
        }
-    } else if (UI.consoletype === 'openvz') {
-       var baseUrl = '/nodes/' + UI.nodename + '/openvz/' + UI.vmid;
+    } else if (UI.consoletype === 'lxc') {
+       var baseUrl = '/nodes/' + UI.nodename + '/lxc/' + UI.vmid;
        url =  baseUrl + '/vncproxy';
        wsurl = baseUrl + '/vncwebsocket';
        title = "CT " + UI.vmid;
@@ -473,7 +504,7 @@ pve_start: function(callback) {
        });
 
        UI.updateSetting('host', window.location.hostname);
-       UI.updateSetting('port', window.location.port);
+       UI.updateSetting('port', window.location.port || 443);
        UI.updateSetting('password', param.ticket);
        UI.updateSetting('encrypt', true);
        UI.updateSetting('true_color', true);
@@ -1146,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;