mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Add the static nat rules to the merge procedure
This commit is contained in:
parent
a789e8bf57
commit
f273fd4659
@ -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
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user