[pve-devel] r6010 - in pve-manager/pve2: lib/PVE/API2 www/new www/new/node

svn-commits at proxmox.com svn-commits at proxmox.com
Mon May 23 13:19:49 CEST 2011


Author: dietmar
Date: 2011-05-23 13:19:49 +0200 (Mon, 23 May 2011)
New Revision: 6010

Modified:
   pve-manager/pve2/lib/PVE/API2/Network.pm
   pve-manager/pve2/www/new/Makefile.am
   pve-manager/pve2/www/new/node/NetworkView.js
Log:
mpl. network create/delete


Modified: pve-manager/pve2/lib/PVE/API2/Network.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Network.pm	2011-05-23 11:19:16 UTC (rev 6009)
+++ pve-manager/pve2/lib/PVE/API2/Network.pm	2011-05-23 11:19:49 UTC (rev 6010)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use PVE::Tools;
+use PVE::Tools qw(extract_param);
 use PVE::SafeSyslog;
 use PVE::INotify;
 use PVE::Exception qw(raise_param_exc);
@@ -15,6 +15,18 @@
 
 use base qw(PVE::RESTHandler);
 
+my $iflockfn = "/etc/network/.pve-interfaces.lock";
+
+my $bond_mode_enum = [
+    'balance-rr',
+    'active-backup',
+    'balance-xor',
+    'broadcast',
+    '802.3ad',
+    'balance-tlb',
+    'balance-alb'
+    ];
+
 __PACKAGE__->register_method({
     name => 'index', 
     path => '', 
@@ -48,7 +60,88 @@
 
 
 __PACKAGE__->register_method({
-    name => 'config', 
+    name => 'create_network', 
+    path => '', 
+    method => 'POST',
+    permissions => {
+	path => '/nodes/{node}',
+	privs => [ 'Sys.Modify' ],
+    },
+    description => "Create 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 => 'ipv4',
+		optional => 1,
+	    },
+	    address => {
+		description => 'IP address.',
+		type => 'string', format => 'ipv4',
+		optional => 1,
+		requires => 'netmask',
+	    },
+
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	my $node = extract_param($param, 'node');
+	my $iface = extract_param($param, 'iface');
+
+	my $code = sub {
+	    my $config = PVE::INotify::read_file('interfaces');
+
+	    raise_param_exc({ iface => "interface already exists" })
+		if $config->{$iface};
+
+	    $config->{$iface} = $param;
+
+	    $param->{method} = $param->{address} ? 'static' : 'manual'; 
+
+	    PVE::INotify::write_file('interfaces', $config);
+	};
+
+	PVE::Tools::lock_file($iflockfn, 10, "network config", $code);
+	die $@ if $@;
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method({
+    name => 'network_config', 
     path => '{iface}', 
     method => 'GET',
     permissions => {
@@ -86,4 +179,44 @@
 	return $config->{$param->{iface}};
    }});
 
+__PACKAGE__->register_method({
+    name => 'delete_network', 
+    path => '{iface}', 
+    method => 'DELETE',
+    permissions => {
+	path => '/nodes/{node}',
+	privs => [ 'Sys.Modify' ],
+    },
+    description => "Delete network device configuration",
+    protected => 1,
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    iface => get_standard_option('pve-iface'),
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
 
+	my $code = sub {
+	    my $config = PVE::INotify::read_file('interfaces');
+
+	    raise_param_exc({ iface => "interface does not exist" })
+		if !$config->{$param->{iface}};
+
+	    delete $config->{$param->{iface}};
+
+	    PVE::INotify::write_file('interfaces', $config);
+	};
+
+	PVE::Tools::lock_file($iflockfn, 10, "network config", $code);
+	die $@ if $@;
+
+	return undef;
+    }});
+
+
+

Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am	2011-05-23 11:19:16 UTC (rev 6009)
+++ pve-manager/pve2/www/new/Makefile.am	2011-05-23 11:19:49 UTC (rev 6010)
@@ -13,6 +13,7 @@
 	data/ObjectStore.js				\
 	data/ResourceStore.js				\
 	form/Checkbox.js				\
+	form/TextField.js				\
 	form/RRDTypeSelector.js				\
 	form/ComboGrid.js				\
 	form/NetworkCardSelector.js			\

Modified: pve-manager/pve2/www/new/node/NetworkView.js
===================================================================
--- pve-manager/pve2/www/new/node/NetworkView.js	2011-05-23 11:19:16 UTC (rev 6009)
+++ pve-manager/pve2/www/new/node/NetworkView.js	2011-05-23 11:19:49 UTC (rev 6010)
@@ -60,6 +60,24 @@
 	    text: 'Delete',
 	    disabled: true,
 	    handler: function(){
+		var sm = me.getSelectionModel();
+		var rec = sm.getLastSelected();
+		if (!rec)
+		    return;
+
+		var iface = rec.data.iface;
+
+		me.setLoading(true, true);
+		PVE.Utils.API2Request({
+		    url: '/nodes/' + nodename + '/network/' + iface,
+		    method: 'DELETE',
+		    callback: function() {
+			me.setLoading(false);
+		    },
+		    failure: function(response, opts) {
+			Ext.Msg.alert('Error', response.htmlStatus);
+		    }
+		});
 	    }
 	});
 




More information about the pve-devel mailing list