Merge branch 'genericisation-1' into 'main'

Genericisation 1

See merge request gblow/ilo-license-setter!2
This commit is contained in:
gblow 2025-01-21 09:35:06 +00:00
commit eda64ed9e6
2 changed files with 59 additions and 1 deletions

View file

@ -1,3 +1,9 @@
This repository contains a number of scripts that are designed to interact with HPE iLO BMCs (Hewlett Packard Enterprises, integrated Lights Out, Baseboard Management Controllers ) to access information and provide limited actuation. If usage information is not provided through the help text for each script, care should be taken when determining what the script will do before running. This repository contains a number of scripts that are designed to interact with HPE iLO BMCs (Hewlett Packard Enterprises, integrated Lights Out, Baseboard Management Controllers ) to access information and provide limited actuation. If usage information is not provided through the help text for each script, care should be taken when determining what the script will do before running.
Recommend to set up a virtual env for python to load appropriate modules (with e.g. python3 -m venv) Recommend to set up a virtual env for python to load appropriate modules (with e.g. `python3 -m venv venv`)
load the venv by sourcing the activate file (e.g. `source venv/bin/activate`)
install requirements manually
`python3 -m pip install paramiko`

52
set-DNS.py Normal file
View file

@ -0,0 +1,52 @@
import csv
import sys
import argparse
import paramiko
import getpass
import logging
#Configure and commence logging
logger = logging.getLogger(__name__)
logging.basicConfig(filename='python.log', level=logging.DEBUG)
logger.debug('logging start')
#Set up argument parsing
parser = argparse.ArgumentParser(prog="set-DNS.py", description="set DNS on iLO")
parser.add_argument('-o', '--read', help="Read only mode. Does not make changes. Currently the only mode that does anything", action='store_true')
parser.add_argument('-v', '--verbose')
args = parser.parse_args()
print(args)
print(args.read)
with open('hosts-in.csv',encoding='utf8') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',')
next(csvreader)
USER_NAME = input("Please enter BMC username:")
PASSWORD=getpass.getpass()
i = 1
for row in csvreader:
print(i)
i += 1
BMC_NAME = (row[1])
print(BMC_NAME)
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']})
DNSout = ("show map1/settings1/DNSSettings1")
#SetDNS = ("set map1/settings1/DNSSettings1 DNSServerAddress=0.0.0.0")
#SetDNSDomain = ("set map1/settings1/DNSSettings1 DomainName=")
if args.read:
stdin, stdout, stderr = client.exec_command(DNSout)
print(stdout.read())
#else:
#stdin, stdout, stderr = client.exec_command(SetDNS)
#print(stdout.read())