Commit 3acadd65 authored by Sigmund Augdal's avatar Sigmund Augdal

Refactor to remove code duplication

parent b0791944
......@@ -50,6 +50,15 @@ class Generator(object):
self.output("create {} {} family {}".format(setname, set_type, family))
return name
def add_ipset_member_family(self, name, member, family, suffix, source, addresses):
setname = self.set_name(name, family)
if source is not None:
if source in self.addresses_v4:
suffix = "{},{}".format(suffix, addresses[source])
self.output("add {} {}{}".format(setname, addresses[member], suffix))
else:
self.output("add {} {}{}".format(setname, addresses[member], suffix))
def add_ipset_member(self, name, member, protocol="tcp", port=None, net=None, source=None):
suffix = ""
if port is not None:
......@@ -58,26 +67,10 @@ class Generator(object):
suffix += ",{}".format(net)
member = member.lower()
if member in self.addresses_v4 and (net is None or "." in net):
setname = self.set_name(name, "inet")
if source is not None:
if source in self.addresses_v4:
suffix4 = "{},{}".format(suffix, self.addresses_v4[source])
self.output("add {} {}{}".format(setname, self.addresses_v4[member],
suffix4))
else:
self.output("add {} {}{}".format(setname, self.addresses_v4[member],
suffix))
self.add_ipset_member_family(name, member, "inet", suffix, source, self.addresses_v4)
if member in self.addresses_v6 and (net is None or ":" in net):
setname = self.set_name(name, "inet6")
if source is not None:
if source in self.addresses_v6:
suffix6 = "{},{}".format(suffix, self.addresses_v6[source])
self.output("add {} {}{}".format(setname, self.addresses_v6[member],
suffix6))
else:
self.output("add {} {}{}".format(setname, self.addresses_v6[member],
suffix))
self.add_ipset_member_family(name, member, "inet6", suffix, source, self.addresses_v6)
def process_security_group(self, group_id, name):
rules = security_groups.get_group_rules(self.etcd_client, group_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment