Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions commands/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (m *Machine) Create(driver string, cpuCount string, memSize string, diskSiz
}

// CheckXhyveRequirements verifies that the correct xhyve environment exists
func (m Machine) CheckXhyveRequirements() error {
func (m *Machine) CheckXhyveRequirements() error {
// Is xhyve installed locally
if err := util.Command("which", "xhyve").Run(); err != nil {
return fmt.Errorf("xhyve is not installed. Install it with 'brew install xhyve'")
Expand All @@ -92,7 +92,7 @@ func (m Machine) CheckXhyveRequirements() error {
}

// Start boots the Docker Machine
func (m Machine) Start() error {
func (m *Machine) Start() error {
if !m.IsRunning() {
m.out.Channel.Verbose.Printf("The machine '%s' is not running, starting...", m.Name)

Expand All @@ -107,20 +107,20 @@ func (m Machine) Start() error {
}

// Stop halts the Docker Machine
func (m Machine) Stop() error {
func (m *Machine) Stop() error {
if m.IsRunning() {
return util.StreamCommand("docker-machine", "stop", m.Name)
}
return nil
}

// Remove deleted the Docker Machine
func (m Machine) Remove() error {
func (m *Machine) Remove() error {
return util.StreamCommand("docker-machine", "rm", "-y", m.Name)
}

// WaitForDev will wait a period of time for communication with the docker daemon to be established
func (m Machine) WaitForDev() error {
func (m *Machine) WaitForDev() error {
maxTries := 10
sleepSecs := 3

Expand All @@ -138,7 +138,7 @@ func (m Machine) WaitForDev() error {
}

// SetEnv will set the Docker proxy variables that determine which machine the docker command communicates
func (m Machine) SetEnv() {
func (m *Machine) SetEnv() {
if js := m.GetData(); js != nil {
tlsVerify := 0
if js.Get("HostOptions").Get("EngineOptions").Get("TlsVerify").MustBool() {
Expand All @@ -152,23 +152,23 @@ func (m Machine) SetEnv() {
}

// UnsetEnv will remove the Docker proxy variables
func (m Machine) UnsetEnv() {
func (m *Machine) UnsetEnv() {
os.Unsetenv("DOCKER_TLS_VERIFY")
os.Unsetenv("DOCKER_HOST")
os.Unsetenv("DOCKER_CERT_PATH")
os.Unsetenv("DOCKER_MACHINE_NAME")
}

// Exists determines if the Docker Machine exist
func (m Machine) Exists() bool {
func (m *Machine) Exists() bool {
if err := util.Command("docker-machine", "status", m.Name).Run(); err != nil {
return false
}
return true
}

// IsRunning returns the Docker Machine running status
func (m Machine) IsRunning() bool {
func (m *Machine) IsRunning() bool {
if err := util.Command("docker-machine", "env", m.Name).Run(); err != nil {
return false
}
Expand All @@ -193,18 +193,18 @@ func (m *Machine) GetData() *simplejson.Json {
}

// GetIP returns the IP address for the Docker Machine
func (m Machine) GetIP() string {
func (m *Machine) GetIP() string {
return m.GetData().Get("Driver").Get("IPAddress").MustString()
}

// GetHostDNSResolver checks if the VirtualBox host DNS resolver is working. This should work okay
// for VMware or other machines without the option, too.
func (m Machine) GetHostDNSResolver() bool {
func (m *Machine) GetHostDNSResolver() bool {
return m.GetData().Get("Driver").Get("HostDNSResolver").MustBool(false)
}

// GetBridgeIP returns the Bridge IP by looking for a bip= option
func (m Machine) GetBridgeIP() string {
func (m *Machine) GetBridgeIP() string {
ip := "172.17.0.1"
r := regexp.MustCompile("bip=([0-9.]+)/[0-9+]")
var matches []string
Expand All @@ -222,7 +222,7 @@ func (m Machine) GetBridgeIP() string {
}

// GetDockerVersion returns the Version of Docker running within Docker Machine
func (m Machine) GetDockerVersion() (*version.Version, error) {
func (m *Machine) GetDockerVersion() (*version.Version, error) {
b2dOutput, err := util.Command("docker-machine", "version", m.Name).CombinedOutput()
if err != nil {
return nil, errors.New(strings.TrimSpace(string(b2dOutput)))
Expand All @@ -232,37 +232,37 @@ func (m Machine) GetDockerVersion() (*version.Version, error) {
}

// GetDriver returns the virtualization driver name
func (m Machine) GetDriver() string {
func (m *Machine) GetDriver() string {
return m.GetData().Get("DriverName").MustString()
}

// IsXhyve returns if the virt driver is xhyve
func (m Machine) IsXhyve() bool {
func (m *Machine) IsXhyve() bool {
return m.GetDriver() == util.Xhyve
}

// GetCPU returns the number of configured CPU for this Docker Machine
func (m Machine) GetCPU() int {
func (m *Machine) GetCPU() int {
return m.GetData().Get("Driver").Get("CPU").MustInt()
}

// GetMemory returns the amount of configured memory for this Docker Machine
func (m Machine) GetMemory() int {
func (m *Machine) GetMemory() int {
return m.GetData().Get("Driver").Get("Memory").MustInt()
}

// GetDisk returns the disk size in MB
func (m Machine) GetDisk() int {
func (m *Machine) GetDisk() int {
return m.GetData().Get("Driver").Get("DiskSize").MustInt()
}

// GetDiskInGB returns the disk size in GB
func (m Machine) GetDiskInGB() int {
func (m *Machine) GetDiskInGB() int {
return m.GetDisk() / 1000
}

// GetSysctl returns the configured value for the provided sysctl setting on the Docker Machine
func (m Machine) GetSysctl(setting string) (string, error) {
func (m *Machine) GetSysctl(setting string) (string, error) {
output, err := util.Command("docker-machine", "ssh", m.Name, "sudo", "sysctl", "-n", setting).CombinedOutput()
if err != nil {
return "", err
Expand All @@ -271,7 +271,7 @@ func (m Machine) GetSysctl(setting string) (string, error) {
}

// SetSysctl sets the sysctl setting on the Docker Machine
func (m Machine) SetSysctl(key string, val string) error {
func (m *Machine) SetSysctl(key string, val string) error {
cmd := fmt.Sprintf("sudo sysctl -w %s=%s", key, val)
m.out.Verbose("Modifying Docker Machine kernel settings: %s", cmd)
_, err := util.Command("docker-machine", "ssh", m.Name, cmd).CombinedOutput()
Expand Down