~junaidali/charms/trusty/plumgrid-gateway/analyst_opsvm

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/network/ufw.py

  • Committer: bbaqar at plumgrid
  • Date: 2016-04-25 09:21:09 UTC
  • mfrom: (26.1.2 plumgrid-gateway)
  • Revision ID: bbaqar@plumgrid.com-20160425092109-kweey25bx97pmj80
Merge: Liberty/Mitaka support

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
import re
41
41
import os
42
42
import subprocess
 
43
 
43
44
from charmhelpers.core import hookenv
 
45
from charmhelpers.core.kernel import modprobe, is_module_loaded
44
46
 
45
47
__author__ = "Felipe Reyes <felipe.reyes@canonical.com>"
46
48
 
82
84
    # do we have IPv6 in the machine?
83
85
    if os.path.isdir('/proc/sys/net/ipv6'):
84
86
        # is ip6tables kernel module loaded?
85
 
        lsmod = subprocess.check_output(['lsmod'], universal_newlines=True)
86
 
        matches = re.findall('^ip6_tables[ ]+', lsmod, re.M)
87
 
        if len(matches) == 0:
 
87
        if not is_module_loaded('ip6_tables'):
88
88
            # ip6tables support isn't complete, let's try to load it
89
89
            try:
90
 
                subprocess.check_output(['modprobe', 'ip6_tables'],
91
 
                                        universal_newlines=True)
92
 
                # great, we could load the module
 
90
                modprobe('ip6_tables')
 
91
                # great, we can load the module
93
92
                return True
94
93
            except subprocess.CalledProcessError as ex:
95
94
                hookenv.log("Couldn't load ip6_tables module: %s" % ex.output,