Ejemplo n.º 1
0
    def __call__(self, *args, **kwargs):
        """
        When you call the registry with the name of a plugin eg: 'NullPlugin', as the first arg, this returns the class
        from the plugin_registry. You can then instantiate the class in any way you need to.

        Example
        >>> import libsolace
        >>> from libsolace.plugin import Plugin
        >>> a = libsolace.plugin_registry("NullPlugin")
        >>> type(a)
        ""


        :param args: name of Plugin to return
        :param kwargs:
        :return: class
        """

        try:
            module = get_calling_module(point=2)
        except:
            module = "Unknown"

        try:
            module_parent = get_calling_module(point=3)
        except:
            module_parent = "Unknown"

        logger.debug(self.plugins_dict)
        logger.info("Module %s->%s->%s" % (module_parent, module, args[0]))

        logger.debug("Plugin Request: args: %s, kwargs: %s" % (args, kwargs))
        try:
            logger.debug("Class: %s" % self.plugins_dict[args[0]])
            return self.plugins_dict[args[0]]
        except:
            logger.warn(
                "No plugin named: %s found, available plugins are: %s" %
                (args[0], self.plugins_dict))
            logger.warn(
                "Please check the plugin is listed in the yaml config and that you have @libsolace.plugin_registry.register in the class"
            )
            raise
Ejemplo n.º 2
0
    def __init__(self, description=None, version=None, **kwargs):

        if version is None:
            version = "soltr/6_0"

        self.__dict__ = OrderedDict()
        self.__setattr__ = None
        if description is not None:
            self.description = description
        self.version = version
        calling_module = get_calling_module()
        logging.info("Called by module: %s - %s description: %s " % (calling_module, self.version, description))
    def __init__(self, description=None, version=None, **kwargs):

        if version is None:
            version = "soltr/6_0"

        self.__dict__ = OrderedDict()
        self.__setattr__ = None
        if description is not None:
            self.description = description
        self.version = version
        calling_module = get_calling_module()
        logger.info("Called by module: %s - %s description: %s " % (calling_module, self.version, description))
Ejemplo n.º 4
0
    def __call__(self, *args, **kwargs):
        """
        When you call the registry with the name of a plugin eg: 'NullPlugin', as the first arg, this returns the class
        from the plugin_registry. You can then instantiate the class in any way you need to.

        Example
        >>> import libsolace
        >>> from libsolace.plugin import Plugin
        >>> a = libsolace.plugin_registry("NullPlugin")
        >>> type(a)
        ""


        :param args: name of Plugin to return
        :param kwargs:
        :return: class
        """

        try:
            module = get_calling_module(point=2)
        except:
            module = "Unknown"

        try:
            module_parent = get_calling_module(point=3)
        except:
            module_parent = "Unknown"

        logging.debug(self.plugins_dict)
        logging.info("Module %s->%s->%s" % (module_parent, module, args[0]))

        logging.debug("Plugin Request: args: %s, kwargs: %s" % (args, kwargs))
        try:
            logging.debug("Class: %s" % self.plugins_dict[args[0]])
            return self.plugins_dict[args[0]]
        except:
            logging.warn("No plugin named: %s found, available plugins are: %s" % (args[0], self.plugins_dict))
            logging.warn(
                    "Please check the plugin is listed in the yaml config and that you have @libsolace.plugin_registry.register in the class")
            raise
Ejemplo n.º 5
0
    def set_exists(self, state):
        """set_exists is used as caching in order to cut down on SEMP queries to validate existence of items. For example,
        if you create a new VPN in "batch" mode, After the "create-vpn" XML is generated, set_exists is set to True so
        subsequent requests decorated with the `only_if_exists` will function correctly since set_exists states that the
        object will exist.

        :param state: the existence state of the object
        :type state: bool
        :return:
        """
        module = get_calling_module(point=3)
        logging.info("Calling module: %s, Setting Exists bit: %s" % (module, state))
        self.exists = state
Ejemplo n.º 6
0
    def set_exists(self, state):
        """set_exists is used as caching in order to cut down on SEMP queries to validate existence of items. For example,
        if you create a new VPN in "batch" mode, After the "create-vpn" XML is generated, set_exists is set to True so
        subsequent requests decorated with the `only_if_exists` will function correctly since set_exists states that the
        object will exist.

        :param state: the existence state of the object
        :type state: bool
        :return:
        """
        module = get_calling_module(point=3)
        logger.info("Calling module: %s, Setting Exists bit: %s" %
                    (module, state))
        self.exists = state
Ejemplo n.º 7
0
        def wrapped_f(*args, **kwargs):

            # if force, return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                args[0].set_exists(True)
                return f(*args, **kwargs)

            mode = kwargs.get('shutdown_on_apply', None)
            if entity == 'queue' and mode in ['b', 'q', True]:
                return f(*args, **kwargs)
            if entity == 'user' and mode in ['b', 'u', True]:
                return f(*args, **kwargs)
            module = get_calling_module()
            logging.info(
                    "Package %s requires shutdown of this object, shutdown_on_apply is not set for this object type, bypassing %s for entity %s" % (
                        module, f.__name__, entity))
Ejemplo n.º 8
0
        def wrapped_f(*args, **kwargs):

            # if force, return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                args[0].set_exists(True)
                return f(*args, **kwargs)

            mode = kwargs.get('shutdown_on_apply', None)
            if entity == 'queue' and mode in ['b', 'q', True]:
                return f(*args, **kwargs)
            if entity == 'user' and mode in ['b', 'u', True]:
                return f(*args, **kwargs)
            module = get_calling_module()
            logger.info(
                "Package %s requires shutdown of this object, shutdown_on_apply is not set for this object type, "
                "bypassing %s for entity %s" % (module, f.__name__, entity))
Ejemplo n.º 9
0
        def wrapped_f(*args, **kwargs):

            logger.info(kwargs)

            # force kwarg, just return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                args[0].set_exists(True)
                return f(*args, **kwargs)

            # default false
            check_primary = False
            check_backup = False

            # extract package name
            module = get_calling_module()

            # force kwarg, just return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                logger.info("Force being used, returning obj")
                args[0].set_exists(False)
                return f(*args, **kwargs)
            else:
                logger.info("Not forcing return of object")

            # determine if were checking both or a single node
            if primaryOnly:
                kwargs['primaryOnly'] = primaryOnly
                check_primary = True
            elif backupOnly:
                kwargs['backupOnly'] = backupOnly
                check_backup = True
            else:
                logger.info(
                    "Package: %s requests that Both primary and backup be queried"
                    % module)
                check_primary = True
                check_backup = True

            # if exists bit is set on the object ( caching )
            try:
                if not args[0].exists:
                    logger.info("Cache hit, object does NOT exist")
                    return f(*args, **kwargs)
            except Exception, e:
                pass
Ejemplo n.º 10
0
        def wrapped_f(*args, **kwargs):

            logging.info(kwargs)

            # force kwarg, just return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                args[0].set_exists(True)
                return f(*args, **kwargs)

            # default false
            check_primary = False
            check_backup = False

            # extract package name
            module = get_calling_module()

            # force kwarg, just return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                logging.info("Force being used, returning obj")
                args[0].set_exists(False)
                return f(*args, **kwargs)
            else:
                logging.info("Not forcing return of object")

            # determine if were checking both or a single node
            if primaryOnly:
                kwargs['primaryOnly'] = primaryOnly
                check_primary = True
            elif backupOnly:
                kwargs['backupOnly'] = backupOnly
                check_backup = True
            else:
                logging.info("Package: %s requests that Both primary and backup be queried" % module)
                check_primary = True
                check_backup = True

            # if exists bit is set on the object ( caching )
            try:
                if not args[0].exists:
                    logging.info("Cache hit, object does NOT exist")
                    return f(*args, **kwargs)
            except Exception, e:
                pass
Ejemplo n.º 11
0
 def wrapped_f(*args, **kwargs):
     kwargs['backupOnly'] = True
     module = get_calling_module()
     logging.info("Calling package %s - Setting backupOnly: %s" % (module, f.__name__))
     return f(*args, **kwargs)
Ejemplo n.º 12
0
    def wrap(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):

            # default false
            check_primary = False
            check_backup = False

            # extract package name
            module = get_calling_module()

            # force kwarg, just return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                logging.info("Force being used, returning obj")
                args[0].set_exists(True)
                return f(*args, **kwargs)
            else:
                logging.info("Not forcing return of object")

            # determine if were checking both or a single node
            if primaryOnly:
                kwargs['primaryOnly'] = primaryOnly
                check_primary = True
            elif backupOnly:
                kwargs['backupOnly'] = backupOnly
                check_backup = True
            else:
                logging.info("Package: %s requests that Both primary and backup be queried" % module)
                check_primary = True
                check_backup = True

            # if exists bit is set on the object ( caching )
            try:
                if args[0].exists:
                    logging.info("Cache hit, object exists")
                    return f(*args, **kwargs)
            except Exception, e:
                pass

            logging.debug("Cache miss")
            logging.info("Package: %s, asking entity: %s, for args: %s, kwargs: %s via data_path: %s" % (
                module, entity, str(args), str(kwargs), data_path))

            response_path = data_path.split('.')

            res = getattr(args[0], entity)(**kwargs)
            o_res = res
            logging.debug("Response %s" % res)

            exists = True

            # try peek into attributes, any raises means one of the nodes does not have the object.
            for p in response_path:
                if check_primary:
                    try:
                        res[0] = res[0][p]
                    except (TypeError, IndexError):
                        logging.info("Object not found on PRIMARY, key:%s error" % p)
                        logging.info(o_res)
                        kwargs['primaryOnly'] = True
                        args[0].set_exists(False)
                        exists = False
                if check_backup:
                    try:
                        res[1] = res[1][p]
                    except (TypeError, IndexError):
                        logging.info("Object not found on BACKUP, key:%s error" % p)
                        logging.info(o_res)
                        kwargs['backupOnly'] = True
                        args[0].set_exists(False)
                        exists = False

            if exists:
                module = get_calling_module()
                logging.info(
                        "Package %s - the requested object exists, calling method %s, check entity was: %s" % (
                            module, f.__name__, entity))
                args[0].set_exists(True)
                return f(*args, **kwargs)
Ejemplo n.º 13
0
 def wrapped_f(*args, **kwargs):
     module = get_calling_module()
     logging.warning("Deprecation Warning: %s: %s %s" % (warning_msg, module, f.__name__))
     return f(*args, **kwargs)
Ejemplo n.º 14
0
 def wrapped_f(*args, **kwargs):
     kwargs['backupOnly'] = True
     module = get_calling_module()
     logger.info("Calling package %s - Setting backupOnly: %s" %
                 (module, f.__name__))
     return f(*args, **kwargs)
Ejemplo n.º 15
0
    def wrap(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):

            # default false
            check_primary = False
            check_backup = False

            # extract package name
            module = get_calling_module()

            # force kwarg, just return the method to allow exec
            if "force" in kwargs and kwargs.get('force'):
                logger.info("Force being used, returning obj")
                args[0].set_exists(True)
                return f(*args, **kwargs)
            else:
                logger.info("Not forcing return of object")

            # determine if were checking both or a single node
            if primaryOnly:
                kwargs['primaryOnly'] = primaryOnly
                check_primary = True
            elif backupOnly:
                kwargs['backupOnly'] = backupOnly
                check_backup = True
            else:
                logger.info(
                    "Package: %s requests that Both primary and backup be queried"
                    % module)
                check_primary = True
                check_backup = True

            # if exists bit is set on the object ( caching )
            try:
                if args[0].exists:
                    logger.info("Cache hit, object exists")
                    return f(*args, **kwargs)
            except Exception, e:
                pass

            logger.debug("Cache miss")
            logger.info(
                "Package: %s, asking entity: %s, for args: %s, kwargs: %s via data_path: %s"
                % (module, entity, str(args), str(kwargs), data_path))

            response_path = data_path.split('.')

            res = getattr(args[0], entity)(**kwargs)
            o_res = res
            logger.debug("Response %s" % res)

            exists = True

            # try peek into attributes, any raises means one of the nodes does not have the object.
            for p in response_path:
                if check_primary:
                    try:
                        res[0] = res[0][p]
                    except (TypeError, IndexError):
                        logger.info(
                            "Object not found on PRIMARY, key:%s error" % p)
                        logger.info(o_res)
                        kwargs['primaryOnly'] = True
                        args[0].set_exists(False)
                        exists = False
                if check_backup:
                    try:
                        res[1] = res[1][p]
                    except (TypeError, IndexError):
                        logger.info(
                            "Object not found on BACKUP, key:%s error" % p)
                        logger.info(o_res)
                        kwargs['backupOnly'] = True
                        args[0].set_exists(False)
                        exists = False

            if exists:
                module = get_calling_module()
                logger.info(
                    "Package %s - the requested object exists, calling method %s, check entity was: %s"
                    % (module, f.__name__, entity))
                args[0].set_exists(True)
                return f(*args, **kwargs)
Ejemplo n.º 16
0
 def wrapped_f(*args, **kwargs):
     module = get_calling_module()
     logger.warning("Deprecation Warning: %s: %s %s" %
                    (warning_msg, module, f.__name__))
     return f(*args, **kwargs)