51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package cloudinit
|
|
|
|
import (
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type NetworkConfig struct {
|
|
Version int `yaml:"version"`
|
|
Config []ConfigEntry `yaml:"config"`
|
|
}
|
|
|
|
type ConfigEntry struct {
|
|
Type string `yaml:"type"`
|
|
Name string `yaml:"name,omitempty"`
|
|
MacAddress string `yaml:"mac_address,omitempty"`
|
|
Subnets []Subnet `yaml:"subnets,omitempty"`
|
|
Address []string `yaml:"address,omitempty"`
|
|
Search []string `yaml:"search,omitempty"`
|
|
}
|
|
|
|
type Subnet struct {
|
|
Type string `yaml:"type"`
|
|
Address string `yaml:"address"`
|
|
Netmask string `yaml:"netmask"`
|
|
Gateway string `yaml:"gateway"`
|
|
}
|
|
|
|
func (c *NetworkConfig) Load(cloudInitDrive string) error {
|
|
data, err := os.ReadFile(cloudInitDrive + "NETWORK_CONFIG")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Unmarshal the YAML data into the Config struct
|
|
err = yaml.Unmarshal(data, &c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *NetworkConfig) GetNameservers() []string {
|
|
for _, config := range c.Config {
|
|
if config.Type == "nameserver" {
|
|
return config.Address
|
|
}
|
|
}
|
|
return []string{}
|
|
}
|