ilo-license-setter/get-serials.py

36 lines
1.4 KiB
Python
Raw Normal View History

2024-05-29 16:42:53 +01:00
import csv
import paramiko
import getpass
import logging
import re
logger = logging.getLogger(__name__)
logging.basicConfig(filename='python.log', level=logging.DEBUG)
logger.debug('logging start')
with open('ceph-license-keys.csv',encoding='utf8') as csvfile,open('serials.csv','w') as csvfile_out:
csvreader = csv.reader(csvfile, delimiter=',')
csvwriter = csv.writer(csvfile_out)
next(csvreader)
PASSWORD=getpass.getpass()
i = 1
SN_PATTERN=re.compile('number=\w{10}')
for row in csvreader:
print(i)
2024-06-04 16:01:12 +01:00
HOST_NAME = ("ceph01-block02-"+row[0]+"-bmc")
2024-05-29 16:42:53 +01:00
LICENSE_KEY = (row[7])
2024-06-04 16:01:12 +01:00
SYSTEM_HOST_NAME = ("ceph01-block02-"+row[0])
2024-05-29 16:42:53 +01:00
print(HOST_NAME)
#print(LICENSE_KEY)
USER_NAME = "admin"
if i > 0:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=HOST_NAME, look_for_keys=False, port=22, username=USER_NAME, password=PASSWORD, disabled_algorithms={'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']})
#command = ("OemHPE_licenseinstall /map1/oemHPE_license1 "+LICENSE_KEY)
command = ("show /system1 number")
stdin, stdout, stderr = client.exec_command(command)
SERIAL_NUMBER_OUT=stdout.read()
SERIAL_NUMBER=(str(SN_PATTERN.findall(str(SERIAL_NUMBER_OUT)))[-12:-2])
csvwriter.writerow([SYSTEM_HOST_NAME,SERIAL_NUMBER])
i += 1