def _load(self, rules):
"""Load IPTables rules
Args:
list: IPTables rules
Returns:
(int, Optional[str]): A tuple where the first object is the return code and the second is an optional error string associated to the return code.
"""
tmpfile = tempfile.NamedTemporaryFile(
dir=self._sessions_dir, delete=False)
tmpfile.write("\n".join(rules))
tmpfile.close()
os.chmod(tmpfile.name, 0755)
proc = subprocess.Popen(tmpfile.name, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
os.remove(tmpfile.name)
return proc.returncode, err
评论列表
文章目录