]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Dns/Plugin.pm
1 package PVE
::Network
::SDN
::Dns
::Plugin
;
6 use PVE
::Tools
qw(run_command);
14 use PVE
::JSONSchema
qw(get_standard_option);
15 use base
qw(PVE::SectionConfig);
17 PVE
::Cluster
::cfs_register_file
('sdn/dns.cfg',
18 sub { __PACKAGE__-
>parse_config(@_); },
19 sub { __PACKAGE__-
>write_config(@_); });
21 PVE
::JSONSchema
::register_standard_option
('pve-sdn-dns-id', {
22 description
=> "The SDN dns object identifier.",
23 type
=> 'string', format
=> 'pve-sdn-dns-id',
26 PVE
::JSONSchema
::register_format
('pve-sdn-dns-id', \
&parse_sdn_dns_id
);
27 sub parse_sdn_dns_id
{
28 my ($id, $noerr) = @_;
30 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
31 return undef if $noerr;
32 die "dns ID '$id' contains illegal characters\n";
41 description
=> "Plugin type.",
42 type
=> 'string', format
=> 'pve-configid',
44 ttl
=> { type
=> 'integer', optional
=> 1 },
45 dns
=> get_standard_option
('pve-sdn-dns-id',
46 { completion
=> \
&PVE
::Network
::SDN
::Dns
::complete_sdn_dns
}),
54 sub parse_section_header
{
55 my ($class, $line) = @_;
57 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
58 my ($type, $id) = (lc($1), $2);
59 my $errmsg = undef; # set if you want to skip whole section
60 eval { PVE
::JSONSchema
::pve_verify_configid
($type); };
62 my $config = {}; # to return additional attributes
63 return ($type, $id, $errmsg, $config);
70 my ($class, $plugin_config, $type, $zone, $reversezone, $hostname, $ip) = @_;
74 my ($class, $plugin_config, $hostname, $ip) = @_;
78 my ($class, $plugin_config) = @_;
83 my ($method, $url, $headers, $data) = @_;
85 my $encoded_data = to_json
($data) if $data;
87 my $req = HTTP
::Request-
>new($method,$url, $headers, $encoded_data);
89 my $ua = LWP
::UserAgent-
>new(protocols_allowed
=> ['http', 'https'], timeout
=> 30);
93 $ua->proxy(['http', 'https'], $proxy);
98 $ua->ssl_opts(verify_hostname
=> 0, SSL_verify_mode
=> 0x00);
100 my $response = $ua->request($req);
101 my $code = $response->code;
103 if ($code !~ /^2(\d+)$/) {
104 my $msg = $response->message || 'unknown';
105 die "Invalid response from server: $code $msg\n";
109 if (defined($response->decoded_content)) {
110 $raw = $response->decoded_content;
112 $raw = $response->content;
114 return from_json
($raw) if $raw ne '';