diff --git a/pkg/drivers/hyperv/hyperv.go b/pkg/drivers/hyperv/hyperv_windows.go similarity index 100% rename from pkg/drivers/hyperv/hyperv.go rename to pkg/drivers/hyperv/hyperv_windows.go diff --git a/pkg/drivers/hyperv/powershell.go b/pkg/drivers/hyperv/powershell_windows.go similarity index 100% rename from pkg/drivers/hyperv/powershell.go rename to pkg/drivers/hyperv/powershell_windows.go diff --git a/pkg/libmachine/libmachine.go b/pkg/libmachine/libmachine.go index d5ff56b2cc..1d4fe76ca0 100644 --- a/pkg/libmachine/libmachine.go +++ b/pkg/libmachine/libmachine.go @@ -1,13 +1,10 @@ package libmachine import ( - "encoding/json" "io" - "github.com/code-ready/crc/pkg/drivers/hyperv" "github.com/code-ready/crc/pkg/libmachine/host" "github.com/code-ready/crc/pkg/libmachine/persist" - "github.com/code-ready/machine/libmachine/drivers" rpcdriver "github.com/code-ready/machine/libmachine/drivers/rpc" ) @@ -29,54 +26,6 @@ func NewClient(storePath string) *Client { } } -func (api *Client) NewHost(driverName string, driverPath string, rawDriver []byte) (*host.Host, error) { - var driver drivers.Driver - if driverName == "hyperv" { - driver = hyperv.NewDriver("", "") - if err := json.Unmarshal(rawDriver, &driver); err != nil { - return nil, err - } - } else { - var err error - driver, err = api.clientDriverFactory.NewRPCClientDriver(driverName, driverPath, rawDriver) - if err != nil { - return nil, err - } - } - - return &host.Host{ - ConfigVersion: host.Version, - Name: driver.GetMachineName(), - Driver: driver, - DriverName: driver.DriverName(), - DriverPath: driverPath, - RawDriver: rawDriver, - }, nil -} - -func (api *Client) Load(name string) (*host.Host, error) { - h, err := api.Filestore.Load(name) - if err != nil { - return nil, err - } - - if h.DriverName == "hyperv" { - driver := hyperv.NewDriver("", "") - if err := json.Unmarshal(h.RawDriver, &driver); err != nil { - return nil, err - } - h.Driver = driver - return h, nil - } - - d, err := api.clientDriverFactory.NewRPCClientDriver(h.DriverName, h.DriverPath, h.RawDriver) - if err != nil { - return nil, err - } - h.Driver = d - return h, nil -} - func (api *Client) Close() error { return api.clientDriverFactory.Close() } diff --git a/pkg/libmachine/load_unix.go b/pkg/libmachine/load_unix.go new file mode 100644 index 0000000000..8cded80838 --- /dev/null +++ b/pkg/libmachine/load_unix.go @@ -0,0 +1,37 @@ +// +build !windows + +package libmachine + +import ( + "github.com/code-ready/crc/pkg/libmachine/host" +) + +func (api *Client) NewHost(driverName string, driverPath string, rawDriver []byte) (*host.Host, error) { + driver, err := api.clientDriverFactory.NewRPCClientDriver(driverName, driverPath, rawDriver) + if err != nil { + return nil, err + } + + return &host.Host{ + ConfigVersion: host.Version, + Name: driver.GetMachineName(), + Driver: driver, + DriverName: driver.DriverName(), + DriverPath: driverPath, + RawDriver: rawDriver, + }, nil +} + +func (api *Client) Load(name string) (*host.Host, error) { + h, err := api.Filestore.Load(name) + if err != nil { + return nil, err + } + + d, err := api.clientDriverFactory.NewRPCClientDriver(h.DriverName, h.DriverPath, h.RawDriver) + if err != nil { + return nil, err + } + h.Driver = d + return h, nil +} diff --git a/pkg/libmachine/load_windows.go b/pkg/libmachine/load_windows.go new file mode 100644 index 0000000000..d69b94f22f --- /dev/null +++ b/pkg/libmachine/load_windows.go @@ -0,0 +1,38 @@ +package libmachine + +import ( + "encoding/json" + + "github.com/code-ready/crc/pkg/drivers/hyperv" + "github.com/code-ready/crc/pkg/libmachine/host" +) + +func (api *Client) NewHost(driverName string, driverPath string, rawDriver []byte) (*host.Host, error) { + driver := hyperv.NewDriver("", "") + if err := json.Unmarshal(rawDriver, &driver); err != nil { + return nil, err + } + + return &host.Host{ + ConfigVersion: host.Version, + Name: driver.GetMachineName(), + Driver: driver, + DriverName: driver.DriverName(), + DriverPath: driverPath, + RawDriver: rawDriver, + }, nil +} + +func (api *Client) Load(name string) (*host.Host, error) { + h, err := api.Filestore.Load(name) + if err != nil { + return nil, err + } + + driver := hyperv.NewDriver("", "") + if err := json.Unmarshal(h.RawDriver, &driver); err != nil { + return nil, err + } + h.Driver = driver + return h, nil +}