Browse Source

Update to new plugin approach

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
getsshkeypath_pr
Jon Ludlam 9 years ago
parent
commit
d6b9e4b0ca
  1. 4
      bin/Makefile
  2. 10
      bin/main.go
  3. 76
      xenserver.go

4
bin/Makefile

@ -0,0 +1,4 @@
default: build
build:
GOGC=off go build -i -o docker-machine-driver-xenserver

10
bin/main.go

@ -0,0 +1,10 @@
package main
import (
"github.com/jonludlam/docker-machine-xenserver"
"github.com/docker/machine/libmachine/drivers/plugin"
)
func main() {
plugin.RegisterDriver(xenserver.NewDriver())
}

76
xenserver.go

@ -14,12 +14,12 @@ import (
"strings" "strings"
"time" "time"
"github.com/codegangsta/cli" "github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/drivers" "github.com/docker/machine/libmachine/log"
"github.com/docker/machine/log" "github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/ssh" "github.com/docker/machine/libmachine/state"
"github.com/docker/machine/state" "github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/utils" "github.com/docker/machine/libmachine/mcnflag"
"github.com/nilshell/xmlrpc" "github.com/nilshell/xmlrpc"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -36,9 +36,8 @@ const (
) )
type Driver struct { type Driver struct {
MachineName string *drivers.BaseDriver
SSHUser string
SSHPort int
Server string Server string
Username string Username string
Password string Password string
@ -49,92 +48,81 @@ type Driver struct {
SR string SR string
Network string Network string
Host string Host string
StorePath string
ISO string ISO string
TAR string TAR string
UploadTimeout uint UploadTimeout uint
WaitTimeout uint WaitTimeout uint
CaCertPath string CaCertPath string
PrivateKeyPath string PrivateKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
xenAPIClient *XenAPIClient xenAPIClient *XenAPIClient
} }
func init() {
drivers.Register("xenserver", &drivers.RegisteredDriver{
New: NewDriver,
GetCreateFlags: GetCreateFlags,
})
}
// GetCreateFlags registers the flags this driver adds to // GetCreateFlags registers the flags this driver adds to
// "docker hosts create" // "docker hosts create"
func GetCreateFlags() []cli.Flag { func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []cli.Flag{ return []mcnflag.Flag{
cli.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_SERVER", EnvVar: "XENSERVER_SERVER",
Name: "xenserver-server", Name: "xenserver-server",
Usage: "XenServer server hostname/IP for docker VM", Usage: "XenServer server hostname/IP for docker VM",
}, },
cli.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_USERNAME", EnvVar: "XENSERVER_USERNAME",
Name: "xenserver-username", Name: "xenserver-username",
Usage: "XenServer username", Usage: "XenServer username",
}, },
cli.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_PASSWORD", EnvVar: "XENSERVER_PASSWORD",
Name: "xenserver-password", Name: "xenserver-password",
Usage: "XenServer password", Usage: "XenServer password",
}, },
cli.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_BOOT2DOCKER_URL", EnvVar: "XENSERVER_BOOT2DOCKER_URL",
Name: "xenserver-boot2docker-url", Name: "xenserver-boot2docker-url",
Usage: "XenServer URL for boot2docker image", Usage: "XenServer URL for boot2docker image",
Value: isoOnlineURL, Value: isoOnlineURL,
}, },
cli.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_VCPU_COUNT", EnvVar: "XENSERVER_VCPU_COUNT",
Name: "xenserver-vcpu-count", Name: "xenserver-vcpu-count",
Usage: "XenServer vCPU number for docker VM", Usage: "XenServer vCPU number for docker VM",
Value: 1, Value: 1,
}, },
cli.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_MEMORY_SIZE", EnvVar: "XENSERVER_MEMORY_SIZE",
Name: "xenserver-memory-size", Name: "xenserver-memory-size",
Usage: "XenServer size of memory for docker VM (in MB)", Usage: "XenServer size of memory for docker VM (in MB)",
Value: 1024, Value: 1024,
}, },
cli.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_DISK_SIZE", EnvVar: "XENSERVER_DISK_SIZE",
Name: "xenserver-disk-size", Name: "xenserver-disk-size",
Usage: "XenServer size of disk for docker VM (in MB)", Usage: "XenServer size of disk for docker VM (in MB)",
Value: 5120, Value: 5120,
}, },
cli.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_SR_LABEL", EnvVar: "XENSERVER_SR_LABEL",
Name: "xenserver-sr-label", Name: "xenserver-sr-label",
Usage: "XenServer SR label where the docker VM will be attached", Usage: "XenServer SR label where the docker VM will be attached",
}, },
cli.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_NETWORK_LABEL", EnvVar: "XENSERVER_NETWORK_LABEL",
Name: "xenserver-network-label", Name: "xenserver-network-label",
Usage: "XenServer network label where the docker VM will be attached", Usage: "XenServer network label where the docker VM will be attached",
}, },
cli.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_HOST_LABEL", EnvVar: "XENSERVER_HOST_LABEL",
Name: "xenserver-host-label", Name: "xenserver-host-label",
Usage: "XenServer host label where the docker VM will be run", Usage: "XenServer host label where the docker VM will be run",
}, },
cli.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_UPLOAD_TIMEOUT", EnvVar: "XENSERVER_UPLOAD_TIMEOUT",
Name: "xenserver-upload-timeout", Name: "xenserver-upload-timeout",
Usage: "XenServer upload VDI timeout(seconds)", Usage: "XenServer upload VDI timeout(seconds)",
Value: 5 * 60, Value: 5 * 60,
}, },
cli.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_WAIT_TIMEOUT", EnvVar: "XENSERVER_WAIT_TIMEOUT",
Name: "xenserver-wait-timeout", Name: "xenserver-wait-timeout",
Usage: "XenServer wait VM start timeout(seconds)", Usage: "XenServer wait VM start timeout(seconds)",
@ -143,16 +131,8 @@ func GetCreateFlags() []cli.Flag {
} }
} }
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) { func NewDriver() *Driver {
return &Driver{MachineName: machineName, StorePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil return &Driver{}
}
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
} }
func (d *Driver) GetMachineName() string { func (d *Driver) GetMachineName() string {
@ -318,12 +298,12 @@ func (d *Driver) Create() error {
// Download boot2docker ISO from Internet // Download boot2docker ISO from Internet
var isoURL string var isoURL string
b2dutils := utils.NewB2dUtils("", "") b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if d.Boot2DockerURL != "" { if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL isoURL = d.Boot2DockerURL
} else { } else {
isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL() isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL("")
if err != nil { if err != nil {
log.Errorf("Unable to check for the latest release: %s", err) log.Errorf("Unable to check for the latest release: %s", err)
return err return err
@ -606,8 +586,8 @@ func (d *Driver) wait(timeout time.Duration) (err error) {
} }
addr := fmt.Sprintf("%s:%d", ip, port) addr := fmt.Sprintf("%s:%d", ip, port)
log.Infof("Got VM address(%v), Now waiting for SSH", addr) log.Infof("Got VM address(%v), Now (not) waiting for SSH", addr)
out <- ssh.WaitForTCP(addr) // out <- ssh.WaitForTCP(addr)
}(ctx, out) }(ctx, out)
select { select {

Loading…
Cancel
Save