Exemplo n.º 1
0
    def _read_nodes(self):
        config = py3bro.configparser.SafeConfigParser()
        fname = self.nodecfg
        try:
            if not config.read(fname):
                raise ConfigurationError("cannot read node config file: %s" % fname)
        except py3bro.configparser.MissingSectionHeaderError as err:
            raise ConfigurationError(err)

        nodestore = {}

        counts = {}
        for sec in config.sections():
            node = node_mod.Node(self, sec)

            for (key, val) in config.items(sec):

                key = key.replace(".", "_")

                if key not in node_mod.Node._keys:
                    self.ui.warn("ignoring unrecognized node config option '%s' given for node '%s'" % (key, sec))
                    continue

                node.__dict__[key] = val

            self._check_node(node, nodestore, counts)

            if node.name in nodestore:
                raise ConfigurationError("duplicate node name '%s'" % node.name)
            nodestore[node.name] = node

        self._check_nodestore(nodestore)
        return nodestore
Exemplo n.º 2
0
    def _read_nodes(self):
        config = py3bro.configparser.SafeConfigParser()
        fname = self.nodecfg
        try:
            if not config.read(fname):
                raise ConfigurationError("cannot read node config file: %s" %
                                         fname)
        except py3bro.configparser.MissingSectionHeaderError as err:
            raise ConfigurationError(err)

        nodestore = NodeStore()

        counts = {}
        for sec in config.sections():
            node = node_mod.Node(self, sec)

            # Note that the keys are converted to lowercase by configparser.
            for (key, val) in config.items(sec):

                key = key.replace(".", "_")

                if key not in node_mod.Node._keys:
                    self.ui.warn(
                        "ignoring unrecognized node config option '%s' given for node '%s'"
                        % (key, sec))
                    continue

                node.__dict__[key] = val

            # Perform a sanity check on the node, and update nodestore.
            self._check_node(node, nodestore, counts)

        # Perform a sanity check on the nodestore (make sure we have a valid
        # cluster config, etc.).
        self._check_nodestore(nodestore.nodestore)

        return nodestore.nodestore
Exemplo n.º 3
0
    def get_capstats_output(self, nodes, interval):
        results = []

        # Construct a list of (node, interface) tuples, one tuple for each
        # unique (host, interface) pair.
        nodenetifs = []
        hosts = {}
        for node in nodes:
            if not node.interface:
                continue

            netif = self._capstats_interface(node)

            if hosts.setdefault((node.addr, netif), node) == node:
                nodenetifs.append((node, netif))

        capstats = self.config.capstatspath
        cmds = [(node, capstats,
                 ["-I", str(interval), "-n", "1", "-i", interface])
                for (node, interface) in nodenetifs]

        outputs = self.executor.run_cmds(cmds)

        totals = {}

        for (node, success, output) in outputs:
            netif = self._capstats_interface(node)

            if not success:
                if output:
                    results += [
                        (node, netif, False,
                         "%s: capstats failed (%s)" % (node.name, output[0]))
                    ]
                else:
                    results += [(node, netif, False,
                                 "%s: cannot execute capstats" % node.name)]
                continue

            if not output:
                results += [(node, netif, False,
                             "%s: no capstats output" % node.name)]
                continue

            fields = output[0].split()[1:]

            if not fields:
                results += [
                    (node, netif, False, "%s: unexpected capstats output: %s" %
                     (node.name, output[0]))
                ]
                continue

            vals = {}

            try:
                for field in fields:
                    (key, val) = field.split("=")
                    val = float(val)
                    vals[key] = val

                    if key in totals:
                        totals[key] += val
                    else:
                        totals[key] = val

                results += [(node, netif, True, vals)]

            except ValueError:
                results += [
                    (node, netif, False, "%s: unexpected capstats output: %s" %
                     (node.name, output[0]))
                ]

        # Add pseudo-node for totals
        if len(nodes) > 1:
            results += [(node_mod.Node(self.config,
                                       "$total"), None, True, totals)]

        return results