コード例 #1
0
    def __init__(self,
                 devices=None,
                 commands=None,
                 creds=None,
                 incremental=None,
                 max_conns=10,
                 verbose=False,
                 timeout=DEFAULT_TIMEOUT,
                 production_only=True,
                 allow_fallback=True,
                 force_cli=False):
        if devices is None:
            raise exceptions.ImproperlyConfigured(
                'You must specify some ``devices`` to interact with!')

        self.devices = devices
        self.commands = self.commands or (commands or []
                                          )  # Always fallback to []
        self.creds = creds
        self.incremental = incremental
        self.max_conns = max_conns
        self.verbose = verbose
        self.timeout = timeout if timeout != self.timeout else self.timeout  # In seconds
        self.nd = NetDevices(production_only=production_only)
        self.allow_fallback = allow_fallback
        self.force_cli = force_cli
        self.curr_conns = 0
        self.jobs = []
        self.errors = {}
        self.results = self.results or {}  # Always fallback to {}
        #self.deferrals = []
        self.supported_platforms = self._validate_platforms()
        self._setup_jobs()
コード例 #2
0
    def __init__(self, *args, **kwargs):
        self.all_done = False
        self.results = []
        self.errors = []
        super(CommandoApplication, self).__init__(*args, **kwargs)

        if not self.devices:
            raise exceptions.ImproperlyConfigured(
                'You must specify some `devices` to interact with!')
        # Commenting out because sometimes the cmds come in the to_<vendor> methods
        #if not self.commands:
        #    raise exceptions.ImproperlyConfigured('You must specify some `commands` to execute!')

        # Make sure that the specified containers are not passed in as strings.
        container_types = ['commands', 'devices']
        for container in container_types:
            if isinstance(getattr(self, container), basestring):
                raise SyntaxError("%r cannot be a string!" % container)

        # Temp hack to avoid ``exceptions.TypeError: Data must not be unicode``
        # Commands that get deserialized from JSON end up as Unicode, and
        # Twisted doesn't like that!
        for idx, cmd in enumerate(self.commands):
            if isinstance(cmd, unicode):
                self.commands[idx] = str(cmd)

        self.deferred = defer.Deferred()
コード例 #3
0
ファイル: handlers.py プロジェクト: zonda80/trigger
def _register_handlers():
    """
    Walk thru the handlers specified in ``settings.NOTIFICATION_HANDLERS`` and
    register them internally.

    Any built-in event handlers need to be defined above this function.
    """
    global HANDLERS_REGISTERED
    from trigger.conf import settings

    for handler_path in settings.NOTIFICATION_HANDLERS:
        # Get the module and func name
        try:
            h_module, h_funcname = handler_path.rsplit('.', 1)
        except ValueError:
            raise exceptions.ImproperlyConfigured("%s isn't a handler module" %
                                                  handler_path)

        # Import the module and get the module object
        try:
            mod = import_module(h_module)
        except ImportError as err:
            raise exceptions.ImproperlyConfigured(
                'Error importing handler %s: "%s"' % (h_module, err))

        # Get the handler function
        try:
            handler = getattr(mod, h_funcname)
        except AttributeError:
            raise exceptions.ImproperlyConfigured(
                'Handler module "%s" does not define a "%s" function' %
                (h_module, h_funcname))

        # Register the handler function
        if handler not in _registered_handlers:
            _registered_handlers.append(handler)

    HANDLERS_REGISTERED = True
コード例 #4
0
    def __init__(self,
                 devices=None,
                 commands=None,
                 creds=None,
                 incremental=None,
                 max_conns=10,
                 verbose=False,
                 timeout=DEFAULT_TIMEOUT,
                 production_only=True,
                 allow_fallback=True,
                 with_errors=True,
                 force_cli=False,
                 with_acls=False,
                 command_interval=0,
                 stop_reactor=True):
        if devices is None:
            raise exceptions.ImproperlyConfigured(
                'You must specify some `devices` to interact with!')

        self.devices = devices
        self.commands = self.commands or (commands or []
                                          )  # Always fallback to []
        self.creds = creds
        self.incremental = incremental
        self.max_conns = max_conns
        self.verbose = verbose
        self.timeout = timeout if timeout != self.timeout else self.timeout
        self.nd = NetDevices(production_only=production_only,
                             with_acls=with_acls)
        self.allow_fallback = allow_fallback
        self.with_errors = with_errors
        self.force_cli = force_cli
        self.command_interval = command_interval
        self.stop_reactor = self.stop_reactor or stop_reactor
        self.curr_conns = 0
        self.jobs = []

        # Always fallback to {} for these
        self.errors = self.errors if self.errors is not None else {}
        self.results = self.results if self.results is not None else {}
        self.parsed_results = self.parsed_results if self.parsed_results is not None else collections.defaultdict(
            dict)

        #self.deferrals = []
        self.supported_platforms = self._validate_platforms()
        self._setup_jobs()
コード例 #5
0
    def _validate_platforms(self):
        """
        Determine the set of supported platforms for this instance by making
        sure the specified vendors/platforms for the class match up.
        """
        supported_platforms = {}
        for vendor in self.vendors:
            if vendor in self.platforms:
                types = self.platforms[vendor]
                if not types:
                    raise exceptions.MissingPlatform('No platforms specified for %r' % vendor)
                else:
                    #self.supported_platforms[vendor] = types
                    supported_platforms[vendor] = types
            else:
                raise exceptions.ImproperlyConfigured('Platforms for vendor %r not found. Please provide it at either the class level or using the arguments.' % vendor)

        return supported_platforms