Skip to content

Commit f5c6286

Browse files
author
Dani Louca
committed
Make ssd portable and usuable outside the default image.
Add error check when network on a particular node has no services Signed-off-by: Dani Louca <dani.louca@docker.com>
1 parent 92888fe commit f5c6286

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

libnetwork/cmd/ssd/ssd.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python
22

3-
import sys, signal, time
3+
import sys, signal, time, os
44
import docker
55
import re
66
import subprocess
@@ -14,6 +14,14 @@
1414
r'(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])'
1515
)
1616

17+
def which(name, defaultPath=""):
18+
if defaultPath and os.path.exists(defaultPath):
19+
return defaultPath
20+
for path in os.getenv("PATH").split(os.path.pathsep):
21+
fullPath = path + os.sep + name
22+
if os.path.exists(fullPath):
23+
return fullPath
24+
1725
def check_iptables(name, plist):
1826
replace = (':', ',')
1927
ports = []
@@ -26,13 +34,13 @@ def check_iptables(name, plist):
2634

2735
# get the ingress sandbox's docker_gwbridge network IP.
2836
# published ports get DNAT'ed to this IP.
29-
ip = subprocess.check_output(['/usr/bin/nsenter', '--net=/var/run/docker/netns/ingress_sbox', '/bin/bash', '-c', 'ifconfig eth1 | grep \"inet\\ addr\" | cut -d: -f2 | cut -d\" \" -f1'])
37+
ip = subprocess.check_output([ which("nsenter","/usr/bin/nsenter"), '--net=/var/run/docker/netns/ingress_sbox', which("bash", "/bin/bash"), '-c', 'ifconfig eth1 | grep \"inet\\ addr\" | cut -d: -f2 | cut -d\" \" -f1'])
3038
ip = ip.rstrip()
3139

3240
for p in ports:
33-
rule = '/sbin/iptables -t nat -C DOCKER-INGRESS -p tcp --dport {0} -j DNAT --to {1}:{2}'.format(p[1], ip, p[1])
41+
rule = which("iptables", "/sbin/iptables") + '-t nat -C DOCKER-INGRESS -p tcp --dport {0} -j DNAT --to {1}:{2}'.format(p[1], ip, p[1])
3442
try:
35-
subprocess.check_output(["/bin/bash", "-c", rule])
43+
subprocess.check_output([which("bash", "/bin/bash"), "-c", rule])
3644
except subprocess.CalledProcessError as e:
3745
print "Service {0}: host iptables DNAT rule for port {1} -> ingress sandbox {2}:{3} missing".format(name, p[1], ip, p[1])
3846

@@ -58,7 +66,12 @@ def check_network(nw_name, ingress=False):
5866

5967
data = cli.inspect_network(nw_name, verbose=True)
6068

61-
services = data["Services"]
69+
if "Services" in data.keys():
70+
services = data["Services"]
71+
else:
72+
print "Network %s has no services. Skipping check" % nw_name
73+
return
74+
6275
fwmarks = {str(service): str(svalue["LocalLBIndex"]) for service, svalue in services.items()}
6376

6477
stasks = {}
@@ -78,7 +91,7 @@ def check_network(nw_name, ingress=False):
7891
containers = get_namespaces(data, ingress)
7992
for container, namespace in containers.items():
8093
print "Verifying container %s..." % container
81-
ipvs = subprocess.check_output(['/usr/bin/nsenter', '--net=%s' % namespace, '/usr/sbin/ipvsadm', '-ln'])
94+
ipvs = subprocess.check_output([which("nsenter","/usr/bin/nsenter"), '--net=%s' % namespace, which("ipvsadm","/usr/sbin/ipvsadm"), '-ln'])
8295

8396
mark = ""
8497
realmark = {}

0 commit comments

Comments
 (0)