Skip to main content

Interface route

The routes of an interface. osapi dsl behavior get --name route and osapi dsl behavior method get show the same. Its chain shows each call that its examples make.

Behavior​

Nameroute
DescriptionThe routes of an interface
Placementnode
Ofinterface
Areanetworking
Internalno
APIyes
CLIyes
Nextno
Platformsdebian, linux, darwin
Sudonone
Runsnone
Writes/etc/netplan/osapi-*-routes.yaml
Keeps stateno
Usesnetplan
Used bynone

Methods (4)​

NAMEVERBHTTPROUTEPERMISSIONDESCRIPTION
listreadGET/api/node/{hostname}/interface/{name}/routeinterface:readList the routes of an interface
createwritePOST/api/node/{hostname}/interface/{name}/routeinterface:writeAdd a static route to an interface
updatewritePUT/api/node/{hostname}/interface/{name}/routeinterface:writeChange the gateway or the metric of a route
deletewriteDELETE/api/node/{hostname}/interface/{name}/routeinterface:writeDrop a route that osapi wrote

Types (4)​

NAMEINPUTOUTPUT
listListInput { name* }[]Entry { destination, gateway, interface, family, metric, proto, scope }
createCreateInput { name*, destination*, via*, metric }Result { destination, changed }
updateUpdateInput { name*, destination*, via*, metric }Result { destination, changed }
deleteDeleteInput { name*, destination* }Result { destination, changed }

Settings (0)​

None. Declare them with behavior.Config.

Telemetry​

Spanbehavior.route.<method>
Child spansbehavior.netplan.<method>, behavior.managedfile.<method>, exec ip, exec ifconfig, exec netstat, exec ethtool, exec netplan, exec chown, exec stat, file.write, file.remove, file.chmod, kv.get, kv.put
Metricsosapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total
Attributesosapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed
Recorded inputsname (list, create, update, delete), destination (create, update, delete)

Method list​

Namelist
Verbread
DescriptionList the routes of an interface
DetailReads the routes of the main table that go out of the interface: ip route on Linux, netstat on macOS. proto says where a route came from, such as dhcp, kernel or static. An interface with no routes has none; one the host does not have is not found.
HTTPGET
Route/api/node/{hostname}/interface/{name}/route
Permissioninterface:read
Commandosapi client node interface route list
Input typeListInput
Output type[]Entry

Input (1)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^(@fact.[a-z0-9_.]+|[a-zA-Z0-9][a-zA-Z0-9._-]{0,14})$The interface, such as eth0, or a fact such as @fact.interface.primary

Output (7)​

FIELDTYPEDESCRIPTION
destinationstringThe destination in CIDR notation, or default
gatewaystringThe gateway; empty for a route on the link
interfacestringThe interface the route goes out of
familystringinet or inet6
metricintegerThe metric; 0 when the kernel gives none
protostringWhere the route came from, such as kernel, dhcp or static; empty on macOS
scopestringThe scope, such as link; empty for a global route

Examples (3)​

EXAMPLEINPUTOUTPUT
An interface with routesname=eth0[destination=default, family=inet, gateway=10.0.0.1, interface=eth0, metric=100, proto=dhcp, scope=] [destination=10.0.0.0/24, family=inet, gateway=, interface=eth0, metric=0, proto=kernel, scope=link] [destination=10.20.0.0/16, family=inet, gateway=10.0.0.254, interface=eth0, metric=50, proto=static, scope=]
An interface with no routesname=eth1
A Macname=en0[destination=default, family=inet, gateway=192.168.0.1, interface=en0, metric=0, proto=, scope=]

Method create​

Namecreate
Verbwrite
DescriptionAdd a static route to an interface
DetailAdds the route to the interface's netplan file, such as /etc/netplan/osapi-osapi0-routes.yaml for osapi0, under a netplan definition that is the interface's own, and applies it. A route osapi already has, the same, does not change; one to the same destination by another gateway or metric is refused: update changes it. A default route is refused: the interface behavior sets the gateway. An interface the host does not have is not found. An interface that a match defines, such as cloud-init's all for en*, is refused, because the route would go on each interface the match takes. It runs on the Debian family, and elsewhere, and in a container, reports skipped.
HTTPPOST
Route/api/node/{hostname}/interface/{name}/route
Permissioninterface:write
Commandosapi client node interface route create
Input typeCreateInput
Output typeResult

Input (4)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^(@fact.[a-z0-9_.]+|[a-zA-Z0-9][a-zA-Z0-9._-]{0,14})$The interface, such as eth0, or a fact such as @fact.interface.primary
destinationstringyesformat cidrWhere the route goes, in CIDR notation, such as 10.0.0.0/8; not a default route
viastringyesformat ipThe gateway, an address of the destination's family, such as 192.168.1.1
metricintegernomin 0, max 4.294967295e+09The metric, from 0 to 4294967295; none when it is 0

Output (2)​

FIELDTYPEDESCRIPTION
destinationstringThe destination of the route
changedbooleanWhether the host changed

Examples (3)​

EXAMPLEINPUTOUTPUT
A routename=osapi0, destination=198.51.100.0/24, via=192.0.2.1destination=198.51.100.0/24, changed=true
A second route, with a metricname=osapi0, destination=2001:db8:1::/48, via=2001:db8::1, metric=200destination=2001:db8:1::/48, changed=true
A route osapi already hasname=osapi0, destination=198.51.100.0/24, via=192.0.2.1destination=198.51.100.0/24, changed=false

Method update​

Nameupdate
Verbwrite
DescriptionChange the gateway or the metric of a route
DetailWrites the route over the one osapi has to the same destination, and applies it. A destination osapi has no route to is not found: create adds it.
HTTPPUT
Route/api/node/{hostname}/interface/{name}/route
Permissioninterface:write
Commandosapi client node interface route update
Input typeUpdateInput
Output typeResult

Input (4)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^(@fact.[a-z0-9_.]+|[a-zA-Z0-9][a-zA-Z0-9._-]{0,14})$The interface, such as eth0, or a fact such as @fact.interface.primary
destinationstringyesformat cidrWhere the route goes, in CIDR notation, such as 10.0.0.0/8; not a default route
viastringyesformat ipThe gateway, an address of the destination's family, such as 192.168.1.1
metricintegernomin 0, max 4.294967295e+09The metric, from 0 to 4294967295; none when it is 0

Output (2)​

FIELDTYPEDESCRIPTION
destinationstringThe destination of the route
changedbooleanWhether the host changed

Examples (1)​

EXAMPLEINPUTOUTPUT
A new gateway and metricname=osapi0, destination=198.51.100.0/24, via=192.0.2.2, metric=10destination=198.51.100.0/24, changed=true

Method delete​

Namedelete
Verbwrite
DescriptionDrop a route that osapi wrote
DetailDrops the route from the interface's netplan file and applies what is left; the last route removes the file. A route osapi does not have does not change.
HTTPDELETE
Route/api/node/{hostname}/interface/{name}/route
Permissioninterface:write
Commandosapi client node interface route delete
Input typeDeleteInput
Output typeResult

Input (2)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^(@fact.[a-z0-9_.]+|[a-zA-Z0-9][a-zA-Z0-9._-]{0,14})$The interface, such as eth0, or a fact such as @fact.interface.primary
destinationstringyesformat cidrThe destination of the route, in CIDR notation, such as 10.0.0.0/8

Output (2)​

FIELDTYPEDESCRIPTION
destinationstringThe destination of the route
changedbooleanWhether the host changed

Examples (3)​

EXAMPLEINPUTOUTPUT
One of two routesname=osapi0, destination=198.51.100.0/24destination=198.51.100.0/24, changed=true
The last routename=osapi0, destination=198.51.100.0/24destination=198.51.100.0/24, changed=true
A route osapi does not havename=osapi0, destination=198.51.100.0/24destination=198.51.100.0/24, changed=false