dnsdisc¶
DNS Discovery module.
-
class
spicerack.dnsdisc.
Discovery
(conftool, remote, records, dry_run=True)[source]¶ Bases:
object
Class to manage Confctl discovery objects.
-
__init__
(conftool, remote, records, dry_run=True)[source]¶ Initialize the instance.
Parameters: - conftool (spicerack.confctl.ConftoolEntity) -- the conftool instance for the discovery type objects.
- remote (spicerack.remote.Remote) -- the Remote instance.
- records (list) -- list of strings, each one must be a Discovery DNS record name.
- dry_run (bool, optional) -- whether this is a DRY-RUN.
Raises: spicerack.dnsdisc.DiscoveryError
-- if unable to initialize the resolvers.
-
_conftool_selector
¶ Generate the Conftool selector for the records.
Returns: the Conftool selector. Return type: str
-
active_datacenters
¶ 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
-
check_if_depoolable
(datacenter)[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, expected_name)[source]¶ Check that a Discovery record resolves on all authoritative resolvers to the correct IP.
The IP to use for the comparison it 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: DiscoveryError
-- if the record doesn't match the IP of the expected_name.
-
check_ttl
(ttl)[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)[source]¶ Set the records as depooled in the given datacenter.
Parameters: datacenter (str) -- the DC from which to depool the discovery records.
-
pool
(datacenter)[source]¶ Set the records as pooled in the given datacenter.
Parameters: datacenter (str) -- the DC in which to pool the discovery records.
-
resolve
(name=None)[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)[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.
-
-
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.