示例#1
0
    def vm_diskspace(vm):
        log = get_logger()
        if conn.getType() == 'OpenVZ':
            return {'/': openvz.get_diskspace(vm.name())}
        # return a total sum of block devices used by KVM VM
        # get list of block devices of a file type

        try:
            script_path = get_config().getstring('general', 'script_prefix',
                                                 '/opt/opennode/bin/')
            cmd = os.path.join(
                script_path, 'libvirt_detect_domain_devices.sh %s' % vm.name())
            devices = execute(cmd).split('\n')
            total_bytes = 0.0
            for dev_path in devices:
                if dev_path.strip() == '-':
                    continue  # simple protection against non-disk base devices
                cmd = os.path.join(
                    script_path,
                    'libvirt_get_device_size.sh %s %s' % (vm.name(), dev_path))
                total_bytes += int(execute(
                    cmd)) / 1024.0 / 1024.0  # we want result to be in MB
        except CommandException as ce:
            log.debug('Failed diskspace detection: \'%s\'' % ce)
            total_bytes = 0.0
        except ValueError as ve:
            log.debug('Failed diskspace conversion: \'%s\'' % ve)
            total_bytes = 0.0
        return {'/': total_bytes}
示例#2
0
 def vm_diskspace(vm):
     log = get_logger()
     if conn.getType() == 'OpenVZ':
         return {'/': openvz.get_diskspace(vm.name())}
     # return a total sum of block devices used by KVM VM
     # get list of block devices of a file type
     
     try:
         cmd = "virsh domblklist --details %s |  grep ^file | awk '{print $4}'" % vm.name()
         devices = execute(cmd).split('\n')
         total_bytes = 0.0
         for dev_path in devices:
             if dev_path.strip() == '-':
                 continue  # simple protection against non-disk base devices
             cmd = "virsh domblkinfo %s %s |grep ^Capacity| awk '{print $2}'" % (vm.name(), dev_path)
             total_bytes += int(execute(cmd)) / 1024.0 / 1024.0  # we want result to be in MB
     except CommandException as ce:
         log.debug('Failed diskspace detection: \'%s\'' % ce)
         total_bytes = 0.0
     except ValueError as ve:
         log.debug('Failed diskspace conversion: \'%s\'' % ve)
         total_bytes = 0.0
     return {'/': total_bytes}
示例#3
0
    def vm_diskspace(vm):
        log = get_logger()
        if conn.getType() == "OpenVZ":
            return {"/": openvz.get_diskspace(vm.name())}
        # return a total sum of block devices used by KVM VM
        # get list of block devices of a file type

        try:
            script_path = get_config().getstring("general", "script_prefix", "/opt/opennode/bin/")
            cmd = os.path.join(script_path, "libvirt_detect_domain_devices.sh %s" % vm.name())
            devices = execute(cmd).split("\n")
            total_bytes = 0.0
            for dev_path in devices:
                if dev_path.strip() == "-":
                    continue  # simple protection against non-disk base devices
                cmd = os.path.join(script_path, "libvirt_get_device_size.sh %s %s" % (vm.name(), dev_path))
                total_bytes += int(execute(cmd)) / 1024.0 / 1024.0  # we want result to be in MB
        except CommandException as ce:
            log.debug("Failed diskspace detection: '%s'" % ce)
            total_bytes = 0.0
        except ValueError as ve:
            log.debug("Failed diskspace conversion: '%s'" % ve)
            total_bytes = 0.0
        return {"/": total_bytes}