43 lines
746 B
Go
43 lines
746 B
Go
package cloudinit
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"jonasled.dev/jonasled/cloud-init-windows/filesystem"
|
|
)
|
|
|
|
type CloudInit struct {
|
|
UserData UserData
|
|
NetworkConfig NetworkConfig
|
|
}
|
|
|
|
func (c *CloudInit) Load() error {
|
|
cloudInitDrive, err := getCloudInitMountpoint()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = c.UserData.Load(cloudInitDrive)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = c.NetworkConfig.Load(cloudInitDrive)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func getCloudInitMountpoint() (string, error) {
|
|
mounts, _, err := filesystem.Mounts()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
for _, mount := range mounts {
|
|
if mount.Device == "cidata" {
|
|
return mount.Mountpoint, nil
|
|
}
|
|
}
|
|
return "", errors.New("no Cloud-Init Mountpoint found")
|
|
|
|
}
|