Skip to content

Commit 4604c12

Browse files
committed
Clear out iptables configuration if using RedHat 6 or 7 image (#6).
1 parent b39f5ce commit 4604c12

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func (driver *Driver) resolveOSImage() error {
227227
}
228228

229229
driver.ImageID = image.ID
230+
driver.ImageOSType = image.OperatingSystem.ID
230231

231232
return nil
232233
}

driver.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type Driver struct {
5454
// The Id of the OS image used to create the machine.
5555
ImageID string
5656

57+
// The operating system type (e.g. "REDHAT764", "CENTOS764", "UBUNTU1464", etc) of the OS image used to create the machine.
58+
ImageOSType string
59+
5760
// The Id of the target server.
5861
ServerID string
5962

@@ -227,6 +230,17 @@ func (driver *Driver) PreCreateCheck() error {
227230
return err
228231
}
229232

233+
switch driver.ImageOSType {
234+
case "REDHAT664":
235+
case "REDHAT764":
236+
log.Warnf("Image '%s' is RedHat 6 or 7 (64-bit).",
237+
driver.ImageName,
238+
)
239+
log.Warnf("This image is known to have problems with Docker Machine (the ddcloud driver will need to clear the server's iptables configuration when it is provisioned).")
240+
241+
break
242+
}
243+
230244
return nil
231245
}
232246

@@ -284,6 +298,17 @@ func (driver *Driver) Create() error {
284298
return err
285299
}
286300

301+
switch driver.ImageOSType {
302+
case "REDHAT664":
303+
case "REDHAT764":
304+
err = driver.clearIPTablesConfiguration()
305+
if err != nil {
306+
return err
307+
}
308+
309+
break
310+
}
311+
287312
log.Infof("Server '%s' has been successfully created.", server.Name)
288313

289314
return nil

iptables.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/docker/machine/libmachine/log"
6+
"github.com/docker/machine/libmachine/ssh"
7+
)
8+
9+
func (driver *Driver) clearIPTablesConfiguration() error {
10+
if !driver.isServerCreated() {
11+
return fmt.Errorf("Server '%s' has not been created", driver.MachineName)
12+
}
13+
14+
log.Debugf("Flushing iptables configuration for server '%s'...",
15+
driver.MachineName,
16+
)
17+
18+
client, err := ssh.NewNativeClient(driver.SSHUser, driver.IPAddress, driver.SSHPort, &ssh.Auth{
19+
Keys: []string{driver.SSHKeyPath},
20+
})
21+
if err != nil {
22+
return err
23+
}
24+
25+
log.Debugf("Run 'iptables -F'...")
26+
output, err := client.Output(`iptables -F`)
27+
if err != nil {
28+
return fmt.Errorf("Failed to run 'iptables -F'\n%s\nOutput:\n%s",
29+
err.Error(),
30+
output,
31+
)
32+
}
33+
34+
log.Debugf("Successfully flushed iptables configuration for server '%s'.",
35+
driver.MachineName,
36+
)
37+
38+
return nil
39+
}

ssh_bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
// Bootstrap key-based SSH authentication by installing an SSH public key on the target machine.
2424
func (driver *Driver) installSSHKey() error {
25-
if driver.ServerID == "" {
25+
if !driver.isServerCreated() {
2626
return errors.New("Server has not been deployed")
2727
}
2828

0 commit comments

Comments
 (0)