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
| Name | route |
| Description | The routes of an interface |
| Placement | node |
| Of | interface |
| Area | networking |
| Internal | no |
| API | yes |
| CLI | yes |
| Next | no |
| Platforms | debian, linux, darwin |
| Sudo | none |
| Runs | none |
| Writes | /etc/netplan/osapi-*-routes.yaml |
| Keeps state | no |
| Uses | netplan |
| Used by | none |
Methods (4)
| NAME | VERB | HTTP | ROUTE | PERMISSION | DESCRIPTION |
|---|---|---|---|---|---|
| list | read | GET | /api/node/{hostname}/interface/{name}/route | interface:read | List the routes of an interface |
| create | write | POST | /api/node/{hostname}/interface/{name}/route | interface:write | Add a static route to an interface |
| update | write | PUT | /api/node/{hostname}/interface/{name}/route | interface:write | Change the gateway or the metric of a route |
| delete | write | DELETE | /api/node/{hostname}/interface/{name}/route | interface:write | Drop a route that osapi wrote |
Types (4)
| NAME | INPUT | OUTPUT |
|---|---|---|
| list | ListInput { name* } | []Entry { destination, gateway, interface, family, metric, proto, scope } |
| create | CreateInput { name*, destination*, via*, metric } | Result { destination, changed } |
| update | UpdateInput { name*, destination*, via*, metric } | Result { destination, changed } |
| delete | DeleteInput { name*, destination* } | Result { destination, changed } |
Settings (0)
None. Declare them with behavior.Config.
Telemetry
| Span | behavior.route.<method> |
| Child spans | behavior.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 |
| Metrics | osapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total |
| Attributes | osapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed |
| Recorded inputs | name (list, create, update, delete), destination (create, update, delete) |
Method list
| Name | list |
| Verb | read |
| Description | List the routes of an interface |
| Detail | Reads 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. |
| HTTP | GET |
| Route | /api/node/{hostname}/interface/{name}/route |
| Permission | interface:read |
| Command | osapi client node interface route list |
| Input type | ListInput |
| Output type | []Entry |
Input (1)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^(@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)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| destination | string | The destination in CIDR notation, or default |
| gateway | string | The gateway; empty for a route on the link |
| interface | string | The interface the route goes out of |
| family | string | inet or inet6 |
| metric | integer | The metric; 0 when the kernel gives none |
| proto | string | Where the route came from, such as kernel, dhcp or static; empty on macOS |
| scope | string | The scope, such as link; empty for a global route |
Examples (3)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| An interface with routes | name=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 routes | name=eth1 | |
| A Mac | name=en0 | [destination=default, family=inet, gateway=192.168.0.1, interface=en0, metric=0, proto=, scope=] |
Method create
| Name | create |
| Verb | write |
| Description | Add a static route to an interface |
| Detail | Adds 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. |
| HTTP | POST |
| Route | /api/node/{hostname}/interface/{name}/route |
| Permission | interface:write |
| Command | osapi client node interface route create |
| Input type | CreateInput |
| Output type | Result |
Input (4)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^(@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 |
| destination | string | yes | format cidr | Where the route goes, in CIDR notation, such as 10.0.0.0/8; not a default route |
| via | string | yes | format ip | The gateway, an address of the destination's family, such as 192.168.1.1 |
| metric | integer | no | min 0, max 4.294967295e+09 | The metric, from 0 to 4294967295; none when it is 0 |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| destination | string | The destination of the route |
| changed | boolean | Whether the host changed |
Examples (3)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| A route | name=osapi0, destination=198.51.100.0/24, via=192.0.2.1 | destination=198.51.100.0/24, changed=true |
| A second route, with a metric | name=osapi0, destination=2001:db8:1::/48, via=2001:db8::1, metric=200 | destination=2001:db8:1::/48, changed=true |
| A route osapi already has | name=osapi0, destination=198.51.100.0/24, via=192.0.2.1 | destination=198.51.100.0/24, changed=false |
Method update
| Name | update |
| Verb | write |
| Description | Change the gateway or the metric of a route |
| Detail | Writes 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. |
| HTTP | PUT |
| Route | /api/node/{hostname}/interface/{name}/route |
| Permission | interface:write |
| Command | osapi client node interface route update |
| Input type | UpdateInput |
| Output type | Result |
Input (4)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^(@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 |
| destination | string | yes | format cidr | Where the route goes, in CIDR notation, such as 10.0.0.0/8; not a default route |
| via | string | yes | format ip | The gateway, an address of the destination's family, such as 192.168.1.1 |
| metric | integer | no | min 0, max 4.294967295e+09 | The metric, from 0 to 4294967295; none when it is 0 |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| destination | string | The destination of the route |
| changed | boolean | Whether the host changed |
Examples (1)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| A new gateway and metric | name=osapi0, destination=198.51.100.0/24, via=192.0.2.2, metric=10 | destination=198.51.100.0/24, changed=true |
Method delete
| Name | delete |
| Verb | write |
| Description | Drop a route that osapi wrote |
| Detail | Drops 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. |
| HTTP | DELETE |
| Route | /api/node/{hostname}/interface/{name}/route |
| Permission | interface:write |
| Command | osapi client node interface route delete |
| Input type | DeleteInput |
| Output type | Result |
Input (2)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^(@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 |
| destination | string | yes | format cidr | The destination of the route, in CIDR notation, such as 10.0.0.0/8 |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| destination | string | The destination of the route |
| changed | boolean | Whether the host changed |
Examples (3)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| One of two routes | name=osapi0, destination=198.51.100.0/24 | destination=198.51.100.0/24, changed=true |
| The last route | name=osapi0, destination=198.51.100.0/24 | destination=198.51.100.0/24, changed=true |
| A route osapi does not have | name=osapi0, destination=198.51.100.0/24 | destination=198.51.100.0/24, changed=false |