def __init__(self, settings_module): # Update this dict from global settings (but only for ALL_CAPS settings) for setting in dir(global_settings): if setting == setting.upper(): setattr(self, setting, getattr(global_settings, setting)) # Store the settings module in case someone later cares self.SETTINGS_MODULE = settings_module mod = import_module_from_path(settings_module, 'settings') # Settings that should be converted into tuples if they're mistakenly entered # as strings. tuple_settings = ("SUPPORTED_VENDORS", "IOSLIKE_VENDORS", "VALID_OWNERS") # Now override anything configured in the custom settings for setting in dir(mod): if setting == setting.upper(): setting_value = getattr(mod, setting) if setting in tuple_settings and type(setting_value) == str: setting_value = (setting_value,) # In case the user forgot the comma. setattr(self, setting, setting_value)
__email__ = '*****@*****.**' __copyright__ = 'Copyright 2012, AOL Inc.' __version__ = '0.1' # Imports from trigger.conf import settings from trigger.utils.importlib import import_module_from_path import warnings # Exports __all__ = ('bounce', ) # Load ``bounce()`` from the location of ``bounce.py`` bounce_mpath = settings.BOUNCE_FILE try: _bounce_module = import_module_from_path(bounce_mpath, '_bounce_module') from _bounce_module import bounce except ImportError: msg = 'Bounce mappings could not be found in %s. using default!' % bounce_mpath warnings.warn(msg, RuntimeWarning) from . import BounceWindow DEFAULT_BOUNCE = BounceWindow(green='5-7', yellow='0-4, 8-15', red='16-23') def bounce(device, default=DEFAULT_BOUNCE): """ Return the bounce window for a given device. :param device: A `~trigger.netdevices.NetDevice` object. :param default:
from trigger.conf import settings from trigger.utils.importlib import import_module_from_path import warnings __all__ = ('autoacl',) module_path = settings.AUTOACL_FILE # In either case we're exporting a single name: autoacl(). try: # Placeholder for the custom autoacl module that will provide the autoacl() # function. Either of these operations will raise an ImportError if they # don't work, so it's safe to have them within the same try statement. _autoacl_module = import_module_from_path(module_path, '_autoacl_module') from _autoacl_module import autoacl except ImportError: msg = 'Function autoacl() could not be found in %s, using default!' % module_path warnings.warn(msg, RuntimeWarning) def autoacl(dev, explicit_acls=None): """ Given a NetDevice object, returns a set of **implicit** (auto) ACLs. We require a device object so that we don't have circular dependencies between netdevices and autoacl. This function MUST return a ``set()`` of acl names or you will break the ACL associations. An empty set is fine, but it must be a set! :param dev: A :class:`~trigger.netdevices.NetDevice` object. :param explicit_acls: A set containing names of ACLs. Default: set()
# Imports from trigger.conf import settings from trigger.utils.importlib import import_module_from_path import warnings # Exports __all__ = ('bounce',) # Load ``bounce()`` from the location of ``bounce.py`` bounce_mpath = settings.BOUNCE_FILE try: _bounce_module = import_module_from_path(bounce_mpath, '_bounce_module') from _bounce_module import bounce except ImportError: msg = 'Bounce mappings could not be found in %s. using default!' % bounce_mpath warnings.warn(msg, RuntimeWarning) from . import BounceWindow DEFAULT_BOUNCE = BounceWindow(green='5-7', yellow='0-4, 8-15', red='16-23') def bounce(device, default=DEFAULT_BOUNCE): """ Return the bounce window for a given device. :param device: A `~trigger.netdevices.NetDevice` object. :param default: A `~trigger.changemgmt.BounceWindow` object.