ilo-license-setter/get-MACs.py

43 lines
1.7 KiB
Python
Raw Normal View History

2024-06-04 16:22:23 +01:00
import csv
import argparse
2024-06-04 16:22:23 +01:00
import paramiko
import getpass
import logging
import re
2024-06-12 15:43:42 +01:00
#Configure and commence logging
2024-06-04 16:22:23 +01:00
logger = logging.getLogger(__name__)
logging.basicConfig(filename='python.log', level=logging.DEBUG)
logger.debug('logging start')
2024-06-12 15:43:42 +01:00
with open('hosts-in.csv',encoding='utf8') as csvfile,open('MACs.csv','w') as csvfile_out:
2024-06-04 16:22:23 +01:00
csvreader = csv.reader(csvfile, delimiter=',')
csvwriter = csv.writer(csvfile_out)
next(csvreader)
USER_NAME = input("Please enter BMC username:")
2024-06-04 16:22:23 +01:00
PASSWORD=getpass.getpass()
i = 1
2024-06-04 16:27:50 +01:00
P1_PATTERN=re.compile('Port1NIC_MACAddress=\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2}')
P2_PATTERN=re.compile('Port2NIC_MACAddress=\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2}')
2024-06-04 16:29:20 +01:00
P3_PATTERN=re.compile('Port3NIC_MACAddress=\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2}')
2024-06-04 16:22:23 +01:00
for row in csvreader:
print(i)
BMC_NAME = (row[1])
SYSTEM_NAME = (row[0])
print(BMC_NAME)
2024-06-04 16:22:23 +01:00
if i > 0:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=BMC_NAME, look_for_keys=False, port=22, username=USER_NAME, password=PASSWORD, disabled_algorithms={'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']})
2024-06-04 16:22:23 +01:00
#command = ("OemHPE_licenseinstall /map1/oemHPE_license1 "+LICENSE_KEY)
command = ("show /system1/network1/Integrated_NICs")
stdin, stdout, stderr = client.exec_command(command)
2024-06-04 16:27:50 +01:00
NET_INFO=stdout.read()
2024-06-04 16:41:53 +01:00
P1_MAC=(str(P1_PATTERN.findall(str(NET_INFO)))[-19:-2])
P2_MAC=(str(P2_PATTERN.findall(str(NET_INFO)))[-19:-2])
P3_MAC=(str(P3_PATTERN.findall(str(NET_INFO)))[-19:-2])
csvwriter.writerow([SYSTEM_NAME,P1_MAC,P2_MAC,P3_MAC])
2024-06-04 16:22:23 +01:00
i += 1