tools: add Dell iDRAC XML generator
This commit is contained in:
parent
3553166073
commit
e74727c5dd
5 changed files with 4144 additions and 0 deletions
52
scripts/drac-xml-writer/dhcp_parser.py
Executable file
52
scripts/drac-xml-writer/dhcp_parser.py
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import pandas as pd
|
||||
|
||||
# File paths
|
||||
ips_csv = './hostnames.csv'
|
||||
dhcp_data = '/srv/web/infra/ansible/roles/dhcp_server/files/dhcpd.conf.noc01.iad2.fedoraproject.org'
|
||||
|
||||
# Read the CSV
|
||||
ips = pd.read_csv(ips_csv)
|
||||
|
||||
# Read the DHCP config file into a list of lines
|
||||
with open(dhcp_data, 'r', encoding='utf-8') as f:
|
||||
dhcp_lines = f.readlines()
|
||||
|
||||
def get_name(ip):
|
||||
# Search for the line containing the IP address
|
||||
for idx, line in enumerate(dhcp_lines):
|
||||
if ip in line:
|
||||
# Get the next line (like grep -A1)
|
||||
if idx + 1 < len(dhcp_lines):
|
||||
next_line = dhcp_lines[idx + 1]
|
||||
# Extract the hostname using the regex
|
||||
match = re.search(r'"(.*)\.mgmt', next_line)
|
||||
if match:
|
||||
return match.group(1)
|
||||
break
|
||||
return None # Return None if not found
|
||||
|
||||
def get_stg(ip):
|
||||
# Search for the line containing the IP address
|
||||
for idx, line in enumerate(dhcp_lines):
|
||||
if ip in line:
|
||||
# Get the next line (like grep -A1)
|
||||
if idx + 1 < len(dhcp_lines):
|
||||
next_line = dhcp_lines[idx + 1]
|
||||
# Extract the hostname using the regex
|
||||
match = re.search(r'stg', next_line)
|
||||
if match:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
break
|
||||
return None # Return None if not found
|
||||
|
||||
# Apply the function to each IP
|
||||
ips['name'] = ips['ip'].apply(get_name)
|
||||
ips['stg'] = ips['ip'].apply(get_stg)
|
||||
|
||||
# Write the updated DataFrame back to CSV
|
||||
ips.to_csv('./hostnames.csv', index=False)
|
Loading…
Add table
Add a link
Reference in a new issue