Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
making some progress on vmware
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Mar 25, 2018
1 parent 53db218 commit fe4e51c
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 442 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ setup: ## Install all the build and lint dependencies
dep ensure
gometalinter --install

.PHONY: run.server
run.server: ## Run vm-proxy server
@echo "===> Running vm-proxy server..."
go run server/*.go -V

.PHONY: test
test: ## Run all the tests
gotestcover $(TEST_OPTIONS) -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s
Expand Down
15 changes: 15 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ Date: Mon, 19 Mar 2018 22:03:43 GMT
VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path
```

## List `VMware` VMs _(via API)_

```sh
$ http --verify=no https://127.0.0.1:3993/vmware/list
```

```http
HTTP/1.1 200 OK
Content-Length: 21
Content-Type: text/plain; charset=UTF-8
Date: Sun, 25 Mar 2018 00:00:58 GMT
Total running VMs: 0
```
94 changes: 94 additions & 0 deletions drivers/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package drivers

import (
"errors"
"path/filepath"
)

const (
DefaultSSHUser = "root"
DefaultSSHPort = 22
DefaultEngineInstallURL = "https://get.docker.com"
)

// BaseDriver - Embed this struct into drivers to provide the common set
// of fields and functions.
type BaseDriver struct {
IPAddress string
MachineName string
SSHUser string
SSHPort int
SSHKeyPath string
StorePath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
}

// DriverName returns the name of the driver
func (d *BaseDriver) DriverName() string {
return "unknown"
}

// GetMachineName returns the machine name
func (d *BaseDriver) GetMachineName() string {
return d.MachineName
}

// GetIP returns the ip
func (d *BaseDriver) GetIP() (string, error) {
if d.IPAddress == "" {
return "", errors.New("IP address is not set")
}
return d.IPAddress, nil
}

// GetSSHKeyPath returns the ssh key path
func (d *BaseDriver) GetSSHKeyPath() string {
if d.SSHKeyPath == "" {
d.SSHKeyPath = d.ResolveStorePath("id_rsa")
}
return d.SSHKeyPath
}

// GetSSHPort returns the ssh port, 22 if not specified
func (d *BaseDriver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = DefaultSSHPort
}

return d.SSHPort, nil
}

// GetSSHUsername returns the ssh user name, root if not specified
func (d *BaseDriver) GetSSHUsername() string {
if d.SSHUser == "" {
d.SSHUser = DefaultSSHUser
}
return d.SSHUser
}

// PreCreateCheck is called to enforce pre-creation steps
func (d *BaseDriver) PreCreateCheck() error {
return nil
}

// ResolveStorePath returns the store path where the machine is
func (d *BaseDriver) ResolveStorePath(file string) string {
return filepath.Join(d.StorePath, "machines", d.MachineName, file)
}

// SetSwarmConfigFromFlags configures the driver for swarm
func (d *BaseDriver) SetSwarmConfigFromFlags(flags DriverOptions) {
d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
}

func EngineInstallURLFlagSet(flags DriverOptions) bool {
return EngineInstallURLSet(flags.String("engine-install-url"))
}

func EngineInstallURLSet(url string) bool {
return url != DefaultEngineInstallURL && url != ""
}
11 changes: 3 additions & 8 deletions drivers/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"

"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/state"
)

Expand All @@ -18,10 +17,6 @@ type Driver interface {
// DriverName returns the name of the driver
DriverName() string

// GetCreateFlags returns the mcnflag.Flag slice representing the flags
// that can be set, their descriptions and defaults.
GetCreateFlags() []mcnflag.Flag

// GetIP returns an IP or hostname that this host is available at
// e.g. 1.2.3.4 or docker-host-d60b70a14d3a.cloudapp.net
GetIP() (string, error)
Expand All @@ -43,7 +38,7 @@ type Driver interface {

// GetURL returns a Docker compatible host URL for connecting to this host
// e.g. tcp://1.2.3.4:2376
GetURL() (string, error)
// GetURL() (string, error)

// GetState returns the state that the host is in (running, stopped, etc)
GetState() (state.State, error)
Expand All @@ -63,7 +58,7 @@ type Driver interface {

// SetConfigFromFlags configures the driver with the object that was returned
// by RegisterCreateFlags
SetConfigFromFlags(opts DriverOptions) error
// SetConfigFromFlags(opts DriverOptions) error

// Start a host
Start() error
Expand All @@ -72,7 +67,7 @@ type Driver interface {
Stop() error

// List VMs
List() string
List() (string, error)
}

var ErrHostIsNotRunning = errors.New("Host is not running")
Expand Down
Loading

0 comments on commit fe4e51c

Please sign in to comment.