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