22.05.2017 Views

nx.os.and.cisco.nexus.switching.2nd.edition.1587143046

Nexus Switching 2nd Edition

Nexus Switching 2nd Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

if protocol == "telnet":<br />

c = "/isan/bin/vsh -c 'telnet " + h<strong>os</strong>t + "<br />

vrf " + vrf + "'"<br />

else:<br />

c = "/isan/bin/vsh -c 'ssh " + username +<br />

"@" + h<strong>os</strong>t + " vrf " +<br />

vrf+ "'"<br />

cmd = pexpect.spawn(c)<br />

\<br />

expect_list = [ \<br />

"(?i)re you sure you want to continue connecting",<br />

"(?i)ogin:", \<br />

"(?i)assword:", \<br />

"(?i)(?:permission denied)|(?:login incorrect)", \<br />

"(?i)onnection refused", \<br />

pexpect.TIMEOUT, \<br />

"[#|$]", \<br />

pexpect.EOF<br />

]<br />

i = cmd.expect(expect_list, timeout=login_timeout)<br />

while i != None:<br />

if i == 0:<br />

cmd.sendline("yes")<br />

i = cmd.expect(expect_list,<br />

timeout=login_timeout)<br />

elif i == 1:<br />

cmd.sendline(username)<br />

i = cmd.expect(expect_list,<br />

timeout=login_timeout)<br />

elif i == 2:<br />

cmd.sendline(password)<br />

i = cmd.expect(expect_list,<br />

timeout=login_timeout)<br />

elif i == 3:<br />

raise<br />

pexpect.ExceptionPexpect("Password was bad. Permis<br />

sion Denied")<br />

i = None<br />

elif i == 4:<br />

raise<br />

pexpect.ExceptionPexpect("Could not connect to the<br />

h<strong>os</strong>t")<br />

i = None

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!