Skip to content

Commit

Permalink
Remove Hyper-V driver code from darwin and linux targets
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose committed Jun 3, 2021
1 parent b1b4a03 commit cfa8082
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 51 deletions.
File renamed without changes.
File renamed without changes.
51 changes: 0 additions & 51 deletions pkg/libmachine/libmachine.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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()
}
37 changes: 37 additions & 0 deletions pkg/libmachine/load_unix.go
Original file line number Diff line number Diff line change
@@ -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
}
38 changes: 38 additions & 0 deletions pkg/libmachine/load_windows.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit cfa8082

Please sign in to comment.