def logger(self): """ .. deprecated:: 3.0 logger attribute has been renamed to ``_logger``. Provided for backward-comptibility """ _deprecate("logger attribute has been renamed to _logger") return self._logger
def metadata(self): """ .. deprecated:: 3.0 metadata is now part of the ``system`` attribute (``plugin.system.metadata``) Provided for backward-comptibility """ _deprecate("metadata is a part of the system attribute (plugin.system.metadata") return self._system.metadata
def bm_client(self): """ .. deprecated:: 3.0 bm_client attribute has been renamed to ``_ez_client``. Provided for backward-comptibility """ _deprecate("bm_client attribute has been renamed to _ez_client") return self._ez_client
def max_attempts(self): """ .. deprecated:: 3.0 max_attempts is now in ``_config`` (``plugin._config.max_attempts``) Provided for backward-comptibility """ _deprecate("max_attempts is now in _config (plugin._config.max_attempts)") return self._config.max_attempts
def max_timeout(self): """ .. deprecated:: 3.0 max_timeout is now in ``_config`` (``plugin._config.max_timeout``) Provided for backward-comptibility """ _deprecate("max_timeout has moved into _config (plugin._config.max_timeout)") return self._config.max_timeout
def bg_url_prefix(self): """ .. deprecated:: 3.0 bg_url_prefix is now in ``_config`` (``plugin._config.bg_url_prefix``) Provided for backward-comptibility """ _deprecate("bg_url_prefix is now in _config (plugin._config.bg_url_prefix)") return self._config.bg_url_prefix
def client_cert(self): """ .. deprecated:: 3.0 client_cert is now in ``_config`` (``plugin._config.client_cert``) Provided for backward-comptibility """ _deprecate("client_cert is now in _config (plugin._config.client_cert)") return self._config.client_cert
def shutdown_event(self): """ .. deprecated:: 3.0 shutdown_event attribute has been renamed to ``_shutdown_event``. Provided for backward-comptibility """ _deprecate("shutdown_event attribute has been renamed to _shutdown_event") return self._shutdown_event
def bg_port(self): """ .. deprecated:: 3.0 bg_port is now in _config (``plugin._config.bg_port``) Provided for backward-comptibility """ _deprecate("bg_port is now in _config (plugin._config.bg_port)") return self._config.bg_port
def ssl_enabled(self): """ .. deprecated:: 3.0 ssl_enabled is now in ``_config`` (``plugin._config.ssl_enabled``) Provided for backward-comptibility """ _deprecate("ssl_enabled is now in _config (plugin._config.ssl_enabled)") return self._config.ssl_enabled
def connection_parameters(self): """ .. deprecated:: 3.0 connection_parameters has been removed. Please use ``_config`` Provided for backward-comptibility """ _deprecate("connection_parameters attribute was removed, please use '_config'") return {key: self._config[key] for key in _CONNECTION_SPEC}
def max_concurrent(self): """ .. deprecated:: 3.0 max_concurrent is now in ``_config`` (``plugin._config.max_concurrent``) Provided for backward-comptibility """ _deprecate("max_concurrent is now in _config (plugin._config.max_concurrent)") return self._config.max_concurrent
def get_instance(self, name): """ .. deprecated::3.0 Will be removed in 4.0. Use ``get_instance_by_name`` instead """ _deprecate( "Heads up! This method is deprecated, please use get_instance_by_name" ) return self.get_instance_by_name(name)
def ca_verify(self): """ .. deprecated:: 3.0 ca_verify is now in ``_config`` (``plugin._config.ca_verify``) Provided for backward-comptibility """ _deprecate("ca_verify is now in _config (plugin._config.ca_verify)") return self._config.ca_verify
def instance_name(self): """ .. deprecated:: 3.0 instance_name is now in ``_config`` (``plugin._config.instance_name``) Provided for backward-comptibility """ _deprecate("instance_name is now in _config (plugin._config.instance_name)") return self._config.instance_name
def register(*args, **kwargs): """ .. deprecated: 3.0 Will be removed in 4.0. Use ``@command`` instead. """ _deprecate( "Looks like you're using the '@register' decorator. Heads up - this name will " "be removed in version 4.0, please use '@command' instead. Thanks!") return command(*args, **kwargs)
def plugin_param(*args, **kwargs): """ .. deprecated: 3.0 Will be removed in 4.0. Use ``@parameter`` instead. """ _deprecate( "Looks like you're using the '@plugin_param' decorator. Heads up - this name " "will be removed in version 4.0, please use '@parameter' instead. Thanks!" ) return parameter(*args, **kwargs)
def command_registrar(*args, **kwargs): """ .. deprecated: 3.0 Will be removed in 4.0. Use ``@client`` instead. """ _deprecate( "Looks like you're using the '@command_registrar' decorator. Heads up - this " "name will be removed in version 4.0, please use '@client' instead. Thanks!" ) return client(*args, **kwargs)
def starting_timeout(self): """ .. deprecated:: 3.0 starting_timeout is now in ``_config`` (``plugin._config.starting_timeout``) Provided for backward-comptibility """ _deprecate( "starting_timeout is now in _config (plugin._config.starting_timeout)" ) return self._config.starting_timeout
def _initialize_parameters(parameter_list): # type: (Iterable[Parameter, object, dict]) -> List[Parameter] """Initialize Parameters from a list of parameter definitions This exists for backwards compatibility with the old way of specifying Models. Previously, models were defined by creating a class with a ``parameters`` class attribute. This required constructing each parameter manually, without using the ``@parameter`` decorator. This function takes a list where members can be any of the following: - A Parameter object - A class object with a ``parameters`` attribute - A dict containing kwargs for constructing a Parameter The Parameters in the returned list will be initialized. See the function ``_initialize_parameter`` for information on what that entails. Args: parameter_list: List of parameter precursors Returns: List of initialized parameters """ initialized_params = [] for param in parameter_list: # This is already a Parameter. Only really need to interpret the choices # definition and recurse down into nested Parameters if isinstance(param, Parameter): initialized_params.append(_initialize_parameter(param=param)) # This is a model class object. Needed for backwards compatibility # See https://github.com/beer-garden/beer-garden/issues/354 elif hasattr(param, "parameters"): _deprecate( "Constructing a nested Parameters list using model class objects " "is deprecated. Please pass the model's parameter list directly." ) initialized_params += _initialize_parameters(param.parameters) # This is a dict of Parameter kwargs elif isinstance(param, dict): initialized_params.append(_initialize_parameter(**param)) # No clue! else: raise PluginParamError("Unable to generate parameter from '%s'" % param) return initialized_params
def get_config(self, **kwargs): # type: (**Any) -> Response """Perform a GET to the config URL Args: **kwargs (deprecated): Unused. Accepted for compatibility. Returns: Requests Response object """ if kwargs: _deprecate( "Keyword arguments for get_config are no longer used and will be " "removed in a future release.") return self.session.get(self.config_url)
def get_instance_status(self, instance_id): """ .. deprecated: 3.0 Will be removed in 4.0. Use ``get_instance()`` instead Get an Instance's status Args: instance_id: The Id Returns: The Instance's status """ _deprecate( "This method is deprecated and scheduled to be removed in 4.0. " "Please use get_instance() instead.") return self.get_instance(instance_id).status
def _translate_kwargs(**kwargs): """Helper function to translate between ambiguously named parameters This functions exists to help with backwards compatibility. Confusion exists around the true name of the "host", "port", and "url_prefix" parameters. Since this only applies when passing kwargs directly (as opposed to other config sources) we need to do the translation before asking yapconf to load the config. This function will: - Convert "host" to "bg_host" - Convert "port" to "bg_port" - Convert "url_prefix" to "bg_url_prefix" Args: **kwargs: Keyword arguments to translate """ name_map = [ # (old_name, new_name, show_deprecation) ("host", "bg_host", True), ("port", "bg_port", True), ("url_prefix", "bg_url_prefix", False), ] for old_name, new_name, show_deprecation in name_map: if old_name in kwargs: old_value = kwargs.pop(old_name) if new_name in kwargs: logger.warning( "Looks like you passed both the '%s' and '%s' keyword arguments. " "As these are aliases only the value from '%s' will be used." % (old_name, new_name, new_name)) else: if show_deprecation: _deprecate( "Looks like you're using the '%s' keyword argument. This name " "will be removed in version 4.0, please use '%s' instead." % (old_name, new_name)) kwargs[new_name] = old_value return kwargs
def _load_config(args, kwargs): """Load a config based on the CONNECTION section of the Brewtils Specification This will load a configuration with the following source precedence: 1. kwargs 2. kwargs with "old" names ("host", "port", "url_prefix") 3. host and port passed as positional arguments 4. the global configuration (brewtils.plugin.CONFIG) Args: args (deprecated): host and port kwargs: Standard connection arguments to be used Returns: The resolved configuration object """ spec = YapconfSpec(_CONNECTION_SPEC) renamed = {} for key in ["host", "port", "url_prefix"]: if kwargs.get(key): renamed["bg_" + key] = kwargs.get(key) positional = {} if len(args) > 0: _deprecate( "Heads up - passing bg_host as a positional argument is deprecated " "and will be removed in version 4.0", stacklevel=kwargs.get("stacklevel", 3), ) positional["bg_host"] = args[0] if len(args) > 1: _deprecate( "Heads up - passing bg_port as a positional argument is deprecated " "and will be removed in version 4.0", stacklevel=kwargs.get("stacklevel", 3), ) positional["bg_port"] = args[1] return spec.load_config( *[kwargs, renamed, positional, brewtils.plugin.CONFIG])
def update_instance_status(self, instance_id, new_status): """ .. deprecated: 3.0 Will be removed in 4.0. Use ``update_instance()`` instead Get an Instance's status Args: instance_id (str): The Instance ID new_status (str): The new status Returns: Instance: The updated Instance """ _deprecate( "This method is deprecated and scheduled to be removed in 4.0. " "Please use update_instance() instead.") return self.update_instance(instance_id, new_status=new_status)
def _legacy_garden(self): """Determine if this plugin is connected to a legacy garden""" legacy = False try: # Need to be careful since v2 doesn't have "beer_garden_version" raw_version = self._ez_client.get_version() if "beer_garden_version" in raw_version: bg_version = Version(raw_version["beer_garden_version"]) else: bg_version = Version(raw_version["brew_view_version"]) if bg_version < Version("3"): legacy = True _deprecate( "Looks like your plugin is using version 3 brewtils but connecting " "to a version 2 Beer Garden. Please be aware that this " "functionality will stop being officially supported in the next " "brewtils minor release." ) self._logger.warning( "This plugin is using brewtils version {0} but is connected to a " "legacy Beer Garden (version {1}). Please be aware that certain " "features such as namespaces and logging configuration will not " "work correctly until the Beer Garden is upgraded.".format( brewtils.__version__, bg_version ) ) except Exception as ex: self._logger.warning( "An exception was raised while attempting to determine Beer Garden " "version, assuming non-legacy." ) self._logger.debug("Underlying exception: %s" % ex, exc_info=True) return legacy
def __init__(self, *args, **kwargs): _deprecate( "Looks like you're creating a 'RemotePlugin'. Heads up - this name will be " "removed in version 4.0, please use 'Plugin' instead. Thanks!" ) super(RemotePlugin, self).__init__(*args, **kwargs)
def parameters(*args, **kwargs): """ .. deprecated:: 3.0 Will be removed in version 4.0. Please use ``@command`` instead. Decorator for specifying multiple Parameter definitions at once This can be useful for commands which have a large number of complicated parameters but aren't good candidates for a Model. .. code-block:: python @parameter(**params[cmd1][param1]) @parameter(**params[cmd1][param2]) @parameter(**params[cmd1][param3]) def cmd1(self, **kwargs): pass Can become: .. code-block:: python @parameters(params[cmd1]) def cmd1(self, **kwargs): pass Args: *args (iterable): Positional arguments The first (and only) positional argument must be a list containing dictionaries that describe parameters. **kwargs: Used for bookkeeping. Don't set any of these yourself! Returns: func: The decorated function """ # This is the first invocation if not kwargs.get("_partial"): # Need the callable check to prevent applying the decorator with no parenthesis if len(args) == 1 and not callable(args[0]): return functools.partial(parameters, args[0], _partial=True) raise PluginParamError("@parameters takes a single argument") # This is the second invocation else: if len(args) != 2: raise PluginParamError( "Incorrect number of arguments for parameters partial call. Did you " "set _partial=True? If so, please don't do that. If not, please let " "the Beergarden team know how you got here!") _deprecate( "Looks like you're using the '@parameters' decorator. This is now deprecated - " "for passing bulk parameter definitions it's recommended to use the @command " "decorator parameters kwarg, like this: @command(parameters=[...])") params = args[0] _wrapped = args[1] if not callable(_wrapped): raise PluginParamError("@parameters must be applied to a callable") try: for param in params: parameter(_wrapped, **param) except TypeError: raise PluginParamError( "@parameters arg must be an iterable of dictionaries") return _wrapped
def __init__(self, *args, **kwargs): self._logger = logging.getLogger(__name__) self._loaded = False self._system = None self._commands = {} # Need this for back-compatibility (see #836) if len(args) > 2: _deprecate( "Heads up - passing system_name as a positional argument is deprecated " "and will be removed in version 4.0", ) kwargs.setdefault("system_name", args[2]) # Now need to determine if the intended target is the current running plugin. # Start by ensuring there's a valid Plugin context active target_self = bool(brewtils.plugin.CONFIG) # If ANY of the target specification arguments don't match the current plugin # then the target is different config_map = { "system_name": "name", "version_constraint": "version", "default_instance": "instance_name", "system_namespace": "namespace", } for key, value in config_map.items(): if (kwargs.get(key) is not None and kwargs.get(key) != brewtils.plugin.CONFIG[value]): target_self = False break # Now assign self._system_name, etc based on the value of target_self if target_self: self._system_name = brewtils.plugin.CONFIG.name self._version_constraint = brewtils.plugin.CONFIG.version self._default_instance = brewtils.plugin.CONFIG.instance_name self._system_namespace = brewtils.plugin.CONFIG.namespace or "" else: self._system_name = kwargs.get("system_name") self._version_constraint = kwargs.get("version_constraint", "latest") self._default_instance = kwargs.get("default_instance", "default") self._system_namespace = kwargs.get( "system_namespace", brewtils.plugin.CONFIG.namespace or "") self._always_update = kwargs.get("always_update", False) self._timeout = kwargs.get("timeout", None) self._max_delay = kwargs.get("max_delay", 30) self._blocking = kwargs.get("blocking", True) self._raise_on_error = kwargs.get("raise_on_error", False) # This is for Python 3.4 compatibility - max_workers MUST be non-None # in that version. This logic is what was added in Python 3.5 max_concurrent = kwargs.get("max_concurrent", (cpu_count() or 1) * 5) self._thread_pool = ThreadPoolExecutor(max_workers=max_concurrent) # This points DeprecationWarnings at the right line kwargs.setdefault("stacklevel", 5) self._easy_client = EasyClient(*args, **kwargs) self._resolver = ResolutionManager(easy_client=self._easy_client)