Saving script variable
Subscription and execution phases
result1_value, result2_description = ops.context.save(varName, value)
Parameter |
Description |
Value |
---|---|---|
varName |
Indicates a variable name. |
The value is a string of 1 to 16 case-sensitive characters, consists of letters, digits, and underscores (_), and starts with a letter. |
value |
Indicates a variable value. |
The value is an integer or a string of characters.
|
The result1_value and result2_description in the API prototype indicate return values.
The result1_value is the first return value, 0 indicates success, and 1 indicates failure.
The result2_description is the second return value, indicating the failure cause. It is returned only when the first return value is 1.
A maximum of 100 script variables can be saved to the device. If two same variable names are configured, only the latter variable value will take effect.
The saving script variable API and restoring script variable API are used together to transmit script variables between contexts.
Read user input from a terminal, and use the script variable input1 to save the user input.
value1, descri_str1 = ops.terminal.read(512, timeout=30, vty=None) value2, descri_str2 = ops.context.save("input1", value1)