-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from OpenCHAMI/njones/dnsmasq-dynamic-update
Added full automation to dnsmasq from smd
- Loading branch information
Showing
4 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
smd.py | ||
update_loop.sh & | ||
dnsmasq -k -d --log-dhcp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
import requests | ||
import os | ||
|
||
import filecmp | ||
import shutil | ||
import sys | ||
import tempfile | ||
def getSMD(url): | ||
r = requests.get(url) | ||
data = r.json() | ||
return data | ||
|
||
|
||
def main(): | ||
sighup = False | ||
smd_endpoint=os.environ['smd_endpoint'] | ||
bss_endpoint=os.environ['bss_endpoint'] | ||
ei_data = getSMD(f'http://{smd_endpoint}:27779/hsm/v2/Inventory/EthernetInterfaces') | ||
f = open("/etc/dhcp-hostsfile","w") | ||
#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': | ||
print(f"{i['MACAddress']},set:{i['ComponentID']},{i['IPAddresses'][0]['IPAddress']},{i['ComponentID']}", file=f) | ||
print(f"{i['MACAddress']},set:{i['ComponentID']},{i['IPAddresses'][0]['IPAddress']},{i['ComponentID']}", file=hostsfile) | ||
else: | ||
print(f"{i['MACAddress']},{i['IPAddresses'][0]['IPAddress']},{i['ComponentID']}", file=f) | ||
f.close() | ||
print(f"{i['MACAddress']},{i['IPAddresses'][0]['IPAddress']},{i['ComponentID']}", file=hostsfile) | ||
hostsfile.close() | ||
if os.path.isfile("/etc/dhcp-hostsfile") == False or filecmp.cmp("/etc/dhcp-hostsfile-new", "/etc/dhcp-hostsfile") == False: | ||
sighup = True | ||
shutil.copyfile("/etc/dhcp-hostsfile-new", "/etc/dhcp-hostsfile") | ||
#TODO actually map all the BMCs straight from redfish, instead of creating dummy endpoints for them. | ||
#rf_data = getSMD(f'http://{smd_endpoint}:27779/hsm/v2/Inventory/RedfishEndpoints') | ||
#for r in rf_data['RedfishEndpoints']: | ||
# print(r['ID'] + ' ' + r['IPAddress']) | ||
f = open("/etc/dhcp-optsfile", "w") | ||
#optsfile = tempfile.TemporaryFile(mode = "r+") | ||
optsfile = open("/etc/dhcp-optsfile-new", "w") | ||
#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']: | ||
print(f"tag:{i['ComponentID']},tag:IPXEBOOT,option:bootfile-name,\"http://{bss_endpoint}:27778/boot/v1/bootscript?mac={i['MACAddress']}\"", file=f) | ||
print(f"tag:{i['ComponentID']},tag:IPXEBOOT,option:bootfile-name,\"http://{bss_endpoint}:27778/boot/v1/bootscript?mac={i['MACAddress']}\"", file=optsfile) | ||
optsfile.close() | ||
if os.path.isfile("/etc/dhcp-optsfile") == False or filecmp.cmp("/etc/dhcp-optsfile-new","/etc/dhcp-optsfile") == False: | ||
sighup = True | ||
shutil.copyfile(optsfile.name, "/etc/dhcp-optsfile") | ||
|
||
f.close() | ||
if sighup: | ||
print("newfile!") | ||
sys.exit(1) | ||
else: | ||
sys.exit(0) | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
while true | ||
do | ||
smd.py | ||
rc=$? | ||
if [$rc -e 1]; then | ||
kill -1 $(pgrep dnsmasq) | ||
fi | ||
sleep 10 | ||
done |