]> git.proxmox.com Git - pve-network.git/commitdiff
api2: sdn: add reload config
authorAlexandre Derumier <aderumier@odiso.com>
Tue, 26 Nov 2019 09:00:18 +0000 (10:00 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 26 Nov 2019 11:33:40 +0000 (12:33 +0100)
fixme: current using pvesh
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Network/SDN.pm
PVE/API2/Network/SDN/Controllers.pm
PVE/API2/Network/SDN/Vnets.pm
PVE/API2/Network/SDN/Zones.pm

index 512e0b2bfe8caef0feb1a055562b066642995c2a..66856c52b31cc123acd147cb1219498482316bca 100644 (file)
@@ -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;
index 99fd1389b6241f15ef9a1efac867b35da58a1c71..7b8356d8d08cba12c0eab08c6208b377568b78a1 100644 (file)
@@ -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,
index 0526b0615a81b9450fac1a7709e3c37304adbfe2..bb3415f3b718b64207c108ed728ae9aa47f00768 100644 (file)
@@ -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,
index a4478130a4eea1a172d5a30600f9e2f7658d6744..ce99bd80d761ebd81d0dd202fa026b413597fc34 100644 (file)
@@ -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,