[pve-devel] r5996 - in pve-manager/pve2: bin lib/PVE/API2

svn-commits at proxmox.com svn-commits at proxmox.com
Wed May 18 12:54:32 CEST 2011


Author: dietmar
Date: 2011-05-18 12:54:32 +0200 (Wed, 18 May 2011)
New Revision: 5996

Added:
   pve-manager/pve2/lib/PVE/API2/Network.pm
Modified:
   pve-manager/pve2/bin/pvesh
   pve-manager/pve2/lib/PVE/API2/Makefile.am
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
Log:
start network API


Modified: pve-manager/pve2/bin/pvesh
===================================================================
--- pve-manager/pve2/bin/pvesh	2011-05-18 10:35:57 UTC (rev 5995)
+++ pve-manager/pve2/bin/pvesh	2011-05-18 10:54:32 UTC (rev 5996)
@@ -84,7 +84,7 @@
     # lcd : lowest common denominator
     my $lcd = '';
     my $tmp = $res[0];
-    for (my $i = 1; $i < length($tmp); $i++) {
+    for (my $i = 1; $i <= length($tmp); $i++) {
 	my $found = 1;
 	foreach my $p (@res) {
 	    if (substr($tmp, 0, $i) ne substr($p, 0, $i)) {

Modified: pve-manager/pve2/lib/PVE/API2/Makefile.am
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Makefile.am	2011-05-18 10:35:57 UTC (rev 5995)
+++ pve-manager/pve2/lib/PVE/API2/Makefile.am	2011-05-18 10:54:32 UTC (rev 5996)
@@ -5,6 +5,7 @@
 pvelib_DATA = 			\
 	Cluster.pm		\
 	Nodes.pm		\
+	Network.pm		\
 	Services.pm
 
 CLEANFILES = *~

Added: pve-manager/pve2/lib/PVE/API2/Network.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Network.pm	                        (rev 0)
+++ pve-manager/pve2/lib/PVE/API2/Network.pm	2011-05-18 10:54:32 UTC (rev 5996)
@@ -0,0 +1,61 @@
+package PVE::API2::Network;
+
+use strict;
+use warnings;
+
+use PVE::Tools;
+use PVE::SafeSyslog;
+use PVE::INotify;
+use PVE::Exception qw(raise_param_exc);
+use PVE::RESTHandler;
+use PVE::RPCEnvironment;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::AccessControl;
+use IO::File;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+    name => 'index', 
+    path => '', 
+    method => 'GET',
+    permissions => { user => 'all' },
+    description => "List available networks",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => "array",
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+	links => [ { rel => 'child', href => "{iface}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $config = PVE::INotify::read_file('interfaces');
+
+	return PVE::RESTHandler::hash_to_array($config, 'iface');
+
+	my $res = [];
+
+	foreach my $iface (keys %$config) {
+	    my $d = $config->{$iface};
+	    push @$res, { 
+		iface => $iface,
+		type => $d->{type},
+		exists => $d->{exists} || 0,
+		active => $d->{active} || 0,
+	    };
+	}
+
+	return $res;
+    }});
+
+

Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-18 10:35:57 UTC (rev 5995)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-18 10:54:32 UTC (rev 5996)
@@ -17,6 +17,7 @@
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::AccessControl;
 use PVE::API2::Services;
+use PVE::API2::Network;
 use PVE::API2::Storage::Scan;
 use PVE::API2::Storage::Status;
 use PVE::API2::Qemu;
@@ -35,6 +36,11 @@
 });
 
 __PACKAGE__->register_method ({
+    subclass => "PVE::API2::Network",  
+    path => 'network',
+});
+
+__PACKAGE__->register_method ({
     subclass => "PVE::API2::Storage::Scan",  
     path => 'scan',
 });
@@ -81,12 +87,39 @@
 	    { name => 'storage' },
 	    { name => 'upload' },
 	    { name => 'qemu' },
+	    { name => 'network' },
+	    { name => 'network_changes' },
 	    ];
 
 	return $result;
     }});
 
 __PACKAGE__->register_method({
+    name => 'network_changes', 
+    path => 'network_changes', 
+    method => 'GET',
+    permissions => {
+	path => '/nodes/{node}',
+	privs => [ 'Sys.Audit' ],
+    },
+    description => "Get network configuration changes (diff) since last boot.",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => { type => "string" },
+    code => sub {
+	my ($param) = @_;
+
+	my $res = PVE::INotify::read_file('interfaces', 1);
+
+	return $res->{changes} || '';
+   }});
+
+__PACKAGE__->register_method({
     name => 'status', 
     path => 'status', 
     method => 'GET',




More information about the pve-devel mailing list