From f273fd46594a0358e6d81eabf08f4dc62a18ba6c Mon Sep 17 00:00:00 2001 From: Hugo Trippaers Date: Wed, 20 Aug 2014 17:29:58 +0200 Subject: [PATCH] Add the static nat rules to the merge procedure --- .../opt/cloud/bin/cs_forwardingrules.py | 33 +++++++++++++++++++ .../debian/config/opt/cloud/bin/merge.py | 7 ++++ 2 files changed, 40 insertions(+) create mode 100644 systemvm/patches/debian/config/opt/cloud/bin/cs_forwardingrules.py diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs_forwardingrules.py b/systemvm/patches/debian/config/opt/cloud/bin/cs_forwardingrules.py new file mode 100644 index 00000000000..d2bba819e0a --- /dev/null +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs_forwardingrules.py @@ -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 diff --git a/systemvm/patches/debian/config/opt/cloud/bin/merge.py b/systemvm/patches/debian/config/opt/cloud/bin/merge.py index 57a57b7eba9..69cf75d5ef0 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/merge.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/merge.py @@ -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)