Provision Script

The provision script describes what is required and how to execute when you upgrade and configure PicOS through ZTP. You can customize the provision script through running the generate_script file. The generate_script is provided in the format of Shell and Python, and you can click or to download. The detailed contents are shown as below.

Generate Script in the Shell Format

Shell Script Content

#!/bin/bash function prompt_choice() { echo "Please choose an option to configure (enter the number to select, enter 'done' to generate the script): 1. Add remote Syslog server 2. Remove remote Syslog server 3. Get file from TFTP server 4. Get file from HTTP server 5. Enable ZTP auto-run when switch boot up 6. Disable ZTP auto-run when switch boot up 7. Get PicOS image from file server and upgrade 8. Get PicOS startup file \"picos_start.conf\" from file server 9. Get PicOS configuration file \"pica_startup.boot\" from file server 10. Get file with PicOS L2/L3 CLI commands list and execute these commands 11. Get PicOS OVS configuration file \"ovs-vswitchd.conf.db\" from file server" read -rp "Enter your choice: " choice } function generate_script() { local config_commands=() local revision="" while true; do prompt_choice case $choice in 1) read -rp "Enter syslog server IP address: " ip config_commands+=("add_remote_syslog_server $ip") ;; 2) read -rp "Enter the syslog server IP address to remove: " ip config_commands+=("remove_remote_syslog_server $ip") ;; 3) read -rp "Enter file name in TFTP server: " remote_file_name read -rp "Enter file name with path in local: " local_file_name read -rp "Enter TFTP server IP address (optional): " ip config_commands+=("tftp_get_file $remote_file_name $local_file_name $ip") ;; 4) read -rp "Enter file name with path in local: " local_file_name read -rp "Enter file name with HTTP server URL: " file_name config_commands+=("http_get_file $local_file_name $file_name") ;; 5) config_commands+=("ztp_enable") ;; 6) config_commands+=("ztp_disable") ;; 7) read -rp "Enter tftp file name or http url: " file_name read -rp "Enter the software revision of the image:" revision read -rp "Enter TFTP server IP address (optional): " ip config_commands+=("if [ \"\$revision\" != \"$revision\" ]; then get_picos_image $file_name $ip; fi") ;; 8) read -rp "Enter tftp file name or http url: " file_name read -rp "Enter TFTP server IP address (optional): " ip config_commands+=("get_picos_startup_file $file_name $ip") ;; 9) read -rp "Enter tftp file name or http url: " file_name read -rp "Enter TFTP server IP address (optional): " ip config_commands+=("get_l2l3_config_file $file_name $ip") ;; 10) read -rp "Enter tftp file name or http url: " file_name read -rp "Enter TFTP server IP address (optional): " ip config_commands+=("l2l3_load_config $file_name $ip") ;; 11) read -rp "Enter tftp file name or http url: " file_name read -rp "Enter TFTP server IP address (optional): " ip config_commands+=("get_ovs_config_file $file_name $ip") ;; done) break ;; *) echo "Invalid choice, please try again." ;; esac printf "\n" done # Generate Shell script local script_name="provision.sh" { echo "#!/bin/bash" echo "source /usr/bin/ztp-functions.sh" echo "" for command in "${config_commands[@]}"; do echo "$command" done } > "$script_name" printf "\n" echo "Generated Shell script has been saved as $script_name" } # Run script generation program generate_script

Option Description of Shell Script

NOTEs:

  • Make sure that names of all files configured in the script is the same with files placed in the file server, or the switch cannot obtain them successfully.

  • The IP address of TFTP server from DHCP server will be valid if it is not configured in the script.

Option

Description

Example

Option

Description

Example

  1. Add remote Syslog server

Specify the IPv4 address of the Syslog server.

1--20240914-082304.png

The IPv4 address of Syslog server is configured as 10.10.30.1.

  1. Remove remote Syslog server

Delete the IPv4 address of the Syslog server.10.10.30.1

2-20240914-082249.png

The IPv4 address 10.10.30.1 of Syslog server is deleted.

  1. Get file from TFTP server

Download a file with specified name from the TFTP server with a specified IP address and path, and save it in local with another specified name.

The path /cftmp is valid if you don’t specify the local path here.

The file remote-file.txt in the TFTP server 10.10.30.2 is downloaded and is saved in local as local-file.txt.

  1. Get file from HTTP server

Download a file with specified name from the HTTP server with a specified URL and save it in local with another specified name.

The root path is valid if you don’t specify the local path here.

The file remote-file.txt in the HTTP server 10.10.30.2 is downloaded and is saved in local as local-file.txt.

  1. Enable ZTP auto-run when switch boot up

Enable ZTP function after completing this ZTP process.

 

 

  1. Disable ZTP auto-run when switch boot up

Disable ZTP function after completing this ZTP process.

 

  1. Get PicOS image from file server and upgrade

Download the PicOS image from the TFTP server with the specified IP address, path and name, or from the HTTP server with URL. Then, upgrade the switch to the new version.

The image onie-installer-picos-9.8.7-main-43d73dd983-x86v.bin in the working path of the TFTP server 10.10.30.2 is downloaded, and the switch is upgraded to this new version with the version number 43d73dd983.

  1. Get PicOS startup file "picos_start.conf" from file server

Download the PicOS startup file picos_start.conf from the TFTP server with the specified IP address, path and name, or from the HTTP server with URL.

The file picos_start.conf from the HTTP server 10.10.30.3 is downloaded.

  1. Get PicOS configuration file "pica_startup.boot" from file server

Download the L2/l3 configuration file pica_startup.boot from the TFTP server with the specified IP address, path and name, or from the HTTP server with URL.

The file pica_startup.boot from the HTTP server 10.10.30.3 is downloaded.

10. Get file with PicOS L2/L3 CLI commands list and execute these commands

Download the L2/l3 command file from the TFTP server with the specified IP address, path and name, or from the HTTP server with URL.

The file ztpl2l3_cfg.cli in the working directory of the TFTP server 10.10.30.2 is downloaded.

11. Get PicOS OVS configuration file "ovs-vswitchd.conf.db" from file server

Download the OVS configuration file ovs-vswitchd.conf.db from the TFTP server with the specified IP address, path and name, or from the HTTP server with URL.

The file ovs-vswitchd.conf.db from the HTTP server 10.10.30.3 is downloaded.

Generate Script in the Python Format

Python Script Content

import os def prompt_choice(): print("""Please choose an option to configure (enter the number to select, enter 'done' to generate the script): 1. Add remote Syslog server 2. Remove remote Syslog server 3. Get file from TFTP server 4. Get file from HTTP server 5. Enable ZTP auto-run when switch boot up 6. Disable ZTP auto-run when switch boot up 7. Get PicOS image from file server and upgrade 8. Get PicOS startup file "picos_start.conf" from file server 9. Get PicOS configuration file "pica_startup.boot" from file server 10. Get file with PicOS L2/L3 CLI commands list and execute these commands 11. Get PicOS OVS configuration file "ovs-vswitchd.conf.db" from file server""") return input("Enter your choice: ") def generate_script(): config_commands = [] while True: choice = prompt_choice() if choice == 'done': break if choice == '1': ip = input("Enter syslog server IP address: ") config_commands.append(f"add_remote_syslog_server {ip}") elif choice == '2': ip = input("Enter the syslog server IP address to remove: ") config_commands.append(f"remove_remote_syslog_server {ip}") elif choice == '3': remote_file_name = input("Enter file name in TFTP server: ") local_file_name = input("Enter file name with path in local: ") ip = input("Enter TFTP server IP address (optional): ") config_commands.append(f"tftp_get_file {remote_file_name} {local_file_name} {ip}") elif choice == '4': local_file_name = input("Enter file name with path in local: ") file_name = input("Enter file name with HTTP server URL:: ") config_commands.append(f"http_get_file {local_file_name} {file_name}") elif choice == '5': config_commands.append("ztp_enable") elif choice == '6': config_commands.append("ztp_disable") elif choice == '7': file_name = input("Enter tftp file name or http url: ") revision = input("Enter the software revision of the image: ") ip = input("Enter TFTP server IP address (optional): ") config_commands.append(f'if [ "$revision" != "{revision}" ]; then get_picos_image {file_name} {ip}; fi') elif choice == '8': file_name = input("Enter tftp file name or http url: ") ip = input("Enter TFTP server IP address (optional): ") config_commands.append(f"get_picos_startup_file {file_name} {ip}") elif choice == '9': file_name = input("Enter tftp file name or http url: ") ip = input("Enter TFTP server IP address (optional): ") config_commands.append(f"get_l2l3_config_file {file_name} {ip}") elif choice == '10': file_name = input("Enter tftp file name or http url: ") ip = input("Enter TFTP server IP address (optional): ") config_commands.append(f"l2l3_load_config {file_name} {ip}") elif choice == '11': file_name = input("Enter tftp file name or http url: ") ip = input("Enter TFTP server IP address (optional): ") config_commands.append(f"get_ovs_config_file {file_name} {ip}") else: print("Invalid choice, please try again.") print("\n") # Generate Shell script script_name = "provision.sh" with open(script_name, 'w') as script_file: script_file.write("#!/bin/bash\n") script_file.write("source /usr/bin/ztp-functions.sh\n") script_file.write("\n") for command in config_commands: script_file.write(f"{command}\n") print(f"\nGenerated Shell script has been saved as {script_name}") # Run script generation program generate_script()

Option Description of Python Script

The description of the Python script is the same with the Shell script. For detailed information, see Option Description of Shell Script.

Configuration Example for Generating Provision.sh

Take the Shell script as an example to introduce how to use it:

  1. Upload the Shell script generate_script.sh to the Linux environment.

  2. Use the command chmod +x generate_script.sh to enable the executable permission.

  3. Enter command ./generate_script.sh to run the script, and options are shown as below.

  1. Select options of 1, 3 and 6 in sequence as needed, and enter done to generate the script.

  1. The file named provision.sh is generated in the current directory, which includes all selected options. The content of provision script is shown as below.

 

Copyright © 2024 Pica8 Inc. All Rights Reserved.