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
build:
go get ./...
@ -9,13 +11,13 @@ build:
.PHONY: clean
clean:
rm -f docker-machine-driver-xenserver \
docker-machine-driver-xenserver_darwin-386.tar.gz \
docker-machine-driver-xenserver_darwin-amd64.tar.gz \
docker-machine-driver-xenserver_linux-386.tar.gz \
docker-machine-driver-xenserver_linux-amd64.tar.gz \
docker-machine-driver-xenserver_windows-386.zip \
docker-machine-driver-xenserver_windows-amd64.zip
rm -f docker-machine-driver-xcp \
docker-machine-driver-xcp_darwin-386.tar.gz \
docker-machine-driver-xcp_darwin-amd64.tar.gz \
docker-machine-driver-xcp_linux-386.tar.gz \
docker-machine-driver-xcp_linux-amd64.tar.gz \
docker-machine-driver-xcp_windows-386.zip \
docker-machine-driver-xcp_windows-amd64.zip
.PHONY: release
release:
@ -23,14 +25,14 @@ release:
# Unix
for arch in 386 amd64 ; do \
for os in darwin linux ; do \
GOOS=$$os GOARCH=$$arch go build -o docker-machine-driver-xenserver; \
tar -cvzf docker-machine-driver-xenserver_$$os-$$arch.tar.gz docker-machine-driver-xenserver; \
rm -f docker-machine-driver-xenserver; \
GOOS=$$os GOARCH=$$arch go build -o docker-machine-driver-xcp; \
tar -cvzf docker-machine-driver-xcp_$$os-$$arch.tar.gz docker-machine-driver-xcp; \
rm -f docker-machine-driver-xcp; \
done \
done
# Windows
for arch in 386 amd64 ; do \
GOOS=windows GOARCH=$$arch go build -o docker-machine-driver-xenserver.exe; \
zip docker-machine-driver-xenserver_windows-$$arch.zip docker-machine-driver-xenserver.exe; \
rm -f docker-machine-driver-xenserver; \
GOOS=windows GOARCH=$$arch go build -o docker-machine-driver-xcp.exe; \
zip docker-machine-driver-xcp_windows-$$arch.zip docker-machine-driver-xcp.exe; \
rm -f docker-machine-driver-xcp; \
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 is the XenServer driver plugin for Docker Machine. It allows the
orchestration of machines on Citrix XenServer 6.5SP1 and later.
This work is derived from https://github.com/xenserver/docker-machine-driver-xenserver.
# 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
Following the installation of Golang and Docker Machine, you can install the
docker-machine-xenserver-driver:
docker-machine-xcp-driver:
```bash
go get github.com/xenserver/docker-machine-driver-xenserver
go get github.com/interlegis/docker-machine-driver-xcp
```
# Usage
The usual Docker Machine commands apply:
```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
```
# CLI Options:
- `--xenserver-vcpu-count`: vCPU number for docker VM.
- `--xenserver-memory-size`: Size of memory for Docker VM (in MB).
- `--xenserver-boot2docker-url`: URL for boot2docker ISO image.
- `--xenserver-server`: **required for create** XenServer hostname/IP for docker VM.
- `--xenserver-disk-size`: Size of disk for Docker VM (in MB).
- `--xenserver-username`: **required** XenServer Username.
- `--xenserver-password`: **required** XenServer Password.
- `--xenserver-network-label`: Network label where the docker VM will be attached
- `--xenserver-sr-label`: SR label where the docker VM will be attached.
- `--xenserver-host-label`: Host label where the docker VM will be run.
- `--xenserver-upload-timeout`: Timeout uploading VDI.
- `--xenserver-wait-timeout`: Timeout wating for VM start.
- `--xcp-vcpu-count`: vCPU number for docker VM.
- `--xcp-memory-size`: Size of memory for Docker VM (in MB).
- `--xcp-boot2docker-url`: URL for boot2docker ISO image.
- `--xcp-server`: **required for create** XenServer hostname/IP for docker VM.
- `--xcp-disk-size`: Size of disk for Docker VM (in MB).
- `--xcp-username`: **required** XenServer Username.
- `--xcp-password`: **required** XenServer Password.
- `--xcp-network-label`: Network label where the docker VM will be attached
- `--xcp-sr-label`: SR label where the docker VM will be attached.
- `--xcp-host-label`: Host label where the docker VM will be run.
- `--xcp-upload-timeout`: Timeout uploading VDI.
- `--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:
| CLI option | Environment variable | Default |
|-----------------------------------|-----------------------------|------------------------------|
| `--xenserver-vcpu-count` | `XENSERVER_VCPU_COUNT` | `1` |
| `--xenserver-memory-size` | `XENSERVER_MEMORY_SIZE` | `2048` |
| `--xenserver-disk-size` | `XENSERVER_DISK_SIZE` | `5120` |
| `--xenserver-boot2docker-url` | `XENSERVER_BOOT2DOCKER_URL` | *boot2docker URL* |
| `--xenserver-server` | `XENSERVER_SERVER` | - |
| `--xenserver-host-label` | `XENSERVER_HOST_LABEL` | - |
| **`--xenserver-username`** | `XENSERVER_USERNAME` | - |
| **`--xenserver-password`** | `XENSERVER_PASSWORD` | - |
| `--xenserver-network-label` | `XENSERVER_NETWORK_LABEL` | - |
| `--xenserver-sr-label` | `XENSERVER_SR_LABEL` | - |
| `--xenserver-upload-timeout` | `XENSERVER_UPLOAD_TIMEOUT` | `300` |
| `--xenserver-wait-timeout` | `XENSERVER_WAIT_TIMEOUT` | `1800` |
|-----------------------------|--------------------------|------------------------------|
| `--xcp-vcpu-count` | `XCP_VCPU_COUNT` | `1` |
| `--xcp-memory-size` | `XCP_MEMORY_SIZE` | `2048` |
| `--xcp-disk-size` | `XCP_DISK_SIZE` | `5120` |
| `--xcp-boot2docker-url` | `XCP_BOOT2DOCKER_URL` | *boot2docker URL* |
| `--xcp-server` | `XCP_SERVER` | - |
| `--xcp-host-label` | `XCP_HOST_LABEL` | - |
| **`--xcp-username`** | `XCP_USERNAME` | - |
| **`--xcp-password`** | `XCP_PASSWORD` | - |
| `--xcp-network-label` | `XCP_NETWORK_LABEL` | - |
| `--xcp-sr-label` | `XCP_SR_LABEL` | - |
| `--xcp-upload-timeout` | `XCP_UPLOAD_TIMEOUT` | `300` |
| `--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
export GITHUB_USER=${GITHUB_USER:-xenserver}
export GITHUB_REPO=${GITHUB_REPO:-docker-machine-driver-xenserver}
export GITHUB_USER=${GITHUB_USER:-xcp}
export GITHUB_REPO=${GITHUB_REPO:-docker-machine-driver-xcp}
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 GOROOT_BOOTSTRAP=${WORKING_DIR}/go1.6
@ -43,8 +43,8 @@ function release_repo() {
pushd ${WORKING_DIR}
if [ -d "${WORKSPACE}" ]; then
local FILENAME=docker-machine-driver-xenserver_$(go env GOOS)-$(go env GOARCH)
cp -rf $GOPATH/bin/docker-machine-driver-xenserver ${WORKSPACE}/${FILENAME}
local FILENAME=docker-machine-driver-xcp_$(go env GOOS)-$(go env GOARCH)
cp -rf $GOPATH/bin/docker-machine-driver-xcp ${WORKSPACE}/${FILENAME}
fi
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 (
"archive/tar"
@ -23,9 +25,8 @@ import (
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/nilshell/xmlrpc"
"golang.org/x/net/context"
xsclient "github.com/xenserver/go-xenserver-client"
"golang.org/x/net/context"
)
const (
@ -65,88 +66,87 @@ type Driver struct {
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{
mcnflag.StringFlag{
EnvVar: "XENSERVER_SERVER",
Name: "xenserver-server",
Usage: "XenServer server hostname/IP for docker VM",
EnvVar: "XCP_SERVER",
Name: "xcp-server",
Usage: "XCP server hostname/IP for docker VM",
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_USERNAME",
Name: "xenserver-username",
Usage: "XenServer username",
EnvVar: "XCP_USERNAME",
Name: "xcp-username",
Usage: "XCP username",
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_PASSWORD",
Name: "xenserver-password",
Usage: "XenServer password",
EnvVar: "XCP_PASSWORD",
Name: "xcp-password",
Usage: "XCP password",
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_BOOT2DOCKER_URL",
Name: "xenserver-boot2docker-url",
Usage: "XenServer URL for boot2docker image",
EnvVar: "XCP_BOOT2DOCKER_URL",
Name: "xcp-boot2docker-url",
Usage: "XCP URL for boot2docker image",
},
mcnflag.IntFlag{
EnvVar: "XENSERVER_VCPU_COUNT",
Name: "xenserver-vcpu-count",
Usage: "XenServer vCPU number for docker VM",
EnvVar: "XCP_VCPU_COUNT",
Name: "xcp-vcpu-count",
Usage: "XCP vCPU number for docker VM",
Value: 1,
},
mcnflag.IntFlag{
EnvVar: "XENSERVER_MEMORY_SIZE",
Name: "xenserver-memory-size",
Usage: "XenServer size of memory for docker VM (in MB)",
EnvVar: "XCP_MEMORY_SIZE",
Name: "xcp-memory-size",
Usage: "XCP size of memory for docker VM (in MB)",
Value: 1024,
},
mcnflag.IntFlag{
EnvVar: "XENSERVER_DISK_SIZE",
Name: "xenserver-disk-size",
Usage: "XenServer size of disk for docker VM (in MB)",
EnvVar: "XCP_DISK_SIZE",
Name: "xcp-disk-size",
Usage: "XCP size of disk for docker VM (in MB)",
Value: 5120,
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_SR_LABEL",
Name: "xenserver-sr-label",
Usage: "XenServer SR label where the docker VM will be attached",
EnvVar: "XCP_SR_LABEL",
Name: "xcp-sr-label",
Usage: "XCP SR label where the docker VM will be attached",
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_NETWORK_LABEL",
Name: "xenserver-network-label",
Usage: "XenServer network label where the docker VM will be attached",
EnvVar: "XCP_NETWORK_LABEL",
Name: "xcp-network-label",
Usage: "XCP network label where the docker VM will be attached",
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_HOST_LABEL",
Name: "xenserver-host-label",
Usage: "XenServer host label where the docker VM will be run",
EnvVar: "XCP_HOST_LABEL",
Name: "xcp-host-label",
Usage: "XCP host label where the docker VM will be run",
},
mcnflag.IntFlag{
EnvVar: "XENSERVER_UPLOAD_TIMEOUT",
Name: "xenserver-upload-timeout",
Usage: "XenServer upload VDI timeout(seconds)",
EnvVar: "XCP_UPLOAD_TIMEOUT",
Name: "xcp-upload-timeout",
Usage: "XCP upload VDI timeout(seconds)",
Value: 5 * 60,
},
mcnflag.IntFlag{
EnvVar: "XENSERVER_WAIT_TIMEOUT",
Name: "xenserver-wait-timeout",
Usage: "XenServer wait VM start timeout(seconds)",
EnvVar: "XCP_WAIT_TIMEOUT",
Name: "xcp-wait-timeout",
Usage: "XCP wait VM start timeout(seconds)",
Value: 30 * 60,
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_OS_TEMPLATE",
Name: "xenserver-os-template",
Usage: "XenServer OS Template Label Name",
EnvVar: "XCP_OS_TEMPLATE",
Name: "xcp-os-template",
Usage: "XCP OS Template Label Name",
Value: "Other install media",
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_OS_USERNAME",
Name: "xenserver-os-username",
Usage: "XenServer Username used to SSH into guest OS",
EnvVar: "XCP_OS_USERNAME",
Name: "xcp-os-username",
Usage: "XCP Username used to SSH into guest OS",
Value: B2D_USER,
},
mcnflag.BoolFlag{
EnvVar: "XENSERVER_COREOS_CONFIGDRIVE",
Name: "xenserver-coreos-configdrive",
Usage: "XenServer Enable CoreOS specific ConfigDrive (requires xscontainer supplemental pack)",
EnvVar: "XCP_COREOS_CONFIGDRIVE",
Name: "xcp-coreos-configdrive",
Usage: "XCP Enable CoreOS specific ConfigDrive (requires xscontainer supplemental pack)",
},
}
}
@ -179,31 +179,31 @@ func (d *Driver) GetSSHUsername() string {
}
func (d *Driver) DriverName() string {
return "xenserver"
return "xcp"
}
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.Server = flags.String("xenserver-server")
d.Username = flags.String("xenserver-username")
d.Password = flags.String("xenserver-password")
d.Boot2DockerURL = flags.String("xenserver-boot2docker-url")
d.CPU = uint(flags.Int("xenserver-vcpu-count"))
d.Memory = uint(flags.Int("xenserver-memory-size"))
d.DiskSize = uint(flags.Int("xenserver-disk-size"))
d.SR = flags.String("xenserver-sr-label")
d.Network = flags.String("xenserver-network-label")
d.Host = flags.String("xenserver-host-label")
d.UploadTimeout = uint(flags.Int("xenserver-upload-timeout"))
d.WaitTimeout = uint(flags.Int("xenserver-wait-timeout"))
d.Server = flags.String("xcp-server")
d.Username = flags.String("xcp-username")
d.Password = flags.String("xcp-password")
d.Boot2DockerURL = flags.String("xcp-boot2docker-url")
d.CPU = uint(flags.Int("xcp-vcpu-count"))
d.Memory = uint(flags.Int("xcp-memory-size"))
d.DiskSize = uint(flags.Int("xcp-disk-size"))
d.SR = flags.String("xcp-sr-label")
d.Network = flags.String("xcp-network-label")
d.Host = flags.String("xcp-host-label")
d.UploadTimeout = uint(flags.Int("xcp-upload-timeout"))
d.WaitTimeout = uint(flags.Int("xcp-wait-timeout"))
d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
d.ISO = d.ResolveStorePath(isoFilename)
d.TAR = d.ResolveStorePath(tarFilename)
d.osTemplateLabelName = flags.String("xenserver-os-template")
d.CoreosConfigDrive = flags.Bool("xenserver-coreos-configdrive")
d.osTemplateLabelName = flags.String("xcp-os-template")
d.CoreosConfigDrive = flags.Bool("xcp-coreos-configdrive")
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
var sr *xsclient.SR
var isoVdiUuid,diskVdiUuid string
var isoVdiUuid, diskVdiUuid string
// Get the SR
if d.SR == "" {
@ -351,7 +351,7 @@ func (d *Driver) Create() error {
if sr.Ref == "OpaqueRef:NULL" {
err := errors.New("No default SR found. Please configure a " +
"default or specify the SR explicitly using " +
"--xenserver-sr-label.")
"--xcp-sr-label.")
log.Errorf("%v", err)
return err
}
@ -522,7 +522,7 @@ func (d *Driver) Create() error {
if err != nil {
return err
}
srUuid,err := sr.GetUuid()
srUuid, err := sr.GetUuid()
if err != nil {
return err
}
@ -906,7 +906,7 @@ func (d *Driver) importVdi(vdi *xsclient.VDI, filename string, timeout time.Dura
if resp.StatusCode != 200 {
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)
return err
}
@ -1005,7 +1005,7 @@ ssh_authorized_keys:
args["vmuuid"] = vmuuid
args["sruuid"] = sruuid
args["configuration"] = userdatatext
ahost.CallPlugin("xscontainer","create_config_drive",args)
ahost.CallPlugin("xscontainer", "create_config_drive", args)
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 (
"crypto/tls"
Loading…
Cancel
Save