Skip to content

Commit

Permalink
Merge pull request #77 from ThorstenHeck/master
Browse files Browse the repository at this point in the history
Add the possibility to change SSH Port and SSH User
  • Loading branch information
JonasProgrammer authored Jan 23, 2022
2 parents 81087ed + d434888 commit 0ffaf03
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
31 changes: 29 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -90,8 +96,6 @@ func NewDriver() *Driver {
Type: defaultType,
IsExistingKey: false,
BaseDriver: &drivers.BaseDriver{
SSHUser: drivers.DefaultSSHUser,
SSHPort: drivers.DefaultSSHPort,
},
}
}
Expand Down Expand Up @@ -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,
},
}
}

Expand All @@ -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 != "" {
Expand All @@ -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) {
Expand Down

0 comments on commit 0ffaf03

Please sign in to comment.