This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
gonetworkmanager/DHCP4Config.go
2019-09-18 10:19:02 +02:00

56 lines
1.1 KiB
Go

package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
DHCP4ConfigInterface = NetworkManagerInterface + ".DHCP4Config"
// Properties
DHCP4ConfigPropertyOptions = DHCP4ConfigInterface + ".Options"
)
type DHCP4Options map[string]interface{}
type DHCP4Config interface {
// GetOptions gets options map of configuration returned by the IPv4 DHCP server.
GetPropertyOptions() (DHCP4Options, error)
MarshalJSON() ([]byte, error)
}
func NewDHCP4Config(objectPath dbus.ObjectPath) (DHCP4Config, error) {
var c dhcp4Config
return &c, c.init(NetworkManagerInterface, objectPath)
}
type dhcp4Config struct {
dbusBase
}
func (c *dhcp4Config) GetPropertyOptions() (DHCP4Options, error) {
options, err := c.getMapStringVariantProperty(DHCP4ConfigPropertyOptions)
rv := make(DHCP4Options)
if err != nil {
return rv, err
}
for k, v := range options {
rv[k] = v.Value()
}
return rv, nil
}
func (c *dhcp4Config) MarshalJSON() ([]byte, error) {
Options, err := c.GetOptions()
if err != nil {
return nil, err
}
return json.Marshal(map[string]interface{}{
"Options": Options,
})
}