Appendix: ZTP Python library

This appendix describes the importable ZTP Python library.

For additional information about the ZTP process, see Zero Touch Provisioning.

ZTPClient

The ZTPClient communicates with the SR Linux ZTP process. The APIClient is the core object of ZTPClient. Each use of the ZTPClient passes through a call to one of its methods.

The path to the API client class:

class ztpclient.ztpclient.APIClient(base_url=None)

Example:

import ztpclient
class ZTP(object):
 
    def __init__(self):
        self.client = ztpclient.APIClient()
    def get_option(self, item):
        ret = self.client.option_list()
        return ret['message'].get(item, None)
    def find_current_version(self):
        response = self.client.image_list()
        if response
            image = response['message']
            if image and isinstance(image, list) and len(list) > 0:
                return image[0].replace('*', '')
        return None
    def perform_ztp(self):
        self.nos_install()
        self.nos_configure()
    def nos_install(self):
        ret = self.client.image_upgrade(srlinux_image_url, srlinux_image_md5_url)
        if ret:
            return int(ret['status'])
        return -1
    def nos_configure(self):
        ret = self.client.configure(srlinux_config_url)
        if ret:
            return int(ret['status'])
        return -1
    if __name__ == '__main__':
        ztp = ZTP()
        ztp.perform_ztp()

Functions

chassis_control()

Lists control card information.

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise. The message attribute contains dictionary with control card information.

Example

>>> client.chassis_control()

{u'status': 0, u'message': {u'operation': u'active'}}

>>> client.chassis_control()

{u'status': 0, u'message': {u'operation': u'standby'}}

chassis_linecards()

Lists line card information of the chassis.

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise. The message attribute contains list of dicts, where list item is dict with line card information.

Example

>>> client.chassis_linecards()

{u'status': 0, u'message': [{u'card_type': 127, u'card_name': u'imm32-100g-qsfp28+4-400g-qsfpdd', u'slot_num': 1}, {u'card_type': 0, u'card_name': u'empty', u'slot_num': 2}, {u'card_type': 0, u'card_name': u'empty', u'slot_num': 3}, {u'card_type': 127, u'card_name': u'imm32-100g-qsfp28+4-400g-qsfpdd', u'slot_num': 4}]}

configure(configurl)

Downloads the configuration from a specific configurl and applies the configuration to SR Linux. If SR Linux service(s) is not running, the service(s) are started and the configuration is applied.

Information

Description

Arguments

configurl (string): The URL from where the configuration will be downloaded.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Example

image_activate(version)

Reboots the chassis to the image version provided. If the current active version is the same as the specified version, then no action is performed. If there is no image in the chassis of specific version, then no action is performed. If the specified version is available, then chassis will be rebooted to that version.

Information

Description

Arguments

version (string): The image version.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Note: This API may result in a chassis reboot to activate the image version.

Examples

>>> client.image_list()

{u'status': 0, u'message': [u'20.6.1-18836*', u'20.6.1-17740', u'20.6.1-17738']}

>>> client.image_activate('20.6.1-3333')

{u'status': 127, u'message': u'20.6.1-3333 is not available'}

>>> client.image_activate('20.6.1-18836')

{u'status': 127, u'message': u'20.6.1-18836 is current active version. No additional change required'}

image_bootorder(bootorder)

Sets the image bootorder in the Grub configuration. On next reboot, the chassis reboots to the first image in the list.

Information

Description

Arguments

bootorder (list): The image version list.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero valuse otherwise.

Examples

>>> client.image_bootorder(['20.6.1-18836','20.6.1-17740','20.6.1-17738'])

{u'status': 0, u'message': None}

>>> client.image_bootorder('20.6.1-18836,20.6.1-17740,20.6.1-17738')

{u'status': 0, u'message': None}

image_delete(version)

Removes the specific image version from the chassis. If the specified version is not available in the chassis, then no action is performed. If the specified version is the current active version in the chassis, then no action is performed.

Information

Description

Arguments

version (string): The image version.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.image_list()

{u'status': 0, u'message': [u'20.6.1-18836*', u'20.6.1-17740', u'20.6.1-17738']}

>>> client.image_delete('20.6.1-3333')

{u'status': 0, u'message': u'20.6.1-3333 version not available'}

>>> client.image_delete('20.6.1-18836')

{u'status': 127, u'message': u'Cannot remove active version'}

image_list()

Lists all currently available image versions on the hardware.

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise. The message attribute contains the list of images. The item in list * indicates the current active image version.

Note: The image_list does not indicate the boot order.

Examples

>>> client.image_list()

{u'status': 0, u'message': [u'20.6.1-18836*', u'20.6.1-17740', u'20.6.1-17738']}

image_upgrade(image_url, md5_url, options)

Performs an image upgrade.

Information

Description

Arguments

image_url (string): The URLfrom where the image should be downloaded.

md5_url (string): The URL from where the pre-calculated md5sum of the image should be downloaded. Once image is downloaded, the calculated md5sum is checked against the downloaded md5sum. If the values do not match, then image upgrade is discarded.

no_reboot (boolean): If set to true, a chassis reboot is not triggered after an image upgrade. The new image will not be taken into use until the next reboot. The default is false.

skip_check (boolean): If set to true, skip status of autoboot parameter and a forced upgrade is performed. If set to false, the image upgrade will only be performed if autoboot is enabled. The default is false.

not_active (boolean): If set to true, after an image install, the image will not be marked as the active image (that is, will not reboot to the upgrade image). The current working image is still marked as active. The default is false.

Note: Based on the setting and outcome, the chassis can be rebooted when invoking this API.

Note: To perform ZTP, the autoboot flag must be enabled

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

option_autoboot(status)

Sets the autoboot option status. This option determines if autoboot should be performed during ZTP. If disabled, ZTP skips all steps and starts the SR Linux application.

Information

Description

Arguments

status (ZtpStatus): ztpclient.ZtpStatus.enable to enable the option, ztpclient.ZtpStatus.disable otherwise.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_autoboot(ztpclient.ZtpStatus.enable)

{u'status': 0, u'message': None}

option_bootintf(interface)

Sets the interface to be used by ZTP in various procedures. Default value is mgmt0.

Information

Description

Arguments

interface (string): The Linux network interface name.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_bootintf('mgmt0')

{u'status': 0, u'message': None}

option_clientid(type)

Sets the client ID used by ZTP when performing a DHCP Request. The possible values are serialid and mac. When serialid is selected, the chassis serial number is used as the client ID in the DHCP Request. When mac is selected, the Linux interface hardware address (chassis MAC address) is used as client identifier.

Information

Description

Arguments

type (ZtpClientId): The client identifier type.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_clientid(ztpclient.ZtpClientId.serialid)

{u'status': 0, u'message': None}

>>> client.option_clientid(ztpclient.ZtpClientId.mac)

{u'status': 0, u'message': None}

option_downgrade(status)

Sets the downgrade option status of ZTP. When enabled, the option allows ZTP to perform a downgrade of the image (that is, move from higher version image to lower version). When the option is disabled, only upgrades are allowed.

Information

Description

Arguments

status (ZtpStatus): ztpclient.ZtpStatus.enable to enable the option, ztpclient.ZtpStatus.disable otherwise.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_downgrade(ztpclient.ZtpStatus.enable)

{u'status': 0, u'message': None}

option_duration(timeout, retry)

Sets the timeout and retry parameters of the ZTP process. If not successful, the ZTP process keeps re-trying for the specified timeout seconds. Once the timeout is reached, the process stops. If the number of attempts are equal to the retry value, then the specified action is taken. The default action is to reboot.

Information

Description

Arguments

timeout (int): The number of seconds to perform ZTP before it is marked as failed.

retry (int): The number of attempts before stopping the ZTP process.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_duration(3600,3)

{u'status': 0, u'message': None}

option_formatovl(status)

Sets the formatovl option status of ZTP. When enabled, the option sets the srl.formatovl flag in the Grub configuration. On the next reboot, if the srl.formatovl flag is enabled, the NOKIA-DATA overlay file system is formatted. Any change performed on the overlay file system will be removed.

Information

Description

Arguments

status (ZtpStatus): ztpclient.ZtpStatus.enable to enable the option, ztpclient.ZtpStatus.disable otherwise.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_formatovl(ztpclient.ZtpStatus.enable)

{u'status': 0, u'message': None}

option_formatsrletc(status)

Sets the formatsrletc option status of ZTP. When enabled, the option sets the srl.formatetc flag in the Grub configuration. On the next reboot, if the srl.formatetc flag is enabled, the NOKIA-ETC overlay file system is formatted. Any change performed on the overlay file system will be removed.

Information

Description

Arguments

status (ZtpStatus): ztpclient.ZtpStatus.enable to enable the option, ztpclient.ZtpStatus.disable otherwise.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_formatsrletc(ztpclient.ZtpStatus.enable)

{u'status': 0, u'message': None}

option_formatsrlopt(status)

When enabled, the option sets the srl.formatopt flag in the Grub configuration. On the next reboot, if the srl.formatopt flag is enabled, the NOKIA-OPT overlay file system is formatted. Any change performed on the overlay file system will be removed.

Information

Description

Arguments

status (ZtpStatus): ztpclient.ZtpStatus.enable to enable the option, ztpclient.ZtpStatus.disable otherwise.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_formatsrlopt(ztpclient.ZtpStatus.enable)

{u'status': 0, u'message': None}

option_list()

Lists all the options of the ZTP process.

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_list()

{u'status': 0, u'message': {u'formatsrletc': False, u'retry': 3, u'bootintf': u'mgmt0', u'clientid': u'serialid', u'autoboot': False, u'srlflags': u'no-reboot', u'formatovl': False, u'formatsrlopt': False, u'timeout': 3600, u'downgrade': True, u'nosinstall': False}}

option_nosinstall(status)

Sets the nosinstall option status. This option determines if an image upgrade should be performed during ZTP. Only the image upgrade step is skipped. All other steps of ZTP are still performed.

Information

Description

Arguments

status (ZtpStatus): ztpclient.ZtpStatus.enable to enable the option, ztpclient.ZtpStatus.disable otherwise.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.option_nosinstall(ztpclient.ZtpStatus.enable)

{u'status': 0, u'message': None}

provision(provisionurl)

Downloads the provision script from a specific provisionurl and executes the script. The script could be either Python or Bash.

Information

Description

Arguments

provisionurl (string): The URL from where the provisioning script will be downloaded.

Returns

(dict) The API response as a Python dictionary. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Note: If the script returns a non-zero exit code, then the status attribute in the return dictionary is set to non-zero. It could be possible that the provisioning script has a chassis reboot command and a chassis will reboot while executing this API.

Note: To perform ZTP, the autoboot flag must be enabled

Examples

>>> client.provision('http://135.227.248.118/duts/IDNS1833F0766/srlinux_ztp.py')

service_restart()

Restarts the ZTP service.

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary, including the service status in message attribute. status attribute is set to 0 if successful, non-zero otherwise.

Examples

>>> client.service_restart()

{u'status': 0, u'message': {u'status': u'Service started'}}

service_start()

Starts the ZTP service (if not already running).

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary, including the service status in message attribute. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.service_start()

{u'status': 0, u'message': {u'status': u'Service started'}}

service_status()

Gets the current status of the ZTP service. The ZTP service will be running as systemd service. It can be checked manually by running ‘systemctl status ztp’.

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary, including the service status in message attribute. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.service_status()

{u'status': 0, u'message': {u'status': u'Inactive'}}

>>> client.service_status()

{u'status': 0, u'message': {u'status': u'Active'}}

service_stop()

Stops the ZTP service (if already running).

Information

Description

Arguments

Returns

(dict) The API response as a Python dictionary, including the service status in message attribute. The status attribute is set to 0 if successful, or a non-zero value otherwise.

Examples

>>> client.service_stop()

{u'status': 0, u'message': {u'status': u'Service stopped'}}