@@ -39,6 +39,7 @@ const (
39
39
defaultVolumeType = "gp2"
40
40
defaultZone = "a"
41
41
defaultSecurityGroup = machineSecurityGroupName
42
+ defaultSSHPort = 22
42
43
defaultSSHUser = "ubuntu"
43
44
defaultSpotPrice = "0.50"
44
45
defaultBlockDurationMinutes = 0
@@ -211,9 +212,15 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
211
212
Usage : "AWS IAM Instance Profile" ,
212
213
EnvVar : "AWS_INSTANCE_PROFILE" ,
213
214
},
215
+ mcnflag.IntFlag {
216
+ Name : "amazonec2-ssh-port" ,
217
+ Usage : "SSH port" ,
218
+ Value : defaultSSHPort ,
219
+ EnvVar : "AWS_SSH_PORT" ,
220
+ },
214
221
mcnflag.StringFlag {
215
222
Name : "amazonec2-ssh-user" ,
216
- Usage : "Set the name of the ssh user " ,
223
+ Usage : "SSH username " ,
217
224
Value : defaultSSHUser ,
218
225
EnvVar : "AWS_SSH_USER" ,
219
226
},
@@ -294,6 +301,7 @@ func NewDriver(hostName, storePath string) *Driver {
294
301
SpotPrice : defaultSpotPrice ,
295
302
BlockDurationMinutes : defaultBlockDurationMinutes ,
296
303
BaseDriver : & drivers.BaseDriver {
304
+ SSHPort : defaultSSHPort ,
297
305
SSHUser : defaultSSHUser ,
298
306
MachineName : hostName ,
299
307
StorePath : storePath ,
@@ -363,7 +371,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
363
371
d .VolumeType = flags .String ("amazonec2-volume-type" )
364
372
d .IamInstanceProfile = flags .String ("amazonec2-iam-instance-profile" )
365
373
d .SSHUser = flags .String ("amazonec2-ssh-user" )
366
- d .SSHPort = 22
374
+ d .SSHPort = flags . Int ( "amazonec2-ssh-port" )
367
375
d .PrivateIPOnly = flags .Bool ("amazonec2-private-address-only" )
368
376
d .UsePrivateIP = flags .Bool ("amazonec2-use-private-address" )
369
377
d .Monitoring = flags .Bool ("amazonec2-monitoring" )
@@ -837,6 +845,14 @@ func (d *Driver) GetSSHHostname() (string, error) {
837
845
return d .GetIP ()
838
846
}
839
847
848
+ func (d * Driver ) GetSSHPort () (int , error ) {
849
+ if d .SSHPort == 0 {
850
+ d .SSHPort = defaultSSHPort
851
+ }
852
+
853
+ return d .SSHPort , nil
854
+ }
855
+
840
856
func (d * Driver ) GetSSHUsername () string {
841
857
if d .SSHUser == "" {
842
858
d .SSHUser = defaultSSHUser
@@ -1161,11 +1177,11 @@ func (d *Driver) configureSecurityGroupPermissions(group *ec2.SecurityGroup) ([]
1161
1177
1162
1178
perms := []* ec2.IpPermission {}
1163
1179
1164
- if ! hasPorts ["22 /tcp" ] {
1180
+ if ! hasPorts [fmt . Sprintf ( "%d /tcp", d . BaseDriver . SSHPort ) ] {
1165
1181
perms = append (perms , & ec2.IpPermission {
1166
1182
IpProtocol : aws .String ("tcp" ),
1167
- FromPort : aws .Int64 (22 ),
1168
- ToPort : aws .Int64 (22 ),
1183
+ FromPort : aws .Int64 (int64 ( d . BaseDriver . SSHPort ) ),
1184
+ ToPort : aws .Int64 (int64 ( d . BaseDriver . SSHPort ) ),
1169
1185
IpRanges : []* ec2.IpRange {{CidrIp : aws .String (ipRange )}},
1170
1186
})
1171
1187
}
0 commit comments