11: Scripts
EMG™ Edge Management Gateway User Guide
232
p.wait()
devicePort = devi 1
pList.append('')
continue
if i == 2: # prompt
devPrompt = p.match.group(1).decode('utf-8')
if devPrompt == "":
print("Timeout waiting for the prompt on DP", devicePort, ".")
devicePort = devi 1
pList.append('')
continue
print("Detected prompt", devPrompt, ".")
# Strip characters not allowed in DP names
devPromptStrip = re.sub("[^0-9A-Za-z\._\-]", "", devPrompt)
devPromptComplete = devPromp "-" + str(devicePort)
pList.append(devPromptComplete)
p.terminate(True)
p.wait()
devicePort = devi 1
# end of while devicePort <= numPorts:
# Connect to the EMG CLI and set the device port names
p=pexpect.spawn('clisession -U sysadmin')
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
print("Timeout waiting to login.")
p.terminate(True)
sys.exit(1)
elif i == 1: # EOF
print("Session unexpectedly terminated.")
p.terminate(True)
sys.exit(1)
elif i == 4: # prompt
loggedIn = True
devicePort = 1
while devicePort <= numPorts:
if skipPorts and devicePort >= 9 and devicePort <= 16:
devicePort = devi 1
continue
if len(pList[devicePort - 1]) > 0:
# Detected a prompt; set it
print("Setting name on DP", devicePort, "to", pList[devicePort -
1], "...")