mirror of https://github.com/docker/docs.git
Merge pull request #3144 from bamarni/do-existing-ssh-key
[DigitalOcean] Allow to use an existing SSH key (closes #1445)
This commit is contained in:
commit
698958f61a
|
|
@ -29,6 +29,7 @@ Options:
|
|||
- `--digitalocean-userdata`: Path to file containing User Data for the droplet.
|
||||
- `--digitalocean-ssh-user`: SSH username.
|
||||
- `--digitalocean-ssh-port`: SSH port.
|
||||
- `--digitalocean-ssh-key-fingerprint`: Use an existing SSH key instead of creating a new one, see [SSH keys](https://developers.digitalocean.com/documentation/v2/#ssh-keys).
|
||||
|
||||
The DigitalOcean driver will use `ubuntu-15-10-x64` as the default image.
|
||||
|
||||
|
|
@ -46,3 +47,4 @@ Environment variables and default values:
|
|||
| `--digitalocean-userdata` | `DIGITALOCEAN_USERDATA` | - |
|
||||
| `--digitalocean-ssh-user` | `DIGITALOCEAN_SSH_USER` | `root` |
|
||||
| `--digitalocean-ssh-port` | `DIGITALOCEAN_SSH_PORT` | 22 |
|
||||
| `--digitalocean-ssh-key-fingerprint`| `DIGITALOCEAN_SSH_KEY_FINGERPRINT`| - |
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type Driver struct {
|
|||
Image string
|
||||
Region string
|
||||
SSHKeyID int
|
||||
SSHKeyFingerprint string
|
||||
Size string
|
||||
IPv6 bool
|
||||
Backups bool
|
||||
|
|
@ -54,6 +55,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
|
|||
Usage: "SSH username",
|
||||
Value: defaultSSHUser,
|
||||
},
|
||||
mcnflag.StringFlag{
|
||||
EnvVar: "DIGITALOCEAN_SSH_KEY_FINGERPRINT",
|
||||
Name: "digitalocean-ssh-key-fingerprint",
|
||||
Usage: "SSH key fingerprint",
|
||||
},
|
||||
mcnflag.IntFlag{
|
||||
EnvVar: "DIGITALOCEAN_SSH_PORT",
|
||||
Name: "digitalocean-ssh-port",
|
||||
|
|
@ -133,6 +139,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
|||
d.UserDataFile = flags.String("digitalocean-userdata")
|
||||
d.SSHUser = flags.String("digitalocean-ssh-user")
|
||||
d.SSHPort = flags.Int("digitalocean-ssh-port")
|
||||
d.SSHKeyFingerprint = flags.String("digitalocean-ssh-key-fingerprint")
|
||||
d.SetSwarmConfigFromFlags(flags)
|
||||
|
||||
if d.AccessToken == "" {
|
||||
|
|
@ -232,6 +239,14 @@ func (d *Driver) Create() error {
|
|||
}
|
||||
|
||||
func (d *Driver) createSSHKey() (*godo.Key, error) {
|
||||
if d.SSHKeyFingerprint != "" {
|
||||
key, resp, err := d.getClient().Keys.GetByFingerprint(d.SSHKeyFingerprint)
|
||||
if err != nil && resp.StatusCode == 404 {
|
||||
return nil, fmt.Errorf("Digital Ocean SSH key with fingerprint %s doesn't exist", d.SSHKeyFingerprint)
|
||||
}
|
||||
return key, err
|
||||
}
|
||||
|
||||
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -305,11 +320,13 @@ func (d *Driver) Kill() error {
|
|||
|
||||
func (d *Driver) Remove() error {
|
||||
client := d.getClient()
|
||||
if resp, err := client.Keys.DeleteByID(d.SSHKeyID); err != nil {
|
||||
if resp.StatusCode == 404 {
|
||||
log.Infof("Digital Ocean SSH key doesn't exist, assuming it is already deleted")
|
||||
} else {
|
||||
return err
|
||||
if d.SSHKeyFingerprint == "" {
|
||||
if resp, err := client.Keys.DeleteByID(d.SSHKeyID); err != nil {
|
||||
if resp.StatusCode == 404 {
|
||||
log.Infof("Digital Ocean SSH key doesn't exist, assuming it is already deleted")
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if resp, err := client.Droplets.Delete(d.DropletID); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue