コード例 #1
0
    def action(self, options):
        try:
            response = vdsc.run_vds_client_cmd(self._address, self._use_ssl, "getVdsStats")
        except Exception as e:
            self._log.error("Failed to getVdsStats: %s", str(e))
            self.update_result(None)
            return

        mem_free = str(response["info"]["memFree"])
        self._log.info("memFree: %s", mem_free, extra=log_filter.lf_args("status", 60))
        self.update_result(mem_free)
コード例 #2
0
    def update_stat_file(self):
        if self.engine_pid:
            # Try the known pid and verify it's the same process
            fname = '/proc/{0}/stat'.format(self.engine_pid)
            try:
                with open(fname, 'r') as f:
                    self.proc_stat = f.readline().split()
            except Exception:
                self.proc_stat = None
            else:
                if int(self.proc_stat[21]) == self.engine_pid_start_time:
                    self._log.debug("VM on this host, pid %d", self.engine_pid,
                                    extra=log_filter.lf_args('vm', 60))
                else:
                    # This isn't the engine qemu process...
                    self.proc_stat = None

        if self.proc_stat is None:
            # Look for the engine vm pid and try to get the stats
            self.engine_pid = None
            self.engine_pid_start_time = None
            try:
                stats = vdsc.run_vds_client_cmd(self._address, self._use_ssl,
                                                'getVmStats', self._vm_uuid)
                pid = int(stats['statsList'][0]['pid'])
            except Exception as e:
                if isinstance(e, exceptions.DetailedError) \
                        and e.detail == "Virtual machine does not exist":
                    self._log.info("VM not on this host",
                                   extra=log_filter.lf_args('vm', 60))
                else:
                    self._log.error("Failed to getVmStats: %s", str(e),
                                    extra=log_filter.lf_args('vm', 60))
            else:
                fname = '/proc/{0}/stat'.format(pid)
                try:
                    with open(fname, 'r') as f:
                        self.proc_stat = f.readline().split()
                    self.engine_pid_start_time = int(self.proc_stat[21])
                    self.engine_pid = pid
                except Exception as e:
                    # Try again next time
                    self._log.error("Failed to read vm stats: %s", str(e),
                                    extra=log_filter.lf_args('vm', 60))
コード例 #3
0
    def action(self, options):
        try:
            response = vdsc.run_vds_client_cmd(self._address, self._use_ssl,
                                               'getVdsCapabilities')
        except Exception as e:
            self._log.error("Failed to getVdsCapabilities: %s", str(e))
            self.update_result(None)
            return

        if ('bridges' in response['info']
                and self._bridge in response['info']['bridges']):
            if response['info']['bridges'][self._bridge]['ports']:
                self._log.info("Found bridge %s with ports", self._bridge,
                               extra=log_filter.lf_args('status', 60))
                self.update_result(True)
            else:
                self._log.info("Found bridge %s with no ports", self._bridge,
                               extra=log_filter.lf_args('status', 60))
                self.update_result(False)
        else:
            self._log.info("Bridge %s not found", self._bridge,
                           extra=log_filter.lf_args('status', 60))
            self.update_result(False)
コード例 #4
0
    def action(self, options):
        # First, see if vdsm tells us it's up
        try:
            stats = vdsc.run_vds_client_cmd(self._address, self._use_ssl,
                                            'getVmStats', self._vm_uuid)
        except Exception as e:
            if isinstance(e, exceptions.DetailedError) \
                    and e.detail == "Virtual machine does not exist":
                # Not on this host
                self._log.info("VM not on this host",
                               extra=log_filter.lf_args('status', 60))
                d = {'vm': 'down', 'health': 'bad', 'detail': 'unknown',
                     'reason': 'vm not running on this host'}
                self.update_result(json.dumps(d))
                return
            else:
                self._log.error("Failed to getVmStats: %s", str(e))
                d = {'vm': 'unknown', 'health': 'unknown', 'detail': 'unknown',
                     'reason': 'failed to getVmStats'}
                self.update_result(json.dumps(d))
                return
        vm_status = stats['statsList'][0]['status'].lower()

        # Report states that are not really Up, but should be
        # reported as such
        if vm_status in ('paused',
                         'waitforlaunch',
                         'restoringstate',
                         'powering up'):
            self._log.info("VM status: %s", vm_status,
                           extra=log_filter.lf_args('status', 60))
            d = {'vm': engine.VMState.UP,
                 'health': engine.Health.BAD,
                 'detail': vm_status,
                 'reason': 'bad vm status'}
            self.update_result(json.dumps(d))
            return

        # Check for states that are definitely down
        if vm_status in ('down', 'migration destination'):
            self._log.info("VM not running on this host, status %s", vm_status,
                           extra=log_filter.lf_args('status', 60))
            d = {'vm': engine.VMState.DOWN,
                 'health': engine.Health.BAD,
                 'detail': vm_status,
                 'reason': 'bad vm status'}
            self.update_result(json.dumps(d))
            return

        # VM is probably up, let's see if engine is up by polling
        # health status page
        p = subprocess.Popen([constants.HOSTED_ENGINE_BINARY,
                              '--check-liveliness'],
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output = p.communicate()
        if p.returncode == 0:
            self._log.info("VM is up on this host with healthy engine",
                           extra=log_filter.lf_args('status', 60))
            d = {'vm': engine.VMState.UP,
                 'health': engine.Health.GOOD,
                 'detail': vm_status}
            self.update_result(json.dumps(d))
        else:
            self._log.warning("bad health status: %s", output[0])
            d = {'vm': engine.VMState.UP,
                 'health': engine.Health.BAD,
                 'detail': vm_status,
                 'reason': 'failed liveliness check'}
            self.update_result(json.dumps(d))