
9: Device Ports
SLC™ 8000 Advanced Console Manager User Guide
217
print("RADIUS command returned: " + s2.split("\\n")[0])
proc.stdin.close()
proc.terminate()
proc.wait()
sys.exit(1)
print("RADIUS settings updated and enabled.")
proc.stdin.close()
proc.terminate()
proc.wait()
sys.exit(0)
Python Custom Script - SLC CLI Session
An example of a Python Custom Script that uses the Pexpect module to interact with the CLI
session and the device ports to detect the prompt on any devices connected to the SLC, and set
the device port name to be the same as the device prompt:
#! python
# Script to detect the prompt on a device connected to a SLC or SLB
device port,
# and set the device port name to the prompt. Punctuation characters are
# removed and the device port number is appended to the name. Prompts
ending
# in '>' are detected. For example, for a Cisco device attached to device
# port 3 and displays this prompt:
# engcisco_cat3560>
# the name for device port 3 will be set to "engcisco_cat3560-3"
import pexpect
import datetime
import time
import sys
import re
now = datetime.datetime.now()
print("Detecting devices on SLC at ", end="")
print(now.strftime("%Y-%m-%d %H:%M"))
# start the CLI session to get number of device ports
p=pexpect.spawn('clisession -U sysadmin')
slcPrompt = ""
numPorts = 0
loggedIn = False
while not loggedIn:
i = p.expect([pexpect.TIMEOUT, pexpect.EOF,
'Model Number: SLC80(\d*)\r\n', 'Model Number:
SLB882\r\n',
'(\[.*>)'], timeout=10)
if i == 0: # Timeout