In [2]:
%%html
<style>
table {float:left}
</style>
In this notebook, we will be covering the basics of using the pyhpimc python module to access the RESTFUL interface ( eAPI ) of the HPE IMC Network Management Server.
The python library is currently available at HPE Github repository
In [5]:
import csv
import time
from pyhpeimc.auth import *
from pyhpeimc.plat.operator import *
In [6]:
auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin")
In this step we list the current operators that exist in the system by using the get_plat_operators function and capturing the output into a varible called ops_list.
We will then run the len which measures the length of the ops_list object, or more simply, measures the number of operators currently configured in the system.
In [7]:
ops_list = get_plat_operator(url=auth.url, auth=auth.creds)
print ("There are currently " + str(len(ops_list)) + " operators configured.")
Shown here is a screen capture of the current operators configured in the HPE IMC system. You can see that there are the same amoutn of operators as shown in the statement above.
note: The screen capture is used for the intial demonstration only. If you are running this notebook against your own IMC server, this screen capture may not match what you have configured on your system.
In the following section, we are going to import a group of operators from a prepared CSV file.
For more information on the contents of the CSV file, please see the documentation available at http://ip_address:8080/imcrs on your local IMC server.
The CSV file provided is for example only. Please feel free to use it as a template, but you are encouraged to look at the documentation for more information on the specific attributes of the CSV file.
This file contains the following operators
| Operator | Fullname |
|---|---|
| cyoung | Christoper Young |
| lstaurt | Les Stuart |
| kgott | Ken Gott |
| rkauffman | Rick Kauffman |
| lknapp | Leonard Knapp |
| clinzell | Chris Linzell |
| dwenger | Dwayne Wenger |
| jmacdonald | James Macdonald |
| tkubica | Tomas Kubica |
| mbreen | Michael Breen |
| mventer | Marius Venter |
In [9]:
with open('imc_operator_list.csv') as f:
s = f.read()
print (s)
In this section, we have created a simple python function to perform the following tasks
This function will allow us to run the create_operator function once for each operator in the csv file.
In [10]:
def import_operator(filename='imc_operator_list.csv'):
with open(filename) as csvfile:
# decodes file as csv as a python dictionary
reader = csv.DictReader(csvfile)
try:
for operator in reader:
# loads each row of the CSV as a JSON string
create_operator(operator, url=auth.url, auth=auth.creds)
except:
pass
In [11]:
start_time = time.time()
import_operator()
print("--- %s seconds ---" % (time.time() - start_time))
In [9]:
ops_list = get_plat_operator(url=auth.url, auth=auth.creds)
print ("There are currently " + str(len(ops_list)) + " operators configured.")
Shown here is a screen capture of the current operators configured in the HPE IMC system. You can see that there are the same amoutn of operators as shown in the statement above.
note: The screen capture is used for the intial demonstration only. If you are running this notebook against your own IMC server, this screen capture may not match what you have configured on your system.
We will now use the set_operator_password function to set the password of the newly created cyoung account to something a little more secure.
Feel free to try using this function to reset the password of another account by replacing the cyoung variable in the function below.
In [10]:
set_operator_password('cyoung', password='newpass',auth=auth.creds,url=auth.url,)
set_operator_password('')
In the following section, we will continue to use the API to clean up the system, using the delete_plat_operator function to delete all the new operators.
We will
In [3]:
ops_list = ['cyoung', 'lstuart', 'clinzell', 'kgott', 'rkauffman', 'lknapp', 'dwenger', 'jmacdonald', 'tkubica', 'mbreen', 'mventer']
In [4]:
for operator in ops_list:
delete_plat_operator(operator,url=auth.url, auth=auth.creds, headers=HEADERS)
In [ ]: