Skip to content
Commits on Source (5)
......@@ -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/3.12.1/docker-machine-driver-hetzner_3.12.1_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_3.12.1_linux_amd64.tar.gz
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.12.2/docker-machine-driver-hetzner_3.12.2_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_3.12.2_linux_amd64.tar.gz
# Make it executable and copy the binary in a directory accessible with your $PATH
$ chmod +x docker-machine-driver-hetzner
......@@ -107,7 +107,7 @@ $ docker-machine create \
- `--hetzner-use-private-network`: Use private network
- `--hetzner-firewalls`: Firewall IDs or names which should be applied on the server
- `--hetzner-server-label`: `key=value` pairs of additional metadata to assign to the server.
- `--hetzner-key-label`: `key=value` pairs of additional metadata to assign to SSH key (only applies if newly creadted).
- `--hetzner-key-label`: `key=value` pairs of additional metadata to assign to SSH key (only applies if newly created).
- `--hetzner-placement-group`: Add to a placement group by name or ID; a spread-group will be created on demand if it does not exist
- `--hetzner-auto-spread`: Add to a `docker-machine` provided `spread` group (mutually exclusive with `--hetzner-placement-group`)
- `--hetzner-ssh-user`: Change the default SSH-User
......@@ -148,8 +148,8 @@ was used during creation.
| `--hetzner-firewalls` | `HETZNER_FIREWALLS` | |
| `--hetzner-volumes` | `HETZNER_VOLUMES` | |
| `--hetzner-use-private-network` | `HETZNER_USE_PRIVATE_NETWORK` | false |
| `--hetzner-disable-public-4` | `HETZNER_DISABLE_PUBLIC_4` | false |
| `--hetzner-disable-public-6` | `HETZNER_DISABLE_PUBLIC_6` | false |
| `--hetzner-disable-public-ipv4` | `HETZNER_DISABLE_PUBLIC_IPV4` | false |
| `--hetzner-disable-public-ipv6` | `HETZNER_DISABLE_PUBLIC_IPV6` | false |
| `--hetzner-disable-public` | `HETZNER_DISABLE_PUBLIC` | false |
| `--hetzner-server-label` | (inoperative) | `[]` |
| `--hetzner-key-label` | (inoperative) | `[]` |
......@@ -177,7 +177,7 @@ Hetzner assigns them at the given time, so users should take care what retention
When disabling all public IPs, `--hetzner-use-private-network` must be given.
`--hetzner-disable-public` will take care of that, and behaves as if
`--hetzner-disable-public-4 --hetzner-disable-public-6 --hetzner-use-private-network`
`--hetzner-disable-public-ipv4 --hetzner-disable-public-ipv6 --hetzner-use-private-network`
were given.
Using `--hetzner-use-private-network` implicitly or explicitly requires at least one `--hetzner-network`
to be given.
......@@ -237,7 +237,9 @@ $ docker-machine create --driver hetzner
### 4.0.0
* `--hetzner-user-data-from-file` will be fully deprecated and its flag description will only read 'DEPRECATED, legacy'; current fallback behaviour will be retained. `--hetzner-flag-user-data-file` should be used instead.
* `--hetzner-disable-public-4`/`--hetzner-disable-public-6` will be fully deprecated and its flag description will only read 'DEPRECATED, legacy'; current fallback behaviour will be retained. `--hetzner-disable-public-ipv4`/`--hetzner-disable-public-ipv6` should be used instead.
### 5.0.0
* `--hetzner-user-data-from-file` will be removed entirely, including its fallback behavior
* `--hetzner-disable-public-4`/`--hetzner-disable-public-6` ill be removed entirely, including their fallback behavior
......@@ -78,8 +78,8 @@ const (
flagVolumes = "hetzner-volumes"
flagNetworks = "hetzner-networks"
flagUsePrivateNetwork = "hetzner-use-private-network"
flagDisablePublic4 = "hetzner-disable-public-4"
flagDisablePublic6 = "hetzner-disable-public-6"
flagDisablePublic4 = "hetzner-disable-public-ipv4"
flagDisablePublic6 = "hetzner-disable-public-ipv6"
flagPrimary4 = "hetzner-primary-ipv4"
flagPrimary6 = "hetzner-primary-ipv6"
flagDisablePublic = "hetzner-disable-public"
......@@ -106,6 +106,8 @@ const (
defaultWaitOnError = 0
legacyFlagUserDataFromFile = "hetzner-user-data-from-file"
legacyFlagDisablePublic4 = "hetzner-disable-public-4"
legacyFlagDisablePublic6 = "hetzner-disable-public-6"
)
// NewDriver initializes a new driver instance; see [drivers.Driver.NewDriver]
......@@ -201,15 +203,25 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Use private network",
},
mcnflag.BoolFlag{
EnvVar: "HETZNER_DISABLE_PUBLIC_4",
EnvVar: "HETZNER_DISABLE_PUBLIC_IPV4",
Name: flagDisablePublic4,
Usage: "Disable public ipv4",
},
mcnflag.BoolFlag{
EnvVar: "HETZNER_DISABLE_PUBLIC_6",
EnvVar: "HETZNER_DISABLE_PUBLIC_4",
Name: legacyFlagDisablePublic4,
Usage: "DEPRECATED, use --hetzner-disable-public-ipv4; disable public ipv4",
},
mcnflag.BoolFlag{
EnvVar: "HETZNER_DISABLE_PUBLIC_IPV6",
Name: flagDisablePublic6,
Usage: "Disable public ipv6",
},
mcnflag.BoolFlag{
EnvVar: "HETZNER_DISABLE_PUBLIC_6",
Name: legacyFlagDisablePublic6,
Usage: "DEPRECATED, use --hetzner-disable-public-ipv6; disable public ipv6",
},
mcnflag.BoolFlag{
EnvVar: "HETZNER_DISABLE_PUBLIC",
Name: flagDisablePublic,
......@@ -306,8 +318,8 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
d.Networks = opts.StringSlice(flagNetworks)
disablePublic := opts.Bool(flagDisablePublic)
d.UsePrivateNetwork = opts.Bool(flagUsePrivateNetwork) || disablePublic
d.DisablePublic4 = opts.Bool(flagDisablePublic4) || disablePublic
d.DisablePublic6 = opts.Bool(flagDisablePublic6) || disablePublic
d.DisablePublic4 = d.deprecatedBooleanFlag(opts, flagDisablePublic4, legacyFlagDisablePublic4) || disablePublic
d.DisablePublic6 = d.deprecatedBooleanFlag(opts, flagDisablePublic6, legacyFlagDisablePublic6) || disablePublic
d.PrimaryIPv4 = opts.String(flagPrimary4)
d.PrimaryIPv6 = opts.String(flagPrimary6)
d.Firewalls = opts.StringSlice(flagFirewalls)
......@@ -361,6 +373,14 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
return nil
}
func (d *Driver) deprecatedBooleanFlag(opts drivers.DriverOptions, flag, deprecatedFlag string) bool {
if opts.Bool(deprecatedFlag) {
log.Warnf("--%v is deprecated, use --%v instead", deprecatedFlag, flag)
return true
}
return opts.Bool(flag)
}
func (d *Driver) setUserDataFlags(opts drivers.DriverOptions) error {
userData := opts.String(flagUserData)
userDataFile := opts.String(flagUserDataFile)
......
......@@ -46,7 +46,6 @@ func TestUserData(t *testing.T) {
d = NewDriver()
err = d.setConfigFromFlagsImpl(&commandstest.FakeFlagger{
Data: map[string]interface{}{
flagAPIToken: "foo",
legacyFlagUserDataFromFile: true,
flagUserDataFile: file,
},
......@@ -56,7 +55,6 @@ func TestUserData(t *testing.T) {
// inline user data
d = NewDriver()
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagAPIToken: "foo",
flagUserData: inlineContents,
}))
if err != nil {
......@@ -74,7 +72,6 @@ func TestUserData(t *testing.T) {
// file user data
d = NewDriver()
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagAPIToken: "foo",
flagUserDataFile: file,
}))
if err != nil {
......@@ -92,7 +89,6 @@ func TestUserData(t *testing.T) {
// legacy file user data
d = NewDriver()
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagAPIToken: "foo",
flagUserData: file,
legacyFlagUserDataFromFile: true,
}))
......@@ -109,6 +105,108 @@ func TestUserData(t *testing.T) {
}
}
func TestDisablePublic(t *testing.T) {
d := NewDriver()
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagDisablePublic: true,
}))
if err != nil {
t.Fatalf("unexpected error, %v", err)
}
if !d.DisablePublic4 {
t.Error("expected public ipv4 to be disabled")
}
if !d.DisablePublic6 {
t.Error("expected public ipv6 to be disabled")
}
if !d.UsePrivateNetwork {
t.Error("expected private network to be enabled")
}
}
func TestDisablePublic46(t *testing.T) {
d := NewDriver()
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagDisablePublic4: true,
}))
if err != nil {
t.Fatalf("unexpected error, %v", err)
}
if !d.DisablePublic4 {
t.Error("expected public ipv4 to be disabled")
}
if d.DisablePublic6 {
t.Error("public ipv6 disabled unexpectedly")
}
if d.UsePrivateNetwork {
t.Error("network enabled unexpectedly")
}
// 6
d = NewDriver()
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagDisablePublic6: true,
}))
if err != nil {
t.Fatalf("unexpected error, %v", err)
}
if d.DisablePublic4 {
t.Error("public ipv4 disabled unexpectedly")
}
if !d.DisablePublic6 {
t.Error("expected public ipv6 to be disabled")
}
if d.UsePrivateNetwork {
t.Error("network enabled unexpectedly")
}
}
func TestDisablePublic46Legacy(t *testing.T) {
d := NewDriver()
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
legacyFlagDisablePublic4: true,
// any truthy flag should take precedence
flagDisablePublic4: false,
}))
if err != nil {
t.Fatalf("unexpected error, %v", err)
}
if !d.DisablePublic4 {
t.Error("expected public ipv4 to be disabled")
}
if d.DisablePublic6 {
t.Error("public ipv6 disabled unexpectedly")
}
if d.UsePrivateNetwork {
t.Error("network enabled unexpectedly")
}
// 6
d = NewDriver()
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
legacyFlagDisablePublic6: true,
// any truthy flag should take precedence
flagDisablePublic6: false,
}))
if err != nil {
t.Fatalf("unexpected error, %v", err)
}
if d.DisablePublic4 {
t.Error("public ipv4 disabled unexpectedly")
}
if !d.DisablePublic6 {
t.Error("expected public ipv6 to be disabled")
}
if d.UsePrivateNetwork {
t.Error("network enabled unexpectedly")
}
}
func assertMutualExclusion(t *testing.T, err error, flag1, flag2 string) {
if err == nil {
t.Errorf("expected mutually exclusive flags to fail, but no error was thrown: %v %v", flag1, flag2)
......