Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 2af6c70bf0bf0d7343038582d24edfa00495b19b
Author: Ralph Schmieder <rschmied@cisco.com>
Date:   Thu Nov 24 11:44:41 2016 +0100

    better command line interaction

    thanks to Jan Lindblad

    Signed-off-by: Ralph Schmieder <rschmied@cisco.com>

commit baf02a57fe9109a0b174d8d5236e3537efa18891
Author: Ralph Schmieder <rschmied@cisco.com>
Date:   Thu Nov 24 11:43:21 2016 +0100

    some minor content changes

    Signed-off-by: Ralph Schmieder <rschmied@cisco.com>
  • Loading branch information
rschmied authored and Glenn Matthews committed Nov 28, 2016
1 parent 0e241e8 commit 2155a66
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 71 deletions.
13 changes: 6 additions & 7 deletions README-CSR1000v.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

It can then be used as a *box* within Vagrant to bring up an IOS XE router that is fully configured to be used with NETCONF and RESTCONF.

`vagrant ssh` provides access to the IOS XE management interface with Internet access via the host. It includes and uses the insecure Vagrant SSH key to provide 'passwordless' authentication.
`vagrant ssh` provides access to the IOS XE management interface with Internet access of IOS XE via the host. It includes and uses the insecure Vagrant SSH key to provide 'passwordless' authentication.

## Origin
For information about additional requirements and dependencies see the master [README.rst](README.rst) file.
Expand All @@ -19,10 +19,10 @@ All contributions under this project are done so under the BSD license detailed
1. *git clone* this repo:

git clone https://github.com/ios-xr/iosxrv-x64-vbox.git

2. Install VirtualBox, Vagrant and socat (see [README.rst](README.rst) for more detail).
3. Download the appropriate ISO file, e.g. `csr1000v-universalk9.16.03.01.iso` from CCO (software image download requires a login with proper access rights)
4. Generate the (VirtualBox-flavored) Vagrant box. Call the script and provide the path to the CSR1kv ISO file. The rest is done automatically. The script has instructions printed when it is done.
4. Generate the (VirtualBox-flavored) Vagrant box by calling the script and provide the path to the CSR1kv ISO file. The rest is done automatically. The script has instructions printed when it is done.

./iosxe_iso2vbox.py csr1000v-universalk9.16.03.01.iso
5. There are a couple of command line options that can be applied. Their purpose is mainly for troubleshooting by increasing the verbosity of the output.
Expand Down Expand Up @@ -67,9 +67,7 @@ As a result of the build script, a *box* file is created. The path to that file
5. Login to the router using `vagrant ssh`

> **Note:** This is not the serial console. The serial console is **not** exposed. A serial port can be added in the Vagrantfile that adds a serial port. See the build-script for an example.
&nbsp;

>
> **Note:** The resulting Vagrant box has only ONE interface. If additional interfaces are required then those must be added in the actual Vagrantfile within the directory where the box has been deployed. If multiple routers should be deployed which are connected to each other than the XR `vagrantfiles` directory has additional examples which can be adapted for use with IOS XE.
## Sample Output
Expand Down Expand Up @@ -212,7 +210,8 @@ And then SSH to the box (note that the password is 'vagrant':
<capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
<capability>urn:ietf:params:netconf:capability:xpath:1.0</capability>
[...]
Note: The SSH server for NETCONF is different from the SSH server of the IOS device and hence does not know the Vagrant insecure SSH key (e.g. the pub key has not been 'accepted' into the SSH daemon / authorized_keys). We have to use password authentication in this case unless there is a way to inject the SSH pub key into the NETCONF agent.

> **Note:** The SSH server for NETCONF is different from the SSH server of the IOS device and hence does not know the Vagrant insecure SSH key (e.g. the pub key has not been 'accepted' into the SSH daemon / authorized_keys). We have to use password authentication in this case unless there is a way to inject the SSH pub key into the NETCONF agent.
### Using RESTCONF
Again, using vagrant port determine the port where the RESTCONF agent is listening on (see above for the example used). The RESTCONF API entry point is at `/restconf/api`:
Expand Down
134 changes: 70 additions & 64 deletions iosxe_iso2vbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,31 @@ def configure_xe(verbose=False, wait=True):
localhost = 'localhost'

PROMPT = r'[\w-]+(\([\w-]+\))?[#>]'
# don't want to rely on specific hostname
# PROMPT = r'(Router|csr1kv).*[#>]'
CRLF = "\r\n"

def send_line(line=CRLF):
# empty line is len 2 b/c of CR/LF
child.sendline(line)
if line != CRLF:
logger.info('IOS Config: %s' % line)
child.sendline(line)
child.expect(re.escape(line))

def send_cmd(cmd):
if not isinstance(cmd, list):
cmd = list((cmd,))
for c in cmd:
send_line(c)
child.expect(PROMPT)

try:
child = pexpect.spawn(
"socat TCP:%s:%s -,raw,echo=0,escape=0x1d" % (localhost, CONSOLE_PORT))
child = pexpect.spawn("socat TCP:%s:%s -,raw,echo=0,escape=0x1d" % (localhost, CONSOLE_PORT))

if verbose:
child.logfile = open("tmp.log", "w")
child.timeout = 600 # Long time for full configuration, waiting for ip address etc

# Long time for full configuration, waiting for ip address etc
child.timeout = 600

# wait for indication that boot has gone through
if (wait):
Expand All @@ -258,93 +267,91 @@ def send_line(line=CRLF):
send_line()
time.sleep(5)
send_line()
send_line("term width 300")
send_cmd("term width 300")

# enable plus config mode
send_line("enable")
send_line("conf t")
send_cmd("enable")
send_cmd("conf t")

# no TFTP config
send_line("no logging console")
send_cmd("no logging console")
time.sleep(5)
send_line("no service config")
send_cmd("no service config")

# NETCONF (odm == Operational Data)
send_line("netconf-yang cisco-odm actions parse.showACL")
send_line("netconf-yang cisco-odm actions parse.showBGP")
send_line("netconf-yang cisco-odm actions parse.showArchive")
send_line("netconf-yang cisco-odm actions parse.showIpRoute")
send_line("netconf-yang cisco-odm actions parse.showInterfaces")
send_line("netconf-yang cisco-odm actions parse.showEnvironment")
send_line("netconf-yang cisco-odm actions parse.showFlowMonitor")
send_line("netconf-yang cisco-odm actions parse.showBFDneighbors")
send_line("netconf-yang cisco-odm actions parse.showBridgeDomain")
send_line("netconf-yang cisco-odm actions parse.showProcessesCPU")
send_line("netconf-yang cisco-odm actions parse.showEfpStatistics")
send_line("netconf-yang cisco-odm actions parse.showLLDPneighbors")
send_line("netconf-yang cisco-odm actions parse.showVirtualService")
send_line("netconf-yang cisco-odm actions parse.showIPslaStatistics")
send_line("netconf-yang cisco-odm actions parse.showMPLSldpNieghbor")
send_line("netconf-yang cisco-odm actions parse.showProcessesMemory")
send_line("netconf-yang cisco-odm actions parse.showMemoryStatistics")
send_line("netconf-yang cisco-odm actions parse.showPlatformSoftware")
send_line("netconf-yang cisco-odm actions parse.showMPLSstaticBinding")
send_line("netconf-yang cisco-odm actions parse.showMPLSforwardingTable")
send_line("netconf-yang cisco-odm actions parse.showIpOspfDatabaseRouter")
send_line("netconf-yang cisco-odm actions parse.showEthernetCFMstatistics")
send_line("netconf-yang cisco-odm polling-enable")
send_line("netconf-yang")
send_cmd("netconf-yang cisco-odm actions parse.showACL")
send_cmd("netconf-yang cisco-odm actions parse.showBGP")
send_cmd("netconf-yang cisco-odm actions parse.showArchive")
send_cmd("netconf-yang cisco-odm actions parse.showIpRoute")
send_cmd("netconf-yang cisco-odm actions parse.showInterfaces")
send_cmd("netconf-yang cisco-odm actions parse.showEnvironment")
send_cmd("netconf-yang cisco-odm actions parse.showFlowMonitor")
send_cmd("netconf-yang cisco-odm actions parse.showBFDneighbors")
send_cmd("netconf-yang cisco-odm actions parse.showBridgeDomain")
send_cmd("netconf-yang cisco-odm actions parse.showProcessesCPU")
send_cmd("netconf-yang cisco-odm actions parse.showEfpStatistics")
send_cmd("netconf-yang cisco-odm actions parse.showLLDPneighbors")
send_cmd("netconf-yang cisco-odm actions parse.showVirtualService")
send_cmd("netconf-yang cisco-odm actions parse.showIPslaStatistics")
send_cmd("netconf-yang cisco-odm actions parse.showMPLSldpNieghbor")
send_cmd("netconf-yang cisco-odm actions parse.showProcessesMemory")
send_cmd("netconf-yang cisco-odm actions parse.showMemoryStatistics")
send_cmd("netconf-yang cisco-odm actions parse.showPlatformSoftware")
send_cmd("netconf-yang cisco-odm actions parse.showMPLSstaticBinding")
send_cmd("netconf-yang cisco-odm actions parse.showMPLSforwardingTable")
send_cmd("netconf-yang cisco-odm actions parse.showIpOspfDatabaseRouter")
send_cmd("netconf-yang cisco-odm actions parse.showEthernetCFMstatistics")
send_cmd("netconf-yang cisco-odm polling-enable")
send_cmd("netconf-yang")
# this is not needed according to Jason
# send_line("netconf ssh")
# send_cmd("netconf ssh")

# hostname / domain-name
send_line("hostname csr1kv")
send_line("ip domain-name dna.lab")
send_cmd("hostname csr1kv")
send_cmd("ip domain-name dna.lab")

# key generation
# send_line("crypto key generate rsa modulus 2048")
# send_cmd("crypto key generate rsa modulus 2048")
# time.sleep(5)

# passwords and username
send_line()
send_line("username vagrant priv 15 password vagrant")
send_line("enable password cisco")
send_line("enable secret cisco")
send_cmd("username vagrant priv 15 password vagrant")
send_cmd("enable password cisco")
send_cmd("enable secret cisco")

# line configuration
send_line("line vty 0 4")
send_line("login local")
send_cmd("line vty 0 4")
send_cmd("login local")

# ssh vagrant insecure public key
send_line("ip ssh pubkey-chain")
send_line("username vagrant")
send_line("key-string")
send_line("AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eW")
send_line("W6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o")
send_line("9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXP")
send_line("ITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pz")
send_line("C6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZE")
send_line("nDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXz")
send_line("cWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==")
send_line("exit")
send_cmd("ip ssh pubkey-chain")
send_cmd("username vagrant")
send_cmd("key-string")
send_cmd("AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eW")
send_cmd("W6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o")
send_cmd("9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXP")
send_cmd("ITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pz")
send_cmd("C6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZE")
send_cmd("nDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXz")
send_cmd("cWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==")
send_cmd("exit")

# restconf
send_line("ip http server")
send_line("ip http secure-server")
send_line("restconf")
send_cmd("ip http server")
send_cmd("ip http secure-server")
send_cmd("restconf")

# done and save
send_line("end")
send_line("copy run start")
send_line()
send_cmd("end")
send_cmd(["copy run start", CRLF])

# just to be sure
logger.warn('Waiting 10 seconds...')
time.sleep(10)

except pexpect.TIMEOUT:
raise pexpect.TIMEOUT(
'Timeout (%s) exceeded in read().' % str(child.timeout))
raise pexpect.TIMEOUT('Timeout (%s) exceeded in read().' % str(child.timeout))


def main(argv):
Expand Down Expand Up @@ -403,8 +410,7 @@ def main(argv):
if re.search(':/', args.ISO_FILE):
# URI Image
cmd_string = 'scp %s@%s .' % (getpass.getuser(), args.ISO_FILE)
logger.warn(
'Will attempt to scp the remote image to current working dir. You may be required to enter your password.')
logger.warn('Will attempt to scp the remote image to current working dir. You may be required to enter your password.')
logger.debug('%s\n', cmd_string)
subprocess.call(cmd_string, shell=True)
input_iso = os.path.basename(args.ISO_FILE)
Expand Down

0 comments on commit 2155a66

Please sign in to comment.