Skip to main content

Create

Add a static route to an interface.

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.

osapi client node interface route create [flags]

Examples​

# A route
osapi client node interface route create --target web-01 --name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1

# A second route, with a metric
osapi client node interface route create --target web-01 --name osapi0 --destination 2001:db8:1::/48 --via 2001:db8::1 --metric 200

# A route osapi already has
osapi client node interface route create --target web-01 --name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1

Result​

A route, on one host:

$ osapi client node interface route create --target web-01 --name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1
Results:
  HOSTNAME  STATUS   DESTINATION
  web-01    changed  198.51.100.0/24

  1 host: 1 changed   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node interface route create --target _all --name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1
Results:
  HOSTNAME  STATUS   DESTINATION
  web-01    changed  198.51.100.0/24
  web-02    changed  198.51.100.0/24

  3 hosts: 2 changed, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"destination": "198.51.100.0/24",
"hostname": "web-01",
"status": "ok"
}
]
}

A second route, with a metric, on one host:

$ osapi client node interface route create --target web-01 --name osapi0 --destination 2001:db8:1::/48 --via 2001:db8::1 --metric 200
Results:
  HOSTNAME  STATUS   DESTINATION
  web-01    changed  2001:db8:1::/48

  1 host: 1 changed   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node interface route create --target _all --name osapi0 --destination 2001:db8:1::/48 --via 2001:db8::1 --metric 200
Results:
  HOSTNAME  STATUS   DESTINATION
  web-01    changed  2001:db8:1::/48
  web-02    changed  2001:db8:1::/48

  3 hosts: 2 changed, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"destination": "2001:db8:1::/48",
"hostname": "web-01",
"status": "ok"
}
]
}

A route osapi already has, on one host:

$ osapi client node interface route create --target web-01 --name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1
Results:
  HOSTNAME  STATUS  DESTINATION
  web-01    ok      198.51.100.0/24

  1 host: 1 ok   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node interface route create --target _all --name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1
Results:
  HOSTNAME  STATUS  DESTINATION
  web-01    ok      198.51.100.0/24
  web-02    ok      198.51.100.0/24

  3 hosts: 2 ok, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": false,
"destination": "198.51.100.0/24",
"hostname": "web-01",
"status": "ok"
}
]
}

With the default settings, each example does this on the host:

ExampleOn the host
A routeruns netplan generate; runs netplan apply; writes /etc/netplan/osapi-osapi0-routes.yaml: network:\n version: 2\n ethernets:\n osapi0:\n routes:\n - to: 198.51.100.0/24\n via: 192.0.2.1
A second route, with a metricruns netplan generate; runs netplan apply; writes /etc/netplan/osapi-osapi0-routes.yaml: network:\n version: 2\n ethernets:\n osapi0:\n routes:\n - to: 198.51.100.0/24\n via: 192.0.2.1\n - to: 2001:db8:1::/48\n via: 2001:db8::1\n metric: 200

The command fails in these cases:

CallFlagsFails with
A default route--name osapi0 --destination 0.0.0.0/0 --via 192.0.2.1default route
A gateway of the other family--name osapi0 --destination 198.51.100.0/24 --via 2001:db8::1not an address of the family
Another route to a destination osapi has--name osapi0 --destination 198.51.100.0/24 --via 192.0.2.2update changes it
An interface in a match that takes other interfaces--name enp0s1 --destination 198.51.100.0/24 --via 192.0.2.1also takes enp0s2
An interface in a match that takes it alone, for now--name enp0s1 --destination 198.51.100.0/24 --via 192.0.2.1any interface it matches later
An interface the host does not have--name eth9 --destination 198.51.100.0/24 --via 192.0.2.1not found
A destination that is not CIDR--name osapi0 --destination 10.0.0.0 --via 192.0.2.1Destination
A gateway that is not an address--name osapi0 --destination 198.51.100.0/24 --via gatewayVia
A metric below 0--name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1 --metric -1Metric
A metric over 4294967295--name osapi0 --destination 198.51.100.0/24 --via 192.0.2.1 --metric 4294967296Metric
A name that is not an interface name--name "eth0;reboot" --destination 198.51.100.0/24 --via 192.0.2.1Name

Permission​

It needs the interface:write permission. osapi controller role get --name <role> shows what a role grants.

Flags​

FlagDescriptionDefault
--destinationWhere the route goes, in CIDR notation, such as 10.0.0.0/8; not a default route (required)
--metricThe metric, from 0 to 4294967295; none when it is 0
--nameThe interface, such as eth0, or a fact such as @fact.interface.primary (required)
-T, --targetTarget: _all, _any, hostname, or label (group:web.dev)_all
--viaThe gateway, an address of the destination's family, such as 192.168.1.1 (required)

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml
--urlBase URL the CLI client connects to (controller.client.url)https://localhost:8080

Output tells how the result is printed, and what --json gives.