Python generate devices

Viewed 22

I would like to generate number devices with same profile based on the per role into dict. For example in the yaml file, if the quantity: 2 for the device_role: leaf. I would like to generate two times with incremental device_name and also generate given interface counts in interface.count. If the interfaces.count: 64, that mean in that role there are 64 interfaces which the name start from ethernet_. I hope I was able to explain properly.. Apologized in advance for the unable to explain correctly. But I have added the example what result should look like. thanks for the help.

# yaml file:
---
devices:
  - device_role: leaf
    quantity: 2
    interfaces:
      - name: ethernet
        optics: 100G
        count: 64
  - device_role: inband
    quantity: 1
    interfaces:
      - name: ethernet
        optics: 1G
        count: 48

parse yaml to read content

def parseyaml(file):
    with open(file) as f:
        output = yaml.load(f, Loader=yaml.FullLoader)
    return output

here what the result I would like to get:

{
    device_role: leaf
    device_name: leaf-01
    interfaces:
        [
            { "name": "ethernet_1", "optic": "100G" },
            . . .
            { "name": "ethernet_64", "optic": "100G" },
],
    device_role: leaf
    device_name: leaf-02
    ports:
        [
            { "name": "ethernet_1", "optic": "100G" },
            . . .
            { "name": "ethernet_64", "optic": "100G" },
],
    device_role: inband
    device_name: inband-01
    ports:
        [
            { "name": "ethernet_1", "optic": "1G" },
            . . .
            { "name": "ethernet_48", "optic": "1G" },
],
}
0 Answers
Related