├── .gitignore ├── Godeps ├── Readme └── Godeps.json ├── .travis.yml ├── CHANGELOG.md ├── version.go ├── vscale_test.go ├── Makefile ├── LICENSE ├── bin └── main.go ├── README.md └── vscale.go /.gitignore: -------------------------------------------------------------------------------- 1 | docker-machine-driver-vscale 2 | *.log 3 | .idea/ 4 | devel/ 5 | Godeps/_workspace/ 6 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | branches: 4 | only: 5 | - master 6 | 7 | go: 8 | - 1.6.3 9 | - 1.7 10 | 11 | install: 12 | - go get github.com/tools/godep 13 | - make dep-restore 14 | 15 | script: 16 | - go test -v 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.1.0 (2016-08-11) 4 | 5 | Official Go api 6 | 7 | ## 1.0.3 (2016-07-18) 8 | 9 | Fixed ssh 10 | 11 | ## 1.0.2 (2016-06-07) 12 | 13 | Bug fix 14 | 15 | ## 1.0.1 (2016-06-02) 16 | 17 | Added SWAP 18 | 19 | ## 1.0.0 (2016-04-11) 20 | 21 | Initial public release -------------------------------------------------------------------------------- /version.go: -------------------------------------------------------------------------------- 1 | package vscale 2 | 3 | import "fmt" 4 | 5 | // GitCommit that was compiled. This will be filled in by the compiler. 6 | var GitCommit string 7 | 8 | // Version number that is being run at the moment. 9 | const Version = "1.1.0" 10 | 11 | // FullVersion formats the version to be printed. 12 | func FullVersion() string { 13 | return fmt.Sprintf("%s, build %s", Version, GitCommit) 14 | } -------------------------------------------------------------------------------- /vscale_test.go: -------------------------------------------------------------------------------- 1 | package vscale 2 | 3 | import ( 4 | "github.com/docker/machine/libmachine/drivers" 5 | "github.com/stretchr/testify/assert" 6 | "testing" 7 | ) 8 | 9 | func TestSetConfigFromFlags(t *testing.T) { 10 | driver := NewDriver("default", "path") 11 | 12 | checkFlags := &drivers.CheckDriverOptions{ 13 | FlagsValues: map[string]interface{}{ 14 | "vscale-access-token": "TOKEN", 15 | }, 16 | CreateFlags: driver.GetCreateFlags(), 17 | } 18 | 19 | err := driver.SetConfigFromFlags(checkFlags) 20 | 21 | assert.NoError(t, err) 22 | assert.Empty(t, checkFlags.InvalidFlags) 23 | } 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GODEP_BIN := $(GOPATH)/bin/godep 2 | GODEP := $(shell [ -x $(GODEP_BIN) ] && echo $(GODEP_BIN) || echo '') 3 | 4 | # Initialize version flag 5 | GO_LDFLAGS := -X $(shell go list ./).GitCommit=$(shell git rev-parse --short HEAD 2>/dev/null) 6 | 7 | default: build 8 | 9 | bin/docker-machine-driver-vscale: 10 | go build -i -ldflags "$(GO_LDFLAGS)" \ 11 | -o ./bin/docker-machine-driver-vscale ./bin 12 | 13 | build: clean bin/docker-machine-driver-vscale 14 | 15 | clean: 16 | $(RM) bin/docker-machine-driver-vscale 17 | 18 | install: bin/docker-machine-driver-vscale 19 | cp -f ./bin/docker-machine-driver-vscale $(GOPATH)/bin/ 20 | 21 | test-acceptance: 22 | test/integration/run-bats.sh test/integration/bats/ 23 | 24 | dep-save: 25 | $(if $(GODEP), , \ 26 | $(error Please install godep: go get github.com/tools/godep)) 27 | $(GODEP) save $(shell go list ./... | grep -v vendor/) 28 | 29 | dep-restore: 30 | $(if $(GODEP), , \ 31 | $(error Please install godep: go get github.com/tools/godep)) 32 | $(GODEP) restore -v -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Alex Vakhitov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bin/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "path" 6 | 7 | "github.com/vahaah/docker-machine-driver-vscale" 8 | "github.com/codegangsta/cli" 9 | "github.com/docker/machine/libmachine/drivers/plugin" 10 | ) 11 | 12 | var appHelpTemplate = `This is a Docker Machine plugin for Vscale. 13 | Plugin binaries are not intended to be invoked directly. 14 | Please use this plugin through the main 'docker-machine' binary. 15 | Version: {{.Version}}{{if or .Author .Email}} 16 | Author:{{if .Author}} 17 | {{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}} 18 | {{.Email}}{{end}}{{end}} 19 | {{if .Flags}} 20 | Options: 21 | {{range .Flags}}{{.}} 22 | {{end}}{{end}} 23 | Commands: 24 | {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}} 25 | {{end}} 26 | ` 27 | 28 | func main() { 29 | cli.AppHelpTemplate = appHelpTemplate 30 | app := cli.NewApp() 31 | app.Name = path.Base(os.Args[0]) 32 | app.Usage = "This is a Docker Machine plugin binary. Please use it through the main 'docker-machine' binary." 33 | app.Author = "Alex Vakhitov" 34 | app.Email = "https://github.com/vahaah/docker-machine-driver-vscale/" 35 | app.Version = vscale.FullVersion() 36 | app.Action = func(c *cli.Context) { 37 | plugin.RegisterDriver(vscale.NewDriver("", "")) 38 | } 39 | 40 | app.Run(os.Args) 41 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/vahaah/docker-machine-driver-vscale.svg?branch=master)](https://travis-ci.org/vahaah/docker-machine-driver-vscale) 2 | 3 | # Docker Machine Vscale Driver 4 | 5 | This is a plugin for [Docker Machine](https://docs.docker.com/machine/) allowing 6 | to create Docker hosts on [Vscale]( http://vscale.io ) cloud services. 7 | 8 | ## Installation 9 | 10 | To install this plugin manually, download the binary `docker-machine-driver-vscale` 11 | and make it available by `$PATH`, for example by putting it to `/usr/local/bin/`: 12 | 13 | ```console 14 | $ curl -L https://github.com/vahaah/docker-machine-driver-vscale/releases/download/1.1.0/docker-machine-driver-vscale > /usr/local/bin/docker-machine-driver-vscale 15 | 16 | $ chmod +x /usr/local/bin/docker-machine-driver-vscale 17 | ``` 18 | 19 | The latest version of `docker-machine-driver-vscale` binary is available on 20 | the ["Releases"](https://github.com/vahaah/docker-machine-driver-vscale/releases) page. 21 | 22 | For Ubuntu 16.04: 23 | 24 | ```console 25 | $ sudo curl -L https://github.com/vahaah/docker-machine-driver-vscale/releases/download/1.1.0/docker-machine-driver-vscale.ubuntu.16.04.x64 > /usr/local/bin/docker-machine-driver-vscale 26 | 27 | $ sudo chmod +x /usr/local/bin/docker-machine-driver-vscale 28 | ``` 29 | 30 | ## Usage 31 | 32 | After compile you can use driver for creating docker hosts. 33 | Get Vscale access token from [your profile](https://vscale.io/panel/settings/tokens/) then run: 34 | 35 | ```console 36 | $ docker-machine create -d vscale --vscale-access-token YOUR_VSCALE_ACCESS_TOKEN machine_name 37 | ``` 38 | 39 | Available options: 40 | 41 | - `--vscale-access-token`: Access token. 42 | - `--vscale-location`: Server location. 43 | - `--vscale-rplan`: Server size. 44 | - `--vscale-made-from`: Server type 45 | - `--vscale-swap-file`: Swap size in MB 46 | 47 | Environment variables and default values: 48 | 49 | | CLI option | Environment variable | Default | 50 | |-------------------------------|-----------------------------|-----------------------------| 51 | | `--vscale-access-token` | `VSCALE_ACCESS_TOKEN` | - | 52 | | `--vscale-location` | `VSCALE_LOCATION` | `spb0` | 53 | | `--vscale-rplan` | `VSCALE_RPLAN` | `small` | 54 | | `--vscale-made-from` | `VSCALE_MADE_FROM` | `ubuntu_14.04_64_002_master`| 55 | | `--vscale-swap-file` | `VSCALE_SWAP_FILE` | `0` | 56 | 57 | ## Development 58 | 59 | ### Build from Source 60 | If you wish to work on Vscale Driver for Docker machine, you'll first need 61 | [Go](http://www.golang.org) installed (version 1.5+ is required). 62 | Make sure Go is properly installed, including setting up a [GOPATH](http://golang.org/doc/code.html#GOPATH). 63 | 64 | Run these commands to build the plugin binary: 65 | 66 | ```bash 67 | $ go get -d github.com/vahaah/docker-machine-driver-vscale 68 | $ cd $GOPATH/github.com/vahaah/docker-machine-driver-vscale 69 | $ make build 70 | ``` 71 | 72 | After the build is complete, `bin/docker-machine-driver-vscale` binary will 73 | be created. If you want to copy it to the `${GOPATH}/bin/`, run `make install`. 74 | -------------------------------------------------------------------------------- /Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/vahaah/docker-machine-driver-vscale", 3 | "GoVersion": "go1.7", 4 | "GodepVersion": "v66", 5 | "Packages": [ 6 | "github.com/vahaah/docker-machine-driver-vscale", 7 | "github.com/vahaah/docker-machine-driver-vscale/bin" 8 | ], 9 | "Deps": [ 10 | { 11 | "ImportPath": "github.com/Azure/go-ansiterm", 12 | "Rev": "388960b655244e76e24c75f48631564eaefade62" 13 | }, 14 | { 15 | "ImportPath": "github.com/Azure/go-ansiterm/winterm", 16 | "Rev": "388960b655244e76e24c75f48631564eaefade62" 17 | }, 18 | { 19 | "ImportPath": "github.com/Sirupsen/logrus", 20 | "Comment": "v0.10.0-16-gcd7d1bb", 21 | "Rev": "cd7d1bbe41066b6c1f19780f895901052150a575" 22 | }, 23 | { 24 | "ImportPath": "github.com/codegangsta/cli", 25 | "Comment": "1.2.0-237-g71f57d3", 26 | "Rev": "71f57d300dd6a780ac1856c005c4b518cfd498ec" 27 | }, 28 | { 29 | "ImportPath": "github.com/davecgh/go-spew/spew", 30 | "Comment": "v1.1.0", 31 | "Rev": "346938d642f2ec3594ed81d874461961cd0faa76" 32 | }, 33 | { 34 | "ImportPath": "github.com/docker/docker/pkg/system", 35 | "Comment": "v1.4.1-12020-gaf60a9e", 36 | "Rev": "af60a9e599543daa70da6d5d3b07343aa780c3ad" 37 | }, 38 | { 39 | "ImportPath": "github.com/docker/docker/pkg/term", 40 | "Comment": "v1.4.1-12020-gaf60a9e", 41 | "Rev": "af60a9e599543daa70da6d5d3b07343aa780c3ad" 42 | }, 43 | { 44 | "ImportPath": "github.com/docker/docker/pkg/term/windows", 45 | "Comment": "v1.4.1-12020-gaf60a9e", 46 | "Rev": "af60a9e599543daa70da6d5d3b07343aa780c3ad" 47 | }, 48 | { 49 | "ImportPath": "github.com/docker/go-units", 50 | "Comment": "v0.3.0", 51 | "Rev": "5d2041e26a699eaca682e2ea41c8f891e1060444" 52 | }, 53 | { 54 | "ImportPath": "github.com/docker/machine/libmachine/drivers", 55 | "Comment": "v0.7.0-rc3", 56 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 57 | }, 58 | { 59 | "ImportPath": "github.com/docker/machine/libmachine/drivers/plugin", 60 | "Comment": "v0.7.0-rc3", 61 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 62 | }, 63 | { 64 | "ImportPath": "github.com/docker/machine/libmachine/drivers/plugin/localbinary", 65 | "Comment": "v0.7.0-rc3", 66 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 67 | }, 68 | { 69 | "ImportPath": "github.com/docker/machine/libmachine/drivers/rpc", 70 | "Comment": "v0.7.0-rc3", 71 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 72 | }, 73 | { 74 | "ImportPath": "github.com/docker/machine/libmachine/log", 75 | "Comment": "v0.7.0-rc3", 76 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 77 | }, 78 | { 79 | "ImportPath": "github.com/docker/machine/libmachine/mcnflag", 80 | "Comment": "v0.7.0-rc3", 81 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 82 | }, 83 | { 84 | "ImportPath": "github.com/docker/machine/libmachine/mcnutils", 85 | "Comment": "v0.7.0-rc3", 86 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 87 | }, 88 | { 89 | "ImportPath": "github.com/docker/machine/libmachine/ssh", 90 | "Comment": "v0.7.0-rc3", 91 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 92 | }, 93 | { 94 | "ImportPath": "github.com/docker/machine/libmachine/state", 95 | "Comment": "v0.7.0-rc3", 96 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 97 | }, 98 | { 99 | "ImportPath": "github.com/docker/machine/libmachine/version", 100 | "Comment": "v0.7.0-rc3", 101 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 102 | }, 103 | { 104 | "ImportPath": "github.com/docker/machine/version", 105 | "Comment": "v0.7.0-rc3", 106 | "Rev": "d6c595f85ee644582e75e1bb9f26c72bd4c26b5f" 107 | }, 108 | { 109 | "ImportPath": "github.com/gorilla/websocket", 110 | "Comment": "v1.0.0-20-ga69d25b", 111 | "Rev": "a69d25be2fe2923a97c2af6849b2f52426f68fc0" 112 | }, 113 | { 114 | "ImportPath": "github.com/pmezard/go-difflib/difflib", 115 | "Comment": "v1.0.0", 116 | "Rev": "792786c7400a136282c1664665ae0a8db921c6c2" 117 | }, 118 | { 119 | "ImportPath": "github.com/stretchr/testify/assert", 120 | "Comment": "v1.1.4-6-g18a02ba", 121 | "Rev": "18a02ba4a312f95da08ff4cfc0055750ce50ae9e" 122 | }, 123 | { 124 | "ImportPath": "github.com/vscale/go-vscale", 125 | "Rev": "3a451bcafddc1af539ad253a3520507099417aaf" 126 | }, 127 | { 128 | "ImportPath": "golang.org/x/crypto/curve25519", 129 | "Rev": "3fbbcd23f1cb824e69491a5930cfeff09b12f4d2" 130 | }, 131 | { 132 | "ImportPath": "golang.org/x/crypto/ssh", 133 | "Rev": "3fbbcd23f1cb824e69491a5930cfeff09b12f4d2" 134 | }, 135 | { 136 | "ImportPath": "golang.org/x/crypto/ssh/terminal", 137 | "Rev": "3fbbcd23f1cb824e69491a5930cfeff09b12f4d2" 138 | }, 139 | { 140 | "ImportPath": "golang.org/x/sys/unix", 141 | "Rev": "b776ec39b3e54652e09028aaaaac9757f4f8211a" 142 | } 143 | ] 144 | } 145 | -------------------------------------------------------------------------------- /vscale.go: -------------------------------------------------------------------------------- 1 | package vscale 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "time" 7 | "io/ioutil" 8 | 9 | "github.com/docker/machine/libmachine/drivers" 10 | "github.com/docker/machine/libmachine/log" 11 | "github.com/docker/machine/libmachine/mcnflag" 12 | "github.com/docker/machine/libmachine/state" 13 | "github.com/docker/machine/libmachine/ssh" 14 | api "github.com/vscale/go-vscale" 15 | ) 16 | 17 | type Driver struct { 18 | *drivers.BaseDriver 19 | AccessToken string 20 | ScaletID int64 21 | ScaletName string 22 | Rplan string 23 | MadeFrom string 24 | Location string 25 | SSHKeyID int64 26 | SwapFile int 27 | } 28 | 29 | const ( 30 | defaultRplan = "small" 31 | defaultLocation = "spb0" 32 | defaultMadeFrom = "ubuntu_14.04_64_002_master" 33 | defaultSwapFile = 0 34 | ) 35 | 36 | func (d *Driver) GetCreateFlags() []mcnflag.Flag { 37 | return []mcnflag.Flag{ 38 | mcnflag.StringFlag{ 39 | EnvVar: "VSCALE_ACCESS_TOKEN", 40 | Name: "vscale-access-token", 41 | Usage: "Vscale access token", 42 | }, 43 | mcnflag.StringFlag{ 44 | EnvVar: "VSCALE_LOCATION", 45 | Name: "vscale-location", 46 | Usage: "Vscale location", 47 | Value: defaultLocation, 48 | }, 49 | mcnflag.StringFlag{ 50 | EnvVar: "VSCALE_RPLAN", 51 | Name: "vscale-rplan", 52 | Usage: "Vscale rplan", 53 | Value: defaultRplan, 54 | }, 55 | mcnflag.StringFlag{ 56 | EnvVar: "VSCALE_MADE_FROM", 57 | Name: "vscale-made-from", 58 | Usage: "Vscale made from", 59 | Value: defaultMadeFrom, 60 | }, 61 | mcnflag.IntFlag{ 62 | EnvVar: "VSCALE_SWAP_FILE", 63 | Name: "vscale-swap-file", 64 | Usage: "Vscale swap file", 65 | Value: defaultSwapFile, 66 | }, 67 | } 68 | } 69 | 70 | func NewDriver(hostName, storePath string) *Driver { 71 | return &Driver{ 72 | Rplan: defaultRplan, 73 | Location: defaultLocation, 74 | MadeFrom: defaultMadeFrom, 75 | SwapFile: defaultSwapFile, 76 | BaseDriver: &drivers.BaseDriver{ 77 | MachineName: hostName, 78 | StorePath: storePath, 79 | }, 80 | } 81 | } 82 | 83 | func (d *Driver) GetSSHHostname() (string, error) { 84 | return d.GetIP() 85 | } 86 | 87 | // DriverName returns the name of the driver 88 | func (d *Driver) DriverName() string { 89 | return "vscale" 90 | } 91 | 92 | func (d *Driver) publicSSHKeyPath() string { 93 | return d.GetSSHKeyPath() + ".pub" 94 | } 95 | 96 | func (d *Driver) createSSHKey() (*api.SSHKey, error) { 97 | if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { 98 | return nil, err 99 | } 100 | 101 | publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath()) 102 | if err != nil { 103 | return nil, err 104 | } 105 | 106 | key, _, err := d.getClient().SSHKey.Create(string(publicKey), d.MachineName) 107 | return key, err 108 | } 109 | 110 | func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { 111 | d.AccessToken = flags.String("vscale-access-token") 112 | d.Location = flags.String("vscale-location") 113 | d.Rplan = flags.String("vscale-rplan") 114 | d.MadeFrom = flags.String("vscale-made-from") 115 | d.SwapFile = flags.Int("vscale-swap-file") 116 | 117 | d.SwarmMaster = flags.Bool("swarm-master") 118 | d.SwarmHost = flags.String("swarm-host") 119 | d.SwarmDiscovery = flags.String("swarm-discovery") 120 | d.SSHPort = 22 121 | 122 | if d.AccessToken == "" { 123 | return fmt.Errorf("vscale driver requres the --vscale-access-token option") 124 | } 125 | 126 | return nil 127 | } 128 | 129 | func (d *Driver) getClient() *api.WebClient { 130 | return api.NewClient(d.AccessToken) 131 | } 132 | 133 | func (d *Driver) PreCreateCheck() error { 134 | client := d.getClient() 135 | if client == nil { 136 | return fmt.Errorf("Cannot create Vscale client. Check --vscale-access-token option") 137 | } 138 | 139 | return nil 140 | } 141 | 142 | func (d *Driver) Create() error { 143 | log.Infof("Creating SSH key...") 144 | key, err := d.createSSHKey() 145 | if err != nil { 146 | return err 147 | } 148 | d.SSHKeyID = key.ID 149 | 150 | log.Infof("Creating Vscale scalet...") 151 | 152 | client := d.getClient() 153 | newScalet, _, err := client.Scalet.CreateWithoutPassword(d.MadeFrom, d.Rplan, d.MachineName, d.Location, true, []int64{d.SSHKeyID}, true) 154 | 155 | if err != nil { 156 | return err 157 | } 158 | 159 | d.ScaletID = newScalet.CTID 160 | 161 | log.Info("Waiting for IP address to be assigned to the Scalet...") 162 | 163 | for { 164 | newScalet, _, err = client.Scalet.Get(d.ScaletID) 165 | if err != nil { 166 | return err 167 | } 168 | 169 | if newScalet.Active == true { 170 | d.IPAddress = newScalet.PublicAddresses.Address 171 | } 172 | 173 | if d.IPAddress != "" { 174 | break 175 | } 176 | 177 | time.Sleep(1 * time.Second) 178 | } 179 | 180 | log.Info(fmt.Sprintf("Scalet created! ID: %v, IPAddress: %v", d.ScaletID, d.IPAddress)) 181 | if d.SwapFile > 0 { 182 | for { 183 | ssh := drivers.WaitForSSH(d) 184 | if ssh == nil { 185 | log.Info(fmt.Sprintf("Creating SWAP file %d MB", d.SwapFile)) 186 | _, err := drivers.RunSSHCommandFromDriver(d, fmt.Sprintf(`touch /var/swap.img && \ 187 | chmod 600 /var/swap.img && \ 188 | dd if=/dev/zero of=/var/swap.img bs=1MB count=%d && \ 189 | mkswap /var/swap.img && swapon /var/swap.img && \ 190 | echo '/var/swap.img none swap sw 0 0' >> /etc/fstab`, d.SwapFile)) 191 | 192 | if err != nil { 193 | return err 194 | } 195 | break 196 | } 197 | 198 | if err != nil { 199 | return err 200 | } 201 | time.Sleep(3 * time.Second) 202 | } 203 | } 204 | return nil 205 | } 206 | 207 | func (d *Driver) GetURL() (string, error) { 208 | ip, err := d.GetIP() 209 | if err != nil { 210 | return "", err 211 | } 212 | return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil 213 | } 214 | 215 | func (d *Driver) GetState() (state.State, error) { 216 | scalet, _, err := d.getClient().Scalet.Get(d.ScaletID) 217 | if err != nil { 218 | return state.Error, err 219 | } 220 | 221 | switch scalet.Status { 222 | case "started": 223 | return state.Running, nil 224 | case "stopped": 225 | return state.Stopped, nil 226 | case "defined": 227 | return state.Starting, nil 228 | } 229 | return state.None, nil 230 | } 231 | 232 | func (d *Driver) Start() error { 233 | _, _, err := d.getClient().Scalet.Start(d.ScaletID, true) 234 | return err 235 | } 236 | 237 | func (d *Driver) Stop() error { 238 | _, _, err := d.getClient().Scalet.Stop(d.ScaletID, true) 239 | return err 240 | } 241 | 242 | func (d *Driver) Remove() error { 243 | client := d.getClient() 244 | _, _, err := client.Scalet.Remove(d.ScaletID, true) 245 | if err != nil { 246 | return err 247 | } 248 | 249 | _, _ , _ = client.SSHKey.Remove(d.SSHKeyID) 250 | 251 | return nil 252 | } 253 | 254 | func (d *Driver) Restart() error { 255 | _, _, err := d.getClient().Scalet.Restart(d.ScaletID, true) 256 | return err 257 | } 258 | 259 | func (d *Driver) Kill() error { 260 | _, _, err := d.getClient().Scalet.Remove(d.ScaletID, true) 261 | return err 262 | } --------------------------------------------------------------------------------