fabric-testbed / InformationModel

FABRIC Information Model library
MIT License
7 stars 1 forks source link

Issue 83 - add ability to serialize/deserialize Node and Network Service slivers from JSON #85

Closed ibaldin closed 2 years ago

ibaldin commented 2 years ago

This implementation relies on ABCPropertyGraph code that already knows how to do it with dictionaries. Adds ability to convert to/from 'deep' dictionaries and slivers. Adds a simple class with static methods to convert slivers to/from JSON.

import fim.user as f
from fim.slivers.json import JSONSliver
from fim.graph.abc_property_graph import ABCPropertyGraph

if __name__ == "__main__":
        t = f.ExperimentTopology()
        t.add_node(name='n1', site='RENC')
        t.nodes['n1'].capacities = f.Capacities(core=1)
        t.nodes['n1'].add_component(name='c1', ctype=f.ComponentType.SmartNIC, model='ConnectX-6')
        d = ABCPropertyGraph.sliver_to_dict(t.nodes['n1'].get_sliver())
        t.add_node(name='n2', site='RENC')
        t.nodes['n2'].add_component(name='c2', ctype=f.ComponentType.SmartNIC, model='ConnectX-6')
        t.nodes['n2'].add_component(name='c3', ctype=f.ComponentType.NVME, model='P4510')
        t.add_network_service(name='s1', nstype=f.ServiceType.L2Bridge, interfaces=t.interface_list)

        # example code begins  here 
        jns = JSONSliver.sliver_to_json(t.nodes['n1'].get_sliver())
        ns1 = JSONSliver.node_sliver_from_json(jns)
        jns = JSONSliver.sliver_to_json(t.nodes['n2'].get_sliver())
        ns2 = JSONSliver.node_sliver_from_json(jns)
        ness = JSONSliver.sliver_to_json(t.network_services['s1'].get_sliver())
        nss1 = JSONSliver.network_service_sliver_from_json(ness)
ibaldin commented 2 years ago

Addresses #83