]>
Commit | Line | Data |
---|---|---|
86d22462 | 1 | package PVE::API2::Network::SDN; |
92b6f291 AD |
2 | |
3 | use strict; | |
4 | use warnings; | |
5 | ||
4140be9e | 6 | use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file); |
14e55c65 TL |
7 | use PVE::Exception qw(raise_param_exc); |
8 | use PVE::JSONSchema qw(get_standard_option); | |
92b6f291 | 9 | use PVE::RESTHandler; |
4140be9e | 10 | use PVE::RPCEnvironment; |
14e55c65 TL |
11 | use PVE::SafeSyslog; |
12 | use PVE::Tools qw(run_command); | |
13 | ||
14 | use PVE::API2::Network::SDN::Controllers; | |
4140be9e AD |
15 | use PVE::API2::Network::SDN::Vnets; |
16 | use PVE::API2::Network::SDN::Zones; | |
c33dd818 | 17 | use PVE::API2::Network::SDN::Subnets; |
70b03506 | 18 | use PVE::API2::Network::SDN::Ipams; |
92b6f291 AD |
19 | |
20 | use 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 | ||
c33dd818 AD |
37 | __PACKAGE__->register_method ({ |
38 | subclass => "PVE::API2::Network::SDN::Subnets", | |
39 | path => 'subnets', | |
40 | }); | |
41 | ||
70b03506 AD |
42 | __PACKAGE__->register_method ({ |
43 | subclass => "PVE::API2::Network::SDN::Ipams", | |
44 | path => 'ipams', | |
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' }, | |
c33dd818 | 76 | { id => 'subnets' }, |
70b03506 | 77 | { id => 'ipams' }, |
4140be9e | 78 | ]; |
92b6f291 AD |
79 | |
80 | return $res; | |
81 | }}); | |
82 | ||
5d50e70b AD |
83 | my $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 | |
141 | 1; |