Browse Source

First version of docker-machine-driver-xcp

master
Fábio Kaiser Rauber 5 years ago
parent
commit
eb241bb0f0
  1. 28
      Makefile
  2. 81
      README.md
  3. 12
      docker-machine-driver-xcp.go
  4. 10
      docker-machine-driver-xenserver.go
  5. 8
      patches/build-docker-machine-driver-xenserver.sh
  6. 140
      xcp/xcp.go
  7. 3
      xcp/xenapiclient.go

28
Makefile

@ -1,3 +1,5 @@
#This file was modified from the original work, https://github.com/xenserver/docker-machine-driver-xenserver
.PHONY: build .PHONY: build
build: build:
go get ./... go get ./...
@ -9,13 +11,13 @@ build:
.PHONY: clean .PHONY: clean
clean: clean:
rm -f docker-machine-driver-xenserver \ rm -f docker-machine-driver-xcp \
docker-machine-driver-xenserver_darwin-386.tar.gz \ docker-machine-driver-xcp_darwin-386.tar.gz \
docker-machine-driver-xenserver_darwin-amd64.tar.gz \ docker-machine-driver-xcp_darwin-amd64.tar.gz \
docker-machine-driver-xenserver_linux-386.tar.gz \ docker-machine-driver-xcp_linux-386.tar.gz \
docker-machine-driver-xenserver_linux-amd64.tar.gz \ docker-machine-driver-xcp_linux-amd64.tar.gz \
docker-machine-driver-xenserver_windows-386.zip \ docker-machine-driver-xcp_windows-386.zip \
docker-machine-driver-xenserver_windows-amd64.zip docker-machine-driver-xcp_windows-amd64.zip
.PHONY: release .PHONY: release
release: release:
@ -23,14 +25,14 @@ release:
# Unix # Unix
for arch in 386 amd64 ; do \ for arch in 386 amd64 ; do \
for os in darwin linux ; do \ for os in darwin linux ; do \
GOOS=$$os GOARCH=$$arch go build -o docker-machine-driver-xenserver; \ GOOS=$$os GOARCH=$$arch go build -o docker-machine-driver-xcp; \
tar -cvzf docker-machine-driver-xenserver_$$os-$$arch.tar.gz docker-machine-driver-xenserver; \ tar -cvzf docker-machine-driver-xcp_$$os-$$arch.tar.gz docker-machine-driver-xcp; \
rm -f docker-machine-driver-xenserver; \ rm -f docker-machine-driver-xcp; \
done \ done \
done done
# Windows # Windows
for arch in 386 amd64 ; do \ for arch in 386 amd64 ; do \
GOOS=windows GOARCH=$$arch go build -o docker-machine-driver-xenserver.exe; \ GOOS=windows GOARCH=$$arch go build -o docker-machine-driver-xcp.exe; \
zip docker-machine-driver-xenserver_windows-$$arch.zip docker-machine-driver-xenserver.exe; \ zip docker-machine-driver-xcp_windows-$$arch.zip docker-machine-driver-xcp.exe; \
rm -f docker-machine-driver-xenserver; \ rm -f docker-machine-driver-xcp; \
done done

81
README.md

@ -1,56 +1,69 @@
[![Build Status](https://travis-ci.org/xenserver/docker-machine-driver-xenserver.svg?branch=master)](https://travis-ci.org/xenserver/docker-machine-driver-xenserver) # docker-machine-driver-xcp
This is the XCP-ng driver plugin for Docker Machine. It allows the
orchestration of machines on XCP-ng (all versions) and probably compatible with Citrix XenServer 6.5SP1 or later.
# docker-machine-driver-xenserver This work is derived from https://github.com/xenserver/docker-machine-driver-xenserver.
This is the XenServer driver plugin for Docker Machine. It allows the
orchestration of machines on Citrix XenServer 6.5SP1 and later.
# Installation from binary # Installation from binary
Please refer to the
[documentation for a release](https://github.com/xenserver/docker-machine-driver-xenserver/releases). The installation steps are:
1. If not done already - download the Docker Machine binary for your OS and architecture
2. If not done already - move the binary to your PATH.
3. Download the driver archive for your OS and architecture.
4. Extract the archive
5. Move the driver binary to your PATH, so it can be found by docker-machine.
# Installation from source # Installation from source
Following the installation of Golang and Docker Machine, you can install the Following the installation of Golang and Docker Machine, you can install the
docker-machine-xenserver-driver: docker-machine-xcp-driver:
```bash ```bash
go get github.com/xenserver/docker-machine-driver-xenserver go get github.com/interlegis/docker-machine-driver-xcp
``` ```
# Usage # Usage
The usual Docker Machine commands apply: The usual Docker Machine commands apply:
```bash ```bash
docker-machine create -d xenserver --xenserver-server myip --xenserver-username myusername --xenserver-password mypassword mynewmmachine docker-machine create -d xcp --xcp-server myip --xcp-username myusername --xcp-password mypassword mynewmmachine
docker-machine env mynewmmachine docker-machine env mynewmmachine
``` ```
# CLI Options: # CLI Options:
- `--xenserver-vcpu-count`: vCPU number for docker VM. - `--xcp-vcpu-count`: vCPU number for docker VM.
- `--xenserver-memory-size`: Size of memory for Docker VM (in MB). - `--xcp-memory-size`: Size of memory for Docker VM (in MB).
- `--xenserver-boot2docker-url`: URL for boot2docker ISO image. - `--xcp-boot2docker-url`: URL for boot2docker ISO image.
- `--xenserver-server`: **required for create** XenServer hostname/IP for docker VM. - `--xcp-server`: **required for create** XenServer hostname/IP for docker VM.
- `--xenserver-disk-size`: Size of disk for Docker VM (in MB). - `--xcp-disk-size`: Size of disk for Docker VM (in MB).
- `--xenserver-username`: **required** XenServer Username. - `--xcp-username`: **required** XenServer Username.
- `--xenserver-password`: **required** XenServer Password. - `--xcp-password`: **required** XenServer Password.
- `--xenserver-network-label`: Network label where the docker VM will be attached - `--xcp-network-label`: Network label where the docker VM will be attached
- `--xenserver-sr-label`: SR label where the docker VM will be attached. - `--xcp-sr-label`: SR label where the docker VM will be attached.
- `--xenserver-host-label`: Host label where the docker VM will be run. - `--xcp-host-label`: Host label where the docker VM will be run.
- `--xenserver-upload-timeout`: Timeout uploading VDI. - `--xcp-upload-timeout`: Timeout uploading VDI.
- `--xenserver-wait-timeout`: Timeout wating for VM start. - `--xcp-wait-timeout`: Timeout wating for VM start.
- `--xcp-os-template`: XCP template name for the new VM.
- `--xcp-os-username`: Username used by docker-machine to SSH to the new VM.
- `--xcp-coreos-configdrive`: Whether to use a CoreOS ConfigDrive or (default) a generic one.
# Environment variables and default values: # Environment variables and default values:
| CLI option | Environment variable | Default | | CLI option | Environment variable | Default |
|-----------------------------------|-----------------------------|------------------------------| |-----------------------------|--------------------------|------------------------------|
| `--xenserver-vcpu-count` | `XENSERVER_VCPU_COUNT` | `1` | | `--xcp-vcpu-count` | `XCP_VCPU_COUNT` | `1` |
| `--xenserver-memory-size` | `XENSERVER_MEMORY_SIZE` | `2048` | | `--xcp-memory-size` | `XCP_MEMORY_SIZE` | `2048` |
| `--xenserver-disk-size` | `XENSERVER_DISK_SIZE` | `5120` | | `--xcp-disk-size` | `XCP_DISK_SIZE` | `5120` |
| `--xenserver-boot2docker-url` | `XENSERVER_BOOT2DOCKER_URL` | *boot2docker URL* | | `--xcp-boot2docker-url` | `XCP_BOOT2DOCKER_URL` | *boot2docker URL* |
| `--xenserver-server` | `XENSERVER_SERVER` | - | | `--xcp-server` | `XCP_SERVER` | - |
| `--xenserver-host-label` | `XENSERVER_HOST_LABEL` | - | | `--xcp-host-label` | `XCP_HOST_LABEL` | - |
| **`--xenserver-username`** | `XENSERVER_USERNAME` | - | | **`--xcp-username`** | `XCP_USERNAME` | - |
| **`--xenserver-password`** | `XENSERVER_PASSWORD` | - | | **`--xcp-password`** | `XCP_PASSWORD` | - |
| `--xenserver-network-label` | `XENSERVER_NETWORK_LABEL` | - | | `--xcp-network-label` | `XCP_NETWORK_LABEL` | - |
| `--xenserver-sr-label` | `XENSERVER_SR_LABEL` | - | | `--xcp-sr-label` | `XCP_SR_LABEL` | - |
| `--xenserver-upload-timeout` | `XENSERVER_UPLOAD_TIMEOUT` | `300` | | `--xcp-upload-timeout` | `XCP_UPLOAD_TIMEOUT` | `300` |
| `--xenserver-wait-timeout` | `XENSERVER_WAIT_TIMEOUT` | `1800` | | `--xcp-wait-timeout` | `XCP_WAIT_TIMEOUT` | `1800` |
| `--xcp-os-template` | `XCP_OS_TEMPLATE` | `Other install media` |
| `--xcp-os-username` | `XCP_OS_USERNAME` | `docker` |
| `--xcp-coreos-configdrive` | `XCP_COREOS_CONFIGDRIVE` | `false` |

12
docker-machine-driver-xcp.go

@ -0,0 +1,12 @@
//This file was modified from the original work, https://github.com/xenserver/docker-machine-driver-xenserver
package main
import (
"github.com/docker/machine/libmachine/drivers/plugin"
"github.com/interlegis/docker-machine-driver-xcp/xcp"
)
func main() {
plugin.RegisterDriver(xcp.NewDriver())
}

10
docker-machine-driver-xenserver.go

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

8
patches/build-docker-machine-driver-xenserver.sh

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
export GITHUB_USER=${GITHUB_USER:-xenserver} export GITHUB_USER=${GITHUB_USER:-xcp}
export GITHUB_REPO=${GITHUB_REPO:-docker-machine-driver-xenserver} export GITHUB_REPO=${GITHUB_REPO:-docker-machine-driver-xcp}
export GITHUB_COMMIT_ID=${TRAVIS_COMMIT:-${COMMIT_ID:-master}} export GITHUB_COMMIT_ID=${TRAVIS_COMMIT:-${COMMIT_ID:-master}}
export WORKING_DIR=/tmp/tmp.$(date "+%Y%m%d%H%M%S").${RANDOM:-$$}.${GITHUB_REPO} export WORKING_DIR=/tmp/tmp.$(date "+%Y%m%d%H%M%S").${RANDOM:-$$}.${GITHUB_REPO}
export GOROOT_BOOTSTRAP=${WORKING_DIR}/go1.6 export GOROOT_BOOTSTRAP=${WORKING_DIR}/go1.6
@ -43,8 +43,8 @@ function release_repo() {
pushd ${WORKING_DIR} pushd ${WORKING_DIR}
if [ -d "${WORKSPACE}" ]; then if [ -d "${WORKSPACE}" ]; then
local FILENAME=docker-machine-driver-xenserver_$(go env GOOS)-$(go env GOARCH) local FILENAME=docker-machine-driver-xcp_$(go env GOOS)-$(go env GOARCH)
cp -rf $GOPATH/bin/docker-machine-driver-xenserver ${WORKSPACE}/${FILENAME} cp -rf $GOPATH/bin/docker-machine-driver-xcp ${WORKSPACE}/${FILENAME}
fi fi
popd popd

140
xenserver/xenserver.go → xcp/xcp.go

@ -1,4 +1,6 @@
package xenserver //This file was modified from the original work, https://github.com/xenserver/docker-machine-driver-xenserver
package xcp
import ( import (
"archive/tar" "archive/tar"
@ -23,9 +25,8 @@ import (
"github.com/docker/machine/libmachine/ssh" "github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state" "github.com/docker/machine/libmachine/state"
"github.com/nilshell/xmlrpc" "github.com/nilshell/xmlrpc"
"golang.org/x/net/context"
xsclient "github.com/xenserver/go-xenserver-client" xsclient "github.com/xenserver/go-xenserver-client"
"golang.org/x/net/context"
) )
const ( const (
@ -65,88 +66,87 @@ type Driver struct {
func (d *Driver) GetCreateFlags() []mcnflag.Flag { func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{ return []mcnflag.Flag{
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_SERVER", EnvVar: "XCP_SERVER",
Name: "xenserver-server", Name: "xcp-server",
Usage: "XenServer server hostname/IP for docker VM", Usage: "XCP server hostname/IP for docker VM",
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_USERNAME", EnvVar: "XCP_USERNAME",
Name: "xenserver-username", Name: "xcp-username",
Usage: "XenServer username", Usage: "XCP username",
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_PASSWORD", EnvVar: "XCP_PASSWORD",
Name: "xenserver-password", Name: "xcp-password",
Usage: "XenServer password", Usage: "XCP password",
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_BOOT2DOCKER_URL", EnvVar: "XCP_BOOT2DOCKER_URL",
Name: "xenserver-boot2docker-url", Name: "xcp-boot2docker-url",
Usage: "XenServer URL for boot2docker image", Usage: "XCP URL for boot2docker image",
}, },
mcnflag.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_VCPU_COUNT", EnvVar: "XCP_VCPU_COUNT",
Name: "xenserver-vcpu-count", Name: "xcp-vcpu-count",
Usage: "XenServer vCPU number for docker VM", Usage: "XCP vCPU number for docker VM",
Value: 1, Value: 1,
}, },
mcnflag.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_MEMORY_SIZE", EnvVar: "XCP_MEMORY_SIZE",
Name: "xenserver-memory-size", Name: "xcp-memory-size",
Usage: "XenServer size of memory for docker VM (in MB)", Usage: "XCP size of memory for docker VM (in MB)",
Value: 1024, Value: 1024,
}, },
mcnflag.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_DISK_SIZE", EnvVar: "XCP_DISK_SIZE",
Name: "xenserver-disk-size", Name: "xcp-disk-size",
Usage: "XenServer size of disk for docker VM (in MB)", Usage: "XCP size of disk for docker VM (in MB)",
Value: 5120, Value: 5120,
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_SR_LABEL", EnvVar: "XCP_SR_LABEL",
Name: "xenserver-sr-label", Name: "xcp-sr-label",
Usage: "XenServer SR label where the docker VM will be attached", Usage: "XCP SR label where the docker VM will be attached",
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_NETWORK_LABEL", EnvVar: "XCP_NETWORK_LABEL",
Name: "xenserver-network-label", Name: "xcp-network-label",
Usage: "XenServer network label where the docker VM will be attached", Usage: "XCP network label where the docker VM will be attached",
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_HOST_LABEL", EnvVar: "XCP_HOST_LABEL",
Name: "xenserver-host-label", Name: "xcp-host-label",
Usage: "XenServer host label where the docker VM will be run", Usage: "XCP host label where the docker VM will be run",
}, },
mcnflag.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_UPLOAD_TIMEOUT", EnvVar: "XCP_UPLOAD_TIMEOUT",
Name: "xenserver-upload-timeout", Name: "xcp-upload-timeout",
Usage: "XenServer upload VDI timeout(seconds)", Usage: "XCP upload VDI timeout(seconds)",
Value: 5 * 60, Value: 5 * 60,
}, },
mcnflag.IntFlag{ mcnflag.IntFlag{
EnvVar: "XENSERVER_WAIT_TIMEOUT", EnvVar: "XCP_WAIT_TIMEOUT",
Name: "xenserver-wait-timeout", Name: "xcp-wait-timeout",
Usage: "XenServer wait VM start timeout(seconds)", Usage: "XCP wait VM start timeout(seconds)",
Value: 30 * 60, Value: 30 * 60,
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_OS_TEMPLATE", EnvVar: "XCP_OS_TEMPLATE",
Name: "xenserver-os-template", Name: "xcp-os-template",
Usage: "XenServer OS Template Label Name", Usage: "XCP OS Template Label Name",
Value: "Other install media", Value: "Other install media",
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
EnvVar: "XENSERVER_OS_USERNAME", EnvVar: "XCP_OS_USERNAME",
Name: "xenserver-os-username", Name: "xcp-os-username",
Usage: "XenServer Username used to SSH into guest OS", Usage: "XCP Username used to SSH into guest OS",
Value: B2D_USER, Value: B2D_USER,
}, },
mcnflag.BoolFlag{ mcnflag.BoolFlag{
EnvVar: "XENSERVER_COREOS_CONFIGDRIVE", EnvVar: "XCP_COREOS_CONFIGDRIVE",
Name: "xenserver-coreos-configdrive", Name: "xcp-coreos-configdrive",
Usage: "XenServer Enable CoreOS specific ConfigDrive (requires xscontainer supplemental pack)", Usage: "XCP Enable CoreOS specific ConfigDrive (requires xscontainer supplemental pack)",
}, },
} }
} }
@ -179,31 +179,31 @@ func (d *Driver) GetSSHUsername() string {
} }
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "xenserver" return "xcp"
} }
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SSHUser = flags.String("xenserver-os-username") d.SSHUser = flags.String("xcp-os-username")
d.SSHPort = 22 d.SSHPort = 22
d.Server = flags.String("xenserver-server") d.Server = flags.String("xcp-server")
d.Username = flags.String("xenserver-username") d.Username = flags.String("xcp-username")
d.Password = flags.String("xenserver-password") d.Password = flags.String("xcp-password")
d.Boot2DockerURL = flags.String("xenserver-boot2docker-url") d.Boot2DockerURL = flags.String("xcp-boot2docker-url")
d.CPU = uint(flags.Int("xenserver-vcpu-count")) d.CPU = uint(flags.Int("xcp-vcpu-count"))
d.Memory = uint(flags.Int("xenserver-memory-size")) d.Memory = uint(flags.Int("xcp-memory-size"))
d.DiskSize = uint(flags.Int("xenserver-disk-size")) d.DiskSize = uint(flags.Int("xcp-disk-size"))
d.SR = flags.String("xenserver-sr-label") d.SR = flags.String("xcp-sr-label")
d.Network = flags.String("xenserver-network-label") d.Network = flags.String("xcp-network-label")
d.Host = flags.String("xenserver-host-label") d.Host = flags.String("xcp-host-label")
d.UploadTimeout = uint(flags.Int("xenserver-upload-timeout")) d.UploadTimeout = uint(flags.Int("xcp-upload-timeout"))
d.WaitTimeout = uint(flags.Int("xenserver-wait-timeout")) d.WaitTimeout = uint(flags.Int("xcp-wait-timeout"))
d.SwarmMaster = flags.Bool("swarm-master") d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host") d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery") d.SwarmDiscovery = flags.String("swarm-discovery")
d.ISO = d.ResolveStorePath(isoFilename) d.ISO = d.ResolveStorePath(isoFilename)
d.TAR = d.ResolveStorePath(tarFilename) d.TAR = d.ResolveStorePath(tarFilename)
d.osTemplateLabelName = flags.String("xenserver-os-template") d.osTemplateLabelName = flags.String("xcp-os-template")
d.CoreosConfigDrive = flags.Bool("xenserver-coreos-configdrive") d.CoreosConfigDrive = flags.Bool("xcp-coreos-configdrive")
return nil return nil
} }
@ -343,7 +343,7 @@ func (d *Driver) Create() error {
// Only upload ISO image if using Other install media, otherwise use existing VM template // Only upload ISO image if using Other install media, otherwise use existing VM template
var sr *xsclient.SR var sr *xsclient.SR
var isoVdiUuid,diskVdiUuid string var isoVdiUuid, diskVdiUuid string
// Get the SR // Get the SR
if d.SR == "" { if d.SR == "" {
@ -351,7 +351,7 @@ func (d *Driver) Create() error {
if sr.Ref == "OpaqueRef:NULL" { if sr.Ref == "OpaqueRef:NULL" {
err := errors.New("No default SR found. Please configure a " + err := errors.New("No default SR found. Please configure a " +
"default or specify the SR explicitly using " + "default or specify the SR explicitly using " +
"--xenserver-sr-label.") "--xcp-sr-label.")
log.Errorf("%v", err) log.Errorf("%v", err)
return err return err
} }
@ -522,7 +522,7 @@ func (d *Driver) Create() error {
if err != nil { if err != nil {
return err return err
} }
srUuid,err := sr.GetUuid() srUuid, err := sr.GetUuid()
if err != nil { if err != nil {
return err return err
} }
@ -906,7 +906,7 @@ func (d *Driver) importVdi(vdi *xsclient.VDI, filename string, timeout time.Dura
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
msg, _ := ioutil.ReadAll(resp.Body) msg, _ := ioutil.ReadAll(resp.Body)
err = fmt.Errorf("xenserver reply %s: %v", resp.Status, string(msg)) err = fmt.Errorf("xcp reply %s: %v", resp.Status, string(msg))
log.Errorf("Unable to upload VDI: %v", err) log.Errorf("Unable to upload VDI: %v", err)
return err return err
} }
@ -1005,7 +1005,7 @@ ssh_authorized_keys:
args["vmuuid"] = vmuuid args["vmuuid"] = vmuuid
args["sruuid"] = sruuid args["sruuid"] = sruuid
args["configuration"] = userdatatext args["configuration"] = userdatatext
ahost.CallPlugin("xscontainer","create_config_drive",args) ahost.CallPlugin("xscontainer", "create_config_drive", args)
return nil return nil
} }

3
xenserver/xenapiclient.go → xcp/xenapiclient.go

@ -1,4 +1,5 @@
package xenserver //This file was modified from the original work, https://github.com/xenserver/docker-machine-driver-xenserver
package xcp
import ( import (
"crypto/tls" "crypto/tls"
Loading…
Cancel
Save