Interface
The network interfaces of the host. osapi dsl behavior get --name interface
and osapi dsl behavior method get show the same.
Its chain shows each call that its
examples make.
Behavior
| Name | interface |
| Description | The network interfaces of the host |
| Placement | node |
| Area | networking |
| Internal | no |
| API | yes |
| CLI | yes |
| Next | no |
| Platforms | debian, linux, darwin |
| Sudo | ip |
| Runs | none |
| Writes | /etc/netplan/osapi-*.yaml |
| Keeps state | no |
| Uses | netplan |
| Used by | none |
Methods (5)
| NAME | VERB | HTTP | ROUTE | PERMISSION | DESCRIPTION |
|---|---|---|---|---|---|
| list | read | GET | /api/node/{hostname}/interface | interface:read | List the network interfaces of the host |
| get | read | GET | /api/node/{hostname}/interface/{name} | interface:read | Get a network interface of the host |
| create | write | POST | /api/node/{hostname}/interface/{name} | interface:write | Configure a network interface |
| update | write | PUT | /api/node/{hostname}/interface/{name} | interface:write | Change the config osapi has of a network interface |
| delete | write | DELETE | /api/node/{hostname}/interface/{name} | interface:write | Drop the config osapi has of a network interface |
Types (5)
| NAME | INPUT | OUTPUT |
|---|---|---|
| list | ListInput | []Entry { name, state, mac, mtu, ipv4, ipv6, addresses, dhcp4, primary } |
| get | GetInput { name* } | Entry { name, state, mac, mtu, ipv4, ipv6, addresses, dhcp4, primary } |
| create | CreateInput { name*, type, dhcp4, dhcp6, addresses, gateway4, gateway6, mtu, mac_address, wakeonlan } | Result { name, changed } |
| update | UpdateInput { name*, type, dhcp4, dhcp6, addresses, gateway4, gateway6, mtu, mac_address, wakeonlan } | Result { name, changed } |
| delete | DeleteInput { name* } | Result { name, changed } |
Settings (0)
None. Declare them with behavior.Config.
Telemetry
| Span | behavior.interface.<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 (get, create, update, delete) |
Method list
| Name | list |
| Verb | read |
| Description | List the network interfaces of the host |
| Detail | Reads each interface but the loopback, in the order of its index: /sys/class/net and ip on Linux, ifconfig and netstat on macOS. dhcp4 is true when a route of the interface has proto dhcp, and primary when it has the default route. |
| HTTP | GET |
| Route | /api/node/{hostname}/interface |
| Permission | interface:read |
| Command | osapi client node interface list |
| Input type | ListInput |
| Output type | []Entry |
Input (0)
None. The method takes no input; its command needs only --target.
Output (9)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The interface |
| state | string | up or down |
| mac | string | Its MAC address; empty for one without, such as lo |
| mtu | integer | Its MTU |
| ipv4 | string | Its first IPv4 address that is not link-local |
| ipv6 | string | Its first IPv6 address that is not link-local |
| addresses | array | Each of its addresses, in CIDR notation |
| dhcp4 | boolean | Whether DHCP gave it an IPv4 address: a route of it has proto dhcp |
| primary | boolean | Whether it has the default route |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| A Linux host | (none) | [addresses=[10.0.0.5/24 2001:db8::5/64 fe80::5054:ff:fe12:3456/64], dhcp4=true, ipv4=10.0.0.5, ipv6=2001:db8::5, mac=52:54:00:12:34:56, mtu=1500, name=eth0, primary=true, state=up] |
| A Mac | (none) | [addresses=[192.168.0.40/24], dhcp4=false, ipv4=192.168.0.40, ipv6=, mac=3c:22:fb:00:00:01, mtu=1500, name=en0, primary=true, state=up] |
Method get
| Name | get |
| Verb | read |
| Description | Get a network interface of the host |
| Detail | Reads the interface as list does. |
| HTTP | GET |
| Route | /api/node/{hostname}/interface/{name} |
| Permission | interface:read |
| Command | osapi client node interface get |
| Input type | GetInput |
| 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 (9)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The interface |
| state | string | up or down |
| mac | string | Its MAC address; empty for one without, such as lo |
| mtu | integer | Its MTU |
| ipv4 | string | Its first IPv4 address that is not link-local |
| ipv6 | string | Its first IPv6 address that is not link-local |
| addresses | array | Each of its addresses, in CIDR notation |
| dhcp4 | boolean | Whether DHCP gave it an IPv4 address: a route of it has proto dhcp |
| primary | boolean | Whether it has the default route |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| An interface with a DHCP address | name=eth0 | name=eth0, state=up, mac=52:54:00:12:34:56, mtu=1500, ipv4=10.0.0.5, ipv6=2001:db8::5, addresses=[10.0.0.5/24 2001:db8::5/64 fe80::5054:ff:fe12:3456/64], dhcp4=true, primary=true |
| A Mac | name=en0 | name=en0, state=up, mac=3c:22:fb:00:00:01, mtu=1500, ipv4=192.168.0.40, ipv6=, addresses=[192.168.0.40/24], dhcp4=false, primary=true |
Method create
| Name | create |
| Verb | write |
| Description | Configure a network interface |
| Detail | Writes a netplan file of the interface's own, such as /etc/netplan/osapi-osapi0.yaml for osapi0, under a netplan definition that is the interface's own, and applies it. type is ethernet, the default, or dummy. An ethernet is an interface the host has, in the netplan section that netplan status gives for it: one the host does not have is not found. A dummy goes under dummy-devices, and netplan apply makes it, so the host need not have it. dummy-devices needs netplan 0.107 or later. dhcp4 and dhcp6 are false unless given, so the interface has only the addresses given. An interface that a match defines, such as cloud-init's all for en*, is refused, because the config would change each interface the match takes, now and later. An interface osapi already configures does not change: update replaces its config. It runs on the Debian family, and elsewhere, and in a container, reports skipped. |
| HTTP | POST |
| Route | /api/node/{hostname}/interface/{name} |
| Permission | interface:write |
| Command | osapi client node interface create |
| Input type | CreateInput |
| Output type | Result |
Input (10)
| 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 |
| type | string | no | one of ethernet dummy | The type: ethernet, the default, for an interface the host has, or dummy for a dummy interface that netplan makes |
| dhcp4 | boolean | no | Take an IPv4 address from DHCP | |
| dhcp6 | boolean | no | Take an IPv6 address from DHCP | |
| addresses | array | no | The static addresses, in CIDR notation, such as 10.0.0.5/24 | |
| gateway4 | string | no | format ipv4 | The IPv4 default gateway |
| gateway6 | string | no | format ipv6 | The IPv6 default gateway |
| mtu | integer | no | min 68, max 9000 | The MTU, from 68 to 9000 |
| mac_address | string | no | pattern ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ | The MAC address to set |
| wakeonlan | boolean | no | Turn on wake-on-LAN |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The interface |
| changed | boolean | Whether the host changed |
Examples (4)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| A dummy interface with a static address | name=osapi0, type=dummy, addresses=[10.0.1.5/24] | name=osapi0, changed=true |
| Each setting | name=osapi0, type=dummy, dhcp6=true, addresses=[2001:db8::5/64], mtu=9000, mac_address=52:54:00:aa:bb:cc | name=osapi0, changed=true |
| An interface the host has | name=eth1, dhcp4=true, wakeonlan=true | name=eth1, changed=true |
| An interface osapi already configures | name=osapi0, type=dummy, addresses=[10.0.1.5/24] | name=osapi0, changed=false |
Method update
| Name | update |
| Verb | write |
| Description | Change the config osapi has of a network interface |
| Detail | Writes the interface's netplan file over the one osapi has, as create writes it, and applies it. Without type dummy, the config goes in the section that netplan status gives, which is dummy-devices for a dummy, so a dummy stays a dummy. An interface osapi does not configure is not found: create configures it. |
| HTTP | PUT |
| Route | /api/node/{hostname}/interface/{name} |
| Permission | interface:write |
| Command | osapi client node interface update |
| Input type | UpdateInput |
| Output type | Result |
Input (10)
| 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 |
| type | string | no | one of ethernet dummy | The type: ethernet, the default, for an interface the host has, or dummy for a dummy interface that netplan makes |
| dhcp4 | boolean | no | Take an IPv4 address from DHCP | |
| dhcp6 | boolean | no | Take an IPv6 address from DHCP | |
| addresses | array | no | The static addresses, in CIDR notation, such as 10.0.0.5/24 | |
| gateway4 | string | no | format ipv4 | The IPv4 default gateway |
| gateway6 | string | no | format ipv6 | The IPv6 default gateway |
| mtu | integer | no | min 68, max 9000 | The MTU, from 68 to 9000 |
| mac_address | string | no | pattern ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ | The MAC address to set |
| wakeonlan | boolean | no | Turn on wake-on-LAN |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The interface |
| changed | boolean | Whether the host changed |
Examples (1)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| Move an interface to DHCP | name=osapi0, type=dummy, dhcp4=true | name=osapi0, changed=true |
Method delete
| Name | delete |
| Verb | write |
| Description | Drop the config osapi has of a network interface |
| Detail | Removes the interface's netplan file and applies what is left. netplan apply leaves the link of a dummy, so delete then deletes the link with ip link delete. An interface osapi does not configure does not change. |
| HTTP | DELETE |
| Route | /api/node/{hostname}/interface/{name} |
| Permission | interface:write |
| Command | osapi client node interface delete |
| Input type | DeleteInput |
| Output type | Result |
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 (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The interface |
| changed | boolean | Whether the host changed |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| A dummy interface osapi configures | name=osapi0 | name=osapi0, changed=true |
| An interface osapi does not configure | name=osapi0 | name=osapi0, changed=false |