From 57c30adb81b509e0e7afdaa565040992077c14da Mon Sep 17 00:00:00 2001 From: edersonbrilhante Date: Mon, 9 May 2016 17:27:21 -0300 Subject: [PATCH] fix: update pool in loop --- networkapi/plugins/F5/Generic.py | 25 ++++++++++++++++--------- networkapi/plugins/F5/lb.py | 17 +++++++++++------ networkapi/plugins/F5/monitor.py | 23 ++++++++++++----------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/networkapi/plugins/F5/Generic.py b/networkapi/plugins/F5/Generic.py index 5918cbef7..76b9367ed 100644 --- a/networkapi/plugins/F5/Generic.py +++ b/networkapi/plugins/F5/Generic.py @@ -121,6 +121,7 @@ def create_pool(self, pools): self.__create_pool(pools) def __create_pool(self, pools): + log.info('__create_pool') monitor_associations = [] pls = util.trata_param_pool(pools) @@ -169,9 +170,6 @@ def __create_pool(self, pools): monitor_state=pls['pools_members']['monitor'], session_state=pls['pools_members']['session']) - nd = node.Node(self._lb) - nd.set_monitor_rule(monitor_associations=monitor_associations_nodes) - except Exception, e: self._lb._channel.System.Session.rollback_transaction() if monitor_associations != []: @@ -183,12 +181,19 @@ def __create_pool(self, pools): else: self._lb._channel.System.Session.submit_transaction() + try: + if monitor_associations_nodes.get('nodes'): + nd = node.Node(self._lb) + nd.set_monitor_rule(monitor_associations=monitor_associations_nodes) + except bigsuds.OperationFailed: + pass + @util.connection def update_pool(self, pools): self.__update_pool(pools) def __update_pool(self, pools): - log.info('update_pool') + log.info('__update_pool') monitor_associations = [] pls = util.trata_param_pool(pools) @@ -315,9 +320,6 @@ def __update_pool(self, pools): monitor_state=pls['pools_members']['monitor'], session_state=pls['pools_members']['session']) - nd = node.Node(self._lb) - nd.set_monitor_rule(monitor_associations=monitor_associations_nodes) - except Exception, e: self._lb._channel.System.Session.rollback_transaction() @@ -332,6 +334,11 @@ def __update_pool(self, pools): self._lb._channel.System.Session.submit_transaction() try: + + if monitor_associations_nodes.get('nodes'): + nd = node.Node(self._lb) + nd.set_monitor_rule(monitor_associations=monitor_associations_nodes) + if pls['pools_confirm']['pools_names']: plm.set_member_monitor_state( names=pls['pools_confirm']['pools_names'], @@ -350,10 +357,10 @@ def __update_pool(self, pools): @util.connection def delete_pool(self, pools): - self.delete_pool(pools) + self.__delete_pool(pools) def __delete_pool(self, pools): - log.info('delete_pool') + log.info('__delete_pool') pls = util.trata_param_pool(pools) diff --git a/networkapi/plugins/F5/lb.py b/networkapi/plugins/F5/lb.py index d3de1d2ed..b9775f3cf 100644 --- a/networkapi/plugins/F5/lb.py +++ b/networkapi/plugins/F5/lb.py @@ -24,9 +24,14 @@ def __init__(self, hostname, username, password): logging.critical("Unable to connect to BIG-IP. Details: %s" % (e)) raise base_exceptions.CommandErrorException(e) else: - self._version = self._channel.System.SystemInfo.get_version() - if self._version[8:len(self._version)].split('.')[0] <= 10: - raise base_exceptions.UnsupportedVersion( - 'This plugin only supports BIG-IP v11 or above') - else: - self._channel = self._channel.with_session_id() + log.info('connected in hostname:%s' % hostname) + try: + self._version = self._channel.System.SystemInfo.get_version() + log.info('self._version %s' % self._version) + if self._version[8:len(self._version)].split('.')[0] <= 10: + raise base_exceptions.UnsupportedVersion( + 'This plugin only supports BIG-IP v11 or above') + else: + self._channel = self._channel.with_session_id() + except: + raise base_exceptions.CommandErrorException('There are too many existing user sessions. Please try later') diff --git a/networkapi/plugins/F5/monitor.py b/networkapi/plugins/F5/monitor.py index ea510bfa3..d45cb4c8c 100644 --- a/networkapi/plugins/F5/monitor.py +++ b/networkapi/plugins/F5/monitor.py @@ -86,17 +86,18 @@ def prepare_template(self, **kwargs): monitor_association['monitor_rule']['quorum'] = 0 monitor_associations.append(monitor_association) - for node in kwargs['members'][i]: - monitor_association_node = { - 'monitor_templates': [], - 'type': None, - 'quorum': None - } - monitor_association_node['monitor_templates'].append('icmp') - monitor_association_node['type'] = 'MONITOR_RULE_TYPE_SINGLE' - monitor_association_node['quorum'] = 0 - monitor_associations_nodes['monitor_rules'].append(monitor_association_node) - monitor_associations_nodes['nodes'].append(node['address']) + if name == 'udp': + for node in kwargs['members'][i]: + monitor_association_node = { + 'monitor_templates': [], + 'type': None, + 'quorum': None + } + monitor_association_node['monitor_templates'].append('icmp') + monitor_association_node['type'] = 'MONITOR_RULE_TYPE_SINGLE' + monitor_association_node['quorum'] = 0 + monitor_associations_nodes['monitor_rules'].append(monitor_association_node) + monitor_associations_nodes['nodes'].append(node['address']) except Exception, e: log.error(e)