├── README.md ├── Makefile ├── .gitignore ├── pkg ├── hyperkit │ ├── vmnet.go │ ├── vmnet_stub.go │ ├── util.go │ ├── network.go │ └── driver.go └── drivers │ └── drivers.go ├── main.go ├── Gopkg.toml ├── Gopkg.lock └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # docker-machine-driver-hyperkit 2 | 3 | The Hyperkit driver will eventually replace the existing xhyve driver and uses [moby/hyperkit](http://github.com/moby/hyperkit) as a Go library. 4 | 5 | To install the hyperkit driver: 6 | 7 | ```shell 8 | make build 9 | ``` 10 | 11 | The hyperkit driver currently requires running as root to use the vmnet framework to setup networking. 12 | 13 | If you encountered errors like `Could not find hyperkit executable`, you might need to install [Docker for Mac](https://store.docker.com/editions/community/docker-ce-desktop-mac) 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Go and compilation related variables 2 | BUILD_DIR ?= out 3 | 4 | ORG := github.com/praveenkumar 5 | REPOPATH ?= $(ORG)/docker-machine-driver-hyperkit 6 | 7 | vendor: 8 | dep ensure -v 9 | 10 | $(BUILD_DIR): 11 | mkdir -p $(BUILD_DIR) 12 | 13 | .PHONY: clean 14 | clean: 15 | rm -rf $(BUILD_DIR) 16 | rm -rf vendor 17 | 18 | .PHONY: build 19 | build: $(BUILD_DIR) vendor 20 | go build \ 21 | -installsuffix "static" \ 22 | -o $(BUILD_DIR)/docker-machine-driver-hyperkit 23 | chmod +x $(BUILD_DIR)/docker-machine-driver-hyperkit 24 | sudo mv $(BUILD_DIR)/docker-machine-driver-hyperkit /usr/local/bin/ && sudo chown root:wheel /usr/local/bin/docker-machine-driver-hyperkit && sudo chmod u+s /usr/local/bin/docker-machine-driver-hyperkit 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | /vendor 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.test 24 | *.prof 25 | 26 | /out 27 | /_gopath 28 | /release 29 | 30 | /minishift 31 | 32 | .DS_Store 33 | 34 | /.idea 35 | /.vscode 36 | *.iml 37 | /.vscode 38 | 39 | # Docs 40 | .ruby-gemset 41 | .ruby-version 42 | docs/build 43 | docs/source/_tmp/*.md 44 | docs/source/command-ref/*.adoc 45 | docs/source/**/variables.adoc 46 | docs/source/using/images/minishift-architecture* 47 | docs/.bundle/ 48 | docs/.sass-cache/ 49 | docs/.java 50 | -------------------------------------------------------------------------------- /pkg/hyperkit/vmnet.go: -------------------------------------------------------------------------------- 1 | // +build darwin,cgo 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors All rights reserved. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package hyperkit 20 | 21 | import ( 22 | vmnet "github.com/zchee/go-vmnet" 23 | ) 24 | 25 | func GetMACAddressFromUUID(UUID string) (string, error) { 26 | return vmnet.GetMACAddressFromUUID(UUID) 27 | } 28 | -------------------------------------------------------------------------------- /pkg/hyperkit/vmnet_stub.go: -------------------------------------------------------------------------------- 1 | // +build darwin,!cgo 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors All rights reserved. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package hyperkit 20 | 21 | import ( 22 | "errors" 23 | ) 24 | 25 | func GetMACAddressFromUUID(UUID string) (string, error) { 26 | return "", errors.New("Function not supported on CGO_ENABLED=0 binaries") 27 | } 28 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // +build darwin 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors All rights reserved. 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package main 17 | 18 | import ( 19 | "github.com/docker/machine/libmachine/drivers/plugin" 20 | "github.com/machine-drivers/docker-machine-driver-hyperkit/pkg/hyperkit" 21 | ) 22 | 23 | func main() { 24 | plugin.RegisterDriver(hyperkit.NewDriver("", "")) 25 | } 26 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | 22 | 23 | [[constraint]] 24 | name = "github.com/cloudflare/cfssl" 25 | version = "1.3.1" 26 | 27 | [[constraint]] 28 | name = "github.com/docker/machine" 29 | version = "0.14.0" 30 | 31 | [[constraint]] 32 | branch = "master" 33 | name = "github.com/johanneswuerbach/nfsexports" 34 | 35 | [[constraint]] 36 | name = "github.com/moby/hyperkit" 37 | version = "0.20171204.0" 38 | 39 | [[constraint]] 40 | name = "github.com/pkg/errors" 41 | version = "0.8.0" 42 | 43 | [[constraint]] 44 | branch = "master" 45 | name = "github.com/zchee/go-vmnet" 46 | -------------------------------------------------------------------------------- /pkg/hyperkit/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package hyperkit 18 | 19 | import ( 20 | "time" 21 | "errors" 22 | "strings" 23 | "os/exec" 24 | "os" 25 | "github.com/docker/machine/libmachine/log" 26 | "bufio" 27 | "fmt" 28 | ) 29 | 30 | type RetriableError struct { 31 | Err error 32 | } 33 | 34 | func (r RetriableError) Error() string { 35 | return "Temporary Error: " + r.Err.Error() 36 | } 37 | 38 | type MultiError struct { 39 | Errors []error 40 | } 41 | 42 | func (m *MultiError) Collect(err error) { 43 | if err != nil { 44 | m.Errors = append(m.Errors, err) 45 | } 46 | } 47 | 48 | func (m MultiError) ToError() error { 49 | if len(m.Errors) == 0 { 50 | return nil 51 | } 52 | 53 | errStrings := []string{} 54 | for _, err := range m.Errors { 55 | errStrings = append(errStrings, err.Error()) 56 | } 57 | return errors.New(strings.Join(errStrings, "\n")) 58 | } 59 | 60 | func RetryAfter(attempts int, callback func() error, d time.Duration) (err error) { 61 | m := MultiError{} 62 | for i := 0; i < attempts; i++ { 63 | err = callback() 64 | if err == nil { 65 | return nil 66 | } 67 | m.Collect(err) 68 | if _, ok := err.(*RetriableError); !ok { 69 | return m.ToError() 70 | } 71 | time.Sleep(d) 72 | } 73 | return m.ToError() 74 | } 75 | 76 | func hdiutil(args ...string) error { 77 | cmd := exec.Command("hdiutil", args...) 78 | cmd.Stdout = os.Stdout 79 | cmd.Stderr = os.Stderr 80 | 81 | log.Debugf("executing: %v %v", cmd, strings.Join(args, " ")) 82 | 83 | err := cmd.Run() 84 | if err != nil { 85 | return err 86 | } 87 | 88 | return nil 89 | } 90 | 91 | func readLine(path string) (string, error) { 92 | inFile, err := os.Open(path) 93 | if err != nil { 94 | return "", err 95 | } 96 | defer inFile.Close() 97 | 98 | scanner := bufio.NewScanner(inFile) 99 | for scanner.Scan() { 100 | if kernelOptionRegexp.Match(scanner.Bytes()) { 101 | m := kernelOptionRegexp.FindSubmatch(scanner.Bytes()) 102 | return string(m[1]), nil 103 | } 104 | } 105 | return "", fmt.Errorf("couldn't find kernel option from %s image", path) 106 | } -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | branch = "master" 6 | name = "github.com/Azure/go-ansiterm" 7 | packages = [ 8 | ".", 9 | "winterm" 10 | ] 11 | revision = "d6e3b3328b783f23731bc4d058875b0371ff8109" 12 | 13 | [[projects]] 14 | name = "github.com/cloudflare/cfssl" 15 | packages = ["log"] 16 | revision = "4e2dcbde500472449917533851bf4bae9bdff562" 17 | version = "1.3.1" 18 | 19 | [[projects]] 20 | branch = "master" 21 | name = "github.com/docker/docker" 22 | packages = [ 23 | "pkg/term", 24 | "pkg/term/windows" 25 | ] 26 | revision = "0c1006f1abc1af7aa6b9847754370d054dfa6c68" 27 | 28 | [[projects]] 29 | name = "github.com/docker/machine" 30 | packages = [ 31 | "libmachine/drivers", 32 | "libmachine/drivers/plugin", 33 | "libmachine/drivers/plugin/localbinary", 34 | "libmachine/drivers/rpc", 35 | "libmachine/log", 36 | "libmachine/mcnflag", 37 | "libmachine/mcnutils", 38 | "libmachine/ssh", 39 | "libmachine/state", 40 | "libmachine/version", 41 | "version" 42 | ] 43 | revision = "89b833253d9412716a0291cbdccc94454c33d1b5" 44 | version = "v0.14.0" 45 | 46 | [[projects]] 47 | branch = "master" 48 | name = "github.com/johanneswuerbach/nfsexports" 49 | packages = ["."] 50 | revision = "a9068f3f0daa39616953aec11c3eb1209ebc4086" 51 | 52 | [[projects]] 53 | branch = "master" 54 | name = "github.com/mitchellh/go-ps" 55 | packages = ["."] 56 | revision = "4fdf99ab29366514c69ccccddab5dc58b8d84062" 57 | 58 | [[projects]] 59 | name = "github.com/moby/hyperkit" 60 | packages = ["go"] 61 | revision = "858492e3d919f8b49a39e1944a49e1d7b4a51e6d" 62 | version = "v0.20171204" 63 | 64 | [[projects]] 65 | name = "github.com/pkg/errors" 66 | packages = ["."] 67 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d" 68 | version = "v0.8.0" 69 | 70 | [[projects]] 71 | name = "github.com/sirupsen/logrus" 72 | packages = ["."] 73 | revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc" 74 | version = "v1.0.5" 75 | 76 | [[projects]] 77 | branch = "master" 78 | name = "github.com/zchee/go-vmnet" 79 | packages = ["."] 80 | revision = "97ebf91740978f1e665defc0a960fb997ebe282b" 81 | 82 | [[projects]] 83 | branch = "master" 84 | name = "golang.org/x/crypto" 85 | packages = [ 86 | "curve25519", 87 | "ed25519", 88 | "ed25519/internal/edwards25519", 89 | "internal/chacha20", 90 | "poly1305", 91 | "ssh", 92 | "ssh/terminal" 93 | ] 94 | revision = "beaf6a35706e5032ae4c3fcf342c663c069f44d2" 95 | 96 | [[projects]] 97 | branch = "master" 98 | name = "golang.org/x/sys" 99 | packages = [ 100 | "unix", 101 | "windows" 102 | ] 103 | revision = "f6cff0780e542efa0c8e864dc8fa522808f6a598" 104 | 105 | [solve-meta] 106 | analyzer-name = "dep" 107 | analyzer-version = 1 108 | inputs-digest = "dc265a7d3de9de2acfed85aa65c5a6c4c2dc1232f25c5f3797ac9f43e388f3e2" 109 | solver-name = "gps-cdcl" 110 | solver-version = 1 111 | -------------------------------------------------------------------------------- /pkg/hyperkit/network.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package hyperkit 18 | 19 | import ( 20 | "bufio" 21 | "fmt" 22 | "io" 23 | "net" 24 | "os" 25 | "os/exec" 26 | "regexp" 27 | "strings" 28 | ) 29 | 30 | const ( 31 | DHCPLeasesFile = "/var/db/dhcpd_leases" 32 | CONFIG_PLIST = "/Library/Preferences/SystemConfiguration/com.apple.vmnet" 33 | NET_ADDR_KEY = "Shared_Net_Address" 34 | ) 35 | 36 | type DHCPEntry struct { 37 | Name string 38 | IPAddress string 39 | HWAddress string 40 | ID string 41 | Lease string 42 | } 43 | 44 | func GetIPAddressByMACAddress(mac string) (string, error) { 45 | return getIpAddressFromFile(mac, DHCPLeasesFile) 46 | } 47 | 48 | func getIpAddressFromFile(mac, path string) (string, error) { 49 | file, err := os.Open(path) 50 | if err != nil { 51 | return "", err 52 | } 53 | defer file.Close() 54 | 55 | dhcpEntries, err := parseDHCPdLeasesFile(file) 56 | if err != nil { 57 | return "", err 58 | } 59 | for _, dhcpEntry := range dhcpEntries { 60 | if dhcpEntry.HWAddress == mac { 61 | return dhcpEntry.IPAddress, nil 62 | } 63 | } 64 | return "", fmt.Errorf("Could not find an IP address for %s", mac) 65 | } 66 | 67 | func parseDHCPdLeasesFile(file io.Reader) ([]DHCPEntry, error) { 68 | var ( 69 | dhcpEntry *DHCPEntry 70 | dhcpEntries []DHCPEntry 71 | ) 72 | 73 | scanner := bufio.NewScanner(file) 74 | for scanner.Scan() { 75 | line := strings.TrimSpace(scanner.Text()) 76 | if line == "{" { 77 | dhcpEntry = new(DHCPEntry) 78 | continue 79 | } else if line == "}" { 80 | dhcpEntries = append(dhcpEntries, *dhcpEntry) 81 | continue 82 | } 83 | 84 | split := strings.SplitN(line, "=", 2) 85 | if len(split) != 2 { 86 | return nil, fmt.Errorf("invalid line in dhcp leases file: %s", line) 87 | } 88 | key, val := split[0], split[1] 89 | switch key { 90 | case "name": 91 | dhcpEntry.Name = val 92 | case "ip_address": 93 | dhcpEntry.IPAddress = val 94 | case "hw_address": 95 | // The mac addresses have a '1,' at the start. 96 | dhcpEntry.HWAddress = val[2:] 97 | case "identifier": 98 | dhcpEntry.ID = val 99 | case "lease": 100 | dhcpEntry.Lease = val 101 | default: 102 | return dhcpEntries, fmt.Errorf("Unable to parse line: %s", line) 103 | } 104 | } 105 | return dhcpEntries, scanner.Err() 106 | } 107 | 108 | // trimMacAddress trimming "0" of the ten's digit 109 | func trimMacAddress(rawUUID string) string { 110 | re := regexp.MustCompile(`0([A-Fa-f0-9](:|$))`) 111 | mac := re.ReplaceAllString(rawUUID, "$1") 112 | 113 | return mac 114 | } 115 | 116 | func GetNetAddr() (net.IP, error) { 117 | _, err := os.Stat(CONFIG_PLIST + ".plist") 118 | if err != nil { 119 | return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist") 120 | } 121 | 122 | out, err := exec.Command("defaults", "read", CONFIG_PLIST, NET_ADDR_KEY).Output() 123 | if err != nil { 124 | return nil, err 125 | } 126 | ip := net.ParseIP(strings.TrimSpace(string(out))) 127 | if ip == nil { 128 | return nil, fmt.Errorf("Could not get the network address for vmnet") 129 | } 130 | return ip, nil 131 | } 132 | -------------------------------------------------------------------------------- /pkg/drivers/drivers.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package drivers 18 | 19 | import ( 20 | "io/ioutil" 21 | "os" 22 | "path/filepath" 23 | "syscall" 24 | 25 | "github.com/cloudflare/cfssl/log" 26 | "github.com/docker/machine/libmachine/drivers" 27 | "github.com/docker/machine/libmachine/mcnflag" 28 | "github.com/docker/machine/libmachine/mcnutils" 29 | "github.com/docker/machine/libmachine/ssh" 30 | "github.com/pkg/errors" 31 | ) 32 | 33 | func GetDiskPath(d *drivers.BaseDriver) string { 34 | return filepath.Join(d.ResolveStorePath("."), d.GetMachineName()+".rawdisk") 35 | } 36 | 37 | type CommonDriver struct{} 38 | 39 | //Not implemented yet 40 | func (d *CommonDriver) GetCreateFlags() []mcnflag.Flag { 41 | return nil 42 | } 43 | 44 | //Not implemented yet 45 | func (d *CommonDriver) SetConfigFromFlags(flags drivers.DriverOptions) error { 46 | return nil 47 | } 48 | 49 | func createRawDiskImage(sshKeyPath, diskPath string, diskSizeMb int) error { 50 | tarBuf, err := mcnutils.MakeDiskImage(sshKeyPath) 51 | if err != nil { 52 | return err 53 | } 54 | 55 | file, err := os.OpenFile(diskPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) 56 | if err != nil { 57 | return err 58 | } 59 | defer file.Close() 60 | file.Seek(0, os.SEEK_SET) 61 | 62 | if _, err := file.Write(tarBuf.Bytes()); err != nil { 63 | return err 64 | } 65 | if err := file.Close(); err != nil { 66 | return errors.Wrapf(err, "closing file %s", diskPath) 67 | } 68 | 69 | if err := os.Truncate(diskPath, int64(diskSizeMb*1000000)); err != nil { 70 | return err 71 | } 72 | return nil 73 | } 74 | 75 | func publicSSHKeyPath(d *drivers.BaseDriver) string { 76 | return d.GetSSHKeyPath() + ".pub" 77 | } 78 | 79 | // Restart a host. This may just call Stop(); Start() if the provider does not 80 | // have any special restart behaviour. 81 | func Restart(d drivers.Driver) error { 82 | for _, f := range []func() error{d.Stop, d.Start} { 83 | if err := f(); err != nil { 84 | return err 85 | } 86 | } 87 | return nil 88 | } 89 | 90 | func MakeDiskImage(d *drivers.BaseDriver, boot2dockerURL string, diskSize int) error { 91 | //TODO(r2d4): rewrite this, not using b2dutils 92 | b2dutils := mcnutils.NewB2dUtils(d.StorePath) 93 | if err := b2dutils.CopyIsoToMachineDir(boot2dockerURL, d.MachineName); err != nil { 94 | return errors.Wrap(err, "Error copying ISO to machine dir") 95 | } 96 | 97 | log.Info("Creating ssh key...") 98 | if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { 99 | return err 100 | } 101 | 102 | log.Info("Creating raw disk image...") 103 | diskPath := GetDiskPath(d) 104 | if _, err := os.Stat(diskPath); os.IsNotExist(err) { 105 | if err := createRawDiskImage(publicSSHKeyPath(d), diskPath, diskSize); err != nil { 106 | return err 107 | } 108 | if err := fixPermissions(d.ResolveStorePath(".")); err != nil { 109 | return err 110 | } 111 | } 112 | return nil 113 | } 114 | 115 | func fixPermissions(path string) error { 116 | os.Chown(path, syscall.Getuid(), syscall.Getegid()) 117 | files, _ := ioutil.ReadDir(path) 118 | for _, f := range files { 119 | fp := filepath.Join(path, f.Name()) 120 | if err := os.Chown(fp, syscall.Getuid(), syscall.Getegid()); err != nil { 121 | return err 122 | } 123 | } 124 | return nil 125 | } 126 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /pkg/hyperkit/driver.go: -------------------------------------------------------------------------------- 1 | // +build darwin 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors All rights reserved. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package hyperkit 20 | 21 | import ( 22 | "encoding/json" 23 | "fmt" 24 | "os" 25 | "os/user" 26 | "path" 27 | "path/filepath" 28 | "strings" 29 | "syscall" 30 | "time" 31 | 32 | "github.com/docker/machine/libmachine/drivers" 33 | "github.com/docker/machine/libmachine/log" 34 | "github.com/docker/machine/libmachine/state" 35 | nfsexports "github.com/johanneswuerbach/nfsexports" 36 | hyperkit "github.com/moby/hyperkit/go" 37 | "github.com/pkg/errors" 38 | pkgdrivers "github.com/machine-drivers/docker-machine-driver-hyperkit/pkg/drivers" 39 | "regexp" 40 | "github.com/docker/machine/libmachine/mcnutils" 41 | ) 42 | 43 | const ( 44 | isoFilename = "boot2docker.iso" 45 | isoMountPath = "b2d-image" 46 | pidFileName = "hyperkit.pid" 47 | machineFileName = "hyperkit.json" 48 | permErr = "%s needs to run with elevated permissions. " + 49 | "Please run the following command, then try again: " + 50 | "sudo chown root:wheel %s && sudo chmod u+s %s" 51 | ) 52 | 53 | var ( 54 | kernelRegexp = regexp.MustCompile(`(vmlinu[xz]|bzImage)[\d]*`) 55 | kernelOptionRegexp = regexp.MustCompile(`(?:\t|\s{2})append\s+([[:print:]]+)`) 56 | ) 57 | 58 | type Driver struct { 59 | *drivers.BaseDriver 60 | *pkgdrivers.CommonDriver 61 | Boot2DockerURL string 62 | DiskSize int 63 | CPU int 64 | Memory int 65 | Cmdline string 66 | NFSShares []string 67 | NFSSharesRoot string 68 | UUID string 69 | BootKernel string 70 | BootInitrd string 71 | Initrd string 72 | Vmlinuz string 73 | } 74 | 75 | func NewDriver(hostName, storePath string) *Driver { 76 | return &Driver{ 77 | BaseDriver: &drivers.BaseDriver{ 78 | SSHUser: "docker", 79 | }, 80 | CommonDriver: &pkgdrivers.CommonDriver{}, 81 | } 82 | } 83 | 84 | // PreCreateCheck is called to enforce pre-creation steps 85 | func (d *Driver) PreCreateCheck() error { 86 | exe, err := os.Executable() 87 | if err != nil { 88 | return err 89 | } 90 | 91 | if syscall.Geteuid() != 0 { 92 | return fmt.Errorf(permErr, filepath.Base(exe), exe, exe) 93 | } 94 | 95 | return nil 96 | } 97 | 98 | func (d *Driver) Create() error { 99 | // TODO: handle different disk types. 100 | if err := pkgdrivers.MakeDiskImage(d.BaseDriver, d.Boot2DockerURL, d.DiskSize); err != nil { 101 | return errors.Wrap(err, "making disk image") 102 | } 103 | 104 | isoPath := d.ResolveStorePath(isoFilename) 105 | if err := d.extractKernel(isoPath); err != nil { 106 | return err 107 | } 108 | 109 | return d.Start() 110 | } 111 | 112 | // DriverName returns the name of the driver 113 | func (d *Driver) DriverName() string { 114 | return "hyperkit" 115 | } 116 | 117 | // GetSSHHostname returns hostname for use with ssh 118 | func (d *Driver) GetSSHHostname() (string, error) { 119 | return d.IPAddress, nil 120 | } 121 | 122 | // GetURL returns a Docker compatible host URL for connecting to this host 123 | // e.g. tcp://1.2.3.4:2376 124 | func (d *Driver) GetURL() (string, error) { 125 | ip, err := d.GetIP() 126 | if err != nil { 127 | return "", err 128 | } 129 | return fmt.Sprintf("tcp://%s:2376", ip), nil 130 | } 131 | 132 | // GetState returns the state that the host is in (running, stopped, etc) 133 | func (d *Driver) GetState() (state.State, error) { 134 | pid := d.getPid() 135 | if pid == 0 { 136 | return state.Stopped, nil 137 | } 138 | p, err := os.FindProcess(pid) 139 | if err != nil { 140 | return state.Error, err 141 | } 142 | 143 | // Sending a signal of 0 can be used to check the existence of a process. 144 | if err := p.Signal(syscall.Signal(0)); err != nil { 145 | return state.Stopped, nil 146 | } 147 | if p == nil { 148 | return state.Stopped, nil 149 | } 150 | return state.Running, nil 151 | } 152 | 153 | // Kill stops a host forcefully 154 | func (d *Driver) Kill() error { 155 | return d.sendSignal(syscall.SIGKILL) 156 | } 157 | 158 | // Remove a host 159 | func (d *Driver) Remove() error { 160 | s, err := d.GetState() 161 | if err != nil || s == state.Error { 162 | log.Infof("Error checking machine status: %s, assuming it has been removed already", err) 163 | } 164 | if s == state.Running { 165 | if err := d.Stop(); err != nil { 166 | return err 167 | } 168 | } 169 | return nil 170 | } 171 | 172 | func (d *Driver) Restart() error { 173 | return pkgdrivers.Restart(d) 174 | } 175 | 176 | // Start a host 177 | func (d *Driver) Start() error { 178 | h, err := hyperkit.New("", "", filepath.Join(d.StorePath, "machines", d.MachineName)) 179 | if err != nil { 180 | return err 181 | } 182 | 183 | // TODO: handle the rest of our settings. 184 | h.Kernel = d.ResolveStorePath(d.Vmlinuz) 185 | h.Initrd =d.ResolveStorePath(d.Initrd) 186 | h.VMNet = true 187 | h.ISOImages = []string{d.ResolveStorePath(isoFilename)} 188 | h.Console = hyperkit.ConsoleFile 189 | h.CPUs = d.CPU 190 | h.Memory = d.Memory 191 | h.UUID = d.UUID 192 | 193 | log.Infof("Using UUID %s", h.UUID) 194 | mac, err := GetMACAddressFromUUID(h.UUID) 195 | if err != nil { 196 | return err 197 | } 198 | 199 | // Need to strip 0's 200 | mac = trimMacAddress(mac) 201 | log.Infof("Generated MAC %s", mac) 202 | h.Disks = []hyperkit.DiskConfig{ 203 | { 204 | Path: pkgdrivers.GetDiskPath(d.BaseDriver), 205 | Size: d.DiskSize, 206 | Driver: "virtio-blk", 207 | }, 208 | } 209 | log.Infof("Starting with cmdline: %s", d.Cmdline) 210 | if err := h.Start(d.Cmdline); err != nil { 211 | return err 212 | } 213 | 214 | getIP := func() error { 215 | var err error 216 | d.IPAddress, err = GetIPAddressByMACAddress(mac) 217 | if err != nil { 218 | return &RetriableError{Err: err} 219 | } 220 | return nil 221 | } 222 | 223 | if err := RetryAfter(30, getIP, 2*time.Second); err != nil { 224 | return fmt.Errorf("IP address never found in dhcp leases file %v", err) 225 | } 226 | 227 | if len(d.NFSShares) > 0 { 228 | log.Info("Setting up NFS mounts") 229 | 230 | // takes some time here for ssh / nfsd to work properly 231 | err = d.waitForIP() 232 | if err != nil { 233 | log.Errorf("Failed to get IP address for VM: %s", err.Error()) 234 | return err 235 | } 236 | 237 | err = d.setupNFSShare() 238 | if err != nil { 239 | log.Errorf("NFS setup failed: %s", err.Error()) 240 | return err 241 | } 242 | } 243 | 244 | return nil 245 | } 246 | 247 | // Stop a host gracefully 248 | func (d *Driver) Stop() error { 249 | d.cleanupNfsExports() 250 | return d.sendSignal(syscall.SIGTERM) 251 | } 252 | 253 | func (d *Driver) extractKernel(isoPath string) error { 254 | log.Debugf("Mounting %s", isoFilename) 255 | 256 | volumeRootDir := d.ResolveStorePath(isoMountPath) 257 | err := hdiutil("attach", d.ResolveStorePath(isoFilename), "-mountpoint", volumeRootDir) 258 | if err != nil { 259 | return err 260 | } 261 | defer func() error { 262 | log.Debugf("Unmounting %s", isoFilename) 263 | return hdiutil("detach", volumeRootDir) 264 | }() 265 | 266 | log.Debugf("Extracting Kernel Options...") 267 | if err := d.extractKernelOptions(); err != nil { 268 | return err 269 | } 270 | 271 | if d.BootKernel == "" && d.BootInitrd == "" { 272 | filepath.Walk(volumeRootDir, func(path string, f os.FileInfo, err error) error { 273 | if kernelRegexp.MatchString(path) { 274 | d.BootKernel = path 275 | _, d.Vmlinuz = filepath.Split(path) 276 | } 277 | if strings.Contains(path, "initrd") { 278 | d.BootInitrd = path 279 | _, d.Initrd = filepath.Split(path) 280 | } 281 | return nil 282 | }) 283 | } 284 | 285 | if d.BootKernel == "" || d.BootInitrd == "" { 286 | err := fmt.Errorf("==== Can't extract Kernel and Ramdisk file ====") 287 | return err 288 | } 289 | 290 | dest := d.ResolveStorePath(d.Vmlinuz) 291 | log.Debugf("Extracting %s into %s", d.BootKernel, dest) 292 | if err := mcnutils.CopyFile(d.BootKernel, dest); err != nil { 293 | return err 294 | } 295 | 296 | dest = d.ResolveStorePath(d.Initrd) 297 | log.Debugf("Extracting %s into %s", d.BootInitrd, dest) 298 | if err := mcnutils.CopyFile(d.BootInitrd, dest); err != nil { 299 | return err 300 | } 301 | 302 | return nil 303 | } 304 | 305 | func (d *Driver) setupNFSShare() error { 306 | user, err := user.Current() 307 | if err != nil { 308 | return err 309 | } 310 | 311 | hostIP, err := GetNetAddr() 312 | if err != nil { 313 | return err 314 | } 315 | 316 | mountCommands := fmt.Sprintf("#/bin/bash\\n") 317 | log.Info(d.IPAddress) 318 | 319 | for _, share := range d.NFSShares { 320 | if !path.IsAbs(share) { 321 | share = d.ResolveStorePath(share) 322 | } 323 | nfsConfig := fmt.Sprintf("%s %s -alldirs -mapall=%s", share, d.IPAddress, user.Username) 324 | 325 | if _, err := nfsexports.Add("", d.nfsExportIdentifier(share), nfsConfig); err != nil { 326 | if strings.Contains(err.Error(), "conflicts with existing export") { 327 | log.Info("Conflicting NFS Share not setup and ignored:", err) 328 | continue 329 | } 330 | return err 331 | } 332 | 333 | root := d.NFSSharesRoot 334 | mountCommands += fmt.Sprintf("sudo mkdir -p %s/%s\\n", root, share) 335 | mountCommands += fmt.Sprintf("sudo mount -t nfs -o noacl,async %s:%s %s/%s\\n", hostIP, share, root, share) 336 | } 337 | 338 | if err := nfsexports.ReloadDaemon(); err != nil { 339 | return err 340 | } 341 | 342 | writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sh", mountCommands) 343 | 344 | if _, err := drivers.RunSSHCommandFromDriver(d, writeScriptCmd); err != nil { 345 | return err 346 | } 347 | 348 | return nil 349 | } 350 | 351 | func (d *Driver) nfsExportIdentifier(path string) string { 352 | return fmt.Sprintf("minikube-hyperkit %s-%s", d.MachineName, path) 353 | } 354 | 355 | func (d *Driver) sendSignal(s os.Signal) error { 356 | pid := d.getPid() 357 | proc, err := os.FindProcess(pid) 358 | if err != nil { 359 | return err 360 | } 361 | 362 | return proc.Signal(s) 363 | } 364 | 365 | func (d *Driver) getPid() int { 366 | pidPath := d.ResolveStorePath(machineFileName) 367 | 368 | f, err := os.Open(pidPath) 369 | if err != nil { 370 | log.Warnf("Error reading pid file: %s", err) 371 | return 0 372 | } 373 | dec := json.NewDecoder(f) 374 | config := hyperkit.HyperKit{} 375 | if err := dec.Decode(&config); err != nil { 376 | log.Warnf("Error decoding pid file: %s", err) 377 | return 0 378 | } 379 | 380 | return config.Pid 381 | } 382 | 383 | func (d *Driver) cleanupNfsExports() { 384 | if len(d.NFSShares) > 0 { 385 | log.Infof("You must be root to remove NFS shared folders. Please type root password.") 386 | for _, share := range d.NFSShares { 387 | if _, err := nfsexports.Remove("", d.nfsExportIdentifier(share)); err != nil { 388 | log.Errorf("failed removing nfs share (%s): %s", share, err.Error()) 389 | } 390 | } 391 | 392 | if err := nfsexports.ReloadDaemon(); err != nil { 393 | log.Errorf("failed to reload the nfs daemon: %s", err.Error()) 394 | } 395 | } 396 | } 397 | 398 | func (d *Driver) extractKernelOptions() error { 399 | volumeRootDir := d.ResolveStorePath(isoMountPath) 400 | if d.Cmdline == "" { 401 | err := filepath.Walk(volumeRootDir, func(path string, f os.FileInfo, err error) error { 402 | if strings.Contains(path, "isolinux.cfg") { 403 | d.Cmdline, err = readLine(path) 404 | if err != nil { 405 | return err 406 | } 407 | } 408 | return nil 409 | }) 410 | if err != nil { 411 | return err 412 | } 413 | 414 | if d.Cmdline == "" { 415 | return errors.New("Not able to parse isolinux.cfg") 416 | } 417 | } 418 | 419 | log.Debugf("Extracted Options %q", d.Cmdline) 420 | return nil 421 | } 422 | 423 | func (d *Driver) waitForIP() error { 424 | var ip string 425 | var err error 426 | mac, err := GetMACAddressFromUUID(d.UUID) 427 | if err != nil { 428 | return err 429 | } 430 | 431 | log.Infof("Waiting for VM to come online...") 432 | for i := 1; i <= 60; i++ { 433 | 434 | ip, err = GetIPAddressByMACAddress(mac) 435 | if err != nil { 436 | log.Debugf("Not there yet %d/%d, error: %s", i, 60, err) 437 | time.Sleep(2 * time.Second) 438 | continue 439 | } 440 | 441 | if ip != "" { 442 | log.Debugf("Got an ip: %s", ip) 443 | d.IPAddress = ip 444 | 445 | break 446 | } 447 | } 448 | 449 | if ip == "" { 450 | return fmt.Errorf("Machine didn't return an IP after 120 seconds, aborting") 451 | } 452 | 453 | // Wait for SSH over NAT to be available before returning to user 454 | if err := drivers.WaitForSSH(d); err != nil { 455 | return err 456 | } 457 | 458 | return nil 459 | } 460 | --------------------------------------------------------------------------------