Skip to content

Commit

Permalink
trying to make less smd calls
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbcotton committed Apr 4, 2024
1 parent e46e5ad commit 19a49a9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dnsmasq-dhcpd-dynamic/smd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def getSMD(url):
data = r.json()
return data

def getNID(c_data, xname):
for c in c_data:
if xname == c['ID']:
return 'nid'+'%0*d' % (3, c['NID'])
else:
return None

def main():
sighup = False
Expand All @@ -18,14 +24,14 @@ def main():
bss_endpoint=os.environ['bss_endpoint']
bss_port=os.environ['bss_port']
ei_data = getSMD(f'http://{smd_endpoint}:{smd_port}/hsm/v2/Inventory/EthernetInterfaces')
component_data = getSMD(f"http://{smd_endpoint}:{smd_port}/hsm/v2/State/Components")['Components']
#hostsfile = tempfile.TemporaryFile(mode = "r+")
hostsfile = open("/etc/dhcp-hostsfile-new", "w")
#this for loop writes host entries
for i in ei_data:
if i['Type'] != 'NodeBMC':
component = getSMD(f"http://{smd_endpoint}:{smd_port}/hsm/v2/State/Components/{i['ComponentID']}")
if 'NID' in component:
nidname='nid'+'%0*d' % (3, component['NID'])
nidname=getNID(component_data, i['ComponentID'])
if nidname:
print(f"{i['MACAddress']},set:{nidname},{i['IPAddresses'][0]['IPAddress']},{nidname}", file=hostsfile)
else:
print(f"{i['MACAddress']},set:{i['ComponentID']},{i['IPAddresses'][0]['IPAddress']},{i['ComponentID']}", file=hostsfile)
Expand All @@ -44,9 +50,8 @@ def main():
#this for loop writes option entries, we wouldn't need it if the BSS wasn't MAC specific
for i in ei_data:
if 'bmc' not in i['Description']:
component = getSMD(f"http://{smd_endpoint}:{smd_port}/hsm/v2/State/Components/{i['ComponentID']}")
if 'NID' in component:
nidname='nid'+'%0*d' % (3, component['NID'])
nidname=getNID(component_data, i['ComponentID'])
if nidname:
print(f"tag:{nidname},tag:IPXEBOOT,option:bootfile-name,\"http://{bss_endpoint}:{bss_port}/boot/v1/bootscript?mac={i['MACAddress']}\"", file=optsfile)
else:
print(f"tag:{i['ComponentID']},tag:IPXEBOOT,option:bootfile-name,\"http://{bss_endpoint}:{bss_port}/boot/v1/bootscript?mac={i['MACAddress']}\"", file=optsfile)
Expand Down

0 comments on commit 19a49a9

Please sign in to comment.