def get_gres_count()

in azure-slurm-install/install.py [0:0]


def get_gres_count(hostname):
    count = 0
    try:
        with open("/etc/slurm/gres.conf", 'r') as file:
            for line in file:
                nodename_match = re.search(r'Nodename=([^\s]+)', line, re.IGNORECASE)
                count_match = re.search(r'count=(\d+)', line, re.IGNORECASE)
                if nodename_match and count_match:
                    nodename = nodename_match.group(1)
                    # This command is local to the node and does not send an RPC to the controller.
                    if hostname in subprocess.run(['scontrol', 'show', 'hostnames', nodename], stdout=subprocess.PIPE, universal_newlines=True).stdout:
                        count = int(count_match.group(1))

    except Exception as e:
        logging.error(f"An error occurred: {e}")

    return count