Пример #1
0
def _hv_ver(conn, uri):
    drv_type = uriutil.get_uri_driver(uri)
    args = ()

    cmd = _get_command("getVersion", obj=conn)
    if not cmd:
        cmd = _get_command("getVersion")
        args = (drv_type, )

    if not cmd:
        return 0

    if not _try_command(cmd, args):
        return 0

    try:
        ret = cmd(*args)
        if type(ret) == tuple:
            ret = ret[1]
    except libvirt.libvirtError:
        ret = 0

    return ret
Пример #2
0
def _hv_ver(conn, uri):
    drv_type = uriutil.get_uri_driver(uri)
    args = ()

    cmd = _get_command("getVersion", obj=conn)
    if not cmd:
        cmd = _get_command("getVersion")
        args = (drv_type,)

    if not cmd:
        return 0

    if not _try_command(cmd, args):
        return 0

    try:
        ret = cmd(*args)
        if type(ret) == tuple:
            ret = ret[1]
    except libvirt.libvirtError:
        ret = 0

    return ret
Пример #3
0
def _check_support(conn, feature, data=None):
    """
    Attempt to determine if a specific libvirt feature is support given
    the passed connection.

    @param conn: Libvirt connection to check feature on
    @type  conn: virConnect
    @param feature: Feature type to check support for
    @type  feature: One of the SUPPORT_* flags
    @param data: Option libvirt object to use in feature checking
    @type  data: Could be virDomain, virNetwork, virStoragePool,
                hv name, etc

    @returns: True if feature is supported, False otherwise
    """
    support_info = _support_dict[feature]
    key_list = support_info.keys()

    if not isinstance(conn, libvirt.virConnect):
        raise ValueError(_("'conn' must be a virConnect instance."))

    def get_value(key):
        if key in key_list:
            key_list.remove(key)
        return support_info.get(key)

    uri = conn.getURI()
    drv_type = uriutil.get_uri_driver(uri)
    is_rhel6 = get_rhel6()
    force_version = get_value("force_version") or False

    minimum_libvirt_version = get_value("version") or 0
    rhel6_min = get_value("rhel6_version") or minimum_libvirt_version
    if is_rhel6:
        minimum_libvirt_version = rhel6_min

    drv_version = get_value("drv_version") or []
    rhel6_drv_version = get_value("rhel6_drv_version") or drv_version
    if is_rhel6:
        drv_version = rhel6_drv_version

    drv_libvirt_version = get_value("drv_libvirt_version") or []

    hv_version = get_value("hv_version") or []
    object_name, function_name = _split_function_name(get_value("function"))
    args = get_value("args")
    flag = get_value("flag")

    actual_lib_ver = _local_lib_ver()
    actual_daemon_ver = _daemon_lib_ver(conn, uri, force_version,
                                        minimum_libvirt_version)
    actual_drv_ver = _hv_ver(conn, uri)

    # Make sure there are no keys left in the key_list. This will
    # ensure we didn't mistype anything above, or in the support_dict
    if key_list:
        raise RuntimeError("Unknown keys in the support_dict: %s" % key_list)

    if function_name:
        # Make sure function is present in either libvirt module or
        # object_name class
        flag_tuple = ()

        if not _has_command(function_name, objname=object_name):
            return False

        if flag:
            found_flag = _get_flag(flag)
            if not bool(found_flag):
                return False
            flag_tuple = (found_flag, )

        if args is not None:
            classobj = None

            # If function requires an object, make sure the passed obj
            # is of the correct type
            if object_name:
                classobj = _get_command(object_name)
                if not isinstance(data, classobj):
                    raise ValueError("Passed obj with args must be of type " +
                                     str(classobj))

            cmd = _get_command(function_name, obj=data)

            # Function with args specified is all the proof we need
            ret = _try_command(cmd,
                               args + flag_tuple,
                               check_all_error=bool(flag_tuple))
            return ret

    # Check that local libvirt version is sufficient
    if minimum_libvirt_version > actual_lib_ver:
        return False

    # Check that daemon version is sufficient
    if minimum_libvirt_version > actual_daemon_ver:
        return False

    # If driver specific version info specified, try to verify
    if drv_version:
        found = False
        for drv, min_drv_ver in drv_version:
            if drv != drv_type:
                continue

            if min_drv_ver < 0:
                if actual_drv_ver <= -min_drv_ver:
                    found = True
                    break
            else:
                if actual_drv_ver >= min_drv_ver:
                    found = True
                    break

        if not found:
            return False

    if drv_libvirt_version:
        found = False
        for drv, min_lib_ver in drv_libvirt_version:
            if drv != drv_type:
                continue

            if min_lib_ver < 0:
                if actual_lib_ver <= -min_lib_ver:
                    found = True
                    break
            else:
                if actual_lib_ver >= min_lib_ver:
                    found = True
                    break

        if not found:
            return False

    if hv_version:
        found = False
        hv_type = data
        for hv, min_hv_ver in hv_version:
            if hv != hv_type:
                continue

            # No HV specific version info, just use driver version
            if min_hv_ver < 0:
                if actual_drv_ver <= -min_hv_ver:
                    found = True
                    break
            else:
                if actual_drv_ver >= min_hv_ver:
                    found = True
                    break

        if not found:
            return False

    return True
Пример #4
0
 def get_driver(self):
     return uriutil.get_uri_driver(self.get_uri())
Пример #5
0
 def get_driver(self):
     return uriutil.get_uri_driver(self.get_uri())
Пример #6
0
def _check_support(conn, feature, data=None):
    """
    Attempt to determine if a specific libvirt feature is support given
    the passed connection.

    @param conn: Libvirt connection to check feature on
    @type  conn: virConnect
    @param feature: Feature type to check support for
    @type  feature: One of the SUPPORT_* flags
    @param data: Option libvirt object to use in feature checking
    @type  data: Could be virDomain, virNetwork, virStoragePool,
                hv name, etc

    @returns: True if feature is supported, False otherwise
    """
    support_info = _support_dict[feature]
    key_list = support_info.keys()

    if not isinstance(conn, libvirt.virConnect):
        raise ValueError(_("'conn' must be a virConnect instance."))

    def get_value(key):
        if key in key_list:
            key_list.remove(key)
        return support_info.get(key)

    uri = conn.getURI()
    drv_type = uriutil.get_uri_driver(uri)
    is_rhel6 = get_rhel6()
    force_version = get_value("force_version") or False

    minimum_libvirt_version = get_value("version") or 0
    rhel6_min = get_value("rhel6_version") or minimum_libvirt_version
    if is_rhel6:
        minimum_libvirt_version = rhel6_min

    drv_version = get_value("drv_version") or []
    rhel6_drv_version = get_value("rhel6_drv_version") or drv_version
    if is_rhel6:
        drv_version = rhel6_drv_version

    drv_libvirt_version = get_value("drv_libvirt_version") or []

    hv_version = get_value("hv_version") or []
    object_name, function_name = _split_function_name(get_value("function"))
    args = get_value("args")
    flag = get_value("flag")

    actual_lib_ver = _local_lib_ver()
    actual_daemon_ver = _daemon_lib_ver(conn, uri, force_version,
                                        minimum_libvirt_version)
    actual_drv_ver = _hv_ver(conn, uri)

    # Make sure there are no keys left in the key_list. This will
    # ensure we didn't mistype anything above, or in the support_dict
    if key_list:
        raise RuntimeError("Unknown keys in the support_dict: %s" % key_list)

    if function_name:
        # Make sure function is present in either libvirt module or
        # object_name class
        flag_tuple = ()

        if not _has_command(function_name, objname=object_name):
            return False

        if flag:
            found_flag = _get_flag(flag)
            if not bool(found_flag):
                return False
            flag_tuple = (found_flag,)

        if args is not None:
            classobj = None

            # If function requires an object, make sure the passed obj
            # is of the correct type
            if object_name:
                classobj = _get_command(object_name)
                if not isinstance(data, classobj):
                    raise ValueError("Passed obj with args must be of type " +
                                     str(classobj))

            cmd = _get_command(function_name, obj=data)

            # Function with args specified is all the proof we need
            ret = _try_command(cmd, args + flag_tuple,
                               check_all_error=bool(flag_tuple))
            return ret

    # Check that local libvirt version is sufficient
    if minimum_libvirt_version > actual_lib_ver:
        return False

    # Check that daemon version is sufficient
    if minimum_libvirt_version > actual_daemon_ver:
        return False

    # If driver specific version info specified, try to verify
    if drv_version:
        found = False
        for drv, min_drv_ver in drv_version:
            if drv != drv_type:
                continue

            if min_drv_ver < 0:
                if actual_drv_ver <= -min_drv_ver:
                    found = True
                    break
            else:
                if actual_drv_ver >= min_drv_ver:
                    found = True
                    break

        if not found:
            return False

    if drv_libvirt_version:
        found = False
        for drv, min_lib_ver in drv_libvirt_version:
            if drv != drv_type:
                continue

            if min_lib_ver < 0:
                if actual_lib_ver <= -min_lib_ver:
                    found = True
                    break
            else:
                if actual_lib_ver >= min_lib_ver:
                    found = True
                    break

        if not found:
            return False

    if hv_version:
        found = False
        hv_type = data
        for hv, min_hv_ver in hv_version:
            if hv != hv_type:
                continue

            # No HV specific version info, just use driver version
            if min_hv_ver < 0:
                if actual_drv_ver <= -min_hv_ver:
                    found = True
                    break
            else:
                if actual_drv_ver >= min_hv_ver:
                    found = True
                    break

        if not found:
            return False

    return True