-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Canux CHENG
authored and
Canux CHENG
committed
Nov 25, 2019
1 parent
45918cb
commit 7944b4e
Showing
11 changed files
with
269 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
asn1crypto==0.24.0 | ||
bcrypt==3.1.7 | ||
bleach==3.1.0 | ||
certifi==2019.6.16 | ||
cffi==1.12.3 | ||
chardet==3.0.4 | ||
colorama==0.4.1 | ||
cryptography==2.7 | ||
docker==4.0.2 | ||
docutils==0.15.2 | ||
enum34==1.1.6 | ||
idna==2.8 | ||
libvirt-python==5.5.0 | ||
ntlm-auth==1.3.0 | ||
paramiko==2.6.0 | ||
pika==1.1.0 | ||
pkginfo==1.5.0.1 | ||
pycparser==2.19 | ||
Pygments==2.4.2 | ||
pymongo==3.8.0 | ||
pymssql==2.1.4 | ||
PyMySQL==0.9.3 | ||
PyNaCl==1.3.0 | ||
python-iptables==0.14.0 | ||
pywinrm==0.3.0 | ||
PyYAML==5.1.1 | ||
readme-renderer==24.0 | ||
redis==3.2.1 | ||
requests==2.22.0 | ||
requests-ntlm==1.1.0 | ||
requests-toolbelt==0.9.1 | ||
robotframework==3.1.2 | ||
selenium==3.141.0 | ||
six==1.12.0 | ||
SQLAlchemy==1.3.5 | ||
tqdm==4.36.1 | ||
twine==2.0.0 | ||
urllib3==1.25.3 | ||
webencodings==0.5.1 | ||
websocket-client==0.56.0 | ||
xmltodict==0.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ | |
DESCRIPTION: | ||
""" | ||
|
||
__version__ = "1.8.4" | ||
__version__ = "1.8.6" | ||
__author__ = "Canux CHENG" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import sys | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
import iptc | ||
|
||
class BaseIptables(object): | ||
def __init__(self, table='filter'): | ||
if table.upper() == "FILTER": | ||
self.table_name = iptc.Table.FILTER | ||
elif table.upper() == "NAT": | ||
self.table_name = iptc.Table.NAT | ||
elif table.upper() == "MANGLE": | ||
self.table_name = iptc.Table.MANGLE | ||
elif table.upper() == "RAW": | ||
self.table_name = iptc.Table.RAW | ||
elif table.upper() == "SECURITY": | ||
self.table_name = iptc.Table.SECURITY | ||
else: | ||
raise ValueError("table not support!") | ||
self.table = iptc.Table(self.table_name) | ||
|
||
def delete_user_define_chain(self): | ||
try: | ||
logger.debug("delete all user define chain.") | ||
self.table.flush() | ||
except Exception: | ||
raise | ||
|
||
def clean_builtin_chain(self): | ||
try: | ||
logger.debug("delete all rules from builtin chain.") | ||
for chain in self.table.chains: | ||
if chain.is_builtin(): | ||
chain.flush() | ||
except Exception: | ||
raise | ||
|
||
def set_policy_for_builtin_chain(self, policy="ACCEPT"): | ||
try: | ||
logger.debug("set policy for all builtin chain.") | ||
for chain in self.table.chains: | ||
if chain.is_builtin(): | ||
chain.set_policy(policy.upper()) | ||
except Exception: | ||
raise | ||
|
||
def check_rule_exist_on_chain(self, chain, rule_dict): | ||
try: | ||
chain = iptc.Chain(self.table, chain.upper()) | ||
for rule in chain.rules: | ||
if iptc.easy.decode_iptc_rule(rule) == rule_dict: | ||
break | ||
else: | ||
logger.debug("rule not exist.") | ||
return False | ||
logger.debug("rule exist.") | ||
return True | ||
except Exception: | ||
raise | ||
|
||
def delete_rule_from_chain(self, chain, rule_dict): | ||
try: | ||
logger.debug("delete rule from chain.") | ||
chain = iptc.Chain(self.table, chain.upper()) | ||
chain.delete_rule(iptc.easy.encode_iptc_rule(rule_dict)) | ||
except Exception: | ||
raise | ||
|
||
def replace_rule_from_chain(self, chain, rule_dict): | ||
try: | ||
logger.debug("replace rule from chain.") | ||
chain = iptc.Chain(self.table, chain.upper()) | ||
chain.replace_rule(iptc.easy.encode_iptc_rule(rule_dict)) | ||
except Exception: | ||
raise | ||
|
||
def append_rule_to_chain(self, chain, rule_dict): | ||
try: | ||
logger.debug("append rule to chain.") | ||
chain = iptc.Chain(self.table, chain.upper()) | ||
chain.append_rule(iptc.easy.encode_iptc_rule(rule_dict)) | ||
except Exception: | ||
raise | ||
|
||
def insert_rule_to_chain(self, chain, rule_dict): | ||
try: | ||
logger.debug("insert rule to chain.") | ||
chain = iptc.Chain(self.table, chain.upper()) | ||
chain.insert_rule(iptc.easy.encode_iptc_rule(rule_dict)) | ||
except Exception: | ||
raise | ||
|
||
|
||
if __name__ == "__main__": | ||
rule_dict = { | ||
'src': '172.20.0.0/16', | ||
'dst': '!172.20.0.0/16', | ||
'target': 'MASQUERADE' | ||
} | ||
it = BaseIptables('nat') | ||
if it.check_rule_exist_on_chain('POSTROUTING', rule_dict): | ||
it.delete_rule_from_chain('postrouting', rule_dict) | ||
|
||
|
||
it = BaseIptables('filter') | ||
it.delete_user_define_chain() | ||
it.clean_builtin_chain() | ||
it.set_policy_for_builtin_chain() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
|
||
from super_devops.grafana.grafana_wrapper import BaseGrafana | ||
|
||
|
||
class GrafanaTestCase(unittest.TestCase): | ||
@unittest.skip('ignore') | ||
def test_check_datasource_exist(self): | ||
grafana = BaseGrafana("http://10.103.64.207:3000", "sandbox", | ||
"password") | ||
result = grafana.check_data_source_exist_by_name("MAF") | ||
self.assertEqual(True, result, msg="check datasource exist failed.") | ||
|
||
def test_check_datasource_exist(self): | ||
grafana = BaseGrafana("http://10.103.64.207:3000", | ||
'eyJrIjoiSU84dnphRGlOUTlaeGNCdTQ3clJlZjBxZG9IUFQ3cGoiLCJuIjoidGVzdCIsImlkIjoxfQ==' | ||
) | ||
result = grafana.check_data_source_exist_by_name("MAF") | ||
self.assertEqual(True, result, msg="check datasource exist failed.") | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import unittest | ||
|
||
from super_devops.nosql.redis_wrapper import BaseRedis | ||
|
||
|
||
class RedisTestCase(unittest.TestCase): | ||
def test_ping(self): | ||
redis = BaseRedis('10.103.64.188') | ||
print(redis.ping()) | ||
|