def write_slurm_topology()

in azure-slurm/slurmcc/topology.py [0:0]


    def write_slurm_topology(self)-> None:
        """
        Writes the SLURM topology configuration to a file or prints it to the console.

        This method generates the SLURM topology configuration based on the `torsets` attribute
        and either writes it to a file specified by `self.slurm_top_file` or prints it to the console,
        depending on the value of the `output` parameter.

        Returns:
            None
        """
        switches=[]
        if self.slurm_top_file:
            with open(self.slurm_top_file, 'w', encoding="utf-8") as file:
                for torset, hosts in self.torsets.items():
                    torset_index=torset[-2:]
                    num_nodes = len(hosts)
                    file.write(f"# Number of Nodes in sw{torset_index}: {num_nodes}\n")
                    print(f"# Number of Nodes in sw{torset_index}: {num_nodes}\n")
                    file.write(f"SwitchName=sw{torset_index} Nodes={','.join(hosts)}\n")
                    print(f"SwitchName=sw{torset_index} Nodes={','.join(hosts)}\n")
                    switches.append(f"sw{torset_index}")
                if len(self.torsets)>1:
                    switch_name=int(torset_index)+1
                    file.write(f"SwitchName=sw{switch_name:02} Switches={','.join(switches)}\n")
                    print(f"SwitchName=sw{switch_name:02} Switches={','.join(switches)}\n")
        else:
            for torset, hosts in self.torsets.items():
                torset_index=torset[-2:]
                num_nodes = len(hosts)
                print(f"# Number of Nodes in sw{torset_index}: {num_nodes}\n")
                print(f"SwitchName=sw{torset_index} Nodes={','.join(hosts)}\n")
                switches.append(f"sw{torset_index}")
            if len(self.torsets)>1:
                switch_name=int(torset_index)+1
                print(f"SwitchName=sw{switch_name:02} Switches={','.join(switches)}\n")