]>
git.proxmox.com Git - pve-network.git/blob - PVE/API2/Network/SDN/Dns.pm
1 package PVE
::API2
::Network
::SDN
::Dns
;
7 use PVE
::Tools
qw(extract_param);
8 use PVE
::Cluster
qw(cfs_read_file cfs_write_file);
10 use PVE
::Network
::SDN
::Dns
;
11 use PVE
::Network
::SDN
::Dns
::Plugin
;
12 use PVE
::Network
::SDN
::Dns
::PowerdnsPlugin
;
14 use Storable
qw(dclone);
15 use PVE
::JSONSchema
qw(get_standard_option);
16 use PVE
::RPCEnvironment
;
20 use base
qw(PVE::RESTHandler);
22 my $sdn_dns_type_enum = PVE
::Network
::SDN
::Dns
::Plugin-
>lookup_types();
24 my $api_sdn_dns_config = sub {
27 my $scfg = dclone
(PVE
::Network
::SDN
::Dns
::sdn_dns_config
($cfg, $id));
29 $scfg->{digest
} = $cfg->{digest
};
34 __PACKAGE__-
>register_method ({
38 description
=> "SDN dns index.",
40 description
=> "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/dns/<dns>'",
44 additionalProperties
=> 0,
47 description
=> "Only list sdn dns of specific type",
49 enum
=> $sdn_dns_type_enum,
58 properties
=> { dns
=> { type
=> 'string'},
59 type
=> { type
=> 'string'},
62 links
=> [ { rel
=> 'child', href
=> "{dns}" } ],
67 my $rpcenv = PVE
::RPCEnvironment
::get
();
68 my $authuser = $rpcenv->get_user();
71 my $cfg = PVE
::Network
::SDN
::Dns
::config
();
73 my @sids = PVE
::Network
::SDN
::Dns
::sdn_dns_ids
($cfg);
75 foreach my $id (@sids) {
76 my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
77 next if !$rpcenv->check_any($authuser, "/sdn/dns/$id", $privs, 1);
79 my $scfg = &$api_sdn_dns_config($cfg, $id);
80 next if $param->{type
} && $param->{type
} ne $scfg->{type
};
82 my $plugin_config = $cfg->{ids
}->{$id};
83 my $plugin = PVE
::Network
::SDN
::Dns
::Plugin-
>lookup($plugin_config->{type
});
90 __PACKAGE__-
>register_method ({
94 description
=> "Read sdn dns configuration.",
96 check
=> ['perm', '/sdn/dns/{dns}', ['SDN.Allocate']],
100 additionalProperties
=> 0,
102 dns
=> get_standard_option
('pve-sdn-dns-id'),
105 returns
=> { type
=> 'object' },
109 my $cfg = PVE
::Network
::SDN
::Dns
::config
();
111 return &$api_sdn_dns_config($cfg, $param->{dns
});
114 __PACKAGE__-
>register_method ({
119 description
=> "Create a new sdn dns object.",
121 check
=> ['perm', '/sdn/dns', ['SDN.Allocate']],
123 parameters
=> PVE
::Network
::SDN
::Dns
::Plugin-
>createSchema(),
124 returns
=> { type
=> 'null' },
128 my $type = extract_param
($param, 'type');
129 my $id = extract_param
($param, 'dns');
131 my $plugin = PVE
::Network
::SDN
::Dns
::Plugin-
>lookup($type);
132 my $opts = $plugin->check_config($id, $param, 1, 1);
134 # create /etc/pve/sdn directory
135 PVE
::Cluster
::check_cfs_quorum
();
136 mkdir("/etc/pve/sdn");
138 PVE
::Network
::SDN
::lock_sdn_config
(
141 my $dns_cfg = PVE
::Network
::SDN
::Dns
::config
();
144 if ($scfg = PVE
::Network
::SDN
::Dns
::sdn_dns_config
($dns_cfg, $id, 1)) {
145 die "sdn dns object ID '$id' already defined\n";
148 $dns_cfg->{ids
}->{$id} = $opts;
150 my $plugin = PVE
::Network
::SDN
::Dns
::Plugin-
>lookup($opts->{type
});
151 $plugin->on_update_hook($opts);
153 PVE
::Network
::SDN
::Dns
::write_config
($dns_cfg);
155 }, "create sdn dns object failed");
160 __PACKAGE__-
>register_method ({
165 description
=> "Update sdn dns object configuration.",
167 check
=> ['perm', '/sdn/dns', ['SDN.Allocate']],
169 parameters
=> PVE
::Network
::SDN
::Dns
::Plugin-
>updateSchema(),
170 returns
=> { type
=> 'null' },
174 my $id = extract_param
($param, 'dns');
175 my $digest = extract_param
($param, 'digest');
177 PVE
::Network
::SDN
::lock_sdn_config
(
180 my $dns_cfg = PVE
::Network
::SDN
::Dns
::config
();
182 PVE
::SectionConfig
::assert_if_modified
($dns_cfg, $digest);
184 my $scfg = PVE
::Network
::SDN
::Dns
::sdn_dns_config
($dns_cfg, $id);
186 my $plugin = PVE
::Network
::SDN
::Dns
::Plugin-
>lookup($scfg->{type
});
187 my $opts = $plugin->check_config($id, $param, 0, 1);
189 foreach my $k (%$opts) {
190 $scfg->{$k} = $opts->{$k};
193 $plugin->on_update_hook($scfg);
195 PVE
::Network
::SDN
::Dns
::write_config
($dns_cfg);
197 }, "update sdn dns object failed");
202 __PACKAGE__-
>register_method ({
207 description
=> "Delete sdn dns object configuration.",
209 check
=> ['perm', '/sdn/dns', ['SDN.Allocate']],
212 additionalProperties
=> 0,
214 dns
=> get_standard_option
('pve-sdn-dns-id', {
215 completion
=> \
&PVE
::Network
::SDN
::Dns
::complete_sdn_dns
,
219 returns
=> { type
=> 'null' },
223 my $id = extract_param
($param, 'dns');
225 PVE
::Network
::SDN
::lock_sdn_config
(
228 my $cfg = PVE
::Network
::SDN
::Dns
::config
();
230 my $scfg = PVE
::Network
::SDN
::Dns
::sdn_dns_config
($cfg, $id);
232 my $plugin = PVE
::Network
::SDN
::Dns
::Plugin-
>lookup($scfg->{type
});
234 delete $cfg->{ids
}->{$id};
235 PVE
::Network
::SDN
::Dns
::write_config
($cfg);
237 }, "delete sdn dns object failed");