Skip to main content

Create

Configure a network interface.

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.

osapi client node interface create [flags]

Examples​

# A dummy interface with a static address
osapi client node interface create --target web-01 --name osapi0 --type dummy --addresses 10.0.1.5/24

# Each setting
osapi client node interface create --target web-01 --name osapi0 --type dummy --dhcp6 --addresses 2001:db8::5/64 --mtu 9000 --mac-address 52:54:00:aa:bb:cc

# An interface the host has
osapi client node interface create --target web-01 --name eth1 --dhcp4 --wakeonlan

# An interface osapi already configures
osapi client node interface create --target web-01 --name osapi0 --type dummy --addresses 10.0.1.5/24

Result​

A dummy interface with a static address, on one host:

$ osapi client node interface create --target web-01 --name osapi0 --type dummy --addresses 10.0.1.5/24
Results:
  HOSTNAME  STATUS   NAME
  web-01    changed  osapi0

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

On each host, where one cannot run it:

$ osapi client node interface create --target _all --name osapi0 --type dummy --addresses 10.0.1.5/24
Results:
  HOSTNAME  STATUS   NAME
  web-01    changed  osapi0
  web-02    changed  osapi0

  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,
"hostname": "web-01",
"name": "osapi0",
"status": "ok"
}
]
}

Each setting, on one host:

$ osapi client node interface create --target web-01 --name osapi0 --type dummy --dhcp6 --addresses 2001:db8::5/64 --mtu 9000 --mac-address 52:54:00:aa:bb:cc
Results:
  HOSTNAME  STATUS   NAME
  web-01    changed  osapi0

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

On each host, where one cannot run it:

$ osapi client node interface create --target _all --name osapi0 --type dummy --dhcp6 --addresses 2001:db8::5/64 --mtu 9000 --mac-address 52:54:00:aa:bb:cc
Results:
  HOSTNAME  STATUS   NAME
  web-01    changed  osapi0
  web-02    changed  osapi0

  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,
"hostname": "web-01",
"name": "osapi0",
"status": "ok"
}
]
}

An interface the host has, on one host:

$ osapi client node interface create --target web-01 --name eth1 --dhcp4 --wakeonlan
Results:
  HOSTNAME  STATUS   NAME
  web-01    changed  eth1

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

On each host, where one cannot run it:

$ osapi client node interface create --target _all --name eth1 --dhcp4 --wakeonlan
Results:
  HOSTNAME  STATUS   NAME
  web-01    changed  eth1
  web-02    changed  eth1

  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,
"hostname": "web-01",
"name": "eth1",
"status": "ok"
}
]
}

An interface osapi already configures, on one host:

$ osapi client node interface create --target web-01 --name osapi0 --type dummy --addresses 10.0.1.5/24
Results:
  HOSTNAME  STATUS  NAME
  web-01    ok      osapi0

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

On each host, where one cannot run it:

$ osapi client node interface create --target _all --name osapi0 --type dummy --addresses 10.0.1.5/24
Results:
  HOSTNAME  STATUS  NAME
  web-01    ok      osapi0
  web-02    ok      osapi0

  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,
"hostname": "web-01",
"name": "osapi0",
"status": "ok"
}
]
}

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

ExampleOn the host
A dummy interface with a static addresswrites /etc/netplan/osapi-osapi0.yaml: network:\n version: 2\n dummy-devices:\n osapi0:\n dhcp4: false\n dhcp6: false\n addresses:\n - 10.0.1.5/24; runs netplan generate; runs netplan apply
Each settingwrites /etc/netplan/osapi-osapi0.yaml: network:\n version: 2\n dummy-devices:\n osapi0:\n dhcp4: false\n dhcp6: true\n addresses:\n - 2001:db8::5/64\n mtu: 9000\n macaddress: 52:54:00:aa:bb:cc; runs netplan generate; runs netplan apply
An interface the host haswrites /etc/netplan/osapi-eth1.yaml: network:\n version: 2\n ethernets:\n eth1:\n dhcp4: true\n dhcp6: false\n wakeonlan: true; runs netplan generate; runs netplan apply

The command fails in these cases:

CallFlagsFails with
An interface in a match that takes other interfaces--name enp0s1 --dhcp4also takes enp0s2
An interface in a match that takes it alone, for now--name enp0s1 --dhcp4any interface it matches later
An interface the host does not have--name eth9 --dhcp4not found
An address without a prefix--name osapi0 --addresses 10.0.1.5Addresses
More than 16 addresses--name osapi0 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24 --addresses 10.0.1.5/24Addresses
An IPv4 gateway that is not IPv4--name osapi0 --gateway4 fe80::1Gateway4
An IPv6 gateway that is not IPv6--name osapi0 --gateway6 10.0.1.1Gateway6
An MTU below 68--name osapi0 --mtu 10MTU
An MTU above 9000--name osapi0 --mtu 9001MTU
A MAC address netplan does not take--name osapi0 --mac-address 0000.5e00.5301MACAddress
A name that is not an interface name--name "eth0;reboot"Name
A type osapi does not know--name osapi0 --type vlanType

Permission​

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

Flags​

FlagDescriptionDefault
--addressesThe static addresses, in CIDR notation, such as 10.0.0.5/24
--dhcp4Take an IPv4 address from DHCP
--dhcp6Take an IPv6 address from DHCP
--gateway4The IPv4 default gateway
--gateway6The IPv6 default gateway
--mac-addressThe MAC address to set
--mtuThe MTU, from 68 to 9000
--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
--typeThe type: ethernet, the default, for an interface the host has, or dummy for a dummy interface that netplan makes (ethernet, dummy)
--wakeonlanTurn on wake-on-LAN

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.