File tree Expand file tree Collapse file tree 2 files changed +32
-7
lines changed Expand file tree Collapse file tree 2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -263,11 +263,19 @@ func (driver *Driver) PreCreateCheck() error {
263
263
264
264
// Create a new Docker Machine instance on CloudControl.
265
265
func (driver * Driver ) Create () error {
266
- log .Infof ("Importing SSH key..." )
267
-
268
- err := driver .importSSHKey ()
269
- if err != nil {
270
- return err
266
+ var err error
267
+ if driver .SSHKey != "" {
268
+ log .Infof ("Importing SSH key '%s'..." , driver .SSHKey )
269
+ err = driver .importSSHKey ()
270
+ if err != nil {
271
+ return err
272
+ }
273
+ } else {
274
+ log .Infof ("Generating new SSH key..." )
275
+ err = driver .generateSSHKey ()
276
+ if err != nil {
277
+ return err
278
+ }
271
279
}
272
280
273
281
log .Infof ("Creating server '%s'..." , driver .MachineName )
Original file line number Diff line number Diff line change @@ -106,6 +106,23 @@ func (driver *Driver) installSSHKey() error {
106
106
return nil
107
107
}
108
108
109
+ // Generate an SSH key pair, and save it into the machine store folder.
110
+ func (driver * Driver ) generateSSHKey () error {
111
+ if driver .SSHKeyPath != "" {
112
+ return errors .New ("SSH key path already configured" )
113
+ }
114
+
115
+ driver .SSHKeyPath = driver .ResolveStorePath ("id_rsa" )
116
+ err := ssh .GenerateSSHKey (driver .SSHKeyPath )
117
+ if err != nil {
118
+ log .Errorf ("Failed to generate SSH key pair: %s" , err .Error ())
119
+
120
+ return err
121
+ }
122
+
123
+ return nil
124
+ }
125
+
109
126
// Import the configured SSH key files into the machine store folder.
110
127
func (driver * Driver ) importSSHKey () error {
111
128
if driver .SSHKey == "" {
@@ -117,14 +134,14 @@ func (driver *Driver) importSSHKey() error {
117
134
)
118
135
err := copySSHKey (driver .SSHKey , driver .SSHKeyPath )
119
136
if err != nil {
120
- log .Infof ("Couldn't copy SSH private key : %s" , err .Error ())
137
+ log .Infof ("Couldn't copy SSH private key: %s" , err .Error ())
121
138
122
139
return err
123
140
}
124
141
125
142
err = copySSHKey (driver .SSHKey + ".pub" , driver .SSHKeyPath + ".pub" )
126
143
if err != nil {
127
- log .Infof ("Couldn't copy SSH public key : %s" , err .Error ())
144
+ log .Infof ("Couldn't copy SSH public key: %s" , err .Error ())
128
145
129
146
return err
130
147
}
You can’t perform that action at this time.
0 commit comments