Upload Config File
Scenario Overview
This use-case demonstrates how to add a configuration file in ZTP. This config file will be attached to a device during device add activity. The same file will be used to set the initial configuration to the device during the onboarding process by downloading it from ZTP Config service.
This functionality is supported by ZTP Config service component of EMF (Element Management Function).
Prerequisites
Before running this example, ensure to setup the required environment. Refer 'Getting Started' section.
Add a Configuration file
1. Create a sample device configuration file
Add the below content to a file named 'day-0.txt'. This is a sample configuration file will be used subsequently to upload it to CNC using ZTP Config service 'Upload Configuration File" API.
!! IOS XR
!
hostname {$hname}
!
interface MgmtEth0/RP0/CPU0/0
ipv4 address dhcp
!
2. Add the below content to a file named 'add_config_file.sh'.
#!/bin/bash
. ./setup.sh
ZTP_CONFIG_URL=https://$CNC_HOST:$CNC_PORT/crosswork/ztpconfig/v1
CONFIG_FILE_ADD_URL=/config/upload
CONFIG_NAME="test-config"
CONFIG_TYPE="Day0-config"
OSNAME="IOS XR"
VERSION="7.10.1"
DEVICE_FAMILY="NCS5500"
VENDOR="Cisco Systems"
USER="admin"
ENCODED_CONFIG_NAME=$(curl -Gso /dev/null -w %{url_effective} --data-urlencode "$CONFIG_NAME" "" | cut -c 3-)
ENCODED_CONFIG_TYPE=$(curl -Gso /dev/null -w %{url_effective} --data-urlencode "$CONFIG_TYPE" "" | cut -c 3-)
ENCODED_OSNAME=$(curl -Gso /dev/null -w %{url_effective} --data-urlencode "$OSNAME" "" | cut -c 3-)
ENCODED_VERSION=$(curl -Gso /dev/null -w %{url_effective} --data-urlencode "$VERSION" "" | cut -c 3-)
ENCODED_DEVICE_FAMILY=$(curl -Gso /dev/null -w %{url_effective} --data-urlencode "$DEVICE_FAMILY" "" | cut -c 3-)
ENCODED_VENDOR=$(curl -Gso /dev/null -w %{url_effective} --data-urlencode "$VENDOR" "" | cut -c 3-)
ENCODED_USER=$(curl -Gso /dev/null -w %{url_effective} --data-urlencode "$USER" "" | cut -c 3-)
QUERY_STR="confname=${ENCODED_CONFIG_NAME}&type=${ENCODED_CONFIG_TYPE}&osname=${ENCODED_OSNAME}&version=${ENCODED_VERSION}&devicefamily=${ENCODED_DEVICE_FAMILY}&vendor=${ENCODED_VENDOR}&user=${ENCODED_USER}"
API_URL=$ZTP_CONFIG_URL$CONFIG_FILE_ADD_URL\?${QUERY_STR}
curl $CURL_OPTS -X POST -H "Authorization: Bearer ${BEARER_TOKEN}" -F "configFile=@day-0.txt;type=text/plain" --trace-ascii trace-form-request.log $API_URL | jq .
2. Set execute permissions for 'add_config_file.sh' file using the below command.
chmod 755 add_config_file.sh
3. Execute 'add_config_file.sh' script.
./add_config_file.sh
This will upload a configuration file with name 'test-config' to CNC. The contents of file 'day-0.txt' will also be uploaded to CNC along with other metadata. Replace the values for the following request body parameters in the above file, as required.
- Config Name
- Config Type
- OS Name
- Version
- Device family
- Vendor
- User
Post successful execution of the above script, 'test-config' would be added as a configuration in CNC. A successful sample execution of the script is shown below.
$ ./add_config_file.sh
{
"confId": "1ad6bf02-c626-4819-a64d-9dac938e55b5",
"confName": "test-config",
"fileName": "day-0.txt",
"osName": "IOS 20",
"version": "10.1.1",
"size": 83,
"deviceFamily": "NCS5500",
"createdBy": "admin",
"modifiedBy": "admin",
"createdTime": 1741339035265,
"modifiedTime": 1741339035265,
"downloadurl": "http://<CW_HOST_IP>:30604/crosswork/configsvc/v1/configs/device/files/1ad6bf02-c626-4819-a64d-9dac938e55b5",
"type": "Day0-config",
"extraPlaceHolders": "hname",
"childIds": "",
"vendor": "Cisco Systems"
}