def sync_monitor_bindings(client, module): log('sync_monitor_bindings') actual_monitor_bindings = get_actual_monitor_bindings(client, module) configured_monitor_proxys = get_configured_monitor_bindings(client, module) # Delete actual bindings not in configured bindings for monitor_name, actual_binding in actual_monitor_bindings.items(): if monitor_name not in configured_monitor_proxys.keys(): log('Deleting absent binding for monitor %s' % monitor_name) log('dir is %s' % dir(actual_binding)) gslbservice_lbmonitor_binding.delete(client, actual_binding) # Delete and re-add actual bindings that differ from configured for proxy_key, binding_proxy in configured_monitor_proxys.items(): if proxy_key in actual_monitor_bindings: actual_binding = actual_monitor_bindings[proxy_key] if not binding_proxy.has_equal_attributes(actual_binding): log('Deleting differing binding for monitor %s' % actual_binding.monitor_name) log('dir %s' % dir(actual_binding)) log('attribute monitor_name %s' % getattr(actual_binding, 'monitor_name')) log('attribute monitorname %s' % getattr(actual_binding, 'monitorname', None)) gslbservice_lbmonitor_binding.delete(client, actual_binding) log('Adding anew binding for monitor %s' % binding_proxy.monitor_name) binding_proxy.add() # Add configured monitors that are missing from actual for proxy_key, binding_proxy in configured_monitor_proxys.items(): if proxy_key not in actual_monitor_bindings.keys(): log('Adding monitor binding for monitor %s' % binding_proxy.monitor_name) binding_proxy.add()