File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -263,11 +263,19 @@ func (driver *Driver) PreCreateCheck() error {
263263
264264// Create a new Docker Machine instance on CloudControl.
265265func (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+ }
271279 }
272280
273281 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 {
106106 return nil
107107}
108108
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+
109126// Import the configured SSH key files into the machine store folder.
110127func (driver * Driver ) importSSHKey () error {
111128 if driver .SSHKey == "" {
@@ -117,14 +134,14 @@ func (driver *Driver) importSSHKey() error {
117134 )
118135 err := copySSHKey (driver .SSHKey , driver .SSHKeyPath )
119136 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 ())
121138
122139 return err
123140 }
124141
125142 err = copySSHKey (driver .SSHKey + ".pub" , driver .SSHKeyPath + ".pub" )
126143 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 ())
128145
129146 return err
130147 }
You can’t perform that action at this time.
0 commit comments