]> git.proxmox.com Git - pve-network.git/blame - PVE/API2/Network/SDN.pm
add DNS plugin
[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;
c33dd818 17use PVE::API2::Network::SDN::Subnets;
70b03506 18use PVE::API2::Network::SDN::Ipams;
ee4f339e 19use PVE::API2::Network::SDN::Dns;
92b6f291
AD
20
21use base qw(PVE::RESTHandler);
22
4140be9e 23__PACKAGE__->register_method ({
35854815 24 subclass => "PVE::API2::Network::SDN::Vnets",
4140be9e 25 path => 'vnets',
35854815 26});
92b6f291 27
4140be9e 28__PACKAGE__->register_method ({
35854815 29 subclass => "PVE::API2::Network::SDN::Zones",
4140be9e 30 path => 'zones',
35854815 31});
92b6f291
AD
32
33__PACKAGE__->register_method ({
35854815 34 subclass => "PVE::API2::Network::SDN::Controllers",
4140be9e
AD
35 path => 'controllers',
36});
37
c33dd818
AD
38__PACKAGE__->register_method ({
39 subclass => "PVE::API2::Network::SDN::Subnets",
40 path => 'subnets',
41});
42
70b03506
AD
43__PACKAGE__->register_method ({
44 subclass => "PVE::API2::Network::SDN::Ipams",
45 path => 'ipams',
46});
47
ee4f339e
AD
48__PACKAGE__->register_method ({
49 subclass => "PVE::API2::Network::SDN::Dns",
50 path => 'dns',
51});
52
4140be9e 53__PACKAGE__->register_method({
35854815
TL
54 name => 'index',
55 path => '',
92b6f291 56 method => 'GET',
4140be9e 57 description => "Directory index.",
7d35eaf5 58 permissions => {
3551b612 59 check => ['perm', '/', [ 'SDN.Audit' ]],
92b6f291
AD
60 },
61 parameters => {
62 additionalProperties => 0,
4140be9e 63 properties => {},
92b6f291
AD
64 },
65 returns => {
66 type => 'array',
67 items => {
68 type => "object",
4140be9e
AD
69 properties => {
70 id => { type => 'string' },
71 },
92b6f291 72 },
4140be9e 73 links => [ { rel => 'child', href => "{id}" } ],
92b6f291
AD
74 },
75 code => sub {
76 my ($param) = @_;
77
35854815 78 my $res = [
4140be9e
AD
79 { id => 'vnets' },
80 { id => 'zones' },
81 { id => 'controllers' },
c33dd818 82 { id => 'subnets' },
70b03506 83 { id => 'ipams' },
ee4f339e 84 { id => 'dns' },
4140be9e 85 ];
92b6f291
AD
86
87 return $res;
88 }});
89
5d50e70b
AD
90my $create_reload_network_worker = sub {
91 my ($nodename) = @_;
92
14e55c65
TL
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 });
5d50e70b
AD
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.",
3551b612
AD
113 permissions => {
114 check => ['perm', '/sdn', ['SDN.Allocate']],
115 },
5d50e70b
AD
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
5d50e70b
AD
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();
14e55c65
TL
132 for my $node (@$nodelist) {
133 my $pid = eval { $create_reload_network_worker->($node) };
5d50e70b 134 warn $@ if $@;
5d50e70b 135 }
14e55c65
TL
136
137 # FIXME: use libpve-apiclient (like in cluster join) to create
138 # tasks and moitor the tasks.
139
5d50e70b
AD
140 return;
141 };
142
143 return $rpcenv->fork_worker('reloadnetworkall', undef, $authuser, $code);
144
145 }});
146
92b6f291
AD
147
1481;