Page MenuHomePhabricator

OKR: Provide a mechanism to obtain the FQDN given a short hostname
Closed, ResolvedPublic

Description

It has been decided that the way to approach this is to concentrate on importing the non-management DNS rather than providing a library.

Event Timeline

crusnov triaged this task as Medium priority.Dec 9 2019, 6:30 AM

I have been working on adapting the current DNS import script to additionally import other DNS entries and create primary IP addresses on hosts in Netbox. This should provide sufficient information in most cases to obtain the FQDN with an extremely simple one liner if the API is already available.

We shall import this information from PuppetDB since this also contains the network device information which is currently missing from Netbox. Of course this does not cover non-host devices, but gets us mostly there in terms of primary IP addresses, hostnames, device names, etc.

PuppetDB data being imported into Netbox turned out to be a bigger project than expected, but the script is currently in review and shall pave the way to complete this.

I think this could be converted into a method in the spicerack's netbox module that checks if there is a device or VM with the shortname and returns the DNS name of any of the primary IPs, if set and None (or raises) otherwise.

Change 670235 had a related patch set uploaded (by Volans; owner: Volans):
[operations/software/spicerack@master] netbox: add NetboxServer class

https://gerrit.wikimedia.org/r/670235

Change 670235 merged by jenkins-bot:
[operations/software/spicerack@master] netbox: add NetboxServer class

https://gerrit.wikimedia.org/r/670235

Volans closed this task as Resolved.EditedMay 6 2021, 5:31 PM
Volans claimed this task.

This is now possible via spicerack in any cookbook using:

>>> s = spicerack.netbox_server('cumin1001')
>>> s.fqdn
'cumin1001.eqiad.wmnet'
>>> s.mgmt_fqdn
'cumin1001.mgmt.eqiad.wmnet'

>>> s = spicerack.netbox_server('netbox1001')
>>> s.fqdn
'netbox1001.wikimedia.org'
>>> s.mgmt_fqdn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/spicerack/netbox.py", line 375, in mgmt_fqdn
    "Server {s} is a virtual machine, does not have a management address.".format(s=self._server.name)
spicerack.netbox.NetboxError: Server netbox1001 is a virtual machine, does not have a management address.