dnsdisc¶
DNS Discovery module.
- exception spicerack.dnsdisc.DiscoveryCheckError[source]¶
Bases:
SpicerackCheckError
Custom exception class for errors while performing checks.
- exception spicerack.dnsdisc.DiscoveryError[source]¶
Bases:
SpicerackError
Custom exception class for errors of the Discovery class.
- class spicerack.dnsdisc.Discovery(*, conftool: spicerack.confctl.ConftoolEntity, authdns_servers: dict[str, str], records: list[str], dry_run: bool = True) None [source]¶
Bases:
object
Class to manage Confctl discovery objects.
Initialize the instance.
- Parameters:
conftool (
spicerack.confctl.ConftoolEntity
) -- the conftool instance for the discovery type objects.authdns_servers (
dict
[str
,str
]) -- a dictionary where keys are the hostnames and values are the IPs of the authoritative nameservers to be used.records (
list
[str
]) -- list of strings, each one must be a Discovery DNS record name.dry_run (
bool
, default:True
) -- whether this is a DRY-RUN.
- Raises:
spicerack.dnsdisc.DiscoveryError -- if unable to initialize the resolvers.
- check_if_depoolable(datacenter: str) None [source]¶
Determine if a datacenter can be depooled for all records.
- Parameters:
datacenter (
str
) -- the datacenter to depool.- Raises:
spicerack.dnsdisc.DiscoveryError -- if any service cannot be depooled.
- Return type:
- check_record(name: str, expected_name: str) None [source]¶
Check that a Discovery record resolves on all authoritative resolvers to the correct IP.
The IP to use for the comparison is obtained resolving the expected_name record. For example with name='servicename-rw.discovery.wmnet' and expected_name='servicename.svc.eqiad.wmnet', this method will resolve the 'expected_name' to get its IP address and then verify that on all authoritative resolvers the record for 'name' resolves to the same IP. It is retried to allow the change to be propagated through all authoritative resolvers.
- Parameters:
- Raises:
spicerack.dnsdisc.DiscoveryError -- if the record doesn't match the IP of the expected_name.
- Return type:
- check_ttl(ttl: int) None [source]¶
Check the TTL for all records.
- Parameters:
ttl (
int
) -- the expected TTL value.- Raises:
spicerack.dnsdisc.DiscoveryError -- if the expected TTL is not found.
- Return type:
- resolve(name: str | None = None) collections.abc.Iterator[dns.resolver.Answer] [source]¶
Generator that yields the resolved records.
Todo
move a more generalized version of this into a DNS resolver module.
- Parameters:
name (
typing.Optional
[str
], default:None
) -- record name to use for the resolution instead of self.records.- Yields:
dns.resolver.Answer -- the DNS response.
- Raises:
spicerack.dnsdic.DiscoveryError -- if unable to resolve the address.
- Return type:
collections.abc.Iterator
[dns.resolver.Answer
]
- resolve_address(name: str) str [source]¶
Resolve the IP of a given record.
Todo
move a more generalized version of this into a DNS resolver module.
- Parameters:
name (
str
) -- the DNS record to resolve.- Raises:
spicerack.dnsdisc.DiscoveryError -- if unable to resolve the address.
- Return type:
- resolve_with_client_ip(record: str, client_ip: ipaddress.IPv4Address | ipaddress.IPv6Address) dict[str, ipaddress.IPv4Address | ipaddress.IPv6Address] [source]¶
Resolves a discovery record with a specific client IP and returns the resolved address grouped by nameserver.
- Parameters:
record (
str
) -- record name to use for the resolution.client_ip (
typing.Union
[ipaddress.IPv4Address
,ipaddress.IPv6Address
]) -- IP address to be used in EDNS client subnet.
- Raises:
spicerack.discovery.DiscoveryError -- if unable to resolve the address.
- Return type:
dict
[str
,typing.Union
[ipaddress.IPv4Address
,ipaddress.IPv6Address
]]
- update_ttl(ttl: int) None [source]¶
Update the TTL for all registered records.
- Parameters:
ttl (
int
) -- the new TTL value to set.- Raises:
spicerack.dnsdisc.DiscoveryError -- if the check of the modified TTL fail and not in DRY-RUN mode.
- Return type:
- property active_datacenters: defaultdict¶
Information about pooled state of services.
- Returns:
A map of services, with values given by a list of datacenters where the service is pooled, i.e.:
{ 'svc_foo': ['dc1', 'dc2'], 'svc_bar': ['dc1'], }