]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Dns/PowerdnsPlugin.pm
1 package PVE
::Network
::SDN
::Dns
::PowerdnsPlugin
;
11 use base
('PVE::Network::SDN::Dns::Plugin');
31 url
=> { optional
=> 0},
32 key
=> { optional
=> 0 },
33 ttl
=> { optional
=> 1 },
37 # Plugin implementation
40 my ($class, $plugin_config, $zone, $hostname, $ip) = @_;
42 my $url = $plugin_config->{url
};
43 my $key = $plugin_config->{key
};
44 my $ttl = $plugin_config->{ttl
} ?
$plugin_config->{ttl
} : 14400;
45 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'X-API-Key' => $key];
47 my $type = Net
::IP
::ip_is_ipv6
($ip) ?
"AAAA" : "A";
48 my $fqdn = $hostname.".".$zone.".";
51 my $record = { content
=> $ip,
52 disabled
=> JSON
::false
,
57 my $rrset = { name
=> $fqdn,
60 changetype
=> "REPLACE",
61 records
=> [ $record ] };
64 my $params = { rrsets
=> [ $rrset ] };
67 PVE
::Network
::SDN
::Dns
::Plugin
::api_request
("PATCH", "$url/zones/$zone", $headers, $params);
71 die "error add $fqdn to zone $zone: $@";
76 my ($class, $plugin_config, $zone, $hostname, $ip) = @_;
78 my $url = $plugin_config->{url
};
79 my $key = $plugin_config->{key
};
80 my $ttl = $plugin_config->{ttl
} ?
$plugin_config->{ttl
} : 14400;
81 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'X-API-Key' => $key];
84 my $reverseip = join(".", reverse(split(/\./, $ip))).".in-addr.arpa.";
87 my $record = { content
=> $hostname,
88 disabled
=> JSON
::false
,
93 my $rrset = { name
=> $reverseip,
96 changetype
=> "REPLACE",
97 records
=> [ $record ] };
100 my $params = { rrsets
=> [ $rrset ] };
103 PVE
::Network
::SDN
::Dns
::Plugin
::api_request
("PATCH", "$url/zones/$zone", $headers, $params);
107 die "error add $reverseip to zone $zone: $@";
112 my ($class, $plugin_config, $zone, $hostname, $ip) = @_;
114 my $url = $plugin_config->{url
};
115 my $key = $plugin_config->{key
};
116 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'X-API-Key' => $key];
117 my $fqdn = $hostname.".".$zone.".";
118 my $type = Net
::IP
::ip_is_ipv6
($ip) ?
"AAAA" : "A";
120 my $rrset = { name
=> $fqdn,
122 changetype
=> "DELETE",
125 my $params = { rrsets
=> [ $rrset ] };
128 PVE
::Network
::SDN
::Dns
::Plugin
::api_request
("PATCH", "$url/zones/$zone", $headers, $params);
132 die "error delete $fqdn from zone $zone: $@";
137 my ($class, $plugin_config, $zone, $ip) = @_;
139 my $url = $plugin_config->{url
};
140 my $key = $plugin_config->{key
};
141 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'X-API-Key' => $key];
143 my $reverseip = join(".", reverse(split(/\./, $ip))).".in-addr.arpa.";
146 my $rrset = { name
=> $reverseip,
148 changetype
=> "DELETE",
151 my $params = { rrsets
=> [ $rrset ] };
154 PVE
::Network
::SDN
::Dns
::Plugin
::api_request
("PATCH", "$url/zones/$zone", $headers, $params);
158 die "error delete $reverseip from zone $zone: $@";
163 my ($class, $plugin_config, $zone) = @_;
165 #verify that api is working
167 my $url = $plugin_config->{url
};
168 my $key = $plugin_config->{key
};
169 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'X-API-Key' => $key];
172 PVE
::Network
::SDN
::Dns
::Plugin
::api_request
("GET", "$url/zones/$zone", $headers);
176 die "can't read zone $zone: $@";
182 my ($class, $plugin_config) = @_;
184 #verify that api is working
186 my $url = $plugin_config->{url
};
187 my $key = $plugin_config->{key
};
188 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'X-API-Key' => $key];
191 PVE
::Network
::SDN
::Dns
::Plugin
::api_request
("GET", "$url", $headers);
195 die "dns api error: $@";