Skip to content

Commit

Permalink
Merge pull request #13 from OpenCHAMI/trcotton/nidname
Browse files Browse the repository at this point in the history
reading Components to get NID number
  • Loading branch information
travisbcotton authored Apr 4, 2024
2 parents 6ef554f + 19a49a9 commit e954be7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 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,13 +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':
if 'NID' in i:
nidname='nid'+'%0*d' % (3, i['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 @@ -43,8 +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']:
if 'NID' in i:
nidname='nid'+'%0*d' % (3, i['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 e954be7

Please sign in to comment.