示例#1
0
    def getVmMemoryStats(self, uuid):
        ret = {}
        try:
            vm = API.VM(uuid)
            response = vm.getStats()
            self._check_status(response)
            usage = int(response['statsList'][0]['memUsage'])
            if usage == 0:
                msg = "VM %s - The ovirt-guest-agent is not active" % uuid
                raise HypervisorInterfaceError(msg)
            stats = response['statsList'][0]['memoryStats']
            if not stats:
                msg = "Detailed guest memory stats are not available, " \
                        "please upgrade guest agent"
                raise HypervisorInterfaceError(msg)

            ret['mem_available'] = int(stats['mem_total'])
            ret['mem_unused'] = int(stats['mem_unused'])
            ret['mem_free'] = int(stats['mem_free'])
            ret['major_fault'] = int(stats['majflt'])
            ret['minor_fault'] = int(stats['pageflt']) - int(stats['majflt'])
            ret['swap_in'] = int(stats['swap_in'])
            ret['swap_out'] = int(stats['swap_out'])

            # get swap size and usage information if available
            ret['swap_total'] = int(stats.get('swap_total', 0))
            ret['swap_usage'] = int(stats.get('swap_usage', 0))

            self.logger.debug('Memory stats: %s', ret)
            return ret
        except vdsmException as e:
            raise HypervisorInterfaceError(e.msg)
示例#2
0
    def getVmMemoryStats(self, uuid):
        ret = {}
        try:
            vm = self.getVmStats(uuid)
        except KeyError as e:
            raise HypervisorInterfaceError("VM %s does not exist" % uuid)

        usage = int(vm['memUsage'])
        if usage == 0:
            msg = "VM %s - The ovirt-guest-agent is not active" % uuid
            raise HypervisorInterfaceError(msg)
        stats = vm['memoryStats']
        if not stats:
            msg = "Detailed guest memory stats are not available, " \
                    "please upgrade guest agent"
            raise HypervisorInterfaceError(msg)

        ret['mem_available'] = int(stats['mem_total'])
        ret['mem_unused'] = int(stats['mem_unused'])
        ret['mem_free'] = int(stats['mem_free'])
        ret['major_fault'] = int(stats['majflt'])
        ret['minor_fault'] = int(stats['pageflt']) - int(stats['majflt'])
        ret['swap_in'] = int(stats['swap_in'])
        ret['swap_out'] = int(stats['swap_out'])

        # get swap size and usage information if available
        ret['swap_total'] = int(stats.get('swap_total', 0))
        ret['swap_usage'] = int(stats.get('swap_usage', 0))

        self.logger.debug('Memory stats: %s', ret)
        return ret
示例#3
0
    def getVmCpuTuneInfo(self, uuid):
        try:
            ret = {}
            vm = self.getVmStats(uuid)
        except KeyError as e:
            raise HypervisorInterfaceError("VM %s does not exist" % uuid)

        # Get user selection for vCPU limit
        vcpuUserLimit = vm.get('vcpuUserLimit', 100)
        ret['vcpu_user_limit'] = vcpuUserLimit

        # Get current vcpu tuning info
        vcpuQuota = vm.get('vcpuQuota', 0)
        ret['vcpu_quota'] = vcpuQuota
        vcpuPeriod = vm.get('vcpuPeriod', 0)
        ret['vcpu_period'] = vcpuPeriod

        #Get num of vCPUs
        vcpuCount = vm.get('vcpuCount', None)
        if vcpuCount == None:
            return None
        else:
            ret['vcpu_count'] = vcpuCount

        # Make sure the values are numbers, VDSM is using str
        # to avoid xml-rpc issues
        # We are modifying the dict keys inside the loop so
        # iterate over copy of the list with keys, also use
        # list() to make this compatible with Python 3
        for key in list(ret.keys()):
            ret[key] = int(ret[key])
        return ret
示例#4
0
    def getVmInfo(self, uuid):
        try:
            vm = self.getVmStats(uuid)
        except KeyError as e:
            raise HypervisorInterfaceError("VM %s does not exist" % uuid)

        data = {}
        data['uuid'] = uuid
        data['pid'] = vm['pid']
        data['name'] = vm['vmName']
        if None in data.values():
            return None
        return data
示例#5
0
    def getVmBalloonInfo(self, uuid):
        try:
            vm = self.getVmStats(uuid)
        except KeyError as e:
            raise HypervisorInterfaceError("VM %s does not exist" % uuid)

        balloon_info = vm.get('balloonInfo', {})
        if balloon_info:
            # Make sure the values are numbers, VDSM is using str
            # to avoid xml-rpc issues
            # We are modifying the dict keys inside the loop so
            # iterate over copy of the list with keys, also use
            # list() to make this compatible with Python 3
            for key in list(balloon_info.keys()):
                # Remove keys that are not important to MoM to make sure
                # the HypervisorInterface stays consistent between
                # libvirt and vdsm platforms.
                if key not in ("balloon_max", "balloon_min", "balloon_cur"):
                    del balloon_info[key]
                    continue
                balloon_info[key] = int(balloon_info[key])
            return balloon_info