1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

F #6586: Remove docker-machine add-on

This commit is contained in:
Ruben S. Montero 2024-05-21 12:47:36 +02:00
parent 0f248706de
commit eda3084beb
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
9 changed files with 0 additions and 1168 deletions

View File

@ -143,7 +143,6 @@ vars.Add('new_xmlrpc', 'Use xmlrpc-c version >=1.31', 'no')
vars.Add('sunstone', 'Build Sunstone', 'no')
vars.Add('fireedge', 'Build FireEdge', 'no')
vars.Add('systemd', 'Build with systemd support', 'no')
vars.Add('docker_machine', 'Build Docker machine driver', 'no')
vars.Add('rubygems', 'Generate Ruby gems', 'no')
vars.Add('svncterm', 'Build VNC support for LXD drivers', 'yes')
vars.Add('context', 'Download guest contextualization packages', 'no')
@ -242,9 +241,6 @@ main_env.Append(fireedge=ARGUMENTS.get('fireedge', 'no'))
# Onedb Marshal files generation
main_env.Append(marshal=ARGUMENTS.get('marshal', 'no'))
# Docker-machine addon generation
main_env.Append(docker_machine=ARGUMENTS.get('docker_machine', 'no'))
# Context packages download
main_env.Append(context=ARGUMENTS.get('context', 'no'))
@ -349,7 +345,6 @@ build_scripts = [
'src/fireedge/SConstruct',
'share/rubygems/SConstruct',
'src/client/SConstruct',
'src/docker_machine/SConstruct',
'src/monitor/SConstruct',
'src/onedb/SConstruct',
'src/protocol/SConstruct',

View File

@ -51,7 +51,6 @@ usage() {
echo "-r: remove Opennebula, only useful if -d was not specified, otherwise"
echo " rm -rf \$ONE_LOCATION would do the job"
echo "-l: creates symlinks instead of copying files, useful for development"
echo "-e: install OpenNebula docker machine driver"
echo "-h: prints this help"
}
#-------------------------------------------------------------------------------
@ -72,11 +71,9 @@ ONEFLOW="no"
ONEADMIN_USER=`id -u`
ONEADMIN_GROUP=`id -g`
SRC_DIR=$PWD
DOCKER_MACHINE="no"
while getopts $PARAMETERS opt; do
case $opt in
e) DOCKER_MACHINE="yes" ;;
h) usage; exit 0;;
k) INSTALL_ETC="no" ;;
r) UNINSTALL="yes" ;;
@ -127,7 +124,6 @@ if [ -z "$ROOT" ] ; then
VM_LOCATION="/var/lib/one/vms"
DOCS_LOCATION="/usr/share/doc/one"
SUNSTONE_MAIN_JS_LOCATION="$VAR_LOCATION/sunstone"
DOCKER_MACHINE_LOCATION="src/docker_machine/src/docker_machine/bin/docker-machine-driver-opennebula"
if [ "$CLIENT" = "yes" ]; then
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION"
@ -169,12 +165,6 @@ if [ -z "$ROOT" ] ; then
DELETE_DIRS="$MAKE_DIRS"
CHOWN_DIRS=""
elif [ "$DOCKER_MACHINE" = "yes" ]; then
MAKE_DIRS="$BIN_LOCATION"
DELETE_DIRS="$MAKE_DIRS"
CHOWN_DIRS=""
else
MAKE_DIRS="$BIN_LOCATION $SBIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \
@ -212,7 +202,6 @@ else
VM_LOCATION="$VAR_LOCATION/vms"
DOCS_LOCATION="$ROOT/share/doc"
SUNSTONE_MAIN_JS_LOCATION="$VAR_LOCATION/sunstone"
DOCKER_MACHINE_LOCATION="src/docker_machine/src/docker_machine/bin/docker-machine-driver-opennebula"
if [ "$CLIENT" = "yes" ]; then
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION"
@ -242,10 +231,6 @@ else
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $VAR_LOCATION $ONEFLOW_LOCATION \
$ETC_LOCATION"
DELETE_DIRS="$MAKE_DIRS"
elif [ "$DOCKER_MACHINE" = "yes" ]; then
MAKE_DIRS="$BIN_LOCATION"
DELETE_DIRS="$MAKE_DIRS"
else
MAKE_DIRS="$BIN_LOCATION $SBIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \
@ -974,10 +959,6 @@ INSTALL_ONEHEM_ETC_FILES=(
ONEHEM_ETC_FILES:$ETC_LOCATION
)
INSTALL_DOCKER_MACHINE_FILES=(
DOCKER_MACHINE_BIN_FILES:$BIN_LOCATION
)
INSTALL_ETC_FILES=(
ETC_FILES:$ETC_LOCATION
ETC_FILES:$SHARE_LOCATION/conf
@ -3132,12 +3113,6 @@ DOCKERFILES_TEMPLATES="src/datastore_mad/remotes/dockerhub/dockerfiles/alpine \
DOCKERFILE_TEMPLATE="src/datastore_mad/remotes/dockerhub/dockerfile"
#-----------------------------------------------------------------------------
# Docker Machine files
#-----------------------------------------------------------------------------
DOCKER_MACHINE_BIN_FILES="src/docker_machine/src/docker_machine/bin/docker-machine-driver-opennebula"
#-----------------------------------------------------------------------------
# SSH files
#-----------------------------------------------------------------------------
@ -3324,8 +3299,6 @@ elif [ "$FIREEDGE" = "yes" ]; then
fi
elif [ "$ONEFLOW" = "yes" ]; then
INSTALL_SET="${INSTALL_ONEFLOW_FILES[@]}"
elif [ "$DOCKER_MACHINE" = "yes" ]; then
INSTALL_SET="${INSTALL_DOCKER_MACHINE_FILES[@]}"
elif [ "$SUNSTONE_DEV" = "no" ]; then
INSTALL_SET="${INSTALL_FILES[@]} \
${INSTALL_SUNSTONE_FILES[@]} ${INSTALL_SUNSTONE_PUBLIC_MINIFIED_FILES[@]}\

View File

@ -1,29 +0,0 @@
# SConstruct for share/scripts/rubygems
# -------------------------------------------------------------------------- #
# Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
import os
Import('env')
if env['docker_machine']=='yes':
print ("Generating docker-machine-driver-opennebula\n")
exit_code=os.system("make -C src/docker_machine build")
if exit_code != 0:
print ("Error generating docker-machine-driver-opennebula\n")
exit(-1)

View File

@ -1,181 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
digest = "1:6da51e5ec493ad2b44cb04129e2d0a068c8fb9bd6cb5739d199573558696bb94"
name = "github.com/Azure/go-ansiterm"
packages = [
".",
"winterm",
]
pruneopts = "T"
revision = "d6e3b3328b783f23731bc4d058875b0371ff8109"
[[projects]]
branch = "master"
digest = "1:159c6f296acc53e6aa6892335c9105fd7956de28940a0035365fad48f75748f9"
name = "github.com/OpenNebula/one"
packages = [
"src/oca/go/src/goca",
"src/oca/go/src/goca/dynamic",
"src/oca/go/src/goca/errors",
"src/oca/go/src/goca/parameters",
"src/oca/go/src/goca/schemas/acl",
"src/oca/go/src/goca/schemas/cluster",
"src/oca/go/src/goca/schemas/cluster/keys",
"src/oca/go/src/goca/schemas/datastore",
"src/oca/go/src/goca/schemas/datastore/keys",
"src/oca/go/src/goca/schemas/document",
"src/oca/go/src/goca/schemas/group",
"src/oca/go/src/goca/schemas/hook",
"src/oca/go/src/goca/schemas/hook/keys",
"src/oca/go/src/goca/schemas/host",
"src/oca/go/src/goca/schemas/host/keys",
"src/oca/go/src/goca/schemas/image",
"src/oca/go/src/goca/schemas/image/keys",
"src/oca/go/src/goca/schemas/marketplace",
"src/oca/go/src/goca/schemas/marketplace/keys",
"src/oca/go/src/goca/schemas/marketplaceapp",
"src/oca/go/src/goca/schemas/marketplaceapp/keys",
"src/oca/go/src/goca/schemas/securitygroup",
"src/oca/go/src/goca/schemas/securitygroup/keys",
"src/oca/go/src/goca/schemas/service",
"src/oca/go/src/goca/schemas/service_template",
"src/oca/go/src/goca/schemas/shared",
"src/oca/go/src/goca/schemas/template",
"src/oca/go/src/goca/schemas/user",
"src/oca/go/src/goca/schemas/vdc",
"src/oca/go/src/goca/schemas/virtualnetwork",
"src/oca/go/src/goca/schemas/virtualnetwork/keys",
"src/oca/go/src/goca/schemas/virtualrouter",
"src/oca/go/src/goca/schemas/virtualrouter/keys",
"src/oca/go/src/goca/schemas/vm",
"src/oca/go/src/goca/schemas/vm/keys",
"src/oca/go/src/goca/schemas/vmgroup",
"src/oca/go/src/goca/schemas/vntemplate",
"src/oca/go/src/goca/schemas/zone",
]
pruneopts = "T"
revision = "master"
[[projects]]
branch = "master"
digest = "1:68a65f52f6ccdea4f1478fe78c81c335839c65f2d8eb314f1146dcfb6986df99"
name = "github.com/docker/docker"
packages = [
"pkg/term",
"pkg/term/windows",
]
pruneopts = "T"
revision = "0c1006f1abc1af7aa6b9847754370d054dfa6c68"
[[projects]]
digest = "1:1e6be0a7617caffa7850e097c9ba53192b8bce152b27c8f3cbcbd093657106fb"
name = "github.com/docker/machine"
packages = [
"libmachine/drivers",
"libmachine/drivers/plugin",
"libmachine/drivers/plugin/localbinary",
"libmachine/drivers/rpc",
"libmachine/log",
"libmachine/mcnflag",
"libmachine/mcnutils",
"libmachine/ssh",
"libmachine/state",
"libmachine/version",
"version",
]
pruneopts = "T"
revision = "89b833253d9412716a0291cbdccc94454c33d1b5"
version = "v0.14.0"
[[projects]]
digest = "1:af105c7c5dc0b4ae41991f122cae860b9600f7d226072c2a83127048c991660c"
name = "github.com/hashicorp/go-cleanhttp"
packages = ["."]
pruneopts = "T"
revision = "eda1e5db218aad1db63ca4642c8906b26bcf2744"
version = "v0.5.1"
[[projects]]
branch = "master"
digest = "1:07c2b6d639ff6288a4c1ee3f8525d8330571588464a22e3173e6f26dc6f1278c"
name = "github.com/kolo/xmlrpc"
packages = ["."]
pruneopts = "T"
revision = "07c4ee3fd1817e1a90254d5b80f215b36b78f800"
[[projects]]
digest = "1:047075087eff9bcda0806c636c479fae29b9ae55da320d3d961eb5d3203e2a75"
name = "github.com/sirupsen/logrus"
packages = ["."]
pruneopts = "T"
revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc"
version = "v1.0.5"
[[projects]]
branch = "master"
digest = "1:159dcb22f15495dfd14932f0a33fee345213c9e9f4d03e6766ce0b9a9daf90aa"
name = "golang.org/x/crypto"
packages = [
"curve25519",
"ed25519",
"ed25519/internal/edwards25519",
"internal/chacha20",
"poly1305",
"ssh",
"ssh/terminal",
]
pruneopts = "T"
revision = "c3a3ad6d03f7a915c0f7e194b7152974bb73d287"
[[projects]]
branch = "master"
digest = "1:8b8bf3935095819181d708503da0b18cf006c9bcee116ad918d993f6a927616f"
name = "golang.org/x/net"
packages = [
"html",
"html/atom",
]
pruneopts = "T"
revision = "6078986fec03a1dcc236c34816c71b0e05018fda"
[[projects]]
branch = "master"
digest = "1:fe307d6b5a21c03664df0421fc56516b2ed11138d4af4646dced7618267e7c36"
name = "golang.org/x/sys"
packages = [
"unix",
"windows",
]
pruneopts = "T"
revision = "7ceb54c8418b8f9cdf0177b511d5cbb06e9fae39"
[[projects]]
branch = "v2"
digest = "1:2a678d87732dac72785bc884cc4f7177655c54fe759d559140d665705edbf9fa"
name = "gopkg.in/xmlpath.v2"
packages = ["."]
pruneopts = "T"
revision = "860cbeca3ebcc600db0b213c0e83ad6ce91f5739"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"github.com/OpenNebula/one/src/oca/go/src/goca",
"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/shared",
"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/vm",
"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/vm/keys",
"github.com/docker/machine/libmachine/drivers",
"github.com/docker/machine/libmachine/drivers/plugin",
"github.com/docker/machine/libmachine/log",
"github.com/docker/machine/libmachine/mcnflag",
"github.com/docker/machine/libmachine/ssh",
"github.com/docker/machine/libmachine/state",
"github.com/kolo/xmlrpc",
"gopkg.in/xmlpath.v2",
]
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -1,46 +0,0 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
required = ["github.com/kolo/xmlrpc", "gopkg.in/xmlpath.v2"]
[[constraint]]
name = "github.com/OpenNebula/one"
branch = "master"
[[constraint]]
name = "github.com/docker/machine"
version = "0.14.0"
[[constraint]]
branch = "master"
name = "github.com/kolo/xmlrpc"
[[constraint]]
branch = "v2"
name = "gopkg.in/xmlpath.v2"
[prune]
go-tests = true

View File

@ -1,40 +0,0 @@
SHELL := /bin/bash
BUILD_ID := $(shell head -c20 /dev/urandom|od -An -tx1|tr -d ' \n')
REPO_ROOT ?= $(shell realpath ../../../../)
GOCA_PATH ?= ${REPO_ROOT}/src/oca/go
GOPATH_REPO ?= ${REPO_ROOT}/src/docker_machine
USE_LOCAL_GOCA ?= yes
TARGET_ARCHS ?= amd64 arm64
ifeq ($(GOPATH),)
GOPATH := $(GOPATH_REPO)
else
GOPATH := $(GOPATH):$(GOPATH_REPO)
endif
.PHONY: clean build
build: \
bin/docker-machine-driver-opennebula \
$(patsubst %, bin/docker-machine-driver-opennebula.%, $(TARGET_ARCHS))
# driver without suffix is always default x86-64 (for backward compatibility)
bin/docker-machine-driver-opennebula: bin/docker-machine-driver-opennebula.amd64
cp -f $< $@
# architecture dependent builds
bin/docker-machine-driver-opennebula.%: vendor
GOPATH=$(GOPATH) GOARCH=${*} go build -ldflags "-B 0x$(BUILD_ID)" -o "$@" ./bin
vendor:
rm -rf vendor/
GOPATH=$(GOPATH) dep ensure
ifeq ($(USE_LOCAL_GOCA),yes)
set -e; trap 'rm -rf vendor/' ERR; \
rm -rf vendor/github.com/OpenNebula/one; \
ln -s ${REPO_ROOT} vendor/github.com/OpenNebula/one
endif
clean:
-rm -rf vendor/ bin/docker-machine-driver-opennebula*

View File

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

View File

@ -1,829 +0,0 @@
package opennebula
import (
"errors"
"fmt"
"io/ioutil"
"net"
"strconv"
"time"
"github.com/OpenNebula/one/src/oca/go/src/goca"
"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/shared"
shared_schemas "github.com/OpenNebula/one/src/oca/go/src/goca/schemas/shared"
vm_schemas "github.com/OpenNebula/one/src/oca/go/src/goca/schemas/vm"
"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/vm/keys"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
)
type Driver struct {
*drivers.BaseDriver
TemplateName string
TemplateID string
NetworkName string
NetworkOwner string
NetworkID string
ImageName string
ImageOwner string
ImageID string
CPU string
VCPU string
Memory string
DiskSize string
ImageDevPrefix string
B2DSize string
User string
Password string
Xmlrpcurl string
Config goca.OneConfig
DisableVNC bool
StartRetries string
MachineId int
}
const (
defaultSSHUser = "docker"
defaultCPU = "1"
defaultVCPU = "1"
defaultMemory = "1024"
defaultStartRetries = "600"
// This is the contextualization script that will be executed by OpenNebula
contextScript = `#!/bin/sh
if [ -f /etc/boot2docker ]; then
USERNAME=docker
USER_HOME=/home/docker
else
USERNAME=$DOCKER_SSH_USER
GROUPNAME=$DOCKER_SSH_USER
if ! getent group $GROUPNAME; then
groupadd $GROUPNAME
fi
if ! getent passwd $USERNAME; then
USER_HOME=/var/lib/$DOCKER_SSH_USER
useradd -m -d $USER_HOME -g $USERNAME $GROUPNAME
else
USER_HOME=$(getent passwd $USERNAME | cut -d: -f 6)
fi
# Write sudoers
if [ ! -f /etc/sudoers.d/$USERNAME ]; then
echo -n "Defaults:$USERNAME " >> /etc/sudoers.d/$USERNAME
echo '!requiretty' >> /etc/sudoers.d/$USERNAME
echo "$USERNAME ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/$USERNAME
fi
fi
# Add DOCKER_SSH_PUBLIC_KEY
AUTH_DIR="${USER_HOME}/.ssh"
AUTH_FILE="${AUTH_DIR}/authorized_keys"
mkdir -m0700 -p $AUTH_DIR
echo "$DOCKER_SSH_PUBLIC_KEY" >> $AUTH_FILE
chown "${USERNAME}": ${AUTH_DIR} ${AUTH_FILE}
chmod 600 $AUTH_FILE`
)
func NewDriver(hostName, storePath string) *Driver {
return &Driver{
BaseDriver: &drivers.BaseDriver{
SSHUser: defaultSSHUser,
MachineName: hostName,
StorePath: storePath,
},
}
}
func (d *Driver) buildConfig() {
d.Config = goca.NewConfig(d.User, d.Password, d.Xmlrpcurl)
}
func (d *Driver) getController() *goca.Controller {
d.buildConfig()
client := goca.NewDefaultClient(d.Config)
return goca.NewController(client)
}
// GetCreateFlags registers the flags this driver adds to
// "docker hosts create"
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{
mcnflag.StringFlag{
Name: "opennebula-cpu",
Usage: fmt.Sprintf("CPU value for the VM. Default: %d", defaultCPU),
EnvVar: "ONE_CPU",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-vcpu",
Usage: fmt.Sprintf("VCPUs for the VM. Default: %d", defaultVCPU),
EnvVar: "ONE_VCPU",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-memory",
Usage: fmt.Sprintf("Size of memory for VM in MB. Default: %d", defaultMemory),
EnvVar: "ONE_MEMORY",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-template-name",
Usage: "Template to use",
EnvVar: "ONE_TEMPLATE_NAME",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-template-id",
Usage: "Template ID to use",
EnvVar: "ONE_TEMPLATE_ID",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-network-name",
Usage: "Network to connect the machine to",
EnvVar: "ONE_NETWORK_NAME",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-network-id",
Usage: "Network ID to connect the machine to",
EnvVar: "ONE_NETWORK_ID",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-network-owner",
Usage: "User ID of the Network to connect the machine to",
EnvVar: "ONE_NETWORK_OWNER",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-image-name",
Usage: "Image to use as the OS",
EnvVar: "ONE_IMAGE_NAME",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-image-id",
Usage: "Image ID to use as the OS",
EnvVar: "ONE_IMAGE_ID",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-image-owner",
Usage: "Owner of the image to use as the OS",
EnvVar: "ONE_IMAGE_OWNER",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-dev-prefix",
Usage: "Dev prefix to use for the images: 'vd', 'sd', 'hd', etc..",
EnvVar: "ONE_IMAGE_DEV_PREFIX",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-disk-resize",
Usage: "Size of disk for VM in MB",
EnvVar: "ONE_DISK_SIZE",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-b2d-size",
Usage: "Size of the Volatile disk in MB (only for b2d)",
EnvVar: "ONE_B2D_DATA_SIZE",
Value: "",
},
mcnflag.StringFlag{
Name: "opennebula-ssh-user",
Usage: "Set the name of the SSH user",
EnvVar: "ONE_SSH_USER",
Value: defaultSSHUser,
},
mcnflag.BoolFlag{
Name: "opennebula-disable-vnc",
Usage: "VNC is enabled by default. Disable it with this flag",
EnvVar: "ONE_DISABLE_VNC",
},
mcnflag.StringFlag{
Name: "opennebula-user",
Usage: "Set the user for authentication",
EnvVar: "ONE_USER",
},
mcnflag.StringFlag{
Name: "opennebula-password",
Usage: "Set the password for authentication",
EnvVar: "ONE_PASSWORD",
},
mcnflag.StringFlag{
Name: "opennebula-xmlrpcurl",
Usage: "Set the url for one xmlrpc server",
EnvVar: "ONE_XMLRPC",
},
mcnflag.StringFlag{
Name: "opennebula-start-retries",
Usage: "Set the number of retries until de vm is running",
EnvVar: "ONE_START_RETRIES",
Value: defaultStartRetries,
},
}
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SetSwarmConfigFromFlags(flags)
// Authentication
d.User = flags.String("opennebula-user")
d.Password = flags.String("opennebula-password")
d.Xmlrpcurl = flags.String("opennebula-xmlrpcurl")
// Capacity
d.CPU = flags.String("opennebula-cpu")
d.VCPU = flags.String("opennebula-vcpu")
d.Memory = flags.String("opennebula-memory")
// Template
d.TemplateName = flags.String("opennebula-template-name")
d.TemplateID = flags.String("opennebula-template-id")
// Network
d.NetworkName = flags.String("opennebula-network-name")
d.NetworkID = flags.String("opennebula-network-id")
d.NetworkOwner = flags.String("opennebula-network-owner")
// Storage
d.ImageID = flags.String("opennebula-image-id")
d.ImageName = flags.String("opennebula-image-name")
d.ImageOwner = flags.String("opennebula-image-owner")
d.ImageDevPrefix = flags.String("opennebula-dev-prefix")
d.DiskSize = flags.String("opennebula-disk-resize")
d.B2DSize = flags.String("opennebula-b2d-size")
// Provision
d.SSHUser = flags.String("opennebula-ssh-user")
// VNC
d.DisableVNC = flags.Bool("opennebula-disable-vnc")
// CONFIG
d.StartRetries = flags.String("opennebula-start-retries")
// Either TemplateName or TemplateID
if d.TemplateName != "" && d.TemplateID != "" {
return errors.New("specify only one of: --opennebula-template-name or --opennebula-template-id, not both")
}
// Either NetworkName or NetworkID
if d.NetworkName != "" && d.NetworkID != "" {
return errors.New("specify only one of: --opennebula-network-name or --opennebula-network-id, not both")
}
// Either ImageName or ImageID
if d.ImageName != "" && d.ImageID != "" {
return errors.New("specify only one of: --opennebula-image-name or --opennebula-image-id, not both")
}
// Required and incompatible options for Template
if d.TemplateName != "" || d.TemplateID != "" {
// Template has been specified:
// ImageName and ImageID are incompatible
if d.ImageName != "" || d.ImageID != "" {
return errors.New("options --opennebula-image-* are incompatible with --opennebula-template-*")
}
// ImageDevPrefix is incompatible
if d.ImageDevPrefix != "" {
return errors.New("option: --opennebula-dev-prefix is incompatible with --opennebula-template-*")
}
// DiskSize is incompatible
if d.DiskSize != "" {
return errors.New("option: --opennebula-disk-resize is incompatible with --opennebula-template-*")
}
// B2DSize is incompatible
if d.B2DSize != "" {
return errors.New("option: --opennebula-disk-resize is incompatible with --opennebula-template-*")
}
// DisableVNC is incompatible
if d.DisableVNC {
return errors.New("option: --opennebula-disable-vnc is incompatible with --opennebula-template-*")
}
} else {
//Template has NOT been specified:
// ImageName or ImageID is required
if d.ImageName == "" && d.ImageID == "" {
return errors.New("specify a image to use as the OS with --opennebula-image-name or --opennebula-image-id")
}
// NetworkName or NetworkID is required
if d.NetworkName == "" && d.NetworkID == "" {
return errors.New("specify a network to connect to with --opennebula-network-name or --opennebula-network-id")
}
// Assign default capacity values
if d.CPU == "" {
d.CPU = defaultCPU
}
if d.VCPU == "" {
d.VCPU = defaultVCPU
}
if d.Memory == "" {
d.Memory = defaultMemory
}
}
return nil
}
func (d *Driver) DriverName() string {
return "opennebula"
}
func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP()
}
func (d *Driver) Create() error {
var err error
var instanceID = -1
// build config and set the xmlrpc client
controller := d.getController()
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
// Create template
template := vm_schemas.NewTemplate()
if d.TemplateName != "" || d.TemplateID != "" {
// Template has been specified
} else {
// Template has NOT been specified
template.Add(keys.Name, d.MachineName)
// OS Boot
template.AddOS(keys.Boot, "disk0")
// OS Disk
disk := template.AddDisk()
if d.ImageID != "" {
disk.Add(shared.ImageID, d.ImageID)
} else {
disk.Add(shared.Image, d.ImageName)
if d.ImageOwner != "" {
disk.Add(shared.ImageUname, d.ImageOwner)
}
}
if d.DiskSize != "" {
disk.Add(shared.Size, d.DiskSize)
}
if d.ImageDevPrefix != "" {
disk.Add(shared.DevPrefix, d.ImageDevPrefix)
}
// Add a volatile disk for b2d
if d.B2DSize != "" {
vdisk := template.AddDisk()
vdisk.Add(shared.Size, d.B2DSize)
vdisk.Add("TYPE", "fs")
vdisk.Add("FORMAT", "raw")
}
// VNC
if !d.DisableVNC {
template.AddIOGraphic(keys.Listen, "0.0.0.0")
template.AddIOGraphic(keys.GraphicType, "vnc")
}
}
// Capacity
if d.CPU != "" {
cpu, _ := strconv.ParseFloat(d.CPU, 64)
template.CPU(cpu)
}
if d.Memory != "" {
memory, _ := strconv.Atoi(d.Memory)
template.Memory(memory)
}
if d.VCPU != "" {
vcpu, _ := strconv.Atoi(d.VCPU)
template.VCPU(vcpu)
}
// Network
if d.NetworkName != "" || d.NetworkID != "" {
nic := template.AddNIC()
if d.NetworkName != "" {
nic.Add(shared.Network, d.NetworkName)
if d.NetworkOwner != "" {
nic.Add(shared.NetworkUName, d.NetworkOwner)
}
}
if d.NetworkID != "" {
nic.Add(shared.NetworkID, d.NetworkID)
}
}
// Context
template.AddCtx(keys.NetworkCtx, "YES")
template.AddCtx(keys.SSHPubKey, "$USER[SSH_PUBLIC_KEY]")
template.AddCtx("DOCKER_SSH_USER", d.SSHUser)
template.AddCtx("DOCKER_SSH_PUBLIC_KEY", string(pubKey))
template.AddB64Ctx(keys.StartScriptB64, contextScript)
// Instantiate
log.Infof("Starting VM...")
// Template has been specified
if d.TemplateName != "" || d.TemplateID != "" {
var templateID int
if d.TemplateName != "" {
templateID, err = controller.Templates().ByName(d.TemplateName)
if err != nil {
return err
}
} else {
templateID, err = strconv.Atoi(d.TemplateID)
if err != nil {
return err
}
}
vmtemplate := controller.Template(templateID)
instanceID, err = vmtemplate.Instantiate(d.MachineName, false, template.String(), false)
} else {
instanceID, err = controller.VMs().Create(template.String(), false)
}
if err != nil {
return err
}
d.MachineId = instanceID
return d.Start()
}
func (d *Driver) GetURL() (string, error) {
if err := drivers.MustBeRunning(d); err != nil {
return "", err
}
ip, err := d.GetIP()
if err != nil {
return "", err
}
if ip == "" {
return "", nil
}
return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil
}
func (d *Driver) GetIP() (string, error) {
if d.IPAddress != "" {
return d.IPAddress, nil
}
log.Debug("Looking for the IP address...")
controller := d.getController()
var err2 error
var vmId int
if d.MachineId == 0 {
vmId, err2 = controller.VMs().ByName(d.MachineName)
if err2 != nil {
return "", err2
}
d.MachineId = vmId
}
vm, err := controller.VM(d.MachineId).Info(false)
if err != nil {
return "", err
}
if len(vm.Template.GetNICs()) > 0 {
// check first for External IP
ip, err := vm.Template.GetNICs()[0].Get(shared_schemas.ExternalIP)
if err == nil && ip != "" {
d.IPAddress = ip
} else {
// check for IP (if External IP is not defined)
ip, err = vm.Template.GetNICs()[0].Get(shared_schemas.IP)
if err == nil && ip != "" {
d.IPAddress = ip
}
}
}
if d.IPAddress == "" {
return "", fmt.Errorf("IP address is not set")
}
return d.IPAddress, nil
}
func (d *Driver) GetState() (state.State, error) {
controller := d.getController()
var err2 error
var vmId int
if d.MachineId == 0 {
vmId, err2 = controller.VMs().ByName(d.MachineName)
if err2 != nil {
return state.None, err2
}
d.MachineId = vmId
}
vm, err := controller.VM(d.MachineId).Info(false)
if err != nil {
return state.None, err
}
vmState, lcmState, err := vm.StateString()
if err != nil {
return state.None, err
}
switch vmState {
case "INIT", "PENDING", "HOLD", "CLONING":
return state.Starting, nil
case "ACTIVE":
switch lcmState {
case "RUNNING",
// migration is considered running
"MIGRATE",
"SAVE_MIGRATE",
"PROLOG_MIGRATE",
"BOOT_MIGRATE",
// recover --recreate is also considered running
"CLEANUP_RESUBMIT",
// operation on the VMs
"HOTPLUG",
"HOTPLUG_SNAPSHOT",
"HOTPLUG_NIC",
"HOTPLUG_SAVEAS",
"DISK_SNAPSHOT",
"DISK_SNAPSHOT_DELETE",
"HOTPLUG_RESIZE":
return state.Running, nil
case "LCM_INIT",
"PROLOG",
"BOOT",
"PROLOG_RESUME",
"BOOT_UNKNOWN",
"BOOT_POWEROFF",
"BOOT_SUSPENDED",
"BOOT_STOPPED",
"PROLOG_UNDEPLOY",
"BOOT_UNDEPLOY",
"PROLOG_MIGRATE_UNKNOWN":
return state.Starting, nil
case "HOTPLUG_SAVEAS_POWEROFF",
"HOTPLUG_SAVEAS_SUSPENDED",
"HOTPLUG_SAVEAS_UNDEPLOYED",
"HOTPLUG_SAVEAS_STOPPED",
"HOTPLUG_PROLOG_POWEROFF",
"HOTPLUG_EPILOG_POWEROFF",
"HOTPLUG_NIC_POWEROFF",
"PROLOG_MIGRATE_POWEROFF",
"PROLOG_MIGRATE_SUSPEND",
"DISK_SNAPSHOT_POWEROFF",
"DISK_SNAPSHOT_REVERT_POWEROFF",
"DISK_SNAPSHOT_DELETE_POWEROFF",
"DISK_SNAPSHOT_SUSPENDED",
"DISK_SNAPSHOT_REVERT_SUSPENDED",
"DISK_SNAPSHOT_DELETE_SUSPENDED":
return state.Stopped, nil
case "SAVE_SUSPEND",
"SAVE_STOP",
"EPILOG_STOP",
"EPILOG",
"SHUTDOWN",
"SHUTDOWN_POWEROFF",
"SHUTDOWN_UNDEPLOY",
"EPILOG_UNDEPLOY":
return state.Stopping, nil
case "UNKNOWN",
"CLEANUP_DELETE",
"BOOT_FAILURE",
"BOOT_MIGRATE_FAILURE",
"PROLOG_MIGRATE_FAILURE",
"PROLOG_FAILURE",
"EPILOG_FAILURE",
"EPILOG_STOP_FAILURE",
"EPILOG_UNDEPLOY_FAILURE",
"PROLOG_MIGRATE_POWEROFF_FAILURE",
"PROLOG_MIGRATE_SUSPEND_FAILURE",
"BOOT_UNDEPLOY_FAILURE",
"BOOT_STOPPED_FAILURE",
"PROLOG_RESUME_FAILURE",
"PROLOG_UNDEPLOY_FAILURE",
"PROLOG_MIGRATE_UNKNOWN_FAILURE":
return state.Error, nil
}
case "POWEROFF", "UNDEPLOYED":
return state.Stopped, nil
case "STOPPED", "SUSPENDED":
return state.Saved, nil
case "DONE", "FAILED", "CLONING_FAILURE":
return state.Error, nil
}
return state.Error, nil
}
func (d *Driver) Start() error {
var err error
if drivers.MachineInState(d, state.Stopped)() {
controller := d.getController()
var vmId int
if d.MachineId == 0 {
vmId, err = controller.VMs().ByName(d.MachineName)
if err != nil {
return err
}
d.MachineId = vmId
}
vm := controller.VM(d.MachineId)
vm.Resume()
}
s := state.None
retries, _ := strconv.Atoi(d.StartRetries)
for retry := 0; retry < retries && s != state.Running; retry++ {
s, err = d.GetState()
if err != nil {
return err
}
switch s {
case state.Error:
return errors.New("VM in error state")
default:
time.Sleep(2 * time.Second)
}
}
if d.IPAddress == "" {
if d.IPAddress, err = d.GetIP(); err != nil {
return err
}
}
log.Infof("Waiting for SSH...")
// Wait for SSH over NAT to be available before returning to user
return drivers.WaitForSSH(d)
}
func (d *Driver) Stop() error {
controller := d.getController()
var err2 error
var vmId int
if d.MachineId == 0 {
vmId, err2 = controller.VMs().ByName(d.MachineName)
if err2 != nil {
return err2
}
d.MachineId = vmId
}
vm := controller.VM(d.MachineId)
err := vm.Poweroff()
if err != nil {
return err
}
return nil
}
func (d *Driver) Remove() error {
controller := d.getController()
var err2 error
var vmId int
if d.MachineId == 0 {
vmId, err2 = controller.VMs().ByName(d.MachineName)
if err2 != nil {
return err2
}
d.MachineId = vmId
}
vm := controller.VM(d.MachineId)
err := vm.TerminateHard()
if err != nil {
return err
}
return nil
}
func (d *Driver) Restart() error {
controller := d.getController()
var err2 error
var vmId int
if d.MachineId == 0 {
vmId, err2 = controller.VMs().ByName(d.MachineName)
if err2 != nil {
return err2
}
d.MachineId = vmId
}
vm := controller.VM(d.MachineId)
err := vm.Reboot()
if err != nil {
return err
}
return nil
}
func (d *Driver) Kill() error {
controller := d.getController()
var err2 error
var vmId int
if d.MachineId == 0 {
vmId, err2 = controller.VMs().ByName(d.MachineName)
if err2 != nil {
return err2
}
d.MachineId = vmId
}
vm := controller.VM(d.MachineId)
err := vm.PoweroffHard()
if err != nil {
return err
}
return nil
}
func (d *Driver) publicSSHKeyPath() string {
return d.GetSSHKeyPath() + ".pub"
}

View File

@ -1 +0,0 @@
package opennebula