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',
13 Ext
.define('Proxmox.node.NetworkView', {
14 extend
: 'Ext.panel.Panel',
16 alias
: ['widget.proxmoxNodeNetworkView'],
18 // defines what types of network devices we want to create
19 // order is always the same
20 types
: ['bridge', 'bond', 'ovs'],
22 initComponent : function() {
26 throw "no node name specified";
29 var baseUrl
= '/nodes/' + me
.nodename
+ '/network';
31 var store
= Ext
.create('Ext.data.Store', {
32 model
: 'proxmox-networks',
35 url
: '/api2/json' + baseUrl
45 var reload = function() {
46 var changeitem
= me
.down('#changes');
47 Proxmox
.Utils
.API2Request({
49 failure: function(response
, opts
) {
51 Proxmox
.Utils
.setErrorMask(me
, response
.htmlStatus
);
52 changeitem
.update('');
53 changeitem
.setHidden(true);
55 success: function(response
, opts
) {
56 var result
= Ext
.decode(response
.responseText
);
57 store
.loadData(result
.data
);
58 var changes
= result
.changes
;
59 if (changes
=== undefined || changes
=== '') {
60 changes
= gettext("No changes");
61 changeitem
.setHidden(true);
63 changeitem
.update("<pre>" + Ext
.htmlEncode(changes
) + "</pre>");
64 changeitem
.setHidden(false);
70 var run_editor = function() {
71 var grid
= me
.down('gridpanel');
72 var sm
= grid
.getSelectionModel();
73 var rec
= sm
.getSelection()[0];
78 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
79 nodename
: me
.nodename
,
80 iface
: rec
.data
.iface
,
84 win
.on('destroy', reload
);
87 var edit_btn
= new Ext
.Button({
88 text
: gettext('Edit'),
93 var del_btn
= new Ext
.Button({
94 text
: gettext('Remove'),
97 var grid
= me
.down('gridpanel');
98 var sm
= grid
.getSelectionModel();
99 var rec
= sm
.getSelection()[0];
104 var iface
= rec
.data
.iface
;
106 Proxmox
.Utils
.API2Request({
107 url
: baseUrl
+ '/' + iface
,
110 callback: function() {
113 failure: function(response
, opts
) {
114 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
120 var set_button_status = function() {
121 var grid
= me
.down('gridpanel');
122 var sm
= grid
.getSelectionModel();
123 var rec
= sm
.getSelection()[0];
125 edit_btn
.setDisabled(!rec
);
126 del_btn
.setDisabled(!rec
);
129 var render_ports = function(value
, metaData
, record
) {
130 if (value
=== 'bridge') {
131 return record
.data
.bridge_ports
;
132 } else if (value
=== 'bond') {
133 return record
.data
.slaves
;
134 } else if (value
=== 'OVSBridge') {
135 return record
.data
.ovs_ports
;
136 } else if (value
=== 'OVSBond') {
137 return record
.data
.ovs_bonds
;
141 var find_next_iface_id = function(prefix
) {
143 for (next
= 0; next
<= 9999; next
++) {
144 if (!store
.getById(prefix
+ next
.toString())) {
148 return prefix
+ next
.toString();
153 if (me
.types
.indexOf('bridge') !== -1) {
155 text
: Proxmox
.Utils
.render_network_iface_type('bridge'),
156 handler: function() {
157 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
158 nodename
: me
.nodename
,
160 iface_default
: find_next_iface_id('vmbr')
162 win
.on('destroy', reload
);
168 if (me
.types
.indexOf('bond') !== -1) {
170 text
: Proxmox
.Utils
.render_network_iface_type('bond'),
171 handler: function() {
172 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
173 nodename
: me
.nodename
,
175 iface_default
: find_next_iface_id('bond')
177 win
.on('destroy', reload
);
183 if (me
.types
.indexOf('ovs') !== -1) {
184 if (menu_items
.length
> 0) {
185 menu_items
.push({ xtype
: 'menuseparator' });
190 text
: Proxmox
.Utils
.render_network_iface_type('OVSBridge'),
191 handler: function() {
192 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
193 nodename
: me
.nodename
,
195 iface_default
: find_next_iface_id('vmbr')
197 win
.on('destroy', reload
);
202 text
: Proxmox
.Utils
.render_network_iface_type('OVSBond'),
203 handler: function() {
204 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
205 nodename
: me
.nodename
,
207 iface_default
: find_next_iface_id('bond')
209 win
.on('destroy', reload
);
214 text
: Proxmox
.Utils
.render_network_iface_type('OVSIntPort'),
215 handler: function() {
216 var win
= Ext
.create('Proxmox.node.NetworkEdit', {
217 nodename
: me
.nodename
,
220 win
.on('destroy', reload
);
231 text
: gettext('Create'),
238 text
: gettext('Revert'),
239 handler: function() {
240 Proxmox
.Utils
.API2Request({
244 callback: function() {
247 failure: function(response
, opts
) {
248 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
260 stateId
: 'grid-node-network',
266 header
: gettext('Name'),
271 header
: gettext('Type'),
274 renderer
: Proxmox
.Utils
.render_network_iface_type
,
278 xtype
: 'booleancolumn',
279 header
: gettext('Active'),
288 xtype
: 'booleancolumn',
289 header
: gettext('Autostart'),
292 dataIndex
: 'autostart',
298 header
: gettext('Ports/Slaves'),
300 renderer
: render_ports
303 header
: gettext('IP address'),
306 dataIndex
: 'address',
307 renderer: function(value
, metaData
, rec
) {
308 if (rec
.data
.address
&& rec
.data
.address6
) {
309 return rec
.data
.address
+ "<br>"
310 + rec
.data
.address6
+ '/' + rec
.data
.netmask6
;
311 } else if (rec
.data
.address6
) {
312 return rec
.data
.address6
+ '/' + rec
.data
.netmask6
;
314 return rec
.data
.address
;
319 header
: gettext('Subnet mask'),
325 header
: gettext('Gateway'),
328 dataIndex
: 'gateway',
329 renderer: function(value
, metaData
, rec
) {
330 if (rec
.data
.gateway
&& rec
.data
.gateway6
) {
331 return rec
.data
.gateway
+ "<br>" + rec
.data
.gateway6
;
332 } else if (rec
.data
.gateway6
) {
333 return rec
.data
.gateway6
;
335 return rec
.data
.gateway
;
340 header
: gettext('Comment'),
341 dataIndex
: 'comments',
343 renderer
: Ext
.String
.htmlEncode
347 selectionchange
: set_button_status
,
348 itemdblclick
: run_editor
358 gettext('Pending changes') + ' (' +
359 gettext('Please reboot to activate changes') + ')'
364 html
: gettext("No changes")