[pve-devel] [PATCH pve-network 2/3] move transport plugins to Network/Transport/

Alexandre Derumier aderumier at odiso.com
Wed Apr 3 00:19:10 CEST 2019


---
 PVE/API2/Network/Transport.pm                      | 32 +++++++++++-----------
 PVE/Network/Makefile                               |  6 ++--
 PVE/Network/Transport.pm                           | 12 ++++----
 PVE/Network/Transport/Makefile                     |  9 ++++++
 PVE/Network/{ => Transport}/Plugin.pm              |  2 +-
 PVE/Network/{ => Transport}/VlanPlugin.pm          | 10 +++----
 .../{ => Transport}/VxlanMulticastPlugin.pm        | 10 +++----
 PVE/Network/Vnet/Makefile                          |  2 +-
 8 files changed, 46 insertions(+), 37 deletions(-)
 create mode 100644 PVE/Network/Transport/Makefile
 rename PVE/Network/{ => Transport}/Plugin.pm (98%)
 rename PVE/Network/{ => Transport}/VlanPlugin.pm (87%)
 rename PVE/Network/{ => Transport}/VxlanMulticastPlugin.pm (85%)

diff --git a/PVE/API2/Network/Transport.pm b/PVE/API2/Network/Transport.pm
index bddae40..0e1610f 100644
--- a/PVE/API2/Network/Transport.pm
+++ b/PVE/API2/Network/Transport.pm
@@ -7,9 +7,9 @@ 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::Plugin;
-use PVE::Network::VlanPlugin;
-use PVE::Network::VxlanMulticastPlugin;
+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;
@@ -18,7 +18,7 @@ use PVE::RESTHandler;
 
 use base qw(PVE::RESTHandler);
 
-my $transport_type_enum = PVE::Network::Plugin->lookup_types();
+my $transport_type_enum = PVE::Network::Transport::Plugin->lookup_types();
 
 my $api_transport_config = sub {
     my ($cfg, $transportid) = @_;
@@ -36,7 +36,7 @@ __PACKAGE__->register_method ({
     method => 'GET',
     description => "Transport index.",
     permissions => { 
-	description => "Only list entries where you have 'NetworkTransport.Audit' or 'NetworkTransport.Allocate' permissions on '/networktransports/<transport>'",
+	description => "Only list entries where you have 'NetworkTransport.Audit' or 'NetworkTransport.Allocate' permissions on '/cluster/network/transport/<transport>'",
 	user => 'all',
     },
     parameters => {
@@ -71,7 +71,7 @@ __PACKAGE__->register_method ({
 	my $res = [];
 	foreach my $transportid (@sids) {
 #	    my $privs = [ 'NetworkTransport.Audit', 'NetworkTransport.Allocate' ];
-#	    next if !$rpcenv->check_any($authuser, "/network/transports/$transportid", $privs, 1);
+#	    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};
@@ -87,7 +87,7 @@ __PACKAGE__->register_method ({
     method => 'GET',
     description => "Read transport configuration.",
 #    permissions => { 
-#	check => ['perm', '/network/transports/{transport}', ['NetworkTransport.Allocate']],
+#	check => ['perm', '/cluster/network/transport/{transport}', ['NetworkTransport.Allocate']],
 #   },
 
     parameters => {
@@ -112,9 +112,9 @@ __PACKAGE__->register_method ({
     method => 'POST',
     description => "Create a new network transport.",
 #    permissions => { 
-#	check => ['perm', '/network/transports', ['NetworkTransport.Allocate']],
+#	check => ['perm', '/cluster/network/transport', ['NetworkTransport.Allocate']],
 #    },
-    parameters => PVE::Network::Plugin->createSchema(),
+    parameters => PVE::Network::Transport::Plugin->createSchema(),
     returns => { type => 'null' },
     code => sub {
 	my ($param) = @_;
@@ -122,7 +122,7 @@ __PACKAGE__->register_method ({
 	my $type = extract_param($param, 'type');
 	my $transportid = extract_param($param, 'transport');
 
-	my $plugin = PVE::Network::Plugin->lookup($type);
+	my $plugin = PVE::Network::Transport::Plugin->lookup($type);
 	my $opts = $plugin->check_config($transportid, $param, 1, 1);
 
         PVE::Network::Transport::lock_transport_config(
@@ -153,9 +153,9 @@ __PACKAGE__->register_method ({
     method => 'PUT',
     description => "Update network transport configuration.",
 #    permissions => { 
-#	check => ['perm', '/network/transports', ['NetworkTransport.Allocate']],
+#	check => ['perm', '/cluster/network/transport', ['NetworkTransport.Allocate']],
 #    },
-    parameters => PVE::Network::Plugin->updateSchema(),
+    parameters => PVE::Network::Transport::Plugin->updateSchema(),
     returns => { type => 'null' },
     code => sub {
 	my ($param) = @_;
@@ -172,7 +172,7 @@ __PACKAGE__->register_method ({
 
 	    my $scfg = PVE::Network::Transport::transport_config($cfg, $transportid);
 
-	    my $plugin = PVE::Network::Plugin->lookup($scfg->{type});
+	    my $plugin = PVE::Network::Transport::Plugin->lookup($scfg->{type});
 	    my $opts = $plugin->check_config($transportid, $param, 0, 1);
 
 	    foreach my $k (%$opts) {
@@ -191,11 +191,11 @@ __PACKAGE__->register_method ({
 __PACKAGE__->register_method ({
     name => 'delete',
     protected => 1,
-    path => '{transport}', # /network/transports/{transport}
+    path => '{transport}', # /cluster/network/transport/{transport}
     method => 'DELETE',
     description => "Delete network transport configuration.",
 #    permissions => { 
-#	check => ['perm', '/network/transports', ['NetworkTransport.Allocate']],
+#	check => ['perm', '/cluster/network/transport', ['NetworkTransport.Allocate']],
 #    },
     parameters => {
     	additionalProperties => 0,
@@ -218,7 +218,7 @@ __PACKAGE__->register_method ({
 
 		my $scfg = PVE::Network::Transport::transport_config($cfg, $transportid);
 
-#		my $plugin = PVE::Network::Plugin->lookup($scfg->{type});
+#		my $plugin = PVE::Network::Transport::Plugin->lookup($scfg->{type});
 #		$plugin->on_delete_hook($transportid, $scfg);
 
 		delete $cfg->{ids}->{$transportid};
diff --git a/PVE/Network/Makefile b/PVE/Network/Makefile
index dd74a2a..66eeec8 100644
--- a/PVE/Network/Makefile
+++ b/PVE/Network/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Plugin.pm VlanPlugin.pm Vnet.pm VxlanMulticastPlugin.pm
+SOURCES=Vnet.pm Transport.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
@@ -6,5 +6,5 @@ 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 Vnet install
+	make -C Transport install
diff --git a/PVE/Network/Transport.pm b/PVE/Network/Transport.pm
index 1b8a2ca..72cb0b5 100644
--- a/PVE/Network/Transport.pm
+++ b/PVE/Network/Transport.pm
@@ -4,13 +4,13 @@ use strict;
 use warnings;
 use Data::Dumper;
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
-use PVE::Network::Plugin;
-use PVE::Network::VlanPlugin;
-use PVE::Network::VxlanMulticastPlugin;
+use PVE::Network::Transport::Plugin;
+use PVE::Network::Transport::VlanPlugin;
+use PVE::Network::Transport::VxlanMulticastPlugin;
 
-PVE::Network::VlanPlugin->register();
-PVE::Network::VxlanMulticastPlugin->register();
-PVE::Network::Plugin->init();
+PVE::Network::Transport::VlanPlugin->register();
+PVE::Network::Transport::VxlanMulticastPlugin->register();
+PVE::Network::Transport::Plugin->init();
 
 
 sub transport_config {
diff --git a/PVE/Network/Transport/Makefile b/PVE/Network/Transport/Makefile
new file mode 100644
index 0000000..938e87b
--- /dev/null
+++ b/PVE/Network/Transport/Makefile
@@ -0,0 +1,9 @@
+SOURCES=Plugin.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
+
diff --git a/PVE/Network/Plugin.pm b/PVE/Network/Transport/Plugin.pm
similarity index 98%
rename from PVE/Network/Plugin.pm
rename to PVE/Network/Transport/Plugin.pm
index 36cd2ed..dcebbcf 100644
--- a/PVE/Network/Plugin.pm
+++ b/PVE/Network/Transport/Plugin.pm
@@ -1,4 +1,4 @@
-package PVE::Network::Plugin;
+package PVE::Network::Transport::Plugin;
 
 use strict;
 use warnings;
diff --git a/PVE/Network/VlanPlugin.pm b/PVE/Network/Transport/VlanPlugin.pm
similarity index 87%
rename from PVE/Network/VlanPlugin.pm
rename to PVE/Network/Transport/VlanPlugin.pm
index 7d64549..8ee8bdc 100644
--- a/PVE/Network/VlanPlugin.pm
+++ b/PVE/Network/Transport/VlanPlugin.pm
@@ -1,10 +1,10 @@
-package PVE::Network::VlanPlugin;
+package PVE::Network::Transport::VlanPlugin;
 
 use strict;
 use warnings;
-use PVE::Network::Plugin;
+use PVE::Network::Transport::Plugin;
 
-use base('PVE::Network::Plugin');
+use base('PVE::Network::Transport::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::Plugin::parse_tag_number_or_range($vlanstr, '4096');
+   PVE::Network::Transport::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::Plugin::parse_tag_number_or_range($vlanallowed, '4096', $tag) if $vlanallowed;
+	PVE::Network::Transport::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/VxlanMulticastPlugin.pm b/PVE/Network/Transport/VxlanMulticastPlugin.pm
similarity index 85%
rename from PVE/Network/VxlanMulticastPlugin.pm
rename to PVE/Network/Transport/VxlanMulticastPlugin.pm
index 3aa6e35..c6fa29d 100644
--- a/PVE/Network/VxlanMulticastPlugin.pm
+++ b/PVE/Network/Transport/VxlanMulticastPlugin.pm
@@ -1,16 +1,16 @@
-package PVE::Network::VxlanMulticastPlugin;
+package PVE::Network::Transport::VxlanMulticastPlugin;
 
 use strict;
 use warnings;
-use PVE::Network::Plugin;
+use PVE::Network::Transport::Plugin;
 
-use base('PVE::Network::Plugin');
+use base('PVE::Network::Transport::Plugin');
 
 PVE::JSONSchema::register_format('pve-network-vxlanrange', \&pve_verify_network_vxlanrange);
 sub pve_verify_network_vxlanrange {
    my ($vxlanstr) = @_;
 
-   PVE::Network::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
+   PVE::Network::Transport::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::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag) if $vxlanallowed;
+	PVE::Network::Transport::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/Vnet/Makefile b/PVE/Network/Vnet/Makefile
index bac1a8c..8d4a818 100644
--- a/PVE/Network/Vnet/Makefile
+++ b/PVE/Network/Vnet/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Plugin.pm VlanPlugin.pm
+SOURCES=Plugin.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
-- 
2.11.0




More information about the pve-devel mailing list