Mercurial > srxproxy
changeset 23:50bbb36cfbec
make the ips unqiue earlier
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Tue, 12 Feb 2013 16:15:54 +0100 |
| parents | b61b4f736cfe |
| children | dedb1841cd15 |
| files | srxproxy.py |
| diffstat | 1 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/srxproxy.py Tue Feb 12 16:03:57 2013 +0100 +++ b/srxproxy.py Tue Feb 12 16:15:54 2013 +0100 @@ -50,29 +50,21 @@ def ensure_floating_forwards(ips): - rules = { - floating_ip: (context, fixed_ip, host, instance_id) - for context, floating_ip, fixed_ip, host, instance_id in ips - } rules_xml = [ RULE_XML.format( name=floating_ip.replace('.', '_'), destination=floating_ip, prefix=fixed_ip, ) - for floating_ip, (context, fixed_ip, host, instance_id) in rules.iteritems() + for context, floating_ip, fixed_ip, host, instance_id in ips ] apply_ruleset(rules_xml, default_operation="merge") def remove_floating_forwards(ips): - rules = { - address: (context, instance_id) - for context, address, instance_id in ips - } rules_xml = [ DELETE_XML.format(name=address.replace('.', '_')) - for address, (context, instance_id) in rules.iteritems() + for context, address, instance_id in ips ] apply_ruleset(rules_xml, default_operation="none") @@ -136,6 +128,13 @@ def associate_floating_ips(ips): if not ips: return + ips = [ + (context, floating_ip, fixed_ip, host, instance_id) + for floating_ip, (context, fixed_ip, host, instance_id) in { + floating_ip: (context, fixed_ip, host, instance_id) + for context, floating_ip, fixed_ip, host, instance_id in ips + }.iteritems() + ] try: # Change the device configuration LOG.info("Changing device configuration for %r", ips) @@ -169,6 +168,13 @@ def disassociate_floating_ips(ips): if not ips: return + ips = [ + (address, context, instance_id) + for address, (context, instance_id) in { + address: (context, instance_id) + for context, address, instance_id in ips + }.iteritems() + ] try: # Change the device configuration LOG.info("Changing device configuration for %r", ips)
