Add the static nat rules to the merge procedure

This commit is contained in:
Hugo Trippaers 2014-08-20 17:29:58 +02:00 committed by wilderrodrigues
parent a789e8bf57
commit f273fd4659
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,33 @@
from pprint import pprint
def merge(dbag, rules):
for rule in rules["rules"]:
source_ip = rule["source_ip_address"]
destination_ip = rule["destination_ip_address"]
revoke = rule["revoke"]
if not revoke:
if rules["type"] == "staticnatrules":
snatrule = dict()
snatrule["type"] = "staticnat"
snatrule["public_ip"] = source_ip
snatrule["internal_ip"] = destination_ip
dbag[source_ip] = ( snatrule )
elif rules["type"] == "forwardrules":
pfrule = dict()
pfrule["type"] = "forward"
pfrule["public_ip"] = source_ip
pfrule["public_ports"] = rule["source_port_range"]
pfrule["internal_ip"] = destination_ip
pfrule["interal_ports"] = rule["destination_port_range"]
pfrule["prootocol"] = rule["protocol"]
if source_ip in dbag.keys():
for forward in dbag[source_ip]:
print "find duplicate here"
else:
dbag[source_ip] = ( pfrule )
elif revoke:
if rules["type"] == "staticnatrules":
if source_ip in dbag.keys():
del dbag[source_ip]
return dbag

View File

@ -11,6 +11,7 @@ import cs_vmp
import cs_network_acl
import cs_vmdata
import cs_dhcp
import cs_forwardingrules
from pprint import pprint
@ -84,6 +85,8 @@ class updateDataBag:
dbag = self.processVmData(self.db.getDataBag())
elif self.qFile.type == 'dhcpentry':
dbag = self.process_dhcp_entry(self.db.getDataBag())
elif self.qFile.type == 'staticnatrules' or self.qFile.type == 'forwardrules':
dbag = self.processForwardingRules(self.db.getDataBag())
else:
logging.error("Error I do not know what to do with file of type %s", self.qFile.type)
return
@ -115,6 +118,10 @@ class updateDataBag:
def processVMpassword(self, dbag):
return cs_vmp.merge(dbag, self.qFile.data)
def processForwardingRules(self, dbag):
# to be used by both staticnat and portforwarding
return cs_forwardingrules.merge(dbag, self.qFile.data)
def processIP(self, dbag):
for ip in self.qFile.data["ip_address"]:
dbag = cs_ip.merge(dbag, ip)