feat(init): add VMware support (#200)
This commit is contained in:
parent
b30ed5dd4e
commit
48b2ea3d83
@ -67,6 +67,12 @@ const (
|
||||
// UserDataCIData is the volume label for NoCloud cloud-init.
|
||||
// See https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html#datasource-nocloud.
|
||||
UserDataCIData = "cidata"
|
||||
|
||||
// UserDataGuestInfo is the name of the VMware guestinfo user data strategy.
|
||||
UserDataGuestInfo = "guestinfo"
|
||||
|
||||
// VMwareGuestInfoUserDataKey is the guestinfo key used to provide a user data file.
|
||||
VMwareGuestInfoUserDataKey = "talos.userdata"
|
||||
)
|
||||
|
||||
// See https://linux.die.net/man/3/klogctl
|
||||
|
69
src/initramfs/cmd/init/pkg/platform/cloud/vmware/vmware.go
Normal file
69
src/initramfs/cmd/init/pkg/platform/cloud/vmware/vmware.go
Normal file
@ -0,0 +1,69 @@
|
||||
// +build linux
|
||||
|
||||
package vmware
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/autonomy/talos/src/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/talos/src/initramfs/cmd/init/pkg/kernel"
|
||||
"github.com/autonomy/talos/src/initramfs/pkg/userdata"
|
||||
"github.com/vmware/vmw-guestinfo/rpcvmx"
|
||||
"github.com/vmware/vmw-guestinfo/vmcheck"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// VMware is the concrete type that implements the platform.Platform interface.
|
||||
type VMware struct{}
|
||||
|
||||
// Name implements the platform.Platform interface.
|
||||
func (vmw *VMware) Name() string {
|
||||
return "VMware"
|
||||
}
|
||||
|
||||
// UserData implements the platform.Platform interface.
|
||||
func (vmw *VMware) UserData() (data userdata.UserData, err error) {
|
||||
arguments, err := kernel.ParseProcCmdline()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
option, ok := arguments[constants.KernelParamUserData]
|
||||
if !ok {
|
||||
return data, fmt.Errorf("no user data option was found")
|
||||
}
|
||||
|
||||
if option == constants.UserDataGuestInfo {
|
||||
ok, err := vmcheck.IsVirtualWorld()
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
|
||||
if !ok {
|
||||
return data, fmt.Errorf("not a virtual world")
|
||||
}
|
||||
|
||||
config := rpcvmx.NewConfig()
|
||||
val, err := config.String(constants.VMwareGuestInfoUserDataKey, "")
|
||||
if err != nil {
|
||||
return data, fmt.Errorf("failed to get guestinfo.%s: %v", constants.VMwareGuestInfoUserDataKey, err)
|
||||
}
|
||||
|
||||
b, err := base64.StdEncoding.DecodeString(val)
|
||||
if err != nil {
|
||||
return data, fmt.Errorf("failed to decode guestinfo.%s: %v", constants.VMwareGuestInfoUserDataKey, err)
|
||||
}
|
||||
|
||||
if err = yaml.Unmarshal(b, &data); err != nil {
|
||||
return data, fmt.Errorf("unmarshal user data: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Prepare implements the platform.Platform interface.
|
||||
func (vmw *VMware) Prepare(data userdata.UserData) (err error) {
|
||||
return nil
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/autonomy/talos/src/initramfs/cmd/init/pkg/kernel"
|
||||
"github.com/autonomy/talos/src/initramfs/cmd/init/pkg/platform/baremetal"
|
||||
"github.com/autonomy/talos/src/initramfs/cmd/init/pkg/platform/cloud/aws"
|
||||
"github.com/autonomy/talos/src/initramfs/cmd/init/pkg/platform/cloud/vmware"
|
||||
"github.com/autonomy/talos/src/initramfs/pkg/userdata"
|
||||
)
|
||||
|
||||
@ -33,10 +34,12 @@ func NewPlatform() (p Platform, err error) {
|
||||
} else {
|
||||
return nil, fmt.Errorf("failed to verify EC2 PKCS7 signature")
|
||||
}
|
||||
case "vmware":
|
||||
p = &vmware.VMware{}
|
||||
case "bare-metal":
|
||||
p = &baremetal.BareMetal{}
|
||||
default:
|
||||
return nil, fmt.Errorf("no platform specified")
|
||||
return nil, fmt.Errorf("platform not supported: %s", platform)
|
||||
}
|
||||
}
|
||||
return p, nil
|
||||
|
@ -57,6 +57,7 @@ require (
|
||||
github.com/spf13/pflag v1.0.1 // indirect
|
||||
github.com/stretchr/testify v1.2.2 // indirect
|
||||
github.com/syndtr/gocapability v0.0.0-20180223013746-33e07d32887e // indirect
|
||||
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728
|
||||
golang.org/x/crypto v0.0.0-20180515001509-1a580b3eff78 // indirect
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225
|
||||
golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced // indirect
|
||||
|
@ -110,6 +110,8 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/syndtr/gocapability v0.0.0-20180223013746-33e07d32887e h1:QjF5rxNgRSLHJDwKUvfYP3qOx1vTDzUi/+oSC8FXnCI=
|
||||
github.com/syndtr/gocapability v0.0.0-20180223013746-33e07d32887e/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
||||
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728 h1:sH9mEk+flyDxiUa5BuPiuhDETMbzrt9A20I2wktMvRQ=
|
||||
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk=
|
||||
golang.org/x/crypto v0.0.0-20180515001509-1a580b3eff78 h1:uJIReYEB1ZZLarzi83Pmig1HhZ/cwFCysx05l0PFBIk=
|
||||
golang.org/x/crypto v0.0.0-20180515001509-1a580b3eff78/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225 h1:kNX+jCowfMYzvlSvJu5pQWEmyWFrBXJ3PBy10xKMXK8=
|
||||
|
Loading…
x
Reference in New Issue
Block a user