Skip to content

Commit

Permalink
Merge pull request machine-drivers#20 from cfergeau/bundlename
Browse files Browse the repository at this point in the history
Issue machine-drivers#19: Add bundle name to base driver
  • Loading branch information
praveenkumar authored Aug 21, 2019
2 parents b6d974a + b6d88ae commit 34d5b60
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions drivers/errdriver/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (d *Driver) GetSSHUsername() string {
return ""
}

func (d *Driver) GetBundleName() (string, error) {
return "", NotLoadable{d.Name}
}

func (d *Driver) GetState() (state.State, error) {
return state.Error, NotLoadable{d.Name}
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type Driver struct {
*drivers.BaseDriver
CrcDiskCopier CRCDiskCopier
BundlePath string
BundleName string
VirtualSwitch string
DiskPath string
DiskPathUrl string
Expand Down Expand Up @@ -85,7 +85,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
}

func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.BundlePath = flags.String("hyperv-bundlepath-url")
d.BundleName = flags.String("hyperv-bundlepath-url")
d.VirtualSwitch = flags.String("hyperv-virtual-switch")
d.Memory = flags.Int("hyperv-memory")
d.CPU = flags.Int("hyperv-cpu-count")
Expand Down
8 changes: 3 additions & 5 deletions drivers/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
const (
defaultCPU = 4
defaultMemory = 8192
defaultBundlePath = ""
defaultBundleName = ""
defaultHostOnlyCIDR = "192.168.99.1/24"
defaultHostOnlyNictype = "82540EM"
defaultHostOnlyPromiscMode = "deny"
Expand All @@ -43,8 +43,6 @@ var (

type Driver struct {
*drivers.BaseDriver
// CRC System bundle
BundlePath string
VBoxManager
HostInterfaces
logsReader LogsReader
Expand Down Expand Up @@ -124,8 +122,8 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
mcnflag.StringFlag{
Name: "virtualbox-bundlepath-url",
Usage: "The URL of the crc bundlepath. Defaults to the latest available version",
Value: defaultBundlePath,
EnvVar: "VIRTUALBOX_BundlePath_URL",
Value: defaultBundleName,
EnvVar: "VIRTUALBOX_BundleName_URL",
},
mcnflag.BoolFlag{
Name: "virtualbox-host-dns-resolver",
Expand Down
6 changes: 6 additions & 0 deletions libmachine/drivers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type BaseDriver struct {
SSHPort int
SSHKeyPath string
StorePath string
BundleName string
}

// DriverName returns the name of the driver
Expand Down Expand Up @@ -79,3 +80,8 @@ func (d *BaseDriver) PreCreateCheck() error {
func (d *BaseDriver) ResolveStorePath(file string) string {
return filepath.Join(d.StorePath, "machines", d.MachineName, file)
}

// Returns the name of the bundle which was used to create this machine
func (d* BaseDriver) GetBundleName() (string, error) {
return d.BundleName, nil
}
3 changes: 3 additions & 0 deletions libmachine/drivers/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Driver interface {
// GetSSHUsername returns username for use with ssh
GetSSHUsername() string

// GetBundleName() Returns the name of the unpacked bundle which was used to create this machine
GetBundleName() (string, error)

// GetURL returns a Docker compatible host URL for connecting to this host
// e.g. tcp://1.2.3.4:2376
GetURL() (string, error)
Expand Down
5 changes: 5 additions & 0 deletions libmachine/drivers/rpc/client_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
GetSSHKeyPathMethod = `.GetSSHKeyPath`
GetSSHPortMethod = `.GetSSHPort`
GetSSHUsernameMethod = `.GetSSHUsername`
GetBundleNameMethod = `.GetBundleName`
GetStateMethod = `.GetState`
PreCreateCheckMethod = `.PreCreateCheck`
CreateMethod = `.Create`
Expand Down Expand Up @@ -334,6 +335,10 @@ func (c *RPCClientDriver) GetSSHUsername() string {
return username
}

func (c *RPCClientDriver) GetBundleName() (string, error) {
return c.rpcStringCall(GetBundleNameMethod)
}

func (c *RPCClientDriver) GetState() (state.State, error) {
var s state.State

Expand Down
6 changes: 6 additions & 0 deletions libmachine/drivers/rpc/server_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ func (r *RPCServerDriver) GetSSHUsername(_ *struct{}, reply *string) error {
return nil
}

func (r *RPCServerDriver) GetBundleName(_ *struct{}, reply *string) error {
path, err := r.ActualDriver.GetBundleName()
*reply = path
return err
}

func (r *RPCServerDriver) GetURL(_ *struct{}, reply *string) error {
info, err := r.ActualDriver.GetURL()
*reply = info
Expand Down

0 comments on commit 34d5b60

Please sign in to comment.