def call_provider(provider, driver_method, *args, **kwargs): """Wrap calls to the provider driver to handle driver errors. This allows Octavia to return user friendly errors when a provider driver has an issue. :param driver_method: Method in the driver to call. :raises ProviderDriverError: Catch all driver error. :raises ProviderNotImplementedError: The driver doesn't support this action. :raises ProviderUnsupportedOptionError: The driver doesn't support a provided option. """ try: return driver_method(*args, **kwargs) except driver_exceptions.DriverError as e: LOG.exception("Provider '%s' raised a driver error: %s", provider, e.operator_fault_string) raise exceptions.ProviderDriverError(prov=provider, user_msg=e.user_fault_string) except (driver_exceptions.NotImplementedError, NotImplementedError) as e: LOG.info("Provider '%s' raised a not implemented error: %s", provider, e.operator_fault_string) raise exceptions.ProviderNotImplementedError( prov=provider, user_msg=e.user_fault_string) except driver_exceptions.UnsupportedOptionError as e: LOG.info("Provider '%s' raised an unsupported option error: " "%s", provider, e.operator_fault_string) raise exceptions.ProviderUnsupportedOptionError( prov=provider, user_msg=e.user_fault_string) except Exception as e: LOG.exception("Provider '%s' raised an unknown error: %s", provider, e) raise exceptions.ProviderDriverError(prov=provider, user_msg=e)
def execute(self, pool, vthunder): try: if pool.protocol == constants.PROTOCOL_PROXY: raise exceptions.ProviderUnsupportedOptionError( prov="A10", user_msg=("A pool with protocol PROXY is not supported by A10 provider." "Failed to create pool {0}").format(pool.id)) self.set(self.axapi_client.slb.service_group.create, pool, vthunder) LOG.debug("Successfully created pool: %s", pool.id) return pool except (acos_errors.ACOSException, ConnectionError) as e: LOG.exception("Failed to create pool: %s", pool.id) raise e
def execute(self, listeners, health_mon, vthunder, flavor=None): method = None url = None expect_code = None if health_mon.type in a10constants.HTTP_TYPE: method = health_mon.http_method url = health_mon.url_path expect_code = health_mon.expected_codes args = utils.meta(health_mon, 'hm', {}) args = utils.dash_to_underscore(args) # overwrite options from flavor if flavor: flavors = flavor.get('health_monitor') if flavors: name_exprs = flavors.get('name_expressions') parsed_exprs = utils.parse_name_expressions( health_mon.name, name_exprs) flavors.pop('name_expressions', None) flavors.update(parsed_exprs) args.update({'monitor': flavors}) try: health_mon.type = openstack_mappings.hm_type( self.axapi_client, health_mon.type) except Exception: raise exceptions.ProviderUnsupportedOptionError( prov="A10", user_msg=("Failed to create health monitor {}, " "A health monitor of type {} is not supported " "by A10 provider").format(health_mon.id, health_mon.type)) try: post_data = CONF.health_monitor.post_data self.axapi_client.slb.hm.create(health_mon.id, health_mon.type, health_mon.delay, health_mon.timeout, health_mon.rise_threshold, method=method, port=listeners[0].protocol_port, url=url, expect_code=expect_code, post_data=post_data, **args) LOG.debug("Successfully created health monitor: %s", health_mon.id) except (acos_errors.ACOSException, ConnectionError) as e: LOG.exception("Failed to create health monitor: %s", health_mon.id) raise e try: self.axapi_client.slb.service_group.update(health_mon.pool_id, hm_name=health_mon.id, health_check_disable=0) LOG.debug("Successfully associated health monitor %s to pool %s", health_mon.id, health_mon.pool_id) except (acos_errors.ACOSException, ConnectionError) as e: LOG.exception("Failed to associate health monitor %s to pool %s", health_mon.id, health_mon.pool_id) raise e