Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Kvm support (#3)
Browse files Browse the repository at this point in the history
* Add support for KVM platform
* Bump version and update README and command help
* Update changelog with kvm-support and release 1.1.0
  • Loading branch information
larsdunemark authored May 11, 2020
1 parent 7aebcf2 commit 85ea453
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.1.0] - 2020-05-11
### Added
- Support for KVM platform

## [1.0.0] - 2017-02-23
### Added
- Initial release
- Initial release
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ docker-machine create -d glesys | grep glesys
--glesys-cpu "2" Number of CPU cores
--glesys-data-center "Falkenberg" Data center to place the machine in
--glesys-memory "2048" Memory in MB
--glesys-root-password Root password to use for the machine. If omitted, a random password will be generated
--glesys-root-password Root password to use for the machine. If omitted, a random password will be generated (VMware only)
--glesys-username-kvm "docker-machine" Username to use in KVM platform
--glesys-ssh-key-path Path to the SSH key file you want to use. If omitted, a new key will be generated
--glesys-storage "20" Storage in GB
--glesys-template "Ubuntu 16.04 LTS 64-bit" Template to use for the machine
--glesys-platform "VMware" Virtualization platform (VMware or KVM)
```

To create a machine you need to specify a project and an API key:
Expand Down
66 changes: 51 additions & 15 deletions glesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package glesys
import (
"context"
"fmt"
"github.com/glesys/glesys-go/v2"
"io/ioutil"
"math/rand"
"net"
Expand All @@ -15,16 +16,17 @@ import (
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/glesys/glesys-go"
)

const (
defaultBandwidth = 100
defaultCPU = 2
defaultDataCenter = "Falkenberg"
defaultMemory = 2048
defaultStorage = 20
defaultTemplate = "Ubuntu 16.04 LTS 64-bit"
defaultBandwidth = 100
defaultCPU = 2
defaultDataCenter = "Falkenberg"
defaultMemory = 2048
defaultStorage = 20
defaultTemplate = "Ubuntu 16.04 LTS 64-bit"
defaultPlatform = "VMware"
defaultUsernameKvm = "docker-machine"
)

const (
Expand All @@ -39,6 +41,8 @@ const (
sshKeyPathFlag = "glesys-ssh-key-path"
storageFlag = "glesys-storage"
templateFlag = "glesys-template"
platformFlag = "glesys-platform"
usernameKVMFlag = "glesys-username-kvm"
)

// Driver for GleSYS
Expand All @@ -55,6 +59,8 @@ type Driver struct {
ServerID string
Storage int
Template string
Platform string
UsernameKVM string
}

// NewDriver creates a new driver
Expand Down Expand Up @@ -111,7 +117,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
},
mcnflag.StringFlag{
Name: rootPasswordFlag,
Usage: "Root password to use for the machine. If omitted, a random password will be generated",
Usage: "Root password to use for the machine. If omitted, a random password will be generated (VMware only)",
},
mcnflag.StringFlag{
Name: templateFlag,
Expand All @@ -128,6 +134,16 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Path to the SSH key file you want to use. If omitted, a new key will be generated",
Value: "",
},
mcnflag.StringFlag{
Name: platformFlag,
Usage: "Virtualization platform (VMware or KVM)",
Value: defaultPlatform,
},
mcnflag.StringFlag{
Name: usernameKVMFlag,
Usage: "Username to use in KVM platform",
Value: defaultUsernameKvm,
},
}
}

Expand All @@ -154,6 +170,12 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
d.SSHKeyPath = opts.String(sshKeyPathFlag)
d.Storage = opts.Int(storageFlag)
d.Template = opts.String(templateFlag)
d.Platform = opts.String(platformFlag)
d.UsernameKVM = opts.String(usernameKVMFlag)

if d.Platform != "VMware" && d.Platform != "KVM" {
return fmt.Errorf("platform %v is not valid, supported platforms are VMware and KVM", d.Platform)
}

return nil
}
Expand Down Expand Up @@ -188,7 +210,7 @@ func (d *Driver) Create() error {
return err
}

server, err := client.Servers.Create(context.Background(), glesys.CreateServerParams{
serverParams := glesys.CreateServerParams{
Bandwidth: d.Bandwidth,
CampaignCode: d.CampaignCode,
CPU: d.CPU,
Expand All @@ -197,12 +219,21 @@ func (d *Driver) Create() error {
IPv4: "any",
IPv6: "any",
Memory: d.Memory,
Password: d.RootPassword,
Platform: "VMware",
PublicKey: string(publicKey),
Platform: d.Platform,
Storage: d.Storage,
Template: d.Template,
})
}
if d.Platform == "KVM" {
publicKeys := []string{
string(publicKey),
}
serverParams = serverParams.WithUser(d.UsernameKVM, publicKeys, "")
} else {
serverParams.Password = d.RootPassword
serverParams.PublicKey = string(publicKey)
}

server, err := client.Servers.Create(context.Background(), serverParams)

if err != nil {
return fmt.Errorf("Failed to create machine: %v", err)
Expand Down Expand Up @@ -231,7 +262,12 @@ func (d *Driver) GetSSHPort() (int, error) {

// GetSSHUsername returns username for use with ssh
func (d *Driver) GetSSHUsername() string {
return "root"
if d.Platform == "KVM" {
return d.UsernameKVM
} else {
return "root"
}

}

// GetURL returns a Docker compatible URL for connecting to this machine
Expand Down Expand Up @@ -317,5 +353,5 @@ func (d *Driver) Stop() error {
}

func (d *Driver) getClient() *glesys.Client {
return glesys.NewClient(d.Project, d.APIKey, "docker-machine-driver-glesys/1.0.0")
return glesys.NewClient(d.Project, d.APIKey, "docker-machine-driver-glesys/1.1.0")
}
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/glesys/docker-machine-driver-glesys

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/docker/docker v1.13.2-0.20170601211448-f5ec1e2936dc // indirect
github.com/docker/machine v0.16.2
github.com/glesys/glesys-go/v2 v2.4.1
github.com/sirupsen/logrus v1.5.0 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect
)

replace (
github.com/Sirupsen/logrus => github.com/sirupsen/logrus v1.5.0
github.com/docker/docker => github.com/docker/engine v1.4.2-0.20190822205725-ed20165a37b4
)

go 1.14

0 comments on commit 85ea453

Please sign in to comment.