示例#1
0
def adjust_setting_to_systems_resources(ovf_template_settings):
    """
    Adjusts maximum required resources to match available system resources.
    NB! Minimum bound is not adjusted.
    """
    st = ovf_template_settings
    st["memory_max"] = str(
        min(sysres.get_ram_size_gb(), float(st.get("memory_max", 10**30))))
    st["memory"] = str(min(float(st["memory"]), float(st["memory_max"])))

    st["vcpu_max"] = str(
        min(sysres.get_cpu_count(), int(st.get("vcpu_max", 10**10))))
    st["vcpu"] = str(min(int(st["vcpu"]), int(st["vcpu_max"])))

    # Checks if minimum required resources exceed maximum available resources
    errors = []
    if float(st["memory_min"]) > float(st["memory_max"]):
        errors.append(
            "Minimum required memory %sGB exceeds total available memory %sGB"
            % (st["memory_min"], st["memory_max"]))
    if int(st["vcpu_min"]) > int(st["vcpu_max"]):
        errors.append(
            "Minimum required number of vcpus %s exceeds available number %s."
            % (st["vcpu_min"], st["vcpu_max"]))
    return errors
示例#2
0
def adjust_setting_to_systems_resources(ovf_template_settings):
    """
    Adjusts maximum required resources to match available system resources.
    NB! Minimum bound is not adjusted.
    """
    def adjusted(norm, minvalue, maxvalue, valtype):
        if minvalue is None:
            minvalue = 0
        if maxvalue is None:
            maxvalue = 10 * 30
        return min(max(valtype(norm), valtype(minvalue)), valtype(maxvalue))

    st = ovf_template_settings
    st["memory_max"] = min(sysres.get_ram_size_gb(),
                           float(st.get("memory_max", 10**30)))
    st["memory"] = adjusted(st.get("memory"), st.get("memory_min"),
                            st.get("memory_max"), float)

    st["swap_max"] = str(
        min(sysres.get_swap_size_gb(), float(st.get("swap_max", 10**30))))
    st["swap"] = adjusted(st.get("swap"), st.get("swap_min"),
                          st.get("swap_max"), float)

    st["vcpu_max"] = str(
        min(sysres.get_cpu_count(), int(st.get("vcpu_max", 10**10))))
    st["vcpu"] = adjusted(st.get("vcpu"), st.get("vcpu_min"),
                          st.get("vcpu_max"), int)

    st["vcpulimit_max"] = min(sysres.get_cpu_usage_limit(),
                              int(st.get("vcpulimit_max", 100)))
    st["vcpulimit"] = adjusted(st.get("vcpulimit"), st.get("vcpulimit_min"),
                               st.get("vcputlimit_max"), int)

    st["disk_max"] = min(sysres.get_disc_space_gb(),
                         float(st.get("disk_max", 10**30)))
    st["disk"] = adjusted(st.get("disk"), st.get("disk_min"),
                          st.get("disk_max"), float)

    dns = list_nameservers()
    if len(dns) > 0:
        st["nameserver"] = dns[0]
    # Checks if minimum required resources exceed maximum available resources.
    errors = []
    if float(st["memory_min"]) > float(st["memory_max"]):
        errors.append(
            "Minimum required memory %sGB exceeds total available memory %sGB"
            % (st["memory_min"], st["memory_max"]))
    if int(st["vcpu_min"]) > int(st["vcpu_max"]):
        errors.append(
            "Minimum required number of vcpus %s exceeds available number %s."
            % (st["vcpu_min"], st["vcpu_max"]))
    if int(st["vcpulimit_min"]) > int(st["vcpulimit_max"]):
        errors.append(
            "Minimum required vcpu usage limit %s%% exceeds available %s%%." %
            (st["vcpulimit_min"], st["vcpulimit_max"]))
    if float(st["disk_min"]) > float(st["disk_max"]):
        errors.append(
            "Minimum required disk space %sGB exceeds available %sGB." %
            (st["disk_min"], st["disk_max"]))
    return errors
示例#3
0
def adjust_setting_to_systems_resources(ovf_template_settings):
    """
    Adjusts maximum required resources to match available system resources.
    NB! Minimum bound is not adjusted.
    """

    def adjusted(norm, minvalue, maxvalue, valtype):
        if minvalue is None:
            minvalue = 0
        if maxvalue is None:
            maxvalue = 10 * 30
        return min(max(valtype(norm), valtype(minvalue)), valtype(maxvalue))

    st = ovf_template_settings
    st["memory_max"] = min(sysres.get_ram_size_gb(), float(st.get("memory_max", 10 ** 30)))
    st["memory"] = adjusted(st.get("memory"), st.get("memory_min"), st.get("memory_max"), float)

    st["swap_max"] = str(min(sysres.get_swap_size_gb(), float(st.get("swap_max", 10 ** 30))))
    st["swap"] = adjusted(st.get("swap"), st.get("swap_min"), st.get("swap_max"), float)

    st["vcpu_max"] = str(min(sysres.get_cpu_count(), int(st.get("vcpu_max", 10 ** 10))))
    st["vcpu"] = adjusted(st.get("vcpu"), st.get("vcpu_min"), st.get("vcpu_max"), int)

    st["vcpulimit_max"] = min(sysres.get_cpu_usage_limit(), int(st.get("vcpulimit_max", 100)))
    st["vcpulimit"] = adjusted(st.get("vcpulimit"), st.get("vcpulimit_min"), st.get("vcputlimit_max"), int)

    st["disk_max"] = min(sysres.get_disc_space_gb(), float(st.get("disk_max", 10 ** 30)))
    st["disk"] = adjusted(st.get("disk"), st.get("disk_min"), st.get("disk_max"), float)

    dns = list_nameservers()
    if len(dns) > 0:
        st["nameserver"] = dns[0]
    # Checks if minimum required resources exceed maximum available resources.
    errors = []
    if float(st["memory_min"]) > float(st["memory_max"]):
        errors.append("Minimum required memory %sGB exceeds total available memory %sGB" %
                      (st["memory_min"], st["memory_max"]))
    if int(st["vcpu_min"]) > int(st["vcpu_max"]):
        errors.append("Minimum required number of vcpus %s exceeds available number %s." %
                      (st["vcpu_min"], st["vcpu_max"]))
    if int(st["vcpulimit_min"]) > int(st["vcpulimit_max"]):
        errors.append("Minimum required vcpu usage limit %s%% exceeds available %s%%." %
                      (st["vcpulimit_min"], st["vcpulimit_max"]))
    if float(st["disk_min"]) > float(st["disk_max"]):
        errors.append("Minimum required disk space %sGB exceeds available %sGB." %
                      (st["disk_min"], st["disk_max"]))
    return errors
示例#4
0
def adjust_setting_to_systems_resources(ovf_template_settings):
    """
    Adjusts maximum required resources to match available system resources.
    NB! Minimum bound is not adjusted.
    """
    st = ovf_template_settings
    st["memory_max"] = str(min(sysres.get_ram_size_gb(), float(st.get("memory_max", 10 ** 30))))
    st["memory"] = str(min(float(st["memory"]), float(st["memory_max"])))

    st["vcpu_max"] = str(min(sysres.get_cpu_count(), int(st.get("vcpu_max", 10 ** 10))))
    st["vcpu"] = str(min(int(st["vcpu"]), int(st["vcpu_max"])))

    # Checks if minimum required resources exceed maximum available resources
    errors = []
    if float(st["memory_min"]) > float(st["memory_max"]):
        errors.append("Minimum required memory %sGB exceeds total available memory %sGB" %
                      (st["memory_min"], st["memory_max"]))
    if int(st["vcpu_min"]) > int(st["vcpu_max"]):
        errors.append("Minimum required number of vcpus %s exceeds available number %s." %
                      (st["vcpu_min"], st["vcpu_max"]))
    return errors