Skip to content

Commit 674f5a4

Browse files
committed
Merge branch 'rschmied-master' (#19)
2 parents 6ec67df + 0eef352 commit 674f5a4

File tree

4 files changed

+944
-0
lines changed

4 files changed

+944
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ machines
44
.pyc
55
*.pyc
66
/README.html
7+
/.Python
8+
/bin
9+
/lib
10+
/pip-selfcheck.json
11+
/include/python2.7

README-CSR1000v.md

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# README-CSR1000v.md
2+
3+
`iosxe_iso2vbox.py` is a tool to create an IOS XE Vagrant VirtualBox box from an IOS XE ISO image. The ISO will be installed into a VM, booted and configured.
4+
5+
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.
6+
7+
`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.
8+
9+
## Origin
10+
For information about additional requirements and dependencies see the master [README.rst](README.rst) file.
11+
12+
This script is a copy of the [iosxr_iso2vbox.py](iosxr_iso2vbox.py) and has been substantially modified and adapted for use with IOS XE. Also, logging and router interaction have been changed.
13+
14+
## Contributions
15+
All contributions under this project are done so under the BSD license detailed in the LICENSE file contained in this repo.
16+
17+
## How to use this tool
18+
19+
1. *git clone* this repo:
20+
21+
git clone https://github.com/ios-xe/something.git
22+
23+
2. Install VirtualBox, Vagrant and socat (see [README.rst](README.rst) for more detail).
24+
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)
25+
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.
26+
27+
./iosxe_iso2vbox.py csr1000v-universalk9.16.03.01.iso
28+
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.
29+
6. Full help output
30+
31+
(iosxe-tools) host:iosxe-tools user$ ./iosxe_iso2vbox.py --help
32+
usage: iosxe_iso2vbox.py [-h] [-o] [-d] [-n] [-v] ISO_FILE
33+
34+
A tool to create an IOS XE Vagrant VirtualBox box from an IOS XE ISO.
35+
36+
The ISO will be installed, booted and configured.
37+
38+
"vagrant ssh" provides access to the IOS XE management interface
39+
with internet access. It uses the insecure Vagrant SSH key.
40+
41+
positional arguments:
42+
ISO_FILE local ISO filename or remote URI ISO filename
43+
44+
optional arguments:
45+
-h, --help show this help message and exit
46+
-o, --create_ova additionally use VBoxManage to export an OVA
47+
-d, --debug will exit with the VM in a running state. Use: socat
48+
TCP:localhost:65000 -,raw,echo=0,escape=0x1d to access
49+
-n, --nocolor don't use colors for logging
50+
-v, --verbose turn on verbose messages
51+
52+
E.g.:
53+
box build with local iso:
54+
iosxe_iso2vbox.py csr1000v-universalk9.16.03.01.iso
55+
box build with remote iso:
56+
iosxe_iso2vbox.py user@server:/myboxes/csr1000v-universalk9.16.03.01.iso
57+
(iosxe-tools) host:iosxe-tools user$
58+
59+
60+
## Vagrant Box Usage
61+
As a result of the build script, a *box* file is created. The path to that file with instruction is printed to the screen as a result of a successful build. To bring up a Vagrant instance based on that IOS XE box one has to go through the following steps:
62+
63+
1. `vagrant box add --name iosxe cisco-iosxe.box --force ` (where `cisco-iosxe.box` is the resulting box name as printed by the script), `--force` is only required if you already have a box installed and need to overwrite it with a newer version of the box
64+
2. Create a directory, in that directory do a `vagrant init iosxe` (assuming the name is `iosxe`. That name can be changed when adding the box to Vagrant)
65+
3. Then bring up the box via `vagrant up`
66+
4. The box will boot and will print a license banner as shown below when fully started
67+
5. Login to the router using `vagrant ssh`
68+
69+
> **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.
70+
71+
 
72+
73+
> **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.
74+
75+
## Sample Output
76+
77+
### Create the Box / Run the Script
78+
79+
(iosxrv-x64-vbox) host:iosxrv-x64-vbox user$ ./iosxe_iso2vbox.py ~/Downloads/csr1000v-universalk9.16.03.01.iso
80+
==> Input ISO is /home/user/Downloads/csr1000v-universalk9.16.03.01.iso
81+
==> Creating VirtualBox VM
82+
==> Starting VM...
83+
==> Successfully started to boot VM disk image
84+
==> Waiting for IOS XE to boot (may take 3 minutes or so)
85+
==> Logging into Vagrant Virtualbox and configuring IOS XE
86+
==> Waiting 10 seconds...
87+
==> Powering down and generating Vagrant VirtualBox
88+
==> Waiting for machine to shutdown
89+
==> Compact VDI
90+
==> Building Vagrant box
91+
==> Created: /home/user/iosxe-tools/iosxrv-x64-vbox/machines/csr1000v-universalk9.16.03.01/csr1000v-universalk9.16.03.01.box
92+
==> Add box to system:
93+
==> vagrant box add --name iosxe /home/user/iosxe-tools/iosxrv-x64-vbox/machines/csr1000v-universalk9.16.03.01/csr1000v-universalk9.16.03.01.box --force
94+
==> Initialize environment:
95+
==> vagrant init iosxe
96+
==> Bring up box:
97+
==> vagrant up
98+
==> Note:
99+
==> Both the XE SSH and NETCONF/RESTCONF username and password is vagrant/vagrant
100+
(iosxrv-x64-vbox) host:iosxrv-x64-vbox user$
101+
102+
### Add Box to Vagrant and Starting an Instance
103+
104+
(iosxrv-x64-vbox) host:iosxrv-x64-vbox user$ vagrant box add --name iosxe /home/user/iosxe-tools/iosxrv-x64-vbox/machines/csr1000v-universalk9.16.03.01/csr1000v-universalk9.16.03.01.box --force
105+
==> box: Box file was not detected as metadata. Adding it directly...
106+
==> box: Adding box 'iosxe' (v0) for provider:
107+
box: Unpacking necessary files from: file:///home/user/iosxe-tools/iosxrv-x64-vbox/machines/csr1000v-universalk9.16.03.01/csr1000v-universalk9.16.03.01.box
108+
==> box: Successfully added box 'iosxe' (v0) for 'virtualbox'!
109+
(iosxrv-x64-vbox) host:iosxrv-x64-vbox user$
110+
Initialize Vagrant Box Instance and Up the Instance
111+
(iosxrv-x64-vbox) host:iosxrv-x64-vbox user$ mkdir TEST
112+
(iosxrv-x64-vbox) host:iosxrv-x64-vbox user$ cd TEST/
113+
(iosxrv-x64-vbox) host:TEST user$ vagrant init iosxe
114+
A `Vagrantfile` has been placed in this directory. You are now
115+
ready to `vagrant up` your first virtual environment! Please read
116+
the comments in the Vagrantfile as well as documentation on
117+
`vagrantup.com` for more information on using Vagrant.
118+
(iosxrv-x64-vbox) host:TEST user$ vagrant up
119+
Bringing machine 'default' up with 'virtualbox' provider...
120+
==> default: Importing base box 'iosxe'...
121+
==> default: Matching MAC address for NAT networking...
122+
==> default: Setting the name of the VM: TEST_default_1473426485832_89279
123+
==> default: Clearing any previously set network interfaces...
124+
==> default: Preparing network interfaces based on configuration...
125+
default: Adapter 1: nat
126+
==> default: Forwarding ports...
127+
default: 830 (guest) => 2223 (host) (adapter 1)
128+
default: 80 (guest) => 2224 (host) (adapter 1)
129+
default: 443 (guest) => 2225 (host) (adapter 1)
130+
default: 22 (guest) => 2222 (host) (adapter 1)
131+
==> default: Running 'pre-boot' VM customizations...
132+
==> default: Booting VM...
133+
==> default: Waiting for machine to boot. This may take a few minutes...
134+
default: SSH address: 127.0.0.1:2222
135+
default: SSH username: vagrant
136+
default: SSH auth method: private key
137+
==> default: Machine booted and ready!
138+
==> default: Checking for guest additions in VM...
139+
default: No guest additions were detected on the base box for this VM! Guest
140+
default: additions are required for forwarded ports, shared folders, host only
141+
default: networking, and more. If SSH fails on this machine, please install
142+
default: the guest additions and repackage the box to continue.
143+
default:
144+
default: This is not an error message; everything may continue to work properly,
145+
default: in which case you may ignore this message.
146+
147+
==> default: Machine 'default' has a post `vagrant up` message. This is a message
148+
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
149+
==> default:
150+
==> default:
151+
==> default: Welcome to the IOS XE VirtualBox.
152+
==> default: To connect to the XE via ssh, use: 'vagrant ssh'.
153+
==> default: To ssh to XE's NETCONF or RESTCONF agent, use:
154+
==> default: 'vagrant port' (vagrant version > 1.8)
155+
==> default: to determine the port that maps to the guestport,
156+
==> default:
157+
==> default: The password for the vagrant user is vagrant
158+
==> default:
159+
==> default: IMPORTANT: READ CAREFULLY
160+
==> default: The Software is subject to and governed by the terms and conditions
161+
==> default: of the End User License Agreement and the Supplemental End User
162+
==> default: License Agreement accompanying the product, made available at the
163+
==> default: time of your order, or posted on the Cisco website at
164+
==> default: www.cisco.com/go/terms (collectively, the 'Agreement').
165+
==> default: As set forth more fully in the Agreement, use of the Software is
166+
==> default: strictly limited to internal use in a non-production environment
167+
==> default: solely for demonstration and evaluation purposes. Downloading,
168+
==> default: installing, or using the Software constitutes acceptance of the
169+
==> default: Agreement, and you are binding yourself and the business entity
170+
==> default: that you represent to the Agreement. If you do not agree to all
171+
==> default: of the terms of the Agreement, then Cisco is unwilling to license
172+
==> default: the Software to you and (a) you may not download, install or use the
173+
==> default: Software, and (b) you may return the Software as more fully set forth
174+
==> default: in the Agreement.
175+
(iosxrv-x64-vbox) host:TEST user$
176+
177+
### Accessing the Router
178+
(iosxrv-x64-vbox) host:TEST user$ vagrant ssh
179+
180+
csr1kv#
181+
csr1kv#
182+
csr1kv#
183+
184+
### Using NETCONF
185+
Display the mapped ports:
186+
187+
(iosxrv-x64-vbox) host:TEST user$ vagrant port
188+
The forwarded ports for the machine are listed below. Please note that
189+
these values may differ from values configured in the Vagrantfile if the
190+
provider supports automatic port collision detection and resolution.
191+
192+
193+
830 (guest) => 2223 (host)
194+
80 (guest) => 2224 (host)
195+
443 (guest) => 2225 (host)
196+
22 (guest) => 2222 (host)
197+
(iosxrv-x64-vbox) host:TEST user$
198+
199+
And then SSH to the box (note that the password is 'vagrant':
200+
201+
(iosxrv-x64-vbox) host:TEST user$ ssh -p 2223 vagrant@localhost -s netconf
202+
The authenticity of host '[localhost]:2223 ([127.0.0.1]:2223)' can't be established.
203+
RSA key fingerprint is SHA256:pH+NMr2hIAbmNUgaJHBg8tyNJEQwTQX+jucUrJTU7RY.
204+
Are you sure you want to continue connecting (yes/no)? yes
205+
Warning: Permanently added '[localhost]:2223' (RSA) to the list of known hosts.
206+
vagrant@localhost's password:
207+
<?xml version="1.0" encoding="UTF-8"?>
208+
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
209+
<capabilities>
210+
<capability>urn:ietf:params:netconf:base:1.0</capability>
211+
<capability>urn:ietf:params:netconf:base:1.1</capability>
212+
<capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
213+
<capability>urn:ietf:params:netconf:capability:xpath:1.0</capability>
214+
[...]
215+
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.
216+
217+
### Using RESTCONF
218+
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`:
219+
220+
(iosxrv-x64-vbox) host:TEST user$ curl --user vagrant:vagrant http://localhost:2224/restconf/api
221+
<api xmlns="http://tail-f.com/ns/rest" xmlns:y="http://tail-f.com/ns/rest">
222+
<version>0.5</version>
223+
<config/>
224+
<running/>
225+
<operational/>
226+
<operations>
227+
<bd:clear-mac-address>/api/operations/bd:clear-mac-address</bd:clear-mac-address>
228+
<bd:clear-bridge-domain>/api/operations/bd:clear-bridge-domain</bd:clear-bridge-domain>
229+
[...]
230+
231+
> **Note:** The data returned by the RESTCONF agent is represented as XML. If we want it to be JSON encoded then we need to send the appropriate HTTP header. E.g. `Accept: application/vnd.yang.data+json` would have achieved JSON encoding.

include/embedded_vagrantfile_xe

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Embedded Vagranfile that will be included in the base box.
5+
# Other Vagrantfiles must be compatible and will be additive
6+
7+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
8+
# configures the configuration version (we support older styles for
9+
# backwards compatibility). Please don't change it unless you know what
10+
# you're doing.
11+
Vagrant.configure(2) do |config|
12+
config.vm.synced_folder '.', '/vagrant', disabled: true
13+
14+
# Give IOS XE 400 seconds to come up
15+
config.vm.boot_timeout = 400
16+
17+
# Port 830 is XE NETCONF
18+
config.vm.network :forwarded_port, guest: 830, host: 2223, id: 'netconf', auto_correct: true
19+
# Port 80 is XE RESTCONF
20+
config.vm.network :forwarded_port, guest: 80, host: 2224, id: 'restconf', auto_correct: true
21+
# Port 443 is XE RESTCONF / SSL
22+
config.vm.network :forwarded_port, guest: 443, host: 2225, id: 'restconf-ssl', auto_correct: true
23+
config.ssh.forward_agent = true
24+
config.ssh.guest_port = 22
25+
config.ssh.insert_key = false
26+
config.vm.guest = :other
27+
28+
# turn off the check if the plugin is installed
29+
if Vagrant.has_plugin?("vagrant-vbguest")
30+
config.vbguest.auto_update = false
31+
end
32+
33+
# Avoid serial port conflicts
34+
config.vm.provider 'virtualbox' do |v|
35+
# Optional, forward the XE console serial port a TCP port on the host
36+
v.customize ['modifyvm', :id, '--uart1', '0x3F8', 4, '--uartmode1', 'disconnected']
37+
# Optional, forward the XE auxiliary serial port a TCP port on the host
38+
v.customize ['modifyvm', :id, '--uart2', '0x2F8', 3, '--uartmode2', 'disconnected']
39+
end
40+
41+
config.vm.post_up_message = "
42+
Welcome to the IOS XE VirtualBox.
43+
To connect to the XE via ssh, use: 'vagrant ssh'.
44+
To ssh to XE's NETCONF or RESTCONF agent, use:
45+
'vagrant port' (vagrant version > 1.8)
46+
to determine the port that maps to the guestport,
47+
48+
The password for the vagrant user is vagrant
49+
50+
IMPORTANT: READ CAREFULLY
51+
The Software is subject to and governed by the terms and conditions
52+
of the End User License Agreement and the Supplemental End User
53+
License Agreement accompanying the product, made available at the
54+
time of your order, or posted on the Cisco website at
55+
www.cisco.com/go/terms (collectively, the 'Agreement').
56+
As set forth more fully in the Agreement, use of the Software is
57+
strictly limited to internal use in a non-production environment
58+
solely for demonstration and evaluation purposes. Downloading,
59+
installing, or using the Software constitutes acceptance of the
60+
Agreement, and you are binding yourself and the business entity
61+
that you represent to the Agreement. If you do not agree to all
62+
of the terms of the Agreement, then Cisco is unwilling to license
63+
the Software to you and (a) you may not download, install or use the
64+
Software, and (b) you may return the Software as more fully set forth
65+
in the Agreement."
66+
end

0 commit comments

Comments
 (0)