]> git.proxmox.com Git - pve-network.git/blame_incremental - PVE/API2/Network/SDN.pm
subnets: move api to /sdn/vnet/<vnet>/subnets && make vnet option not optionnal
[pve-network.git] / PVE / API2 / Network / SDN.pm
... / ...
CommitLineData
1package PVE::API2::Network::SDN;
2
3use strict;
4use warnings;
5
6use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file);
7use PVE::Exception qw(raise_param_exc);
8use PVE::JSONSchema qw(get_standard_option);
9use PVE::RESTHandler;
10use PVE::RPCEnvironment;
11use PVE::SafeSyslog;
12use PVE::Tools qw(run_command);
13
14use PVE::API2::Network::SDN::Controllers;
15use PVE::API2::Network::SDN::Vnets;
16use PVE::API2::Network::SDN::Zones;
17use PVE::API2::Network::SDN::Ipams;
18use PVE::API2::Network::SDN::Dns;
19
20use base qw(PVE::RESTHandler);
21
22__PACKAGE__->register_method ({
23 subclass => "PVE::API2::Network::SDN::Vnets",
24 path => 'vnets',
25});
26
27__PACKAGE__->register_method ({
28 subclass => "PVE::API2::Network::SDN::Zones",
29 path => 'zones',
30});
31
32__PACKAGE__->register_method ({
33 subclass => "PVE::API2::Network::SDN::Controllers",
34 path => 'controllers',
35});
36
37__PACKAGE__->register_method ({
38 subclass => "PVE::API2::Network::SDN::Ipams",
39 path => 'ipams',
40});
41
42__PACKAGE__->register_method ({
43 subclass => "PVE::API2::Network::SDN::Dns",
44 path => 'dns',
45});
46
47__PACKAGE__->register_method({
48 name => 'index',
49 path => '',
50 method => 'GET',
51 description => "Directory index.",
52 permissions => {
53 check => ['perm', '/', [ 'SDN.Audit' ]],
54 },
55 parameters => {
56 additionalProperties => 0,
57 properties => {},
58 },
59 returns => {
60 type => 'array',
61 items => {
62 type => "object",
63 properties => {
64 id => { type => 'string' },
65 },
66 },
67 links => [ { rel => 'child', href => "{id}" } ],
68 },
69 code => sub {
70 my ($param) = @_;
71
72 my $res = [
73 { id => 'vnets' },
74 { id => 'zones' },
75 { id => 'controllers' },
76 { id => 'ipams' },
77 { id => 'dns' },
78 ];
79
80 return $res;
81 }});
82
83my $create_reload_network_worker = sub {
84 my ($nodename) = @_;
85
86 # FIXME: how to proxy to final node ?
87 my $upid;
88 run_command(['pvesh', 'set', "/nodes/$nodename/network"], outfunc => sub {
89 my $line = shift;
90 if ($line =~ /^["']?(UPID:[^\s"']+)["']?$/) {
91 $upid = $1;
92 }
93 });
94 #my $upid = PVE::API2::Network->reload_network_config(node => $nodename});
95 my $res = PVE::Tools::upid_decode($upid);
96
97 return $res->{pid};
98};
99
100__PACKAGE__->register_method ({
101 name => 'reload',
102 protected => 1,
103 path => '',
104 method => 'PUT',
105 description => "Apply sdn controller changes && reload.",
106 permissions => {
107 check => ['perm', '/sdn', ['SDN.Allocate']],
108 },
109 parameters => {
110 additionalProperties => 0,
111 },
112 returns => {
113 type => 'string',
114 },
115 code => sub {
116 my ($param) = @_;
117
118 my $rpcenv = PVE::RPCEnvironment::get();
119 my $authuser = $rpcenv->get_user();
120
121 my $code = sub {
122 $rpcenv->{type} = 'priv'; # to start tasks in background
123 PVE::Cluster::check_cfs_quorum();
124 my $nodelist = PVE::Cluster::get_nodelist();
125 for my $node (@$nodelist) {
126 my $pid = eval { $create_reload_network_worker->($node) };
127 warn $@ if $@;
128 }
129
130 # FIXME: use libpve-apiclient (like in cluster join) to create
131 # tasks and moitor the tasks.
132
133 return;
134 };
135
136 return $rpcenv->fork_worker('reloadnetworkall', undef, $authuser, $code);
137
138 }});
139
140
1411;