2019-06-07 06:52:13 +02:00
|
|
|
package PVE::API2::Network::SDN;
|
2019-04-04 09:14:22 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2019-11-26 10:00:17 +01:00
|
|
|
use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file);
|
2020-05-12 14:48:31 +02:00
|
|
|
use PVE::Exception qw(raise_param_exc);
|
|
|
|
use PVE::JSONSchema qw(get_standard_option);
|
2019-04-04 09:14:22 +02:00
|
|
|
use PVE::RESTHandler;
|
2019-11-26 10:00:17 +01:00
|
|
|
use PVE::RPCEnvironment;
|
2020-05-12 14:48:31 +02:00
|
|
|
use PVE::SafeSyslog;
|
|
|
|
use PVE::Tools qw(run_command);
|
2020-10-05 17:08:46 +02:00
|
|
|
use PVE::Network::SDN;
|
2020-05-12 14:48:31 +02:00
|
|
|
|
|
|
|
use PVE::API2::Network::SDN::Controllers;
|
2019-11-26 10:00:17 +01:00
|
|
|
use PVE::API2::Network::SDN::Vnets;
|
|
|
|
use PVE::API2::Network::SDN::Zones;
|
2020-10-05 17:08:47 +02:00
|
|
|
use PVE::API2::Network::SDN::Ipams;
|
2020-10-05 17:08:52 +02:00
|
|
|
use PVE::API2::Network::SDN::Dns;
|
2019-04-04 09:14:22 +02:00
|
|
|
|
|
|
|
use base qw(PVE::RESTHandler);
|
|
|
|
|
2019-11-26 10:00:17 +01:00
|
|
|
__PACKAGE__->register_method ({
|
2020-03-10 18:58:52 +01:00
|
|
|
subclass => "PVE::API2::Network::SDN::Vnets",
|
2019-11-26 10:00:17 +01:00
|
|
|
path => 'vnets',
|
2020-03-10 18:58:52 +01:00
|
|
|
});
|
2019-04-04 09:14:22 +02:00
|
|
|
|
2019-11-26 10:00:17 +01:00
|
|
|
__PACKAGE__->register_method ({
|
2020-03-10 18:58:52 +01:00
|
|
|
subclass => "PVE::API2::Network::SDN::Zones",
|
2019-11-26 10:00:17 +01:00
|
|
|
path => 'zones',
|
2020-03-10 18:58:52 +01:00
|
|
|
});
|
2019-04-04 09:14:22 +02:00
|
|
|
|
|
|
|
__PACKAGE__->register_method ({
|
2020-03-10 18:58:52 +01:00
|
|
|
subclass => "PVE::API2::Network::SDN::Controllers",
|
2019-11-26 10:00:17 +01:00
|
|
|
path => 'controllers',
|
|
|
|
});
|
|
|
|
|
2020-10-05 17:08:47 +02:00
|
|
|
__PACKAGE__->register_method ({
|
|
|
|
subclass => "PVE::API2::Network::SDN::Ipams",
|
|
|
|
path => 'ipams',
|
|
|
|
});
|
|
|
|
|
2020-10-05 17:08:52 +02:00
|
|
|
__PACKAGE__->register_method ({
|
|
|
|
subclass => "PVE::API2::Network::SDN::Dns",
|
|
|
|
path => 'dns',
|
|
|
|
});
|
|
|
|
|
2019-11-26 10:00:17 +01:00
|
|
|
__PACKAGE__->register_method({
|
2020-03-10 18:58:52 +01:00
|
|
|
name => 'index',
|
|
|
|
path => '',
|
2019-04-04 09:14:22 +02:00
|
|
|
method => 'GET',
|
2019-11-26 10:00:17 +01:00
|
|
|
description => "Directory index.",
|
2019-09-03 08:25:00 +02:00
|
|
|
permissions => {
|
2019-11-26 10:00:26 +01:00
|
|
|
check => ['perm', '/', [ 'SDN.Audit' ]],
|
2019-04-04 09:14:22 +02:00
|
|
|
},
|
|
|
|
parameters => {
|
|
|
|
additionalProperties => 0,
|
2019-11-26 10:00:17 +01:00
|
|
|
properties => {},
|
2019-04-04 09:14:22 +02:00
|
|
|
},
|
|
|
|
returns => {
|
|
|
|
type => 'array',
|
|
|
|
items => {
|
|
|
|
type => "object",
|
2019-11-26 10:00:17 +01:00
|
|
|
properties => {
|
|
|
|
id => { type => 'string' },
|
|
|
|
},
|
2019-04-04 09:14:22 +02:00
|
|
|
},
|
2019-11-26 10:00:17 +01:00
|
|
|
links => [ { rel => 'child', href => "{id}" } ],
|
2019-04-04 09:14:22 +02:00
|
|
|
},
|
|
|
|
code => sub {
|
|
|
|
my ($param) = @_;
|
|
|
|
|
2020-03-10 18:58:52 +01:00
|
|
|
my $res = [
|
2019-11-26 10:00:17 +01:00
|
|
|
{ id => 'vnets' },
|
|
|
|
{ id => 'zones' },
|
|
|
|
{ id => 'controllers' },
|
2020-10-05 17:08:47 +02:00
|
|
|
{ id => 'ipams' },
|
2020-10-05 17:08:52 +02:00
|
|
|
{ id => 'dns' },
|
2019-11-26 10:00:17 +01:00
|
|
|
];
|
2019-04-04 09:14:22 +02:00
|
|
|
|
|
|
|
return $res;
|
|
|
|
}});
|
|
|
|
|
2019-11-26 10:00:18 +01:00
|
|
|
my $create_reload_network_worker = sub {
|
|
|
|
my ($nodename) = @_;
|
|
|
|
|
2020-05-12 14:48:31 +02:00
|
|
|
# FIXME: how to proxy to final node ?
|
|
|
|
my $upid;
|
|
|
|
run_command(['pvesh', 'set', "/nodes/$nodename/network"], outfunc => sub {
|
|
|
|
my $line = shift;
|
|
|
|
if ($line =~ /^["']?(UPID:[^\s"']+)["']?$/) {
|
|
|
|
$upid = $1;
|
|
|
|
}
|
|
|
|
});
|
2019-11-26 10:00:18 +01:00
|
|
|
#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.",
|
2019-11-26 10:00:26 +01:00
|
|
|
permissions => {
|
|
|
|
check => ['perm', '/sdn', ['SDN.Allocate']],
|
|
|
|
},
|
2019-11-26 10:00:18 +01:00
|
|
|
parameters => {
|
|
|
|
additionalProperties => 0,
|
|
|
|
},
|
|
|
|
returns => {
|
|
|
|
type => 'string',
|
|
|
|
},
|
|
|
|
code => sub {
|
|
|
|
my ($param) = @_;
|
|
|
|
|
|
|
|
my $rpcenv = PVE::RPCEnvironment::get();
|
|
|
|
my $authuser = $rpcenv->get_user();
|
|
|
|
|
2020-10-05 17:08:46 +02:00
|
|
|
PVE::Network::SDN::commit_config();
|
|
|
|
|
2019-11-26 10:00:18 +01:00
|
|
|
my $code = sub {
|
|
|
|
$rpcenv->{type} = 'priv'; # to start tasks in background
|
|
|
|
PVE::Cluster::check_cfs_quorum();
|
|
|
|
my $nodelist = PVE::Cluster::get_nodelist();
|
2020-05-12 14:48:31 +02:00
|
|
|
for my $node (@$nodelist) {
|
|
|
|
my $pid = eval { $create_reload_network_worker->($node) };
|
2019-11-26 10:00:18 +01:00
|
|
|
warn $@ if $@;
|
|
|
|
}
|
2020-05-12 14:48:31 +02:00
|
|
|
|
|
|
|
# FIXME: use libpve-apiclient (like in cluster join) to create
|
|
|
|
# tasks and moitor the tasks.
|
|
|
|
|
2019-11-26 10:00:18 +01:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
return $rpcenv->fork_worker('reloadnetworkall', undef, $authuser, $code);
|
|
|
|
|
|
|
|
}});
|
|
|
|
|
2019-04-04 09:14:22 +02:00
|
|
|
|
|
|
|
1;
|