1 Ext
.define('proxmox-networks', {
2 extend
: 'Ext.data.Model',
4 'iface', 'type', 'active', 'autostart',
5 'bridge_ports', 'slaves',
6 'address', 'netmask', 'gateway',
7 'address6', 'netmask6', 'gateway6',
14 Ext
.define('Proxmox.node.NetworkView', {
15 extend
: 'Ext.panel.Panel',
17 alias
: ['widget.proxmoxNodeNetworkView'],
19 // defines what types of network devices we want to create
20 // order is always the same
21 types
: ['bridge', 'bond', 'ovs'],
25 initComponent : function() {
29 throw "no node name specified";
32 var baseUrl
= '/nodes/' + me
.nodename
+ '/network';
34 var store
= Ext
.create('Ext.data.Store', {
35 model
: 'proxmox-networks',
38 url
: '/api2/json' + baseUrl
48 var reload = function() {
49 var changeitem
= me
.down('#changes');
50 var apply_btn
= me
.down('#apply');
51 var revert_btn
= me
.down('#revert');
52 Proxmox
.Utils
.API2Request({
54 failure: function(response
, opts
) {
56 Proxmox
.Utils
.setErrorMask(me
, response
.htmlStatus
);
57 changeitem
.update('');
58 changeitem
.setHidden(true);
60 success: function(response
, opts
) {
61 var result
= Ext
.decode(response
.responseText
);
62 store
.loadData(result
.data
);
63 var changes
= result
.changes
;
64 if (changes
=== undefined || changes
=== '') {
65 changes
= gettext("No changes");
66 changeitem
.setHidden(true);
67 apply_btn
.setDisabled(true);
68 revert_btn
.setDisabled(true);
70 changeitem
.update("<pre>" + Ext
.htmlEncode(changes
) + "</pre>");
71 changeitem
.setHidden(false);
72 apply_btn
.setDisabled(false);
73 revert_btn
.setDisabled(false);
79 var run_editor = function() {
80 var grid
= me
.down('gridpanel');
81 var sm
= grid
.getSelectionModel();
82 var rec
= sm
.getSelection()[0];
87 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
88 nodename
: me
.nodename
,
89 iface
: rec
.data
.iface
,
93 win
.on('destroy', reload
);
96 var edit_btn
= new Ext
.Button({
97 text
: gettext('Edit'),
102 var del_btn
= new Ext
.Button({
103 text
: gettext('Remove'),
106 var grid
= me
.down('gridpanel');
107 var sm
= grid
.getSelectionModel();
108 var rec
= sm
.getSelection()[0];
113 var iface
= rec
.data
.iface
;
115 Proxmox
.Utils
.API2Request({
116 url
: baseUrl
+ '/' + iface
,
119 callback: function() {
122 failure: function(response
, opts
) {
123 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
129 var apply_btn
= Ext
.create('Proxmox.button.Button', {
130 text
: gettext('Apply Configuration'),
133 confirmMsg
: 'Do you want to apply pending network changes?',
134 hidden
: !me
.showApplyBtn
,
135 handler: function() {
136 Proxmox
.Utils
.API2Request({
140 success: function(response
, opts
) {
141 var upid
= response
.result
.data
;
143 var win
= Ext
.create('Proxmox.window.TaskProgress', {
149 failure: function(response
, opts
) {
150 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
156 var set_button_status = function() {
157 var grid
= me
.down('gridpanel');
158 var sm
= grid
.getSelectionModel();
159 var rec
= sm
.getSelection()[0];
161 edit_btn
.setDisabled(!rec
);
162 del_btn
.setDisabled(!rec
);
165 var render_ports = function(value
, metaData
, record
) {
166 if (value
=== 'bridge') {
167 return record
.data
.bridge_ports
;
168 } else if (value
=== 'bond') {
169 return record
.data
.slaves
;
170 } else if (value
=== 'OVSBridge') {
171 return record
.data
.ovs_ports
;
172 } else if (value
=== 'OVSBond') {
173 return record
.data
.ovs_bonds
;
177 var find_next_iface_id = function(prefix
) {
179 for (next
= 0; next
<= 9999; next
++) {
180 if (!store
.getById(prefix
+ next
.toString())) {
184 return prefix
+ next
.toString();
189 if (me
.types
.indexOf('bridge') !== -1) {
191 text
: Proxmox
.Utils
.render_network_iface_type('bridge'),
192 handler: function() {
193 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
194 nodename
: me
.nodename
,
196 iface_default
: find_next_iface_id('vmbr')
198 win
.on('destroy', reload
);
204 if (me
.types
.indexOf('bond') !== -1) {
206 text
: Proxmox
.Utils
.render_network_iface_type('bond'),
207 handler: function() {
208 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
209 nodename
: me
.nodename
,
211 iface_default
: find_next_iface_id('bond')
213 win
.on('destroy', reload
);
219 if (me
.types
.indexOf('ovs') !== -1) {
220 if (menu_items
.length
> 0) {
221 menu_items
.push({ xtype
: 'menuseparator' });
226 text
: Proxmox
.Utils
.render_network_iface_type('OVSBridge'),
227 handler: function() {
228 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
229 nodename
: me
.nodename
,
231 iface_default
: find_next_iface_id('vmbr')
233 win
.on('destroy', reload
);
238 text
: Proxmox
.Utils
.render_network_iface_type('OVSBond'),
239 handler: function() {
240 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
241 nodename
: me
.nodename
,
243 iface_default
: find_next_iface_id('bond')
245 win
.on('destroy', reload
);
250 text
: Proxmox
.Utils
.render_network_iface_type('OVSIntPort'),
251 handler: function() {
252 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
253 nodename
: me
.nodename
,
256 win
.on('destroy', reload
);
263 var renderer_generator = function(fieldname
) {
264 return function(val
, metaData
, rec
) {
266 if (rec
.data
[fieldname
]) {
267 tmp
.push(rec
.data
[fieldname
]);
269 if (rec
.data
[fieldname
+ '6']) {
270 tmp
.push(rec
.data
[fieldname
+ '6']);
272 return tmp
.join('<br>') || '';
280 text
: gettext('Create'),
287 text
: gettext('Revert'),
289 handler: function() {
290 Proxmox
.Utils
.API2Request({
294 callback: function() {
297 failure: function(response
, opts
) {
298 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
312 stateId
: 'grid-node-network',
318 header
: gettext('Name'),
323 header
: gettext('Type'),
326 renderer
: Proxmox
.Utils
.render_network_iface_type
,
330 xtype
: 'booleancolumn',
331 header
: gettext('Active'),
335 trueText
: Proxmox
.Utils
.yesText
,
336 falseText
: Proxmox
.Utils
.noText
,
337 undefinedText
: Proxmox
.Utils
.noText
,
340 xtype
: 'booleancolumn',
341 header
: gettext('Autostart'),
344 dataIndex
: 'autostart',
345 trueText
: Proxmox
.Utils
.yesText
,
346 falseText
: Proxmox
.Utils
.noText
,
347 undefinedText
: Proxmox
.Utils
.noText
350 xtype
: 'booleancolumn',
351 header
: gettext('VLAN aware'),
354 dataIndex
: 'bridge_vlan_aware',
355 trueText
: Proxmox
.Utils
.yesText
,
356 falseText
: Proxmox
.Utils
.noText
,
357 undefinedText
: Proxmox
.Utils
.noText
360 header
: gettext('Ports/Slaves'),
362 renderer
: render_ports
365 header
: gettext('Bond Mode'),
366 dataIndex
: 'bond_mode',
367 renderer
: Proxmox
.Utils
.render_bond_mode
,
370 header
: gettext('Hash Policy'),
372 dataIndex
: 'bond_xmit_hash_policy',
375 header
: gettext('IP address'),
379 dataIndex
: 'address',
380 renderer
: renderer_generator('address'),
383 header
: gettext('Subnet mask'),
387 dataIndex
: 'netmask',
388 renderer
: renderer_generator('netmask'),
391 header
: gettext('CIDR'),
395 renderer
: renderer_generator('cidr'),
398 header
: gettext('Gateway'),
401 dataIndex
: 'gateway',
402 renderer
: renderer_generator('gateway'),
405 header
: gettext('Comment'),
406 dataIndex
: 'comments',
408 renderer
: Ext
.String
.htmlEncode
412 selectionchange
: set_button_status
,
413 itemdblclick
: run_editor
423 gettext('Pending changes') + ' (' +
424 gettext('Please reboot or apply to activate changes') + ')'
429 html
: gettext("No changes")