NodeSelector.js 2.11 KB
Newer Older
1 2 3 4 5 6 7
Ext.define('PVE.form.NodeSelector', {
    extend: 'PVE.form.ComboGrid',
    alias: ['widget.PVE.form.NodeSelector'],

    // invalidate nodes which are offline
    onlineValidator: false,

8 9
    selectCurNode: false,

10 11 12
    // only allow those nodes (array)
    allowedNodes: undefined,

13 14 15 16
    initComponent: function() {
	var me = this;

	var store = Ext.create('Ext.data.Store', {
17
	    fields: [ 'node', 'cpu', 'maxcpu', 'mem', 'maxmem', 'uptime' ],
18 19 20 21 22 23
	    autoLoad: true,
	    proxy: {
		type: 'pve',
		url: '/api2/json/nodes'
	    },
	    sorters: [
24 25 26 27
		{
		    property : 'node',
		    direction: 'ASC'
		},
28 29 30
		{
		    property : 'mem',
		    direction: 'DESC'
Dietmar Maurer's avatar
Dietmar Maurer committed
31
		}
32 33 34 35 36
	    ]
	});

	Ext.apply(me, {
	    store: store,
37 38
	    valueField: 'node',
	    displayField: 'node',
39 40 41
            listConfig: {
		columns: [
		    {
Damien PIQUET's avatar
Damien PIQUET committed
42
			header: gettext('Node'),
43
			dataIndex: 'node',
44
			sortable: true,
45 46 47 48
			hideable: false,
			flex: 1
		    },
		    {
Damien PIQUET's avatar
Damien PIQUET committed
49
			header: gettext('Memory usage'),			
50
			renderer: PVE.Utils.render_mem_usage,
51
			sortable: true,
52 53 54 55
			width: 100,
			dataIndex: 'mem'
		    },
		    {
Damien PIQUET's avatar
Damien PIQUET committed
56
			header: gettext('CPU usage'),
57 58 59 60 61 62 63 64 65 66 67 68 69 70
			renderer: PVE.Utils.render_cpu,
			sortable: true,
			width: 100,
			dataIndex: 'cpu'
		    }
		]
	    },
	    validator: function(value) {
		/*jslint confusion: true */
		if (!me.onlineValidator || (me.allowBlank && !value)) {
		    return true;
		}
		
		var offline = [];
71 72
		var notAllowed = [];

73 74 75 76
		Ext.Array.each(value.split(/\s*,\s*/), function(node) {
		    var rec = me.store.findRecord(me.valueField, node);
		    if (!(rec && rec.data) || !Ext.isNumeric(rec.data.mem)) {
			offline.push(node);
77 78 79
		    } else if (me.allowedNodes && !Ext.Array.contains(me.allowedNodes, node)) {
			notAllowed.push(node);
		    }
80 81
		});

82
		if (notAllowed.length !== 0) {
83
		    return "Node " + notAllowed.join(', ') + " is not allowed for this action!";
84
		} 
85

86 87 88 89
		if (offline.length !== 0) {
		    return "Node " + offline.join(', ') + " seems to be offline!";
		}
		return true;
90 91 92
	    }
	});

93
        if (me.selectCurNode && PVE.curSelectedNode.data.node) {
Dietmar Maurer's avatar
Dietmar Maurer committed
94
            me.preferredValue = PVE.curSelectedNode.data.node;
95 96
        }

97 98
        me.callParent();
    }
99
});