To bootstrap
configuration to an instance of XR running on a vagrant box, use the following
steps.
-
Generate an API
key and a CCO ID by using the steps described in
https://xrdocs.github.io/getting-started/steps-download-iosxr-vagrant.
-
Download the
latest stable version of the IOS XR vagrant box.
$ curl <cco-id>:<API-KEY>
$ BOXURL --output ~/iosxrv-fullk9-x64.box
$ vagrant box add --name IOS-XRv ~/iosxrv-fullk9-x64.box
-
Verify if the
vagrant box has been successfully installed.
annseque@ANNSEQUE-WS02 MINGW64 ~ vagrant box list
IOS-XRv (virtualbox, 0)
-
Create a working
directory.
annseque@ANNSEQUE-WS02 MINGW64 ~ mkdir ~/iosxrv
annseque@ANNSEQUE-WS02 MINGW64 ~ cd ~/iosxrv
-
Initialize the
vagrant file with the new vagrant box.
ANNSEQUE-WS02 MINGW64:iosxrv annseque$ vagrant init IOS-XRv
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
-
Clone the
vagrant-xrdocs
repository.
annseque@ANNSEQUE-WS02 MINGW64 ~
$ git clone https://github.com/ios-xr/vagrant-xrdocs.git
-
Navigate to the
vagrant-xrdocs
repository and locate the vagrant file
containing the configuration with which you want to bootstrap the XR.
annseque@ANNSEQUE-WS02 MINGW64 ~
$ cd vagrant-xrdocs/
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs (master)
$ ls
ansible-tutorials/ native-app-topo-bootstrap/ simple-mixed-topo/
lxc-app-topo-bootstrap/ README.md single_node_bootstrap/
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs (master)
$ ls single_node_bootstrap/
configs/ scripts/ Vagrantfile
-
Create the
bootstrap configuration file which uses a vagrant shell provisioner.
You would need a
shell provisioner section for each node in your network. A sample configuration
file is as follows:
#Source a config file and apply it to XR
config.vm.provision "file", source: "configs/rtr_config", destination: "/home/vagrant/rtr_config"
config.vm.provision "shell" do |s|
s.path = "scripts/apply_config.sh"
s.args = ["/home/vagrant/rtr_config"]
end
In the shown
sample file, you are using a vagrant file provisioner (config.vm.provision
"file"
) to transfer a file from your host machine to the XR Linux
shell. The root of the source directory is the working directory for your
vagrant instance. Hence, the
rtr_config
file is located in the
configs
directory.
You are using a
shell script (config.vm.provision "shell"
) to apply the bootstrap
configuration to XR. The shell script eventually runs on the XR Linux shell of
the vagrant instance. This script is placed in the
scripts
directory and is named as
apply_config.sh
. The script uses the location of the
router configuration file as the destination parameter in the vagrant file
provisioner.
-
Verify the
directory structure for the single node bootstrap configuration example used in
this section.
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs (master)
$ cd single_node_bootstrap/
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs/single_node_bootstrap (master)
$ tree ./
./
├── Vagrantfile
├── configs
│ └── rtr_config
└── scripts
└── apply_config.sh
2 directories, 3 files
-
Verify the
contents of the bootstrap configuration file.
The bootstrap
configuration example we are using in this section configures the gRPC server
on port 57789.
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs/single_node_bootstrap (master)
$ cat configs/rtr_config
!! XR configuration
!
grpc
port 57789
!
end
Note
|
The bootstrap
configuration is appended to the existing configuration on the instance of XR.
|
-
Verify the
contents of the shell script you are using to apply the configuration to XR.
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs/single_node_bootstrap (master)
$ cat scripts/apply_config.sh
#!/bin/bash
## Source ztp_helper.sh to get the xrapply and xrcmd functions.
source /pkg/bin/ztp_helper.sh
function configure_xr()
{
## Apply a blind config
xrapply $1
if [ $? -ne 0 ]; then
echo "xrapply failed to run"
fi
xrcmd "show config failed" > /home/vagrant/config_failed_check
}
## The location of the config file is an argument to the script
config_file=$1
## Call the configure_xr() function to use xrapply and xrcmd in parallel
configure_xr $config_file
## Check if there was an error during config application
grep -q "ERROR" /home/vagrant/config_failed_check
## Condition based on the result of grep ($?)
if [ $? -ne 0 ]; then
echo "Configuration was successful!"
echo "Last applied configuration was:"
xrcmd "show configuration commit changes last 1"
else
echo "Configuration Failed. Check /home/vagrant/config_failed on the router for logs"
xrcmd "show configuration failed" > /home/vagrant/config_failed
exit 1
fi
In this example,
the shell script blindly applies the configuration file specified as an
argument ($1) and then checks to see if there was an error while applying the
configuration.
The following
new commands are introduced in the shell script:
-
xrcmd: Allows you
to run privileged exec commands at the XR router prompt on the XR Linux shell.
For example,
show
run,
show version, and so on.
-
xrapply: Allows
you to apply (append) a configuration file to the existing configuration.
-
xrapply_string:
Applies a configuration directly using a single inline string.
For
example,
xrapply_string "interface Gig0/0/0/0\n ip address 1.1.1.2/24 \n
no shutdown
Note
|
To enable
the
xrapply,
xrapply_string, and
xrcmd commandssource
/pkg/bin/ztp_helper.sh , it is mandatory to include
source /pkg/bin/ztp_helper.sh in the script.
|
-
Verify if the
shell provisioner code has been included in the vagrant file.
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs/single_node_bootstrap (master)
$ cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
config.vm.box = "IOS-XRv"
#Source a config file and apply it to XR
config.vm.provision "file", source: "configs/rtr_config", destination: "/home/vagrant/rtr_config"
config.vm.provision "shell" do |s|
s.path = "scripts/apply_config.sh"
s.args = ["/home/vagrant/rtr_config"]
end
end
-
Launch the
vagrant instance from the current directory.
Launching the
vagrant instance should bootstrap the configuration to XR.
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs/single_node_bootstrap (master)
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'IOS-XRv'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: single_node_bootstrap_default_1472117544017_81536
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 57722 (guest) => 2222 (host) (adapter 1)
default: 22 (guest) => 2223 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Remote connection disconnect. Retrying...
...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: file...
==> default: Running provisioner: shell...
default: Running: C:/Users/annseque/AppData/Local/Temp/vagrant-shell20160825-3292-1wncpa3.sh
==> default: Configuration was successful!
==> default: Last applied configuration was:
==> default: Building configuration...
==> default: !! IOS XR Configuration version = 6.1.1.18I
==> default: grpc
==> default: port 57789
==> default: !
==> default: end
==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default:
==> default:
==> default: Welcome to the IOS XRv (64-bit) Virtualbox.
==> default: To connect to the XR Linux shell, use: 'vagrant ssh'.
==> default: To ssh to the XR Console, use: 'vagrant port' (vagrant version > 1.8)
==> default: to determine the port that maps to guestport 22,
==> default: then: 'ssh vagrant@localhost -p <forwarded port>'
==> default:
==> default: IMPORTANT: READ CAREFULLY
==> default: The Software is subject to and governed by the terms and conditions
==> default: of the End User License Agreement and the Supplemental End User
==> default: License Agreement accompanying the product, made available at the
==> default: time of your order, or posted on the Cisco website at
==> default: www.cisco.com/go/terms (collectively, the 'Agreement').
==> default: As set forth more fully in the Agreement, use of the Software is
==> default: strictly limited to internal use in a non-production environment
==> default: solely for demonstration and evaluation purposes. Downloading,
==> default: installing, or using the Software constitutes acceptance of the
==> default: Agreement, and you are binding yourself and the business entity
==> default: that you represent to the Agreement. If you do not agree to all
==> default: of the terms of the Agreement, then Cisco is unwilling to license
==> default: the Software to you and (a) you may not download, install or use the
==> default: Software, and (b) you may return the Software as more fully set forth
==> default: in the Agreement.
You can see
the vagrant file and shell provisioner applying the gPRC server port
configuration to XR.
-
(Optional) You
can verify the bootstrap configuration on the XR router console from the XR
Linux shell.
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs/single_node_bootstrap (master)
$ vagrant port
The forwarded ports for the machine are listed below. Please note that
these values may differ from values configured in the Vagrantfile if the
provider supports automatic port collision detection and resolution.
22 (guest) => 2223 (host)
57722 (guest) => 2222 (host)
annseque@ANNSEQUE-WS02 MINGW64 ~/vagrant-xrdocs/single_node_bootstrap (master)
$ ssh -p 2223 vagrant@localhost
vagrant@localhost's password:
RP/0/RP0/CPU0:ios# show running-config grpc
Thu Aug 25 09:42:24.010 UTC
grpc
port 57789
!
RP/0/RP0/CPU0:ios# show configuration commit changes last 1
Thu Aug 25 09:42:34.971 UTC
Building configuration...
!! IOS XR Configuration version = 6.1.1.18I
grpc
port 57789
!
end
RP/0/RP0/CPU0:ios#
You have
successfully applied a bootstrap configuration to XR.