diff --git a/README.md b/README.md index 009376bc786cb773b7ced8f4e49d27ab673f84f8..1f38cf5c249be50a58f9930be6d308194660dfd4 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ You can find sources and pre-compiled binaries [here](https://github.com/JonasPr ```bash # Download the binary (this example downloads the binary for linux amd64) -$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/1.3.0/docker-machine-driver-hetzner_1.3.0_linux_amd64.tar.gz -$ tar -xvf docker-machine-driver-hetzner_1.3.0_linux_amd64.tar.gz +$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/1.4.0/docker-machine-driver-hetzner_1.4.0_linux_amd64.tar.gz +$ tar -xvf docker-machine-driver-hetzner_1.4.0_linux_amd64.tar.gz # Make it executable and copy the binary in a directory accessible with your $PATH $ chmod +x docker-machine-driver-hetzner @@ -99,6 +99,8 @@ $ docker-machine create \ - `--hetzner-existing-key-id`: **requires `--hetzner-existing-key-path`**. Use an existing (remote) SSH key instead of uploading the imported key pair, see [SSH Keys API](https://docs.hetzner.cloud/#resources-ssh-keys-get) for how to get a list - `--hetzner-user-data`: Cloud-init based User data +- `--hetzner-volumes`: Volume IDs or names which should be attached to the server +- `--hetzner-networks`: Network IDs or names which should be attached to the server private network interface #### Existing SSH keys @@ -127,6 +129,8 @@ was used during creation. | `--hetzner-existing-key-path` | `HETZNER_EXISTING_KEY_PATH` | - *(generate new keypair)* | | `--hetzner-existing-key-id` | `HETZNER_EXISTING_KEY_ID` | 0 *(upload new key)* | | `--hetzner-user-data` | `HETZNER_USER_DATA` | - | +| `--hetzner-networks` | `HETZNER_NETWORKS` | - | +| `--hetzner-volumes` | `HETZNER_VOLUMES` | - | ## Building from source diff --git a/driver.go b/driver.go index 3fb2618d39420c275e4ef688d2b79e9d9c4a62fc..3f3bbe66275252cfbaeb55e1f7d8ba342fcce9d8 100644 --- a/driver.go +++ b/driver.go @@ -37,6 +37,8 @@ type Driver struct { danglingKey bool ServerID int userData string + volumes []string + networks []string cachedServer *hcloud.Server } @@ -52,6 +54,8 @@ const ( flagExKeyID = "hetzner-existing-key-id" flagExKeyPath = "hetzner-existing-key-path" flagUserData = "hetzner-user-data" + flagVolumes = "hetzner-volumes" + flagNetworks = "hetzner-networks" ) func NewDriver() *Driver { @@ -120,6 +124,18 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { Usage: "Cloud-init based User data", Value: "", }, + mcnflag.StringSliceFlag{ + EnvVar: "HETZNER_VOLUMES", + Name: flagVolumes, + Usage: "Volume IDs or names which should be attached to the server", + Value: []string{}, + }, + mcnflag.StringSliceFlag{ + EnvVar: "HETZNER_NETWORKS", + Name: flagNetworks, + Usage: "Network IDs or names which should be attached to the server private network interface", + Value: []string{}, + }, } } @@ -133,6 +149,8 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error { d.IsExistingKey = d.KeyID != 0 d.originalKey = opts.String(flagExKeyPath) d.userData = opts.String(flagUserData) + d.volumes = opts.StringSlice(flagVolumes) + d.networks = opts.StringSlice(flagNetworks) d.SetSwarmConfigFromFlags(opts) @@ -233,6 +251,25 @@ func (d *Driver) Create() error { Name: d.GetMachineName(), UserData: d.userData, } + networks := []*hcloud.Network{} + for _, networkIDorName := range d.networks { + network, _, err := d.getClient().Network.Get(context.Background(), networkIDorName) + if err != nil { + return errors.Wrap(err, "could not get network by ID or name") + } + networks = append(networks, network) + } + srvopts.Networks = networks + + volumes := []*hcloud.Volume{} + for _, volumeIDorName := range d.volumes { + volume, _, err := d.getClient().Volume.Get(context.Background(), volumeIDorName) + if err != nil { + return errors.Wrap(err, "could not get volume by ID or name") + } + volumes = append(volumes, volume) + } + srvopts.Volumes = volumes var err error if srvopts.Location, err = d.getLocation(); err != nil { diff --git a/go.mod b/go.mod index 8fc3a6499201f5c4f3f41656a2095ad88cf98dc6..6bb12253d6de1869987066cdf956a24aa487ac1e 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,12 @@ require ( github.com/docker/docker v0.0.0-20181018193557-f7e5154f37a4 // indirect github.com/docker/machine v0.16.1 github.com/google/go-cmp v0.3.0 // indirect - github.com/hetznercloud/hcloud-go v1.13.0 + github.com/hetznercloud/hcloud-go v1.14.0 github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/pkg/errors v0.8.1 github.com/sirupsen/logrus v1.4.2 // indirect github.com/stretchr/testify v1.3.0 // indirect - golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f - golang.org/x/sys v0.0.0-20190516110030-61b9204099cb // indirect + golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 + golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect gotest.tools v2.2.0+incompatible // indirect ) diff --git a/go.sum b/go.sum index 451d2c891b4511bd7e01f4acdd7f1422d1d74595..2f27c8bc854af6565b1a405faea75cc0f857c154 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/docker/machine v0.16.1 h1:zrgroZounGVkxLmBqMyc1uT2GgapXVjIWHCfBf0udrA github.com/docker/machine v0.16.1/go.mod h1:I8mPNDeK1uH+JTcUU7X0ZW8KiYz0jyAgNaeSJ1rCfDI= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/hetznercloud/hcloud-go v1.13.0 h1:8K60QdD50ZX0vG+eNkJtmEzR+rj1mn/NBUNWtVgi8II= -github.com/hetznercloud/hcloud-go v1.13.0/go.mod h1:g5pff0YNAZywQaivY/CmhUYFVp7oP0nu3MiODC2W4Hw= +github.com/hetznercloud/hcloud-go v1.14.0 h1:6IdF0Vox/6j1pyEdUCbFPIzEH/K9xZZzVuSFro8Y2vw= +github.com/hetznercloud/hcloud-go v1.14.0/go.mod h1:8lR3yHBHZWy2uGcUi9Ibt4UOoop2wrVdERJgCtxsF3Q= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= @@ -28,14 +28,14 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= -golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190516110030-61b9204099cb h1:k07iPOt0d6nEnwXF+kHB+iEg+WSuKe/SOQuFM2QoD+E= -golang.org/x/sys v0.0.0-20190516110030-61b9204099cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=