[pve-devel] r6013 - in pve-manager/pve2: lib/PVE/API2 www/new/form www/new/node
svn-commits at proxmox.com
svn-commits at proxmox.com
Tue May 24 09:31:25 CEST 2011
Author: dietmar
Date: 2011-05-24 09:31:25 +0200 (Tue, 24 May 2011)
New Revision: 6013
Modified:
pve-manager/pve2/lib/PVE/API2/Network.pm
pve-manager/pve2/www/new/form/TextField.js
pve-manager/pve2/www/new/node/NetworkEdit.js
pve-manager/pve2/www/new/node/NetworkView.js
Log:
improve network editor
Modified: pve-manager/pve2/lib/PVE/API2/Network.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Network.pm 2011-05-24 05:38:03 UTC (rev 6012)
+++ pve-manager/pve2/lib/PVE/API2/Network.pm 2011-05-24 07:31:25 UTC (rev 6013)
@@ -59,6 +59,16 @@
}});
+my $check_duplicate_gateway = sub {
+ my ($config) = @_;
+
+ foreach my $iface (keys %$config) {
+ raise_param_exc({ gateway => "Default gateway already exists on interface '$iface'." })
+ if ($config->{$iface}->{gateway})
+ }
+};
+
+
__PACKAGE__->register_method({
name => 'create_network',
path => '',
@@ -102,7 +112,7 @@
},
netmask => {
description => 'Network mask.',
- type => 'string', format => 'ipv4',
+ type => 'string', format => 'ipv4mask',
optional => 1,
},
address => {
@@ -127,10 +137,108 @@
raise_param_exc({ iface => "interface already exists" })
if $config->{$iface};
+ &$check_duplicate_gateway($config)
+ if $param->{gateway};
+
+ $param->{method} = $param->{address} ? 'static' : 'manual';
+
$config->{$iface} = $param;
+ PVE::INotify::write_file('interfaces', $config);
+ };
+
+ PVE::Tools::lock_file($iflockfn, 10, "network config", $code);
+ die $@ if $@;
+
+ return undef;
+ }});
+
+__PACKAGE__->register_method({
+ name => 'update_network',
+ path => '{iface}',
+ method => 'PUT',
+ permissions => {
+ path => '/nodes/{node}',
+ privs => [ 'Sys.Modify' ],
+ },
+ description => "Update network device configuration",
+ protected => 1,
+ proxyto => 'node',
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ iface => get_standard_option('pve-iface'),
+ autostart => {
+ description => "Automatically start interface on boot.",
+ type => 'boolean',
+ optional => 1,
+ },
+ bridge_ports => {
+ description => "Specify the iterfaces you want to add to your bridge.",
+ optional => 1,
+ type => 'string', format => 'pve-iface-list',
+ },
+ slaves => {
+ description => "Specify the interfaces used by the bonding device.",
+ optional => 1,
+ type => 'string', format => 'pve-iface-list',
+ },
+ bond_mode => {
+ description => "Bonding mode.",
+ optional => 1,
+ type => 'string', enum => $bond_mode_enum,
+ },
+ gateway => {
+ description => 'Default gateway address.',
+ type => 'string', format => 'ipv4',
+ optional => 1,
+ },
+ netmask => {
+ description => 'Network mask.',
+ type => 'string', format => 'ipv4mask',
+ optional => 1,
+ },
+ address => {
+ description => 'IP address.',
+ type => 'string', format => 'ipv4',
+ optional => 1,
+ requires => 'netmask',
+ },
+ delete => {
+ type => 'string', format => 'pve-configid-list',
+ description => "A list of settings you want to delete.",
+ optional => 1,
+ },
+ },
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ my $node = extract_param($param, 'node');
+ my $iface = extract_param($param, 'iface');
+ my $delete = extract_param($param, 'delete');
+
+ my $code = sub {
+ my $config = PVE::INotify::read_file('interfaces');
+
+ raise_param_exc({ iface => "interface does not exist" })
+ if !$config->{$iface};
+
+ foreach my $k (PVE::Tools::split_list($delete)) {
+ delete $config->{$iface}->{$k};
+ }
+
+ &$check_duplicate_gateway($config)
+ if $param->{gateway};
+
$param->{method} = $param->{address} ? 'static' : 'manual';
+ foreach my $k (keys %$param) {
+ $config->{$iface}->{$k} = $param->{$k};
+ }
+
PVE::INotify::write_file('interfaces', $config);
};
Modified: pve-manager/pve2/www/new/form/TextField.js
===================================================================
--- pve-manager/pve2/www/new/form/TextField.js 2011-05-24 05:38:03 UTC (rev 6012)
+++ pve-manager/pve2/www/new/form/TextField.js 2011-05-24 07:31:25 UTC (rev 6013)
@@ -3,6 +3,25 @@
alias: ['widget.pvetextfield'],
skipEmptyText: true,
+
+ deleteEmpty: false,
+
+ getSubmitData: function() {
+ var me = this,
+ data = null,
+ val;
+ if (!me.disabled && me.submitValue && !me.isFileUpload()) {
+ val = me.getSubmitValue();
+ if (val !== null) {
+ data = {};
+ data[me.getName()] = val;
+ } else if (me.deleteEmpty) {
+ data = {};
+ data['delete'] = me.getName();
+ }
+ }
+ return data;
+ },
getSubmitValue: function() {
var me = this;
Modified: pve-manager/pve2/www/new/node/NetworkEdit.js
===================================================================
--- pve-manager/pve2/www/new/node/NetworkEdit.js 2011-05-24 05:38:03 UTC (rev 6012)
+++ pve-manager/pve2/www/new/node/NetworkEdit.js 2011-05-24 07:31:25 UTC (rev 6013)
@@ -14,7 +14,7 @@
var create = !me.iface;
- var title = "Edit network device";
+ var title;
var iface_vtype;
if (create) {
@@ -26,6 +26,8 @@
iface_vtype = 'BondName';
} else
throw "can't create unknown device type";
+ } else {
+ title = "Edit network device '" + me.iface + "'";
}
var col2 = [
@@ -91,22 +93,26 @@
fieldLabel: 'Name',
name: 'iface',
value: me.iface,
- readOnly: !create,
+ disabled: !create,
vtype: iface_vtype,
allowBlank: false
},
{
xtype: 'pvetextfield',
+ deleteEmpty: !create,
fieldLabel: 'IP address',
vtype: 'IPAddress',
name: 'address'
},
{
xtype: 'pvetextfield',
+ deleteEmpty: !create,
fieldLabel: 'Subnet mask',
vtype: 'IPAddress',
name: 'netmask',
validator: function(value) {
+ if (!me.items)
+ return true;
var address = me.down('field[name=address]').getValue();
if (value !== '') {
if (address === '')
@@ -121,6 +127,7 @@
},
{
xtype: 'pvetextfield',
+ deleteEmpty: !create,
fieldLabel: 'Gateway',
vtype: 'IPAddress',
name: 'gateway'
@@ -203,6 +210,9 @@
buttons: [ submitBtn, resetBtn ]
});
+ if (create)
+ form.findField('iface').setValue(me.iface_default);
+
me.callParent();
}
});
Modified: pve-manager/pve2/www/new/node/NetworkView.js
===================================================================
--- pve-manager/pve2/www/new/node/NetworkView.js 2011-05-24 05:38:03 UTC (rev 6012)
+++ pve-manager/pve2/www/new/node/NetworkView.js 2011-05-24 07:31:25 UTC (rev 6013)
@@ -116,9 +116,16 @@
{
text: 'Bridge',
handler: function() {
+ var next;
+ for (next = 0; next <= 9999; next++) {
+ if (!rstore.data.get('vmbr' + next))
+ break;
+ }
+
var win = Ext.create('PVE.node.NetworkEdit', {
pveSelNode: me.pveSelNode,
iftype: 'bridge',
+ iface_default: 'vmbr' + next
});
win.show();
}
@@ -126,9 +133,15 @@
{
text: 'Bond',
handler: function() {
+ var next;
+ for (next = 0; next <= 9999; next++) {
+ if (!rstore.data.get('bond' + next))
+ break;
+ }
var win = Ext.create('PVE.node.NetworkEdit', {
pveSelNode: me.pveSelNode,
iftype: 'bond',
+ iface_default: 'bond' + next
});
win.show();
}
More information about the pve-devel
mailing list