def _assure_monitors(self, service):
        if not (("pools" in service) and ("healthmonitors" in service)):
            return

        monitors = service["healthmonitors"]
        loadbalancer = service["loadbalancer"]
        bigips = self.driver.get_config_bigips()

        for monitor in monitors:
            svc = {
                "loadbalancer": loadbalancer,
                "healthmonitor": monitor,
                "pool": self.get_pool_by_id(service, monitor["pool_id"])
            }
            if monitor['provisioning_status'] == plugin_const.PENDING_DELETE:
                try:
                    self.pool_builder.delete_healthmonitor(svc, bigips)
                except Exception as err:
                    monitor['provisioning_status'] = plugin_const.ERROR
                    raise f5_ex.MonitorDeleteException(err.message)
            else:
                try:
                    self.pool_builder.create_healthmonitor(svc, bigips)
                except HTTPError as err:
                    if err.response.status_code != 409:
                        # pool['provisioning_status'] = plugin_const.ERROR
                        loadbalancer['provisioning_status'] = (
                            plugin_const.ERROR)
                        raise f5_ex.MonitorCreationException(err.message)
                    else:
                        self.pool_builder.update_healthmonitor(svc, bigips)
                except Exception as err:
                    monitor['provisioning_status'] = plugin_const.ERROR
                    raise f5_ex.MonitorCreationException(err.message)
Example #2
0
    def delete_healthmonitor(self, service, bigips):
        # delete health monitor
        hm = self.service_adapter.get_healthmonitor(service)
        hm_helper = self._get_monitor_helper(service)
        error = None

        for bigip in bigips:
            # after updating pool, delete monitor
            try:
                hm_helper.delete(
                    bigip, name=hm["name"], partition=hm["partition"])
            except HTTPError as err:
                if err.response.status_code != 404:
                    error = f5_ex.MonitorDeleteException(err.message)
                    LOG.error("Failed to remove monitor %s from %s: %s",
                              hm['name'], bigip, error.message)
            except Exception as err:
                error = f5_ex.MonitorDeleteException(err.message)
                LOG.error("Failed to remove monitor %s from %s: %s",
                          hm['name'], bigip, error.message)

        return error