]> git.proxmox.com Git - pve-network.git/blame - 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
86d22462 1package PVE::API2::Network::SDN;
92b6f291
AD
2
3use strict;
4use warnings;
5
4140be9e 6use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file);
14e55c65
TL
7use PVE::Exception qw(raise_param_exc);
8use PVE::JSONSchema qw(get_standard_option);
92b6f291 9use PVE::RESTHandler;
4140be9e 10use PVE::RPCEnvironment;
14e55c65
TL
11use PVE::SafeSyslog;
12use PVE::Tools qw(run_command);
13
14use PVE::API2::Network::SDN::Controllers;
4140be9e
AD
15use PVE::API2::Network::SDN::Vnets;
16use PVE::API2::Network::SDN::Zones;
70b03506 17use PVE::API2::Network::SDN::Ipams;
ee4f339e 18use PVE::API2::Network::SDN::Dns;
92b6f291
AD
19
20use base qw(PVE::RESTHandler);
21
4140be9e 22__PACKAGE__->register_method ({
35854815 23 subclass => "PVE::API2::Network::SDN::Vnets",
4140be9e 24 path => 'vnets',
35854815 25});
92b6f291 26
4140be9e 27__PACKAGE__->register_method ({
35854815 28 subclass => "PVE::API2::Network::SDN::Zones",
4140be9e 29 path => 'zones',
35854815 30});
92b6f291
AD
31
32__PACKAGE__->register_method ({
35854815 33 subclass => "PVE::API2::Network::SDN::Controllers",
4140be9e
AD
34 path => 'controllers',
35});
36
70b03506
AD
37__PACKAGE__->register_method ({
38 subclass => "PVE::API2::Network::SDN::Ipams",
39 path => 'ipams',
40});
41
ee4f339e
AD
42__PACKAGE__->register_method ({
43 subclass => "PVE::API2::Network::SDN::Dns",
44 path => 'dns',
45});
46
4140be9e 47__PACKAGE__->register_method({
35854815
TL
48 name => 'index',
49 path => '',
92b6f291 50 method => 'GET',
4140be9e 51 description => "Directory index.",
7d35eaf5 52 permissions => {
3551b612 53 check => ['perm', '/', [ 'SDN.Audit' ]],
92b6f291
AD
54 },
55 parameters => {
56 additionalProperties => 0,
4140be9e 57 properties => {},
92b6f291
AD
58 },
59 returns => {
60 type => 'array',
61 items => {
62 type => "object",
4140be9e
AD
63 properties => {
64 id => { type => 'string' },
65 },
92b6f291 66 },
4140be9e 67 links => [ { rel => 'child', href => "{id}" } ],
92b6f291
AD
68 },
69 code => sub {
70 my ($param) = @_;
71
35854815 72 my $res = [
4140be9e
AD
73 { id => 'vnets' },
74 { id => 'zones' },
75 { id => 'controllers' },
70b03506 76 { id => 'ipams' },
ee4f339e 77 { id => 'dns' },
4140be9e 78 ];
92b6f291
AD
79
80 return $res;
81 }});
82
5d50e70b
AD
83my $create_reload_network_worker = sub {
84 my ($nodename) = @_;
85
14e55c65
TL
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 });
5d50e70b
AD
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.",
3551b612
AD
106 permissions => {
107 check => ['perm', '/sdn', ['SDN.Allocate']],
108 },
5d50e70b
AD
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
5d50e70b
AD
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();
14e55c65
TL
125 for my $node (@$nodelist) {
126 my $pid = eval { $create_reload_network_worker->($node) };
5d50e70b 127 warn $@ if $@;
5d50e70b 128 }
14e55c65
TL
129
130 # FIXME: use libpve-apiclient (like in cluster join) to create
131 # tasks and moitor the tasks.
132
5d50e70b
AD
133 return;
134 };
135
136 return $rpcenv->fork_worker('reloadnetworkall', undef, $authuser, $code);
137
138 }});
139
92b6f291
AD
140
1411;