Scripts property helps you to automate your deployment and achieve other automation goals. If you want to run a python or
a bash script on Day0 under guestshell context, you can achieve the same by providing the public URL and arguments of the
python or the bash script in Scripts property.
A script must include a piece of code that includes the shebang (!) character in the first line of the script. This line tells
Cisco IOS-XE which script interpreter (Python or Bash) must be used to parse the script code. For example, the first line
of a python script can contain #!/usr/bin/env python
, while the first line of a bash script can contain #!/bin/bash
. This line allows the Python or Bash script to run as executable code in a Linux environment.
When you execute the script, the script runs in the guestshell container of the Cisco Catalyst 8000V instance. To access the guestshell container, use the guestshell EXEC mode command. For more information on guestshell commands, see the Programmability Configuration Guide.
To configure the Scripts property, follow the format given here:
Section: scripts
public_url <arg1> <arg2>
In this script, the first line of the property should read Section: Scripts
.
In the second line of the property, enter the URL of the script and the script's arguments. The script can be either a python
or a bash script. The script is run in guestshell in the first boot when the bootstrap file is uploaded when you create theCisco Catalyst 8000V instance.
To view more examples of the scrips, see the Scripts section in https://github.com/csr1000v/customdata-examples. Also refer to the following two examples:
Example 1
Section: Script
https://raw.githubusercontent.com/csr1000v/customdata-
examples/master/scripts/smartLicensingConfigurator.py --idtoken "<token_string>" --throughput <throughput_value>
The two lines in the scripts property retrieve the smartLicensingConfigurator.py
script from the customdata-examples
repository at the specified URL. The script runs in the guestshell container of the Cisco Catalyst 8000V with the arguments idtoken
and throughput
.
Example 2
Section: Scripts
ftp://10.11.0.4/dir1/dir2/script.py -a arg1 -s arg2
These two lines in the Scripts property retrieve the script.py
script from the ftp server with the IP address 10.11.0.4, and runs the script with the ./script.py -a arg1 -s arg2
bash command in the guestshell container of the Cisco Catalyst 8000V using arguments arg1 and arg2.
Note
|
If a script in the Scripts property requires a Python package that is not included in the standard CentOS Linux release (the
CentOS Linux release that is used by the guestshell, which is currently CentOS Linux release 7.1.1503), you must include information
about the Python package in the Python package property. For more information, see Configuring the Python package Property.
|
Prior to uploading the bootstrap file and running the bash or python script, Cisco recommends that you test the URL that you
intend to use in the Scripts property. You can test the ftp://10.11.0.4/dir1/dir2/script.py -a arg1 -s arg2
URL by first running the curl software tool to download the script file. In the guestshell, enter the curl command, as shown
in the following example:
curl -m 30 --retry 5 --user username:password
ftp://10.11.0.4/dir1/dir2/script_needs_credentials.py.
If the curl command is successful, a copy of the python script is downloaded which verifies whether the URL is correct.