Skip to content

Commit 2a02743

Browse files
committed
Add support for using private IPs rather than public ones (#6).
1 parent 663970c commit 2a02743

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

CHANGES.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changes
22

3-
## v0.3
3+
## v0.4
4+
5+
New features:
6+
7+
* Add support for using private IP addresses instead of public ones (#6)
8+
9+
## v0.4
410

511
Breaking changes:
612

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = 0.3
1+
VERSION = 0.4
22

33
default: fmt build test
44

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Environment: `MCP_SSH_PORT`
5353
This password is removed once the SSH key has been installed
5454
Environment: `MCP_SSH_BOOTSTRAP_PASSWORD`
5555
* `ddcloud-create-ssh-firewall-rule` - Automatically create a firewall rule to enable inbound SSH to the target server?
56+
* `ddcloud-use-private-ip` - Don't create NAT and firewall rules for target server (you will need to be connected to the VPN for your target data centre).
5657

5758
## Installing the provider
5859

driver.go

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ type Driver struct {
6060
// The private IPv4 address of the target server.
6161
PrivateIPAddress string
6262

63+
// Only use the target server's private IP address?
64+
//
65+
// If true, then no NAT rule or firewall rule will be created.
66+
UsePrivateIP bool
67+
6368
// The Id of the NAT rule (if any) for the target server.
6469
NATRuleID string
6570

@@ -149,6 +154,10 @@ func (driver *Driver) GetCreateFlags() []mcnflag.Flag {
149154
Name: "ddcloud-create-ssh-firewall-rule",
150155
Usage: "Create a firewall rule to allow SSH access to the target server? Default: false",
151156
},
157+
mcnflag.BoolFlag{
158+
Name: "ddcloud-use-private-ip",
159+
Usage: "Don't create NAT and firewall rules for target server (you will need to be connected to the VPN for your target data centre). Default: false",
160+
},
152161
}
153162
}
154163

@@ -175,6 +184,7 @@ func (driver *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
175184
driver.SSHBootstrapPassword = flags.String("ddcloud-ssh-bootstrap-password")
176185

177186
driver.CreateSSHFirewallRule = flags.Bool("ddcloud-create-ssh-firewall-rule")
187+
driver.UsePrivateIP = flags.Bool("ddcloud-use-private-ip")
178188

179189
log.Debugf("docker-machine-driver-ddcloud %s", DriverVersion)
180190

@@ -235,34 +245,37 @@ func (driver *Driver) Create() error {
235245
return err
236246
}
237247

238-
log.Infof("Exposing server '%s'...", driver.MachineName)
239-
err = driver.createNATRuleForServer()
240-
if err != nil {
241-
return err
242-
}
243-
244-
log.Infof("Server '%s' has private IP '%s'.", driver.MachineName, driver.PrivateIPAddress)
245-
log.Infof("Server '%s' has public IP '%s'.", driver.MachineName, driver.IPAddress)
246-
247-
if driver.CreateSSHFirewallRule {
248-
var clientPublicIPAddress string
249-
clientPublicIPAddress, err = getClientPublicIPv4Address()
248+
if !driver.UsePrivateIP {
249+
log.Infof("Exposing server '%s'...", driver.MachineName)
250+
err = driver.createNATRuleForServer()
250251
if err != nil {
251252
return err
252253
}
253254

254-
log.Infof("Creating firewall rule to enable inbound SSH traffic from local machine '%s' ('%s') to '%s' ('%s':%d)...",
255-
os.Getenv("HOST"),
256-
clientPublicIPAddress,
257-
driver.MachineName,
258-
driver.IPAddress,
259-
driver.SSHPort,
260-
)
261-
262-
err = driver.createSSHFirewallRule(clientPublicIPAddress)
263-
if err != nil {
264-
return err
255+
log.Infof("Server '%s' has public IP '%s'.", driver.MachineName, driver.IPAddress)
256+
257+
if driver.CreateSSHFirewallRule {
258+
var clientPublicIPAddress string
259+
clientPublicIPAddress, err = getClientPublicIPv4Address()
260+
if err != nil {
261+
return err
262+
}
263+
264+
log.Infof("Creating firewall rule to enable inbound SSH traffic from local machine '%s' ('%s') to '%s' ('%s':%d)...",
265+
os.Getenv("HOST"),
266+
clientPublicIPAddress,
267+
driver.MachineName,
268+
driver.IPAddress,
269+
driver.SSHPort,
270+
)
271+
272+
err = driver.createSSHFirewallRule(clientPublicIPAddress)
273+
if err != nil {
274+
return err
275+
}
265276
}
277+
} else {
278+
log.Infof("Server '%s' has private IP '%s'.", driver.MachineName, driver.PrivateIPAddress)
266279
}
267280

268281
log.Infof("Installing SSH key for server '%s' ('%s')...", driver.MachineName, driver.IPAddress)

0 commit comments

Comments
 (0)