diff --git a/README.md b/README.md index 4150f64..e94948d 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,8 @@ $ docker-machine create \ - `--hetzner-key-label`: `key=value` pairs of additional metadata to assign to SSH key (only applies if newly creadted). - `--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 +- `--hetzner-ssh-port`: Change the default SSH-Port #### Existing SSH keys @@ -145,6 +147,9 @@ was used during creation. | `--hetzner-key-label` | (inoperative) | `[]` | | `--hetzner-placement-group` | `HETZNER_PLACEMENT_GROUP` | | | `--hetzner-auto-spread` | `HETZNER_AUTO_SPREAD` | false | +| `--hetzner-ssh-user` | `HETZNER_SSH_USER` | root | +| `--hetzner-ssh-port` | `HETZNER_SSH_PORT` | 22 | + ## Building from source diff --git a/driver.go b/driver.go index b274958..345dda3 100644 --- a/driver.go +++ b/driver.go @@ -76,11 +76,17 @@ const ( flagPlacementGroup = "hetzner-placement-group" flagAutoSpread = "hetzner-auto-spread" + flagSshUser = "hetzner-ssh-user" + flagSshPort = "hetzner-ssh-port" + labelNamespace = "docker-machine" labelAutoSpreadPg = "auto-spread" labelAutoCreated = "auto-created" autoSpreadPgName = "__auto_spread" + + defaultSSHPort = 22 + defaultSSHUser = "root" ) // NewDriver initializes a new driver instance; see [drivers.Driver.NewDriver] @@ -90,8 +96,6 @@ func NewDriver() *Driver { Type: defaultType, IsExistingKey: false, BaseDriver: &drivers.BaseDriver{ - SSHUser: drivers.DefaultSSHUser, - SSHPort: drivers.DefaultSSHPort, }, } } @@ -203,6 +207,18 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { Name: flagAutoSpread, Usage: "Auto-spread on a docker-machine-specific default placement group", }, + mcnflag.StringFlag{ + EnvVar: "HETZNER_SSH_USER", + Name: flagSshUser, + Usage: "SSH username", + Value: defaultSSHUser, + }, + mcnflag.IntFlag{ + EnvVar: "HETZNER_SSH_PORT", + Name: flagSshPort, + Usage: "SSH port", + Value: defaultSSHPort, + }, } } @@ -224,6 +240,9 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error { d.Firewalls = opts.StringSlice(flagFirewalls) d.AdditionalKeys = opts.StringSlice(flagAdditionalKeys) + d.SSHUser = opts.String(flagSshUser) + d.SSHPort = opts.Int(flagSshPort) + d.placementGroup = opts.String(flagPlacementGroup) if opts.Bool(flagAutoSpread) { if d.placementGroup != "" { @@ -250,6 +269,14 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error { return nil } +func (d *Driver) GetSSHUsername() string { + return d.SSHUser +} + +func (d *Driver) GetSSHPort() (int, error) { + return d.SSHPort, nil +} + func (d *Driver) setLabelsFromFlags(opts drivers.DriverOptions) error { d.ServerLabels = make(map[string]string) for _, label := range opts.StringSlice(flagServerLabel) {