Esempio n. 1
0
    def _get_instances_info(self):
        """Get information e.g. ip link  stats for each port on a vm"""
        instances = self.running_instances
        if instances is None:
            return

        guest_info = {}
        ps_output = cli_helpers.get_ps()
        for uuid in instances:
            for line in ps_output:
                expr = r".+guest=(\S+),.+product=OpenStack Nova.+uuid={}.+"
                ret = re.compile(expr.format(uuid)).match(line)
                if ret:
                    guest = ret[1]
                    if guest not in guest_info:
                        guest_info[uuid] = {"ports": []}

                    ret = re.compile(r"mac=([a-z0-9:]+)").findall(line)
                    if ret:
                        if "ports" not in guest_info[uuid]:
                            guest_info[uuid]["ports"] = []

                        for port in ret:
                            guest_info[uuid]["ports"].append({
                                "mac": port,
                                "health": {}
                            })

        return guest_info
Esempio n. 2
0
    def test_get_ps(self, mock_subprocess):
        path = os.path.join(os.environ["DATA_ROOT"], "ps")
        with open(path, 'r') as fd:
            out = fd.readlines()

        ret = cli_helpers.get_ps()
        self.assertEquals(ret, out)
        self.assertFalse(mock_subprocess.called)
Esempio n. 3
0
    def get_ps_units(self):
        units = set()
        for line in cli_helpers.get_ps():
            if "unit-" in line:
                ret = re.compile(r".+unit-([0-9a-z\-]+-[0-9]+).*").match(line)
                if ret:
                    units.add(ret[1])

        return units
Esempio n. 4
0
    def running_instances(self):
        if self._instances:
            return self._instances

        for line in cli_helpers.get_ps():
            ret = re.compile(".+product=OpenStack Nova.+").match(line)
            if ret:
                expr = r".+uuid\s+([a-z0-9\-]+)[\s,]+.+"
                ret = re.compile(expr).match(ret[0])
                if ret:
                    self._instances.append(ret[1])

        return self._instances
Esempio n. 5
0
    def get_machine_info(self):
        ps_machines = set()
        log_machines = set()
        machines_running = set()
        machines_stopped = set()

        if not os.path.exists(JUJU_LOG_PATH):
            return

        for line in cli_helpers.get_ps():
            if "machine-" in line:
                ret = re.compile(r".+machine-([0-9]+).*").match(line)
                if ret:
                    ps_machines.add(ret[1])

        for f in os.listdir(JUJU_LOG_PATH):
            ret = re.compile(r"machine-([0-9]+)\.log.*").match(f)
            if ret:
                log_machines.add(ret[1])

        combined_machines = ps_machines.union(log_machines)
        for machine in combined_machines:
            conf_path = (
                "var/lib/juju/agents/machine-{}/agent.conf".format(machine))
            agent_conf = os.path.join(constants.DATA_ROOT, conf_path)
            version = "unknown"
            if os.path.exists(agent_conf):
                for line in open(agent_conf).readlines():
                    ret = re.compile(r"upgradedToVersion:\s+(.+)").match(line)
                    if ret:
                        version = ret[1]

            if machine in ps_machines:
                machines_running.add("{} (version={})".format(
                    machine, version))
            else:
                machines_stopped.add(machine)

        if machines_running:
            JUJU_MACHINE_INFO["machines"]["running"] = list(machines_running)

        if machines_stopped:
            JUJU_MACHINE_INFO["machines"]["stopped"] = list(machines_stopped)

        if not machines_running and (machines_stopped
                                     or self.get_local_running_units):
            msg = ("there is no Juju machined running on this host but it "
                   "seems there should be")
            add_issue(JujuWarning(msg))