[pve-devel] [PATCH pve-network] merge Transport && Vnet to PVE::Network::Network

Alexandre Derumier aderumier at odiso.com
Wed Apr 3 15:36:07 CEST 2019


config is now merged in /etc/pve/networks.cfg
Vnet is a Plugin
---
 PVE/API2/Makefile                                  |   4 -
 PVE/API2/Network/Makefile                          |   2 +-
 PVE/API2/Network/Transport.pm                      | 235 ---------------------
 PVE/API2/Network/Vnet.pm                           | 218 -------------------
 PVE/API2/NetworkConfig.pm                          |  62 ------
 PVE/Network/Makefile                               |   5 +-
 PVE/Network/{Transport => Network}/Makefile        |   4 +-
 PVE/Network/{Transport => Network}/Plugin.pm       |  12 +-
 PVE/Network/{Transport => Network}/VlanPlugin.pm   |  10 +-
 .../{Vnet/Plugin.pm => Network/VnetPlugin.pm}      |  67 ++----
 .../{Transport => Network}/VxlanMulticastPlugin.pm |  10 +-
 PVE/Network/Transport.pm                           |  62 ------
 PVE/Network/Vnet.pm                                |  71 -------
 PVE/Network/Vnet/Makefile                          |   9 -
 14 files changed, 39 insertions(+), 732 deletions(-)
 delete mode 100644 PVE/API2/Network/Transport.pm
 delete mode 100644 PVE/API2/Network/Vnet.pm
 delete mode 100644 PVE/API2/NetworkConfig.pm
 rename PVE/Network/{Transport => Network}/Makefile (57%)
 rename PVE/Network/{Transport => Network}/Plugin.pm (84%)
 rename PVE/Network/{Transport => Network}/VlanPlugin.pm (87%)
 rename PVE/Network/{Vnet/Plugin.pm => Network/VnetPlugin.pm} (52%)
 rename PVE/Network/{Transport => Network}/VxlanMulticastPlugin.pm (85%)
 delete mode 100644 PVE/Network/Transport.pm
 delete mode 100644 PVE/Network/Vnet.pm
 delete mode 100644 PVE/Network/Vnet/Makefile

diff --git a/PVE/API2/Makefile b/PVE/API2/Makefile
index 3e0ae7e..28b2830 100644
--- a/PVE/API2/Makefile
+++ b/PVE/API2/Makefile
@@ -1,8 +1,4 @@
-SOURCES=NetworkConfig.pm
-
-PERL5DIR=${DESTDIR}/usr/share/perl5
 
 .PHONY: install
 install:
-	for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/API2/$$i; done
 	make -C Network install
diff --git a/PVE/API2/Network/Makefile b/PVE/API2/Network/Makefile
index b563481..a7f3c31 100644
--- a/PVE/API2/Network/Makefile
+++ b/PVE/API2/Network/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Transport.pm Vnet.pm
+SOURCES=Network.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/PVE/API2/Network/Transport.pm b/PVE/API2/Network/Transport.pm
deleted file mode 100644
index 0e1610f..0000000
--- a/PVE/API2/Network/Transport.pm
+++ /dev/null
@@ -1,235 +0,0 @@
-package PVE::API2::Network::Transport;
-
-use strict;
-use warnings;
-
-use PVE::SafeSyslog;
-use PVE::Tools qw(extract_param);
-use PVE::Cluster qw(cfs_read_file cfs_write_file);
-use PVE::Network::Transport;
-use PVE::Network::Transport::Plugin;
-use PVE::Network::Transport::VlanPlugin;
-use PVE::Network::Transport::VxlanMulticastPlugin;
-use Storable qw(dclone);
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::RPCEnvironment;
-
-use PVE::RESTHandler;
-
-use base qw(PVE::RESTHandler);
-
-my $transport_type_enum = PVE::Network::Transport::Plugin->lookup_types();
-
-my $api_transport_config = sub {
-    my ($cfg, $transportid) = @_;
-
-    my $scfg = dclone(PVE::Network::Transport::transport_config($cfg, $transportid));
-    $scfg->{transport} = $transportid;
-    $scfg->{digest} = $cfg->{digest};
-
-    return $scfg;
-};
-
-__PACKAGE__->register_method ({
-    name => 'index', 
-    path => '',
-    method => 'GET',
-    description => "Transport index.",
-    permissions => { 
-	description => "Only list entries where you have 'NetworkTransport.Audit' or 'NetworkTransport.Allocate' permissions on '/cluster/network/transport/<transport>'",
-	user => 'all',
-    },
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    type => { 
-		description => "Only list transport of specific type",
-		type => 'string', 
-		enum => $transport_type_enum,
-		optional => 1,
-	    },
-	},
-    },
-    returns => {
-	type => 'array',
-	items => {
-	    type => "object",
-	    properties => { transport => { type => 'string'} },
-	},
-	links => [ { rel => 'child', href => "{transport}" } ],
-    },
-    code => sub {
-	my ($param) = @_;
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-	my $authuser = $rpcenv->get_user();
-
-
-	my $cfg = PVE::Network::Transport::config();
-
-	my @sids = PVE::Network::Transport::transports_ids($cfg);
-	my $res = [];
-	foreach my $transportid (@sids) {
-#	    my $privs = [ 'NetworkTransport.Audit', 'NetworkTransport.Allocate' ];
-#	    next if !$rpcenv->check_any($authuser, "/cluster/network/transport/$transportid", $privs, 1);
-
-	    my $scfg = &$api_transport_config($cfg, $transportid);
-	    next if $param->{type} && $param->{type} ne $scfg->{type};
-	    push @$res, $scfg;
-	}
-
-	return $res;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'read', 
-    path => '{transport}',
-    method => 'GET',
-    description => "Read transport configuration.",
-#    permissions => { 
-#	check => ['perm', '/cluster/network/transport/{transport}', ['NetworkTransport.Allocate']],
-#   },
-
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    transport => get_standard_option('pve-transport-id'),
-	},
-    },
-    returns => { type => 'object' },
-    code => sub {
-	my ($param) = @_;
-
-	my $cfg = PVE::Network::Transport::config();
-
-	return &$api_transport_config($cfg, $param->{transport});
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'create',
-    protected => 1,
-    path => '', 
-    method => 'POST',
-    description => "Create a new network transport.",
-#    permissions => { 
-#	check => ['perm', '/cluster/network/transport', ['NetworkTransport.Allocate']],
-#    },
-    parameters => PVE::Network::Transport::Plugin->createSchema(),
-    returns => { type => 'null' },
-    code => sub {
-	my ($param) = @_;
-
-	my $type = extract_param($param, 'type');
-	my $transportid = extract_param($param, 'transport');
-
-	my $plugin = PVE::Network::Transport::Plugin->lookup($type);
-	my $opts = $plugin->check_config($transportid, $param, 1, 1);
-
-        PVE::Network::Transport::lock_transport_config(
-	    sub {
-
-		my $cfg = PVE::Network::Transport::config();
-
-		if (my $scfg = PVE::Network::Transport::transport_config($cfg, $transportid, 1)) {
-		    die "network transport ID '$transportid' already defined\n";
-		}
-
-		$cfg->{ids}->{$transportid} = $opts;
-
-		#improveme:
-		#check local configuration of all nodes for conflict
-
-		PVE::Network::Transport::write_config($cfg);
-	    
-	    }, "create network transport failed");
-
-	return undef;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'update',
-    protected => 1,
-    path => '{transport}',
-    method => 'PUT',
-    description => "Update network transport configuration.",
-#    permissions => { 
-#	check => ['perm', '/cluster/network/transport', ['NetworkTransport.Allocate']],
-#    },
-    parameters => PVE::Network::Transport::Plugin->updateSchema(),
-    returns => { type => 'null' },
-    code => sub {
-	my ($param) = @_;
-
-	my $transportid = extract_param($param, 'transport');
-	my $digest = extract_param($param, 'digest');
-
-        PVE::Network::Transport::lock_transport_config(
-	 sub {
-
-	    my $cfg = PVE::Network::Transport::config();
-
-	    PVE::SectionConfig::assert_if_modified($cfg, $digest);
-
-	    my $scfg = PVE::Network::Transport::transport_config($cfg, $transportid);
-
-	    my $plugin = PVE::Network::Transport::Plugin->lookup($scfg->{type});
-	    my $opts = $plugin->check_config($transportid, $param, 0, 1);
-
-	    foreach my $k (%$opts) {
-		$scfg->{$k} = $opts->{$k};
-	    }
-	    #improveme:
-            #add vlan/vxlan check on existingvnets
-	    #check local configuration of all nodes for conflict
-	    PVE::Network::Transport::write_config($cfg);
-
-	    }, "update network transport failed");
-
-	return undef;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'delete',
-    protected => 1,
-    path => '{transport}', # /cluster/network/transport/{transport}
-    method => 'DELETE',
-    description => "Delete network transport configuration.",
-#    permissions => { 
-#	check => ['perm', '/cluster/network/transport', ['NetworkTransport.Allocate']],
-#    },
-    parameters => {
-    	additionalProperties => 0,
-	properties => { 
-	    transport => get_standard_option('pve-transport-id', {
-                completion => \&PVE::Network::Transport::complete_transport,
-            }),
-	},
-    },
-    returns => { type => 'null' },
-    code => sub {
-	my ($param) = @_;
-
-	my $transportid = extract_param($param, 'transport');
-
-        PVE::Network::Transport::lock_transport_config(
-	    sub {
-
-		my $cfg = PVE::Network::Transport::config();
-
-		my $scfg = PVE::Network::Transport::transport_config($cfg, $transportid);
-
-#		my $plugin = PVE::Network::Transport::Plugin->lookup($scfg->{type});
-#		$plugin->on_delete_hook($transportid, $scfg);
-
-		delete $cfg->{ids}->{$transportid};
-		#improveme:
- 		#check that vnet don't use this transport
-		PVE::Network::Transport::write_config($cfg);
-
-	    }, "delete network transport failed");
-
-
-	return undef;
-    }});
-
-1;
diff --git a/PVE/API2/Network/Vnet.pm b/PVE/API2/Network/Vnet.pm
deleted file mode 100644
index 74f59fc..0000000
--- a/PVE/API2/Network/Vnet.pm
+++ /dev/null
@@ -1,218 +0,0 @@
-package PVE::API2::Network::Vnet;
-
-use strict;
-use warnings;
-
-use PVE::SafeSyslog;
-use PVE::Tools qw(extract_param);
-use PVE::Cluster qw(cfs_read_file cfs_write_file);
-use PVE::Network::Vnet;
-use PVE::Network::Vnet::Plugin;
-use Storable qw(dclone);
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::RPCEnvironment;
-
-use PVE::RESTHandler;
-
-use base qw(PVE::RESTHandler);
-
-my $api_vnet_config = sub {
-    my ($cfg, $vnetid) = @_;
-
-    my $scfg = dclone(PVE::Network::Vnet::vnet_config($cfg, $vnetid));
-    $scfg->{vnet} = $vnetid;
-    $scfg->{digest} = $cfg->{digest};
-
-    return $scfg;
-};
-
-__PACKAGE__->register_method ({
-    name => 'index', 
-    path => '',
-    method => 'GET',
-    description => "Vnet index.",
-    permissions => { 
-	description => "Only list entries where you have 'NetworkVnet.Audit' or 'NetworkVnet.Allocate' permissions on '/cluster/network/vnet/<vnet>'",
-	user => 'all',
-    },
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    type => { 
-		description => "Only list vnet of specific type",
-		type => 'string', 
-		optional => 1,
-	    },
-	},
-    },
-    returns => {
-	type => 'array',
-	items => {
-	    type => "object",
-	    properties => { vnet => { type => 'string'} },
-	},
-	links => [ { rel => 'child', href => "{vnet}" } ],
-    },
-    code => sub {
-	my ($param) = @_;
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-	my $authuser = $rpcenv->get_user();
-
-
-	my $cfg = PVE::Network::Vnet::config();
-
-	my @sids = PVE::Network::Vnet::vnets_ids($cfg);
-	my $res = [];
-	foreach my $vnetid (@sids) {
-#	    my $privs = [ 'NetworkVnet.Audit', 'NetworkVnet.Allocate' ];
-#	    next if !$rpcenv->check_any($authuser, "/cluster/network/vnet/$vnetid", $privs, 1);
-
-	    my $scfg = &$api_vnet_config($cfg, $vnetid);
-	    next if $param->{type} && $param->{type} ne $scfg->{type};
-	    push @$res, $scfg;
-	}
-
-	return $res;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'read', 
-    path => '{vnet}',
-    method => 'GET',
-    description => "Read vnet configuration.",
-#    permissions => { 
-#	check => ['perm', '/cluster/network/vnet/{vnet}', ['NetworkVnet.Allocate']],
-#   },
-
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    vnet => get_standard_option('pve-vnet-id'),
-	},
-    },
-    returns => { type => 'object' },
-    code => sub {
-	my ($param) = @_;
-
-	my $cfg = PVE::Network::Vnet::config();
-
-	return &$api_vnet_config($cfg, $param->{vnet});
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'create',
-    protected => 1,
-    path => '', 
-    method => 'POST',
-    description => "Create a new network vnet.",
-#    permissions => { 
-#	check => ['perm', '/cluster/network/vnet', ['NetworkVnet.Allocate']],
-#    },
-    parameters => PVE::Network::Vnet::Plugin->createSchema(),
-    returns => { type => 'null' },
-    code => sub {
-	my ($param) = @_;
-
-	my $vnetid = extract_param($param, 'vnet');
-	my $type = "vnet";
-	my $plugin = PVE::Network::Vnet::Plugin->lookup($type);
-	my $opts = $plugin->check_config($vnetid, $param, 1, 1);
-
-        PVE::Network::Vnet::lock_vnet_config(
-	    sub {
-
-		my $cfg = PVE::Network::Vnet::config();
-
-		if (my $scfg = PVE::Network::Vnet::vnet_config($cfg, $vnetid, 1)) {
-		    die "network vnet ID '$vnetid' already defined\n";
-		}
-
-		$cfg->{ids}->{$vnetid} = $opts;
-
-		PVE::Network::Vnet::write_config($cfg);
-	    
-	    }, "create network vnet failed");
-
-	return undef;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'update',
-    protected => 1,
-    path => '{vnet}',
-    method => 'PUT',
-    description => "Update network vnet configuration.",
-#    permissions => { 
-#	check => ['perm', '/cluster/network/vnet', ['NetworkVnet.Allocate']],
-#    },
-    parameters => PVE::Network::Vnet::Plugin->updateSchema(),
-    returns => { type => 'null' },
-    code => sub {
-	my ($param) = @_;
-
-	my $vnetid = extract_param($param, 'vnet');
-	my $digest = extract_param($param, 'digest');
-
-        PVE::Network::Vnet::lock_vnet_config(
-	 sub {
-
-	    my $cfg = PVE::Network::Vnet::config();
-
-	    PVE::SectionConfig::assert_if_modified($cfg, $digest);
-
-	    my $scfg = PVE::Network::Vnet::vnet_config($cfg, $vnetid);
-	    my $plugin = PVE::Network::Vnet::Plugin->lookup($scfg->{type});
-	    my $opts = $plugin->check_config($vnetid, $param, 0, 1);
-
-	    foreach my $k (%$opts) {
-		$scfg->{$k} = $opts->{$k};
-	    }
-	    PVE::Network::Vnet::write_config($cfg);
-
-	    }, "update network vnet failed");
-
-	return undef;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'delete',
-    protected => 1,
-    path => '{vnet}', # /networkvnets/{vnet}
-    method => 'DELETE',
-    description => "Delete network vnet configuration.",
-#    permissions => { 
-#	check => ['perm', '/networkvnets', ['NetworkVnet.Allocate']],
-#    },
-    parameters => {
-    	additionalProperties => 0,
-	properties => { 
-	    vnet => get_standard_option('pve-vnet-id', {
-                completion => \&PVE::Network::Vnet::complete_vnet,
-            }),
-	},
-    },
-    returns => { type => 'null' },
-    code => sub {
-	my ($param) = @_;
-
-	my $vnetid = extract_param($param, 'vnet');
-
-        PVE::Network::Vnet::lock_vnet_config(
-	    sub {
-
-		my $cfg = PVE::Network::Vnet::config();
-
-		my $scfg = PVE::Network::Vnet::vnet_config($cfg, $vnetid);
-
-		delete $cfg->{ids}->{$vnetid};
-
-		PVE::Network::Vnet::write_config($cfg);
-
-	    }, "delete network vnet failed");
-
-
-	return undef;
-    }});
-
-1;
diff --git a/PVE/API2/NetworkConfig.pm b/PVE/API2/NetworkConfig.pm
deleted file mode 100644
index 91b7699..0000000
--- a/PVE/API2/NetworkConfig.pm
+++ /dev/null
@@ -1,62 +0,0 @@
-package PVE::API2::NetworkConfig;
-
-use strict;
-use warnings;
-
-use PVE::SafeSyslog;
-use PVE::Tools;
-use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file);
-use PVE::RESTHandler;
-use PVE::RPCEnvironment;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::Exception qw(raise_param_exc);
-use PVE::API2::Network::Transport;
-use PVE::API2::Network::Vnet;
-
-use base qw(PVE::RESTHandler);
-
-__PACKAGE__->register_method ({
-    subclass => "PVE::API2::Network::Transport",  
-    path => 'transport',
-			      });
-
-__PACKAGE__->register_method ({
-    subclass => "PVE::API2::Network::Vnet",  
-    path => 'vnet',
-			      });
-
-__PACKAGE__->register_method({
-    name => 'index', 
-    path => '', 
-    method => 'GET',
-    description => "Directory index.",
-    permissions => {
-	check => ['perm', '/', [ 'Sys.Audit' ]],
-    },
-    parameters => {
-    	additionalProperties => 0,
-	properties => {},
-    },
-    returns => {
-	type => 'array',
-	items => {
-	    type => "object",
-	    properties => {
-		id => { type => 'string' },
-	    },
-	},
-	links => [ { rel => 'child', href => "{id}" } ],
-    },
-    code => sub {
-	my ($param) = @_;
-
-	my $res = [ 
-	    { id => 'transport' },
-	    { id => 'vnet' },
-	];
-
-	return $res;
-    }});
-
-
-1;
diff --git a/PVE/Network/Makefile b/PVE/Network/Makefile
index 66eeec8..6f17f37 100644
--- a/PVE/Network/Makefile
+++ b/PVE/Network/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Vnet.pm Transport.pm
+SOURCES=Network.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
@@ -6,5 +6,4 @@ PERL5DIR=${DESTDIR}/usr/share/perl5
 .PHONY: install
 install:
 	for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/Network/$$i; done
-	make -C Vnet install
-	make -C Transport install
+	make -C Network install
diff --git a/PVE/Network/Transport/Makefile b/PVE/Network/Network/Makefile
similarity index 57%
rename from PVE/Network/Transport/Makefile
rename to PVE/Network/Network/Makefile
index 938e87b..085f93d 100644
--- a/PVE/Network/Transport/Makefile
+++ b/PVE/Network/Network/Makefile
@@ -1,9 +1,9 @@
-SOURCES=Plugin.pm VlanPlugin.pm  VxlanMulticastPlugin.pm
+SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm  VxlanMulticastPlugin.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
 
 .PHONY: install
 install:
-	for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/Network/Transport/$$i; done
+	for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/Network/Network/$$i; done
 
diff --git a/PVE/Network/Transport/Plugin.pm b/PVE/Network/Network/Plugin.pm
similarity index 84%
rename from PVE/Network/Transport/Plugin.pm
rename to PVE/Network/Network/Plugin.pm
index dcebbcf..4ec6d0a 100644
--- a/PVE/Network/Transport/Plugin.pm
+++ b/PVE/Network/Network/Plugin.pm
@@ -1,4 +1,4 @@
-package PVE::Network::Transport::Plugin;
+package PVE::Network::Network::Plugin;
 
 use strict;
 use warnings;
@@ -11,7 +11,7 @@ use Data::Dumper;
 use PVE::JSONSchema qw(get_standard_option);
 use base qw(PVE::SectionConfig);
 
-PVE::Cluster::cfs_register_file('network/transports.cfg',
+PVE::Cluster::cfs_register_file('networks.cfg',
 				 sub { __PACKAGE__->parse_config(@_); },
 				 sub { __PACKAGE__->write_config(@_); });
 
@@ -23,8 +23,8 @@ my $defaultData = {
 	    type => 'string', format => 'pve-configid',
 	    type => 'string',
 	},
-        transport => get_standard_option('pve-transport-id',
-            { completion => \&PVE::Network::Transport::complete_transport }),
+        network => get_standard_option('pve-network-id',
+            { completion => \&PVE::Network::Network::complete_network }),
     },
 };
 
@@ -36,12 +36,12 @@ sub parse_section_header {
     my ($class, $line) = @_;
 
     if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
-        my ($type, $transportid) = (lc($1), $2);
+        my ($type, $networkid) = (lc($1), $2);
 	my $errmsg = undef; # set if you want to skip whole section
 	eval { PVE::JSONSchema::pve_verify_configid($type); };
 	$errmsg = $@ if $@;
 	my $config = {}; # to return additional attributes
-	return ($type, $transportid, $errmsg, $config);
+	return ($type, $networkid, $errmsg, $config);
     }
     return undef;
 }
diff --git a/PVE/Network/Transport/VlanPlugin.pm b/PVE/Network/Network/VlanPlugin.pm
similarity index 87%
rename from PVE/Network/Transport/VlanPlugin.pm
rename to PVE/Network/Network/VlanPlugin.pm
index 8ee8bdc..fd53617 100644
--- a/PVE/Network/Transport/VlanPlugin.pm
+++ b/PVE/Network/Network/VlanPlugin.pm
@@ -1,10 +1,10 @@
-package PVE::Network::Transport::VlanPlugin;
+package PVE::Network::Network::VlanPlugin;
 
 use strict;
 use warnings;
-use PVE::Network::Transport::Plugin;
+use PVE::Network::Network::Plugin;
 
-use base('PVE::Network::Transport::Plugin');
+use base('PVE::Network::Network::Plugin');
 
 sub type {
     return 'vlan';
@@ -14,7 +14,7 @@ PVE::JSONSchema::register_format('pve-network-vlanrange', \&pve_verify_network_v
 sub pve_verify_network_vlanrange {
    my ($vlanstr) = @_;
 
-   PVE::Network::Transport::Plugin::parse_tag_number_or_range($vlanstr, '4096');
+   PVE::Network::Network::Plugin::parse_tag_number_or_range($vlanstr, '4096');
 
    return $vlanstr;
 }
@@ -70,7 +70,7 @@ sub generate_network_config {
     die "uplink $uplink is not defined" if !$uplinks->{$uplink};
 
     eval {
-	PVE::Network::Transport::Plugin::parse_tag_number_or_range($vlanallowed, '4096', $tag) if $vlanallowed;
+	PVE::Network::Network::Plugin::parse_tag_number_or_range($vlanallowed, '4096', $tag) if $vlanallowed;
     };
     if($@) {
 	die "vlan $tag is not allowed in transport $zoneid";
diff --git a/PVE/Network/Vnet/Plugin.pm b/PVE/Network/Network/VnetPlugin.pm
similarity index 52%
rename from PVE/Network/Vnet/Plugin.pm
rename to PVE/Network/Network/VnetPlugin.pm
index 0a7053c..c2a4020 100644
--- a/PVE/Network/Vnet/Plugin.pm
+++ b/PVE/Network/Network/VnetPlugin.pm
@@ -1,37 +1,19 @@
-package PVE::Network::Vnet::Plugin;
+package PVE::Network::Network::VnetPlugin;
 
 use strict;
 use warnings;
+use PVE::Network::Network::Plugin;
 
-use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::SectionConfig;
+use base('PVE::Network::Network::Plugin');
 
-use base qw(PVE::SectionConfig);
+sub type {
+    return 'vnet';
+}
 
-PVE::Cluster::cfs_register_file('network/vnet.cfg',
-                                 sub { __PACKAGE__->parse_config(@_); },
-                                 sub { __PACKAGE__->write_config(@_); });
 
 
-sub options {
+sub properties {
     return {
-        vnet => { optional => 1 },
-        transportzone => { optional => 1 },
-        tag => { optional => 1 },
-        name => { optional => 1 },
-        ipv4 => { optional => 1 },
-        ipv6 => { optional => 1 },
-        name => { optional => 1 },
-        mtu => { optional => 1 },
-    };
-}
-
-my $defaultData = {
-    propertyList => {
-        vnet => get_standard_option('pve-vnet-id',
-            { completion => \&PVE::Network::Vnet::complete_vnet }),
-
 	transportzone => {
             type => 'string',
             description => "transportzone id",
@@ -67,33 +49,20 @@ my $defaultData = {
             description => "Anycast router mac address",
 	    optional => 1,
         }
-    },
-};
-
-sub type {
-    return 'vnet';
-}
-
-sub private {
-    return $defaultData;
+    };
 }
 
-
-sub parse_section_header {
-    my ($class, $line) = @_;
-
-    if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
-        my ($type, $vnetid) = (lc($1), $2);
-        my $errmsg = undef; # set if you want to skip whole section
-        eval { PVE::JSONSchema::pve_verify_configid($type); };
-        $errmsg = $@ if $@;
-        my $config = {}; # to return additional attributes
-        return ($type, $vnetid, $errmsg, $config);
-    }
-    return undef;
+sub options {
+    return {
+        transportzone => { optional => 1 },
+        tag => { optional => 1 },
+        name => { optional => 1 },
+        ipv4 => { optional => 1 },
+        ipv6 => { optional => 1 },
+        name => { optional => 1 },
+        mtu => { optional => 1 },
+    };
 }
 
-__PACKAGE__->register();
-__PACKAGE__->init();
 
 1;
diff --git a/PVE/Network/Transport/VxlanMulticastPlugin.pm b/PVE/Network/Network/VxlanMulticastPlugin.pm
similarity index 85%
rename from PVE/Network/Transport/VxlanMulticastPlugin.pm
rename to PVE/Network/Network/VxlanMulticastPlugin.pm
index c6fa29d..bcdc133 100644
--- a/PVE/Network/Transport/VxlanMulticastPlugin.pm
+++ b/PVE/Network/Network/VxlanMulticastPlugin.pm
@@ -1,16 +1,16 @@
-package PVE::Network::Transport::VxlanMulticastPlugin;
+package PVE::Network::Network::VxlanMulticastPlugin;
 
 use strict;
 use warnings;
-use PVE::Network::Transport::Plugin;
+use PVE::Network::Network::Plugin;
 
-use base('PVE::Network::Transport::Plugin');
+use base('PVE::Network::Network::Plugin');
 
 PVE::JSONSchema::register_format('pve-network-vxlanrange', \&pve_verify_network_vxlanrange);
 sub pve_verify_network_vxlanrange {
    my ($vxlanstr) = @_;
 
-   PVE::Network::Transport::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
+   PVE::Network::Network::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
 
    return $vxlanstr;
 }
@@ -57,7 +57,7 @@ sub generate_network_config {
     my $iface = $uplinks->{$uplink};
 
     eval {
-	PVE::Network::Transport::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag) if $vxlanallowed;
+	PVE::Network::Network::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag) if $vxlanallowed;
     };
     if($@) {
 	die "vlan $tag is not allowed in transport $zoneid";
diff --git a/PVE/Network/Transport.pm b/PVE/Network/Transport.pm
deleted file mode 100644
index 72cb0b5..0000000
--- a/PVE/Network/Transport.pm
+++ /dev/null
@@ -1,62 +0,0 @@
-package PVE::Network::Transport;
-
-use strict;
-use warnings;
-use Data::Dumper;
-use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
-use PVE::Network::Transport::Plugin;
-use PVE::Network::Transport::VlanPlugin;
-use PVE::Network::Transport::VxlanMulticastPlugin;
-
-PVE::Network::Transport::VlanPlugin->register();
-PVE::Network::Transport::VxlanMulticastPlugin->register();
-PVE::Network::Transport::Plugin->init();
-
-
-sub transport_config {
-    my ($cfg, $transportid, $noerr) = @_;
-
-    die "no transport ID specified\n" if !$transportid;
-
-    my $scfg = $cfg->{ids}->{$transportid};
-    die "transport '$transportid' does not exists\n" if (!$noerr && !$scfg);
-
-    return $scfg;
-}
-
-sub config {
-
-    return cfs_read_file("network/transports.cfg");
-}
-
-sub write_config {
-    my ($cfg) = @_;
-
-    cfs_write_file("network/transports.cfg", $cfg);
-}
-
-sub lock_transport_config {
-    my ($code, $errmsg) = @_;
-
-    cfs_lock_file("network/transports.cfg", undef, $code);
-    my $err = $@;
-    if ($err) {
-        $errmsg ? die "$errmsg: $err" : die $err;
-    }
-}
-
-sub transports_ids {
-    my ($cfg) = @_;
-
-    return keys %{$cfg->{ids}};
-}
-
-sub complete_transport {
-    my ($cmdname, $pname, $cvalue) = @_;
-
-    my $cfg = PVE::Network::Transport::config();
-
-    return  $cmdname eq 'add' ? [] : [ PVE::Network::Transport::transports_ids($cfg) ];
-}
-
-1;
diff --git a/PVE/Network/Vnet.pm b/PVE/Network/Vnet.pm
deleted file mode 100644
index 947dae6..0000000
--- a/PVE/Network/Vnet.pm
+++ /dev/null
@@ -1,71 +0,0 @@
-package PVE::Network::Vnet;
-
-use strict;
-use warnings;
-use Data::Dumper;
-use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
-
-
-sub vnet_config {
-    my ($cfg, $vnetid, $noerr) = @_;
-
-    die "no vnet ID specified\n" if !$vnetid;
-
-    my $scfg = $cfg->{ids}->{$vnetid};
-    die "vnet '$vnetid' does not exists\n" if (!$noerr && !$scfg);
-
-    return $scfg;
-}
-
-sub config {
-
-    return cfs_read_file("network/vnet.cfg");
-}
-
-sub write_config {
-    my ($cfg) = @_;
-    cfs_write_file("network/vnet.cfg", $cfg);
-}
-
-sub lock_vnet_config {
-    my ($code, $errmsg) = @_;
-
-    cfs_lock_file("network/vnet.cfg", undef, $code);
-    my $err = $@;
-    if ($err) {
-        $errmsg ? die "$errmsg: $err" : die $err;
-    }
-}
-
-sub vnets_ids {
-    my ($cfg) = @_;
-
-    return keys %{$cfg->{ids}};
-}
-
-sub complete_vnet {
-    my ($cmdname, $pname, $cvalue) = @_;
-
-    my $cfg = PVE::Network::Vnet::config();
-
-    return  $cmdname eq 'add' ? [] : [ PVE::Network::Vnet::vnets_ids($cfg) ];
-}
-
-
-my $format_config_line = sub {
-    my ($schema, $key, $value) = @_;
-
-    my $ct = $schema->{type};
-
-    die "property '$key' contains a line feed\n"
-        if ($key =~ m/[\n\r]/) || ($value =~ m/[\n\r]/);
-
-    if ($ct eq 'boolean') {
-        return "\t$key " . ($value ? 1 : 0) . "\n"
-            if defined($value);
-    } else {
-        return "\t$key $value\n" if "$value" ne '';
-    }
-};
-
-1;
diff --git a/PVE/Network/Vnet/Makefile b/PVE/Network/Vnet/Makefile
deleted file mode 100644
index 8d4a818..0000000
--- a/PVE/Network/Vnet/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-SOURCES=Plugin.pm
-
-
-PERL5DIR=${DESTDIR}/usr/share/perl5
-
-.PHONY: install
-install:
-	for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/Network/Vnet/$$i; done
-
-- 
2.11.0




More information about the pve-devel mailing list