Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Commit

Permalink
added swap
Browse files Browse the repository at this point in the history
  • Loading branch information
vahaah committed Jun 2, 2016
1 parent 88ba669 commit 7f45475
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docker-machine-driver-vscale
*.log
*.log
.idea/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.1 (2016-06-02)

Added SWAP

## 1.0.0 (2016-04-11)

Initial public release
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To install this plugin manually, download the binary `docker-machine-driver-vsca
and make it available by `$PATH`, for example by putting it to `/usr/local/bin/`:

```console
$ curl -L https://github.com/vahaah/docker-machine-driver-vscale/releases/download/1.0.0/docker-machine-driver-vscale > /usr/local/bin/docker-machine-driver-vscale
$ curl -L https://github.com/vahaah/docker-machine-driver-vscale/releases/download/1.0.1/docker-machine-driver-vscale > /usr/local/bin/docker-machine-driver-vscale

$ chmod +x /usr/local/bin/docker-machine-driver-vscale
```
Expand All @@ -34,6 +34,7 @@ Available options:
- `--vscale-location`: Server location.
- `--vscale-rplan`: Server size.
- `--vscale-made-from`: Server type
- `--vscale-swap-file`: Swap size in MB

Environment variables and default values:

Expand All @@ -43,6 +44,7 @@ Environment variables and default values:
| `--vscale-location` | `VSCALE_LOCATION` | `spb0` |
| `--vscale-rplan` | `VSCALE_RPLAN` | `small` |
| `--vscale-made-from` | `VSCALE_MADE_FROM` | `ubuntu_14.04_64_002_master`|
| `--vscale-swap-file` | `VSCALE_SWAP_FILE` | `0` |

## Development

Expand Down
2 changes: 1 addition & 1 deletion bin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
app.Name = path.Base(os.Args[0])
app.Usage = "This is a Docker Machine plugin binary. Please use it through the main 'docker-machine' binary."
app.Author = "Alex Vakhitov"
app.Email = "https://github.com/vahaah/docker-machine-vscale/"
app.Email = "https://github.com/vahaah/docker-machine-driver-vscale/"
app.Version = vscale.FullVersion()
app.Action = func(c *cli.Context) {
plugin.RegisterDriver(vscale.NewDriver("", ""))
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "fmt"
var GitCommit string

// Version number that is being run at the moment.
const Version = "1.0.0"
const Version = "1.0.1"

// FullVersion formats the version to be printed.
func FullVersion() string {
Expand Down
25 changes: 24 additions & 1 deletion vscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ type Driver struct {
MadeFrom string
Location string
SSHKeyID int
SwapFile int
}

const (
defaultRplan = "small"
defaultLocation = "spb0"
defaultMadeFrom = "ubuntu_14.04_64_002_master"
defaultSwapFile = 0
)

func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Expand Down Expand Up @@ -56,6 +58,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Vscale made from",
Value: defaultMadeFrom,
},
mcnflag.IntFlag{
EnvVar: "VSCALE_SWAP_FILE",
Name: "vscale-swap-file",
Usage: "Vscale swap file",
Value: defaultSwapFile,
},
}
}

Expand All @@ -64,6 +72,7 @@ func NewDriver(hostName, storePath string) *Driver {
Rplan: defaultRplan,
Location: defaultLocation,
MadeFrom: defaultMadeFrom,
SwapFile: defaultSwapFile,
BaseDriver: &drivers.BaseDriver{
MachineName: hostName,
StorePath: storePath,
Expand Down Expand Up @@ -108,6 +117,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Location = flags.String("vscale-location")
d.Rplan = flags.String("vscale-rplan")
d.MadeFrom = flags.String("vscale-made-from")
d.SwapFile = flags.Int("vscale-swap-file")

d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
Expand Down Expand Up @@ -180,7 +190,20 @@ func (d *Driver) Create() error {
time.Sleep(1 * time.Second)
}

log.Debugf("Created scalet with ID: %v, IPAddress: %v", d.ScaletID, d.IPAddress)
log.Info(fmt.Sprintf("Created scalet with ID: %v, IPAddress: %v", d.ScaletID, d.IPAddress))
if d.SwapFile > 0 {
log.Info(fmt.Sprintf("Creating SWAP file %d MB", d.SwapFile))

_, err := drivers.RunSSHCommandFromDriver(d, fmt.Sprintf(`touch /var/swap.img && \
chmod 600 /var/swap.img && \
dd if=/dev/zero of=/var/swap.img bs=1MB count=%d && \
mkswap /var/swap.img && swapon /var/swap.img && \
echo '/var/swap.img none swap sw 0 0' >> /etc/fstab`, d.SwapFile))

if err != nil {
return err
}
}
return nil
}

Expand Down

0 comments on commit 7f45475

Please sign in to comment.