charmed-hpc / slurmutils

Utilities and APIs for interfacing with the Slurm workload manager ⚙️🔌
GNU Lesser General Public License v3.0
1 stars 3 forks source link

feat!: add `from_dict` method to construct configuration from dictionary #15

Closed NucciTheBoss closed 3 weeks ago

NucciTheBoss commented 3 weeks ago

TL;DR - adds the from_dict class method to all the configuration data models to enable creating new model objects from dictionaries. For example, here's how you could create a node using the from_dict method:

new_node = Node.from_dict(
    {
        "juju-c9fc6f-5": {
            "NodeAddr": "10.152.28.51",
            "CPUs": "1",
            "RealMemory": "1000",
            "TmpDisk": "10000",
        }
    }
)

The new option module is then responsible for validating that the values passed to from_dict are correct, add provides the marshallers for when you go to dump the configuration into a file. The option module also removes the "hacky" implementation for callbacks which just uses a MappingProxy embedded into the data model as a protected attribute.

BREAKING CHANGES: I removed the NodeMap, PartitionMap, DownNodesList wrappers as I was not enamored with their implementation. They were rushed. I took them out as I'd like to spend more time refining their implementation so they aren't as hacky/clunky. Let me know if you'd like for me to add them back in. We can like open a follow-on PR that focuses on their implementation, but for now we have enough to unblock https://github.com/charmed-hpc/hpc-libs/pull/22

Side note: I need to update the README and pyproject.toml before merging this PR, but I want to know your thoughts on the "from_dict(...) and back again" implementation before going ahead and handling that.

Closes #14

NucciTheBoss commented 3 weeks ago

@jedel1043 R4R 🔍

jamesbeedy commented 3 weeks ago

Wow! @NucciTheBoss , nice work!