From 85a80ca5e80d7e1537c4f42b2cbd44f4285acf52 Mon Sep 17 00:00:00 2001 From: hpcsys Date: Thu, 13 Jun 2024 16:22:27 +0100 Subject: [PATCH 1/3] first draf DNS setter --- set-DNS.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 set-DNS.py diff --git a/set-DNS.py b/set-DNS.py new file mode 100644 index 0000000..2e5900b --- /dev/null +++ b/set-DNS.py @@ -0,0 +1,48 @@ +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.", 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']}) + if args.read: + command = ("show map1/settings1/DNSSettings1") + else: + command = ("show map1/settings1/DNSSettings1") + stdin, stdout, stderr = client.exec_command(command) + print(stdout.read()) + + From 2dd74bdfe1e40e63461a1d19f91b379aa039b82b Mon Sep 17 00:00:00 2001 From: hpcsys Date: Thu, 13 Jun 2024 16:49:14 +0100 Subject: [PATCH 2/3] set-DNS read mode coded --- set-DNS.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/set-DNS.py b/set-DNS.py index 2e5900b..36d322b 100644 --- a/set-DNS.py +++ b/set-DNS.py @@ -15,7 +15,7 @@ logger.debug('logging start') 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.", action='store_true') +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() @@ -38,11 +38,15 @@ with open('hosts-in.csv',encoding='utf8') as csvfile: 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: - command = ("show map1/settings1/DNSSettings1") - else: - command = ("show map1/settings1/DNSSettings1") - stdin, stdout, stderr = client.exec_command(command) - print(stdout.read()) + stdin, stdout, stderr = client.exec_command(DNSout) + print(stdout.read()) + #else: + #stdin, stdout, stderr = client.exec_command(SetDNS) + #print(stdout.read()) From 8b152ac71d1844424073f4a45df826f274f2ba19 Mon Sep 17 00:00:00 2001 From: gblow Date: Thu, 10 Oct 2024 17:12:38 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ff13e5..04dfaf4 100644 --- a/README.md +++ b/README.md @@ -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. -Recommend to set up a virtual env for python to load appropriate modules (with e.g. python3 -m venv) \ No newline at end of file +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`