Skip to main content

Interface

Network interface configuration management via Netplan.

Methods​

MethodDescription
List(ctx, target)List all interfaces
Get(ctx, target, name)Get a specific interface
Create(ctx, target, name, opts)Create a new interface config
Update(ctx, target, name, opts)Update an existing interface config
Delete(ctx, target, name)Delete an interface config

Request Types​

TypeFields
InterfaceConfigOptsDHCP4, DHCP6, Addresses, Gateway4, Gateway6, MTU, MACAddress, WakeOnLAN

Result Types​

InterfaceListResult (List)​

FieldTypeDescription
HostnamestringAgent hostname
StatusstringResult status (ok, skipped)
Interfaces[]InterfaceInfoList of interfaces on the host
ErrorstringError message (if any)

InterfaceInfo​

FieldTypeDescription
NamestringInterface name
DHCP4boolWhether DHCPv4 is enabled
DHCP6boolWhether DHCPv6 is enabled
Addresses[]stringIP addresses in CIDR notation
Gateway4stringIPv4 gateway address
Gateway6stringIPv6 gateway address
MTUintMaximum transmission unit
MACAddressstringHardware MAC address
WakeOnLANboolWhether Wake-on-LAN is enabled
StatestringInterface state (up, down)

InterfaceGetResult (Get)​

FieldTypeDescription
HostnamestringAgent hostname
StatusstringResult status (ok, skipped)
Interface*InterfaceInfoInterface configuration
ErrorstringError message (if any)

InterfaceMutationResult (Create, Update, Delete)​

FieldTypeDescription
HostnamestringAgent hostname
StatusstringResult status (ok, skipped)
NamestringInterface name
ChangedboolWhether a change was made
ErrorstringError message (if any)

Usage​

import "github.com/osapi-io/osapi/pkg/sdk/client"

c := client.New("http://localhost:8080", token)

// List all interfaces
resp, err := c.Interface.List(ctx, "web-01")
for _, r := range resp.Data.Results {
for _, iface := range r.Interfaces {
fmt.Printf("%s: state=%s\n",
iface.Name, iface.State)
}
}

// Get a specific interface
resp, err := c.Interface.Get(ctx, "web-01", "eth0")
iface := resp.Data.First().Interface
fmt.Printf("Addresses: %v\n", iface.Addresses)

// Create a static interface config
dhcp4 := false
resp, err := c.Interface.Create(ctx, "web-01", "eth0",
client.InterfaceConfigOpts{
DHCP4: &dhcp4,
Addresses: []string{"192.168.1.100/24"},
Gateway4: "192.168.1.1",
})
fmt.Printf("changed=%v\n", resp.Data.First().Changed)

// Update an existing config
resp, err := c.Interface.Update(ctx, "web-01", "eth0",
client.InterfaceConfigOpts{
Addresses: []string{"192.168.1.200/24"},
Gateway4: "192.168.1.1",
})

// Delete an interface config
resp, err := c.Interface.Delete(ctx, "web-01", "eth0")
fmt.Printf("changed=%v\n", resp.Data.First().Changed)

// Broadcast interface create to all hosts
dhcp4 := true
resp, err := c.Interface.Create(ctx, "_all", "eth1",
client.InterfaceConfigOpts{DHCP4: &dhcp4})
for _, r := range resp.Data.Results {
fmt.Printf("%s changed=%v\n", r.Hostname, r.Changed)
}

Example​

See examples/sdk/client/interface.go for a complete working example.

Permissions​

OperationPermission
List, Getnetwork:read
Create, Update, Deletenetwork:write

Interface management is supported on the Debian OS family (Ubuntu, Debian, Raspbian). On unsupported platforms (Darwin, generic Linux), operations return status: skipped.