You can subscribe to IPv4 route change events. After you subscribe to IPv4 route change events and an IPv4 route change event is triggered, the system executes the ops_execute() function in the maintenance assistant script.
This API can only be used in the ops_condition() function of the maintenance assistant script.
opsObj.route.subscribe (tag, network, maskLen, minLen=None, maxLen=None, neLen=None, type="all", protocol="all")
Method |
Description |
---|---|
opsObj |
Specifies an OPS object. It is obtained through ops.ops() instantiation. |
tag |
Specifies a condition ID. The value is a string of 1 to 8 case-sensitive characters that starts with a letter and contains letters, digits, and underscores (_). Enter double quotation marks ("") or None for the only one condition. tag cannot be set to and, or, or not. |
network |
Specifies a route prefix. The value is in the IPv4 address format, such as 10.1.1.1. |
maskLen |
Specifies a mask length. The value is an integer ranging from 0 to 32. |
minLen |
Specifies the minimum mask length. The value must be greater than or equal to the value of maskLen. |
maxLen |
Specifies the maximum mask length. The value must be greater than or equal to the value of minLen. |
neLen |
Specifies a length that cannot be a mask length. The value must be greater than or equal to the value of minLen and less than or equal to the value of maxLen. |
type |
Specifies an IPv4 route change event type. The value can be add, remove, modify, or all. The value all indicates all route changes. |
protocol |
Specifies a routing protocol. After this parameter is set, change events of routes of the specified protocol are subscribed to. The value can be direct, static, isis, ospf, bgp, rip, unr, or all. The default value is all, indicating that routes are not filtered by protocol type. |
test.py import ops def ops_condition(_ops): ret, reason = _ops.route.subscribe("con0", "10.1.1.1",maskLen=32, type="all", protocol="all") ret, reason = _ops.correlate("(con0 and con1)") return ret def ops_execute(_ops): a, des = _ops.context.save("test.py", 'Route event trigger') return 0
When a route with the prefix 10.1.1.1/32 is added or deleted, a route change event is triggered.