71
Check if IPv6 support is present and ip6tables functional
73
:returns: True if IPv6 is working, False otherwise
76
# do we have IPv6 in the machine?
77
if os.path.isdir('/proc/sys/net/ipv6'):
78
# is ip6tables kernel module loaded?
79
lsmod = subprocess.check_output(['lsmod'], universal_newlines=True)
80
matches = re.findall('^ip6_tables[ ]+', lsmod, re.M)
82
# ip6tables support isn't complete, let's try to load it
84
subprocess.check_output(['modprobe', 'ip6_tables'],
85
universal_newlines=True)
86
# great, we could load the module
88
except subprocess.CalledProcessError as ex:
89
hookenv.log("Couldn't load ip6_tables module: %s" % ex.output,
91
# we are in a world where ip6tables isn't working
92
# so we inform that the machine doesn't have IPv6
95
# the module is present :)
99
# the system doesn't have IPv6
105
Disable ufw IPv6 support in /etc/default/ufw
107
exit_code = subprocess.call(['sed', '-i', 's/IPV6=.*/IPV6=no/g',
110
hookenv.log('IPv6 support in ufw disabled', level='INFO')
112
hookenv.log("Couldn't disable IPv6 support in ufw", level="ERROR")
113
raise UFWError("Couldn't disable IPv6 support in ufw")
73
if not os.path.isdir('/proc/sys/net/ipv6'):
74
# disable IPv6 support in ufw
75
hookenv.log("This machine doesn't have IPv6 enabled", level="INFO")
76
exit_code = subprocess.call(['sed', '-i', 's/IPV6=yes/IPV6=no/g',
79
hookenv.log('IPv6 support in ufw disabled', level='INFO')
81
hookenv.log("Couldn't disable IPv6 support in ufw", level="ERROR")
82
raise Exception("Couldn't disable IPv6 support in ufw")
84
128
output = subprocess.check_output(['ufw', 'enable'],
129
universal_newlines=True,
85
130
env={'LANG': 'en_US',
86
131
'PATH': os.environ['PATH']})
208
254
:param action: `open` or `close`
210
256
if action == 'open':
211
subprocess.check_output(['ufw', 'allow', name])
257
subprocess.check_output(['ufw', 'allow', str(name)],
258
universal_newlines=True)
212
259
elif action == 'close':
213
subprocess.check_output(['ufw', 'delete', 'allow', name])
260
subprocess.check_output(['ufw', 'delete', 'allow', str(name)],
261
universal_newlines=True)
215
raise Exception(("'{}' not supported, use 'allow' "
216
"or 'delete'").format(action))
263
raise UFWError(("'{}' not supported, use 'allow' "
264
"or 'delete'").format(action))