Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

_ "github.com/boot2docker/boot2docker-cli/dummy"
_ "github.com/boot2docker/boot2docker-cli/virtualbox"
_ "github.com/boot2docker/boot2docker-cli/vsphere"

"github.com/boot2docker/boot2docker-cli/driver"
)
Expand Down Expand Up @@ -84,7 +85,7 @@ func cmdUp() error {
fmt.Println("Waiting for VM and Docker daemon to start...")
//give the VM a little time to start, so we don't kill the Serial Pipe/Socket
time.Sleep(time.Duration(B2D.Waittime) * time.Millisecond)
natSSH := fmt.Sprintf("localhost:%d", m.GetSSHPort())
natSSH := fmt.Sprintf("%s:%d", m.GetAddr(), m.GetSSHPort())
IP := ""
for i := 1; i < B2D.Retries; i++ {
print(".")
Expand Down
1 change: 1 addition & 0 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Machine interface {
GetSerialFile() string
GetDockerPort() uint
GetSSHPort() uint
GetAddr() string
}

var (
Expand Down
5 changes: 5 additions & 0 deletions dummy/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func (m *Machine) GetName() string {
return m.Name
}

// Get machine address
func (m *Machine) GetAddr() string {
return "localhost"
}

// Get current state
func (m *Machine) GetState() driver.MachineState {
return m.State
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func getSSHCommand(m driver.Machine, args ...string) *exec.Cmd {
"-o", "LogLevel=quiet", // suppress "Warning: Permanently added '[localhost]:2022' (ECDSA) to the list of known hosts."
"-p", fmt.Sprintf("%d", m.GetSSHPort()),
"-i", B2D.SSHKey,
"docker@localhost",
fmt.Sprintf("docker@%s", m.GetAddr()),
}

sshArgs := append(DefaultSSHArgs, args...)
Expand Down
5 changes: 5 additions & 0 deletions virtualbox/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ func (m *Machine) GetName() string {
return m.Name
}

// Get machine address
func (m *Machine) GetAddr() string {
return "localhost"
}

// Get current state
func (m *Machine) GetState() driver.MachineState {
return m.State
Expand Down
51 changes: 51 additions & 0 deletions vsphere/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Boot2docker vSphere Driver
==========================

The vSphere driver is to support running vSphere environment.

vSphere Environment Requirement
---------------

The vSphere environment requires DHCP on the VM network the boot2docker VM is running on.


Configuration
---------------

The boot2docker reads the driver information from its profile, and a sample snippet configuration is provided below:

```ini
# boot2docker profile filename: /Users/my/.boot2docker/profile
......
Driver = "vsphere"
......

[DriverCfg.vsphere]
# path to the govc binary
Govc = "govc"

# vCenter IP address
VcenterIp = "10.150.100.200"

# vCenter Username (console should prompt for password)
VcenterUser = "root"

# target datacenter to deploy the boot2docker virtual machine
VcenterDatacenter = "Datacenter"

# target datastore to upload the boot2docker ISO and store the boot2docker virtual machine
VcenterDatastore = "datastore1"

# target network to add the boot2docker virtual machine (requires DHCP)
VcenterNetwork = "VM Network"

# (optional) required when user want to deploy to a specified host or multiple clusters/hosts exist in the environment
VcenterHostIp = "10.120.180.160"

# (optional) required when user wants to deploy to a specified cluster or multiple clusters/hosts exist in this environment
VcenterPool = "cluster"

# (optional) the default vm CPU number is 2
VmCPU = 4
```

18 changes: 18 additions & 0 deletions vsphere/errors/config_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package errors

import "fmt"

type IncompleteVcConfigError struct {
component string
}

func NewIncompleteVcConfigError(component string) error {
err := IncompleteVcConfigError{
component: component,
}
return &err
}

func (err *IncompleteVcConfigError) Error() string {
return fmt.Sprintf("Incomplete vCenter information: missing %s", err.component)
}
22 changes: 22 additions & 0 deletions vsphere/errors/datastore_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package errors

import "fmt"

type DatastoreError struct {
datastore string
operation string
reason string
}

func NewDatastoreError(datastore, operation, reason string) error {
err := DatastoreError{
datastore: datastore,
operation: operation,
reason: reason,
}
return &err
}

func (err *DatastoreError) Error() string {
return fmt.Sprintf("Unable to %s on datastore %s due to %s", err.operation, err.datastore, err.reason)
}
18 changes: 18 additions & 0 deletions vsphere/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package errors

import (
original "errors"
"fmt"
)

func New(message string) error {
return original.New(message)
}

func NewWithFmt(message string, args ...interface{}) error {
return original.New(fmt.Sprintf(message, args...))
}

func NewWithError(message string, err error) error {
return NewWithFmt("%s: %s", message, err.Error())
}
18 changes: 18 additions & 0 deletions vsphere/errors/govc_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package errors

import "fmt"

type GovcNotFoundError struct {
path string
}

func NewGovcNotFoundError(path string) error {
err := GovcNotFoundError{
path: path,
}
return &err
}

func (err *GovcNotFoundError) Error() string {
return fmt.Sprintf("govc not found: %s", err.path)
}
22 changes: 22 additions & 0 deletions vsphere/errors/guest_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package errors

import "fmt"

type GuestError struct {
vm string
operation string
reason string
}

func NewGuestError(vm, operation, reason string) error {
err := GuestError{
vm: vm,
operation: operation,
reason: reason,
}
return &err
}

func (err *GuestError) Error() string {
return fmt.Sprintf("Unable to %s on vm %s due to %s", err.operation, err.vm, err.reason)
}
13 changes: 13 additions & 0 deletions vsphere/errors/login_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package errors

type InvalidLoginError struct {
}

func NewInvalidLoginError() error {
err := InvalidLoginError{}
return &err
}

func (err *InvalidLoginError) Error() string {
return "cannot complete operation due to incorrect vSphere username or password"
}
18 changes: 18 additions & 0 deletions vsphere/errors/state_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package errors

import "fmt"

type InvalidStateError struct {
vm string
}

func NewInvalidStateError(vm string) error {
err := InvalidStateError{
vm: vm,
}
return &err
}

func (err *InvalidStateError) Error() string {
return fmt.Sprintf("Machine %s state invalid", err.vm)
}
22 changes: 22 additions & 0 deletions vsphere/errors/vm_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package errors

import "fmt"

type VmError struct {
operation string
vm string
reason string
}

func NewVmError(operation, vm, reason string) error {
err := VmError{
vm: vm,
operation: operation,
reason: reason,
}
return &err
}

func (err *VmError) Error() string {
return fmt.Sprintf("Unable to %s docker host %s: %s", err.operation, err.vm, err.reason)
}
55 changes: 55 additions & 0 deletions vsphere/govc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package vsphere

import (
"bytes"
"log"
"os"
"os/exec"
"strings"

"github.com/boot2docker/boot2docker-cli/vsphere/errors"
)

func init() {
}

func govc(args ...string) error {
err := lookPath(cfg.Govc)
if err != nil {
return errors.NewGovcNotFoundError(cfg.Govc)
}

cmd := exec.Command(cfg.Govc, args...)
if verbose {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Printf("executing: %v %v", cfg.Govc, strings.Join(args, " "))
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}

func govcOutErr(args ...string) (string, string, error) {
err := lookPath(cfg.Govc)
if err != nil {
return "", "", errors.NewGovcNotFoundError(cfg.Govc)
}

cmd := exec.Command(cfg.Govc, args...)
if verbose {
log.Printf("executing: %v %v", cfg.Govc, strings.Join(args, " "))
}
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err = cmd.Run()
return stdout.String(), stderr.String(), err
}

func lookPath(file string) error {
_, err := exec.LookPath(file)
return err
}
Loading