Ejemplo n.º 1
0
def load():
    helper = ImporterHelper(os.path.join('sos', 'policies'))
    for module in helper.get_modules():
        for policy in import_policy(module):
            if policy.check():
                return policy()
    raise Exception("No policy could be loaded.")
Ejemplo n.º 2
0
def load(cache={},
         sysroot=None,
         init=None,
         probe_runtime=True,
         remote_exec=None,
         remote_check=''):
    if 'policy' in cache:
        return cache.get('policy')

    import sos.policies.distros
    helper = ImporterHelper(sos.policies.distros)
    for module in helper.get_modules():
        for policy in import_policy(module):
            if policy.check(remote=remote_check):
                cache['policy'] = policy(sysroot=sysroot,
                                         init=init,
                                         probe_runtime=probe_runtime,
                                         remote_exec=remote_exec)

    if sys.platform != 'linux':
        raise Exception("SoS is not supported on this platform")

    if 'policy' not in cache:
        cache['policy'] = sos.policies.distros.GenericLinuxPolicy()

    return cache['policy']
Ejemplo n.º 3
0
def load():
    helper = ImporterHelper(os.path.join('sos', 'policies'))
    for module in helper.get_modules():
        for policy in import_policy(module):
            if policy.check():
                return policy()
    raise Exception("No policy could be loaded.")
Ejemplo n.º 4
0
 def setUp(self):
     # get all plugin classes defined locally
     import sos.report.plugins
     self.plugs = []
     self.plug_classes = []
     helper = ImporterHelper(sos.report.plugins)
     self.plugs = helper.get_modules()
     for plug in self.plugs:
         self.plug_classes.extend(import_plugin(plug))
Ejemplo n.º 5
0
    def load_plugins(self):

        import sos.plugins
        helper = ImporterHelper(sos.plugins)
        plugins = helper.get_modules()
        self.plugin_names = deque()

        # validate and load plugins
        for plug in plugins:
            plugbase, ext = os.path.splitext(plug)
            try:
                plugin_classes = import_plugin(
                    plugbase, tuple(self.policy.valid_subclasses))
                if not len(plugin_classes):
                    # no valid plugin classes for this policy
                    continue

                plugin_class = self.policy.match_plugin(plugin_classes)
                if not self.policy.validate_plugin(plugin_class):
                    self.soslog.warning(
                        _("plugin %s does not validate, skipping") % plug)
                    if self.opts.verbosity > 0:
                        self._skip(plugin_class, _("does not validate"))
                        continue

                if plugin_class.requires_root and not self._is_root:
                    self.soslog.info(
                        _("plugin %s requires root permissions to execute, skipping"
                          ) % plug)
                    self._skip(plugin_class, _("requires root"))
                    continue

                # plug-in is valid, let's decide whether run it or not
                self.plugin_names.append(plugbase)

                if self._is_skipped(plugbase):
                    self._skip(plugin_class, _("skipped"))
                    continue

                if self._is_inactive(plugbase, plugin_class):
                    self._skip(plugin_class, _("inactive"))
                    continue

                if self._is_not_default(plugbase, plugin_class):
                    self._skip(plugin_class, _("not default"))
                    continue

                if self._is_not_specified(plugbase):
                    self._skip(plugin_class, _("not specified"))
                    continue

                self._load(plugin_class)
            except Exception as e:
                self.soslog.warning(
                    _("plugin %s does not install, skipping: %s") % (plug, e))
                if self.raise_plugins:
                    raise
Ejemplo n.º 6
0
    def load_plugins(self):

        import sos.plugins
        helper = ImporterHelper(sos.plugins)
        plugins = helper.get_modules()
        self.plugin_names = deque()

        # validate and load plugins
        for plug in plugins:
            plugbase, ext = os.path.splitext(plug)
            try:
                plugin_classes = import_plugin(
                    plugbase, tuple(self.policy.valid_subclasses))
                if not len(plugin_classes):
                    # no valid plugin classes for this policy
                    continue

                plugin_class = self.policy.match_plugin(plugin_classes)
                if not self.policy.validate_plugin(plugin_class):
                    self.soslog.warning(
                        _("plugin %s does not validate, skipping") % plug)
                    if self.opts.verbosity > 0:
                        self._skip(plugin_class, _("does not validate"))
                        continue

                if plugin_class.requires_root and not self._is_root:
                    self.soslog.info(_("plugin %s requires root permissions"
                                       "to execute, skipping") % plug)
                    self._skip(plugin_class, _("requires root"))
                    continue

                # plug-in is valid, let's decide whether run it or not
                self.plugin_names.append(plugbase)

                if self._is_skipped(plugbase):
                    self._skip(plugin_class, _("skipped"))
                    continue

                if self._is_inactive(plugbase, plugin_class):
                    self._skip(plugin_class, _("inactive"))
                    continue

                if self._is_not_default(plugbase, plugin_class):
                    self._skip(plugin_class, _("not default"))
                    continue

                if self._is_not_specified(plugbase):
                    self._skip(plugin_class, _("not specified"))
                    continue

                self._load(plugin_class)
            except Exception as e:
                self.soslog.warning(_("plugin %s does not install, "
                                    "skipping: %s") % (plug, e))
                if self.raise_plugins:
                    raise
Ejemplo n.º 7
0
 def _get_policy_by_name(self):
     _topic = self.opts.topic.split('.')[-1]
     # mimic policy loading to discover all policiy classes without
     # needing to manually define each here
     import sos.policies.distros
     _helper = ImporterHelper(sos.policies.distros)
     for mod in _helper.get_modules():
         for policy in import_policy(mod):
             _p = policy.__name__.lower().replace('policy', '')
             if _p == _topic:
                 return policy
Ejemplo n.º 8
0
def load(cache={}):
    if 'policy' in cache:
        return cache.get('policy')

    helper = ImporterHelper(os.path.join('sos', 'policies'))
    for module in helper.get_modules():
        for policy in import_policy(module):
            if policy.check():
                cache['policy'] = policy()
                return policy()
    raise Exception("No policy could be loaded.")
Ejemplo n.º 9
0
def load(cache={}):
    if 'policy' in cache:
        return cache.get('policy')

    import sos.policies
    helper = ImporterHelper(sos.policies)
    for module in helper.get_modules():
        for policy in import_policy(module):
            if policy.check():
                cache['policy'] = policy()
                return policy()
    return GenericPolicy()
Ejemplo n.º 10
0
def load(cache={}):
    if "policy" in cache:
        return cache.get("policy")

    import sos.policies

    helper = ImporterHelper(sos.policies)
    for module in helper.get_modules():
        for policy in import_policy(module):
            if policy.check():
                cache["policy"] = policy()

    if "policy" not in cache:
        cache["policy"] = GenericPolicy()

    return cache["policy"]
Ejemplo n.º 11
0
    def load_plugins(self):

        import sos.plugins
        helper = ImporterHelper(sos.plugins)
        plugins = helper.get_modules()
        self.plugin_names = deque()

        # validate and load plugins
        for plug in plugins:
            plugbase, ext = os.path.splitext(plug)
            try:
                plugin_classes = import_plugin(plugbase)

                for plugin_class in plugin_classes:
                    if not self.policy.validatePlugin(plugin_class):
                        self.soslog.debug(
                            _("plugin %s does not validate, skipping") % plug)
                        self._skip(plugin_class, _("does not validate"))
                        continue

                    if plugin_class.requires_root and not self._is_root:
                        self.soslog.debug(
                            _("plugin %s requires root permissions to execute, skipping"
                              ) % plug)
                        self._skip(plugin_class, _("requires root"))
                        continue

                    # plug-in is valid, let's decide whether run it or not
                    self.plugin_names.append(plugbase)

                    if any((
                            self._is_skipped(plugbase),
                            self._is_inactive(plugbase, plugin_class),
                            self._is_not_default(plugbase, plugin_class),
                            self._is_not_specified(plugbase),
                    )):
                        self._skip(plugin_class, _("inactive"))
                        continue

                    self._load(plugin_class)
            except Exception, e:
                self.soslog.warning(
                    _("plugin %s does not install, skipping: %s") % (plug, e))
                if self.raise_plugins:
                    raise
Ejemplo n.º 12
0
def load(cache={}, sysroot=None, init=None, probe_runtime=True,
         remote_exec=None, remote_check=''):
    if 'policy' in cache:
        return cache.get('policy')

    import sos.policies
    helper = ImporterHelper(sos.policies)
    for module in helper.get_modules():
        for policy in import_policy(module):
            if policy.check(remote=remote_check):
                cache['policy'] = policy(sysroot=sysroot, init=init,
                                         probe_runtime=probe_runtime,
                                         remote_exec=remote_exec)

    if 'policy' not in cache:
        cache['policy'] = GenericPolicy()

    return cache['policy']
Ejemplo n.º 13
0
    def load_plugins(self):

        helper = ImporterHelper(package_path=os.path.join('sos', 'plugins'))
        plugins = helper.get_modules()
        self.plugin_names = deque()

        # validate and load plugins
        for plug in plugins:
            plugbase, ext = os.path.splitext(plug)
            try:
                plugin_classes = import_plugin(plugbase)

                for plugin_class in plugin_classes:
                    if not self.policy.validatePlugin(plugin_class):
                        self.soslog.debug(_("plugin %s does not validate, skipping") % plug)
                        self._skip(plugin_class, "does not validate")
                        continue

                    if plugin_class.requires_root and not self._is_root:
                        self.soslog.debug(_("plugin %s requires root permissions to execute, skipping") % plug)
                        self._skip(plugin_class, "requires root")
                        continue

                    # plug-in is valid, let's decide whether run it or not
                    self.plugin_names.append(plugbase)

                    if any((self._is_skipped(plugbase),
                            self._is_inactive(plugbase, plugin_class),
                            self._is_not_default(plugbase, plugin_class),
                            self._is_not_specified(plugbase),
                            )):
                        self._skip(plugin_class, "inactive")
                        continue

                    self._load(plugin_class)
            except Exception, e:
                self.soslog.warning(_("plugin %s does not install, skipping: %s") % (plug, e))
                if self.raise_plugins:
                    raise
Ejemplo n.º 14
0
 def test_runs(self):
     h = ImporterHelper(unittest)
     modules = h.get_modules()
     self.assertTrue('main' in modules)
Ejemplo n.º 15
0
 def test_runs(self):
     h = ImporterHelper(unittest)
     modules = h.get_modules()
     self.assertTrue('main' in modules)