Skip to content

Commit 31867e8

Browse files
gbraadanjannath
authored andcommitted
Issue #148 Add Hyper-V machine support
1 parent ae56b75 commit 31867e8

File tree

13 files changed

+617
-35
lines changed

13 files changed

+617
-35
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/cavaliercoder/grab v2.0.0+incompatible
88
github.com/code-ready/clicumber v0.0.0-20190503113956-2563aed4ef12
99
github.com/code-ready/goodhosts v0.0.0-20190712111040-f090f3f77c26
10-
github.com/code-ready/machine v0.0.0-20190717101121-b310e5ddb702
10+
github.com/code-ready/machine v0.0.0-20190731093717-b6d974ad44d0
1111
github.com/docker/go-units v0.4.0
1212
github.com/inconshreveable/mousetrap v1.0.0 // indirect
1313
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ github.com/code-ready/machine v0.0.0-20190717092700-c8790c03edf3 h1:wOj0jnpe0p2o
2121
github.com/code-ready/machine v0.0.0-20190717092700-c8790c03edf3/go.mod h1:2Kr23hBx5xUHetynE+4hFBwn7Xkx5qoF0SY1FzmLz74=
2222
github.com/code-ready/machine v0.0.0-20190717101121-b310e5ddb702 h1:DLrbSIhvNYRmX3JNjWWlorz83Z+HvcVY4JYpqBu1hu4=
2323
github.com/code-ready/machine v0.0.0-20190717101121-b310e5ddb702/go.mod h1:2Kr23hBx5xUHetynE+4hFBwn7Xkx5qoF0SY1FzmLz74=
24+
github.com/code-ready/machine v0.0.0-20190723085830-e8c8edb7c88d h1:tUtGbx3gDEkGW3GEWku5qlFXHezQ6DZ+hS1JvQCTIMk=
25+
github.com/code-ready/machine v0.0.0-20190723085830-e8c8edb7c88d/go.mod h1:2Kr23hBx5xUHetynE+4hFBwn7Xkx5qoF0SY1FzmLz74=
26+
github.com/code-ready/machine v0.0.0-20190731093717-b6d974ad44d0 h1:036aGx7BK4a7FtdBUprV64az1cY2cQC4PrhMU63Wzxs=
27+
github.com/code-ready/machine v0.0.0-20190731093717-b6d974ad44d0/go.mod h1:2Kr23hBx5xUHetynE+4hFBwn7Xkx5qoF0SY1FzmLz74=
2428
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
2529
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
2630
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=

pkg/crc/machine/client/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66

77
"github.com/code-ready/crc/pkg/crc/errors"
8+
"github.com/code-ready/machine/drivers/hyperv"
89
"github.com/code-ready/machine/drivers/virtualbox"
910
"github.com/code-ready/machine/libmachine/drivers/plugin"
1011
"github.com/code-ready/machine/libmachine/drivers/plugin/localbinary"
@@ -17,8 +18,10 @@ func StartDriver() {
1718
switch driverName {
1819
case "virtualbox":
1920
plugin.RegisterDriver(virtualbox.NewDriver("", ""))
21+
case "hyperv":
22+
plugin.RegisterDriver(hyperv.NewDriver("", ""))
2023
default:
21-
errors.ExitWithMessage(1, fmt.Sprintf("Unsupported driver: %s\n", driverName))
24+
errors.ExitWithMessage(1, fmt.Sprintf("Unregistered driver: %s\n", driverName))
2225
}
2326
return
2427
}

pkg/crc/machine/driver.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package machine
22

33
import (
44
"github.com/code-ready/crc/pkg/crc/errors"
5+
"github.com/code-ready/crc/pkg/crc/machine/config"
6+
"github.com/code-ready/crc/pkg/crc/machine/hyperkit"
7+
"github.com/code-ready/crc/pkg/crc/machine/hyperv"
8+
"github.com/code-ready/crc/pkg/crc/machine/libvirt"
9+
"github.com/code-ready/crc/pkg/crc/machine/virtualbox"
510
crcos "github.com/code-ready/crc/pkg/os"
611
)
712

@@ -34,3 +39,25 @@ func getDriverInfo(driver string) (*MachineDriver, error) {
3439
}
3540
return nil, errors.Newf("No info about unknown driver: %s", driver)
3641
}
42+
43+
func getDriverOptions(machineConfig config.MachineConfig) interface{} {
44+
var driver interface{}
45+
46+
// Supported drivers
47+
switch machineConfig.VMDriver {
48+
49+
case "libvirt":
50+
driver = libvirt.CreateHost(machineConfig)
51+
case "virtualbox":
52+
driver = virtualbox.CreateHost(machineConfig)
53+
case "hyperkit":
54+
driver = hyperkit.CreateHost(machineConfig)
55+
case "hyperv":
56+
driver = hyperv.CreateHost(machineConfig)
57+
58+
default:
59+
errors.ExitWithMessage(1, "Unsupported driver: %s", machineConfig.VMDriver)
60+
}
61+
62+
return driver
63+
}

pkg/crc/machine/hyperv/driver.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package hyperv
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/code-ready/crc/pkg/crc/constants"
7+
"github.com/code-ready/machine/drivers/hyperv"
8+
9+
"github.com/code-ready/crc/pkg/crc/machine/config"
10+
)
11+
12+
func CreateHost(machineConfig config.MachineConfig) *hyperv.Driver {
13+
hypervDriver := hyperv.NewDriver(machineConfig.Name, constants.MachineBaseDir)
14+
15+
hypervDriver.CPU = machineConfig.CPUs
16+
hypervDriver.BundlePath = machineConfig.BundlePath
17+
hypervDriver.Memory = machineConfig.Memory
18+
19+
// TODO: VirtualSwitch name is supposed to be localized or by ID
20+
hypervDriver.VirtualSwitch = "Default Switch"
21+
22+
// DiskPath should come from the bundle's metadata (unflattened)
23+
// This force to add entry of DiskPath under crc machine config.json
24+
hypervDriver.DiskPath = filepath.Join(constants.MachineBaseDir, "machines", machineConfig.Name, "crc.vhdx")
25+
// The DiskPathURL will contain the cache path of where the image is located (not the actual image location)
26+
hypervDriver.DiskPathUrl = machineConfig.DiskPathURL
27+
hypervDriver.SSHKeyPath = machineConfig.SSHKeyPath
28+
29+
return hypervDriver
30+
}

pkg/crc/machine/machine.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package machine
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/code-ready/crc/pkg/crc/pullsecret"
76
"io/ioutil"
87
"path/filepath"
8+
"strings"
99
"time"
1010

11+
"github.com/code-ready/crc/pkg/crc/pullsecret"
12+
1113
"github.com/code-ready/crc/pkg/crc/constants"
1214
"github.com/code-ready/crc/pkg/crc/errors"
1315
"github.com/code-ready/crc/pkg/crc/logging"
@@ -24,9 +26,6 @@ import (
2426
// machine related imports
2527
"github.com/code-ready/crc/pkg/crc/machine/bundle"
2628
"github.com/code-ready/crc/pkg/crc/machine/config"
27-
"github.com/code-ready/crc/pkg/crc/machine/hyperkit"
28-
"github.com/code-ready/crc/pkg/crc/machine/libvirt"
29-
"github.com/code-ready/crc/pkg/crc/machine/virtualbox"
3029

3130
"github.com/code-ready/machine/libmachine"
3231
"github.com/code-ready/machine/libmachine/drivers"
@@ -69,7 +68,9 @@ func Start(startConfig StartConfig) (StartResult, error) {
6968

7069
// Retrieve metadata info
7170
diskPath := filepath.Join(extractedPath, crcBundleMetadata.Storage.DiskImages[0].Name)
72-
machineConfig.DiskPathURL = fmt.Sprintf("file://%s", diskPath)
71+
// TODO: QnD Windows workaround hack
72+
machineConfig.DiskPathURL = fmt.Sprintf("file://%s", strings.Replace(diskPath, "\\", "/", -1))
73+
7374
machineConfig.SSHKeyPath = filepath.Join(extractedPath, crcBundleMetadata.ClusterInfo.SSHPrivateKeyFile)
7475
machineConfig.KernelCmdLine = crcBundleMetadata.Nodes[0].KernelCmdLine
7576
machineConfig.Initramfs = filepath.Join(extractedPath, crcBundleMetadata.Nodes[0].Initramfs)
@@ -464,26 +465,6 @@ func createHost(api libmachine.API, driverPath string, machineConfig config.Mach
464465
return vm, nil
465466
}
466467

467-
func getDriverOptions(machineConfig config.MachineConfig) interface{} {
468-
var driver interface{}
469-
470-
// Supported drivers
471-
switch machineConfig.VMDriver {
472-
473-
case "libvirt":
474-
driver = libvirt.CreateHost(machineConfig)
475-
case "virtualbox":
476-
driver = virtualbox.CreateHost(machineConfig)
477-
case "hyperkit":
478-
driver = hyperkit.CreateHost(machineConfig)
479-
480-
default:
481-
errors.ExitWithMessage(1, "Unsupported driver: %s", machineConfig.VMDriver)
482-
}
483-
484-
return driver
485-
}
486-
487468
func setMachineLogging(logs bool) error {
488469
if !logs {
489470
log.SetDebug(true)

pkg/crc/machine/virtualbox/driver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package virtualbox
22

33
import (
4+
"path/filepath"
5+
46
"github.com/code-ready/crc/pkg/crc/constants"
57
"github.com/code-ready/machine/drivers/virtualbox"
6-
"path/filepath"
78

89
"github.com/code-ready/crc/pkg/crc/machine/config"
910
)

0 commit comments

Comments
 (0)