dnsdisc

DNS Discovery module.

exception spicerack.dnsdisc.DiscoveryCheckError[source]

Bases: spicerack.exceptions.SpicerackCheckError

Custom exception class for errors while performing checks.

exception spicerack.dnsdisc.DiscoveryError[source]

Bases: spicerack.exceptions.SpicerackError

Custom exception class for errors of the Discovery class.

class spicerack.dnsdisc.Discovery(conftool: spicerack.confctl.ConftoolEntity, remote: spicerack.remote.Remote, records: List[str], dry_run: bool = True)[source]

Bases: object

Class to manage Confctl discovery objects.

Initialize the instance.

Parameters
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.discovery.DiscoveryError -- if any service cannot be depooled.

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
  • name (str) -- the record to check the resolution for.

  • expected_name (str) -- the name of a record to be resolved and used as the expected address.

Raises

DiscoveryError -- if the record doesn't match the IP of the expected_name.

check_ttl(ttl: int) None[source]

Check the TTL for all records.

Parameters

ttl (int) -- the expected TTL value.

Raises

DiscoveryError -- if the expected TTL is not found.

depool(datacenter: str) None[source]

Set the records as depooled in the given datacenter.

Parameters

datacenter (str) -- the DC from which to depool the discovery records.

pool(datacenter: str) None[source]

Set the records as pooled in the given datacenter.

Parameters

datacenter (str) -- the DC in which to pool the discovery records.

resolve(name: Optional[str] = None) 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 (str, optional) -- record name to use for the resolution instead of self.records.

Yields

dns.resolver.Answer -- the DNS response.

Raises

spicerack.discovery.DiscoveryError -- if unable to resolve the address.

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.

Returns

the resolved IP address.

Return type

str

Raises

spicerack.discovery.DiscoveryError -- if unable to resolve the address.

update_ttl(ttl: int) None[source]

Update the TTL for all registered records.

Parameters

ttl (int) -- the new TTL value to set.

Raises

spicerack.discovery.DiscoveryError -- if the check of the modified TTL fail and not in DRY-RUN mode.

property active_datacenters: collections.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'],
}

Return type

dict