]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
add 'max_{relocate, restart}' fields to UI
[pve-manager.git] / www / manager6 / Utils.js
index 36c551c76401e2265653d0e618dabaab5e4f1000..463a546a9fb8db0cd0e5036045e2f9eb0471892d 100644 (file)
@@ -29,39 +29,14 @@ Ext.Ajax.on('beforerequest', function(conn, options) {
     }
 });
 
-var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
-var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
-var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
-var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
+Ext.define('PVE.Utils', { utilities: {
 
-
-var IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
-var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
-
-var IPV6_REGEXP = "(?:" +
-    "(?:(?:"                                                  + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
-    "(?:(?:"                                         +   "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
-    "(?:(?:(?:"                           + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
-    "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
-    "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
-    "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
-    "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" +                         ")" + IPV6_LS32 + ")|" +
-    "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" +                         ")" + IPV6_H16  + ")|" +
-    "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" +                         ")"             + ")"  +
-    ")";
-
-var IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
-var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
-var IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
-
-var IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
-
-Ext.define('PVE.Utils', { statics: {
-
-    // this class only contains static functions
+    // this singleton contains miscellaneous utilities
 
     toolkit: undefined, // (extjs|touch), set inside Toolkit.js
 
+    bus_match: /^(ide|sata|virtio|scsi)\d+$/,
+
     log_severity_hash: {
        0: "panic",
        1: "alert",
@@ -534,6 +509,7 @@ Ext.define('PVE.Utils', { statics: {
     },
 
     task_desc_table: {
+       diskinit: [ 'Disk', gettext('Initialize GPT') ],
        vncproxy: [ 'VM/CT', gettext('Console') ],
        spiceproxy: [ 'VM/CT', gettext('Console') + ' (Spice)' ],
        vncshell: [ '', gettext('Shell') ],
@@ -985,6 +961,11 @@ Ext.define('PVE.Utils', { statics: {
            }
        }
 
+       // overwrite anything else
+       if (record.data.hastate === 'error') {
+           gridcls = '-offline';
+       }
+
        var fa = '<i class="fa fa-fw x-fa-grid' + gridcls  +  ' fa-' + icon  + '"></i> ';
        return fa + value;
     },
@@ -1015,6 +996,36 @@ Ext.define('PVE.Utils', { statics: {
        return PVE.Utils.format_task_description(type, id);
     },
 
+    /* render functions for new status panel */
+
+    render_usage: function(val) {
+       return (val*100).toFixed(2) + '%';
+    },
+
+    render_cpu_usage: function(val, max) {
+       return Ext.String.format(gettext('{0}% of {1}') +
+           ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
+    },
+
+    render_size_usage: function(val, max) {
+       if (max === 0) {
+           return gettext('N/A');
+       }
+       return (val*100/max).toFixed(2) + '% '+ '(' +
+           Ext.String.format(gettext('{0} of {1}'),
+           PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
+    },
+
+    /* this is different for nodes */
+    render_node_cpu_usage: function(value, record) {
+       return PVE.Utils.render_cpu_usage(value, record.cpus);
+    },
+
+    /* this is different for nodes */
+    render_node_size_usage: function(record) {
+       return PVE.Utils.render_size_usage(record.used, record.total);
+    },
+
     dialog_title: function(subject, create, isAdd) {
        if (create) {
            if (isAdd) {
@@ -1028,7 +1039,7 @@ Ext.define('PVE.Utils', { statics: {
     },
 
     windowHostname: function() {
-       return window.location.hostname.replace(IP6_bracket_match,
+       return window.location.hostname.replace(PVE.Utils.IP6_bracket_match,
             function(m, addr, offset, original) { return addr; });
     },
 
@@ -1188,6 +1199,27 @@ Ext.define('PVE.Utils', { statics: {
        });
     },
 
+    openTreeConsole: function(tree, record, item, index, e) {
+       e.stopEvent();
+       var nodename = record.data.node;
+       var vmid = record.data.vmid;
+       var vmname = record.data.name;
+       if (record.data.type === 'qemu' && !record.data.template) {
+           PVE.Utils.API2Request({
+               url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
+               failure: function(response, opts) {
+                   Ext.Msg.alert('Error', response.htmlStatus);
+               },
+               success: function(response, opts) {
+                   var allowSpice = response.result.data.spice;
+                   PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
+               }
+           });
+       } else if (record.data.type === 'lxc' && !record.data.template) {
+           PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
+       }
+    },
+
     createCmdMenu: function(v, record, item, index, event) {
        event.stopEvent();
        if (!(v instanceof Ext.tree.View)) {
@@ -1219,6 +1251,46 @@ Ext.define('PVE.Utils', { statics: {
        }
 
        menu.showAt(event.getXY());
+    }},
+
+    singleton: true,
+    constructor: function() {
+       var me = this;
+       Ext.apply(me, me.utilities);
+
+       var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
+       var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
+       var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
+       var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
+
+
+       me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
+       me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
+
+       var IPV6_REGEXP = "(?:" +
+           "(?:(?:"                                                  + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
+           "(?:(?:"                                         +   "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
+           "(?:(?:(?:"                           + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
+           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
+           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
+           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
+           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" +                         ")" + IPV6_LS32 + ")|" +
+           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" +                         ")" + IPV6_H16  + ")|" +
+           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" +                         ")"             + ")"  +
+           ")";
+
+       me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
+       me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
+       me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
+
+       me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
+
+       var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
+       me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
+
+       me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
+       me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
+       me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
     }
-}});
+});