Skip to content

Instantly share code, notes, and snippets.

@grafuls
Created April 9, 2025 14:01
Show Gist options
  • Save grafuls/49ac6e9958da66c0ef749a103ef37594 to your computer and use it in GitHub Desktop.
Save grafuls/49ac6e9958da66c0ef749a103ef37594 to your computer and use it in GitHub Desktop.
Quads hostname2meta converter
#! /usr/bin/env python3
import re
from quads.quads_api import QuadsApi
from quads.config import Config
quads = QuadsApi(Config)
hosts = quads.get_hosts()
pattern = r"^(?P<rack>[^-]+)-(?P<uloc>[^-]+)-(?P<blade>[^-]+)-(?P<host_type>[^.]+)\.(?P<domain>.+)$"
for host in hosts:
match = re.match(pattern, host.name)
if match:
components = match.groupdict()
rack = components["rack"]
uloc = components["uloc"]
blade = components["blade"]
#print(f"{host.name}: rack {rack}, uloc {uloc}, blade {blade}")
quads.update_host(host.name, {"rack":rack, "uloc":uloc, "blade":blade})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment