added get-serials.py first draft
This commit is contained in:
parent
96e6a12976
commit
01e2a49c33
1 changed files with 35 additions and 0 deletions
35
get-serials.py
Normal file
35
get-serials.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
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)
|
||||
HOST_NAME = ("ceph01-block01-"+row[0]+"-bmc")
|
||||
LICENSE_KEY = (row[7])
|
||||
SYSTEM_HOST_NAME = ("ceph01-block01-"+row[0])
|
||||
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
|
Loading…
Add table
Reference in a new issue