[pve-devel] [PATCH v2 pve-network 03/15] api2: sdn: add reload config
Alexandre Derumier
aderumier at odiso.com
Tue Nov 26 10:00:18 CET 2019
fixme: current using pvesh
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Network/SDN.pm | 65 +++++++++++++++++++++++++++++
PVE/API2/Network/SDN/Controllers.pm | 24 -----------
PVE/API2/Network/SDN/Vnets.pm | 24 -----------
PVE/API2/Network/SDN/Zones.pm | 24 -----------
4 files changed, 65 insertions(+), 72 deletions(-)
diff --git a/PVE/API2/Network/SDN.pm b/PVE/API2/Network/SDN.pm
index 512e0b2..66856c5 100644
--- a/PVE/API2/Network/SDN.pm
+++ b/PVE/API2/Network/SDN.pm
@@ -65,5 +65,70 @@ __PACKAGE__->register_method({
return $res;
}});
+my $create_reload_network_worker = sub {
+ my ($nodename) = @_;
+
+ #fixme: how to proxy to final node ?
+ my $upid = PVE::Tools::run_command(['pvesh', 'set', "/nodes/$nodename/network"]);
+ #my $upid = PVE::API2::Network->reload_network_config(node => $nodename});
+ my $res = PVE::Tools::upid_decode($upid);
+
+ return $res->{pid};
+};
+
+__PACKAGE__->register_method ({
+ name => 'reload',
+ protected => 1,
+ path => '',
+ method => 'PUT',
+ description => "Apply sdn controller changes && reload.",
+# permissions => {
+# check => ['perm', '/cluster/sdn/controllers', ['SDN.Allocate']],
+# },
+ parameters => {
+ additionalProperties => 0,
+ },
+ returns => {
+ type => 'string',
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+ my $authuser = $rpcenv->get_user();
+
+ if (-e "/etc/pve/sdn/controllers.cfg.new") {
+ rename("/etc/pve/sdn/controllers.cfg.new", "/etc/pve/sdn/controllers.cfg")
+ || die "applying sdn/controllers.cfg changes failed - $!\n";
+ }
+
+ if (-e "/etc/pve/sdn/zones.cfg.new") {
+ rename("/etc/pve/sdn/zones.cfg.new", "/etc/pve/sdn/zones.cfg")
+ || die "applying sdn/zones.cfg changes failed - $!\n";
+ }
+
+ if (-e "/etc/pve/sdn/vnets.cfg.new") {
+ rename("/etc/pve/sdn/vnets.cfg.new", "/etc/pve/sdn/vnets.cfg")
+ || die "applying sdn/vnets.cfg changes failed - $!\n";
+ }
+
+ my $code = sub {
+ $rpcenv->{type} = 'priv'; # to start tasks in background
+ PVE::Cluster::check_cfs_quorum();
+ my $nodelist = PVE::Cluster::get_nodelist();
+ foreach my $node (@$nodelist) {
+
+ my $pid;
+ eval { $pid = &$create_reload_network_worker($node); };
+ warn $@ if $@;
+ next if !$pid;
+ }
+ return;
+ };
+
+ return $rpcenv->fork_worker('reloadnetworkall', undef, $authuser, $code);
+
+ }});
+
1;
diff --git a/PVE/API2/Network/SDN/Controllers.pm b/PVE/API2/Network/SDN/Controllers.pm
index 99fd138..7b8356d 100644
--- a/PVE/API2/Network/SDN/Controllers.pm
+++ b/PVE/API2/Network/SDN/Controllers.pm
@@ -152,30 +152,6 @@ __PACKAGE__->register_method ({
return undef;
}});
-__PACKAGE__->register_method ({
- name => 'apply_configuration',
- protected => 1,
- path => '',
- method => 'PUT',
- description => "Apply sdn controller changes.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/controllers', ['SDN.Allocate']],
-# },
- parameters => {
- additionalProperties => 0,
- },
- returns => { type => 'null' },
- code => sub {
- my ($param) = @_;
-
- die "no sdn controller changes to apply" if !-e "/etc/pve/sdn/controllers.cfg.new";
- rename("/etc/pve/sdn/controllers.cfg.new", "/etc/pve/sdn/controllers.cfg")
- || die "applying sdn/controllers.cfg changes failed - $!\n";
-
-
- return undef;
- }});
-
__PACKAGE__->register_method ({
name => 'revert_configuration',
protected => 1,
diff --git a/PVE/API2/Network/SDN/Vnets.pm b/PVE/API2/Network/SDN/Vnets.pm
index 0526b06..bb3415f 100644
--- a/PVE/API2/Network/SDN/Vnets.pm
+++ b/PVE/API2/Network/SDN/Vnets.pm
@@ -133,30 +133,6 @@ __PACKAGE__->register_method ({
return undef;
}});
-__PACKAGE__->register_method ({
- name => 'apply_configuration',
- protected => 1,
- path => '',
- method => 'PUT',
- description => "Apply sdn vnet changes.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/vnets', ['SDN.Allocate']],
-# },
- parameters => {
- additionalProperties => 0,
- },
- returns => { type => 'null' },
- code => sub {
- my ($param) = @_;
-
- die "no sdn vnet changes to apply" if !-e "/etc/pve/sdn/vnets.cfg.new";
- rename("/etc/pve/sdn/vnets.cfg.new", "/etc/pve/sdn/vnets.cfg")
- || die "applying sdn/vnets.cfg changes failed - $!\n";
-
-
- return undef;
- }});
-
__PACKAGE__->register_method ({
name => 'revert_configuration',
protected => 1,
diff --git a/PVE/API2/Network/SDN/Zones.pm b/PVE/API2/Network/SDN/Zones.pm
index a447813..ce99bd8 100644
--- a/PVE/API2/Network/SDN/Zones.pm
+++ b/PVE/API2/Network/SDN/Zones.pm
@@ -155,30 +155,6 @@ __PACKAGE__->register_method ({
return undef;
}});
-__PACKAGE__->register_method ({
- name => 'apply_configuration',
- protected => 1,
- path => '',
- method => 'PUT',
- description => "Apply sdn zone changes.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
-# },
- parameters => {
- additionalProperties => 0,
- },
- returns => { type => 'null' },
- code => sub {
- my ($param) = @_;
-
- die "no sdn zone changes to apply" if !-e "/etc/pve/sdn/zones.cfg.new";
- rename("/etc/pve/sdn/zones.cfg.new", "/etc/pve/sdn/zones.cfg")
- || die "applying sdn/zones.cfg changes failed - $!\n";
-
-
- return undef;
- }});
-
__PACKAGE__->register_method ({
name => 'revert_configuration',
protected => 1,
--
2.20.1
More information about the pve-devel
mailing list