Python Maagic Examples

I noticed there are many examples of the “maapi” ConfD python API in the intro/python folder with in the examples. However, are there some “Maagic” python API examples that could be added? In the meantime could someone provide some examples for things like iterating over a List, Leaf-List, making a change to a Leaf node, opening a transaction/committing change and rolling them back?

I am thinking something along the lines of what I have created here for NSO Maagic Python API:

Obviously ConfD would iterate over some custom yang model rather than a NED CDB config, but it would help me connect the dots between NCS/NSO Maagic and ConfD Maagic usage.

1 Like

I think I have a few examples to provide to others, was playing around with it in iPython, but still would appreciate any other samples out there:


m.start_user_session('admin', 'test_context')

t = m.start_write_trans()

root = maagic.get_root(t)

address = root.mif__interface.ip_address.address

print address
8.40.99.11

netmask  = root.mif__interface.ip_address.netmask

print netmask
/21

for the following yang module

module pyntc_interface {
  yang-version "1";

  namespace "http://www.networktocode.com/yang/interfaces";
  prefix "mif";

  container interface {

    leaf color {
      type enumeration {
        enum yellow {
          value 1;
          description
            "The color of bananas";
        }

        enum green {
          value 2;
          description
            "The color of cucumbers.";
        }

        enum blue {
          value 3;
          description
            "The color of blueberrries.";
        }
      }
      mandatory true;
      description
        "The desired color of the interface.";
    }

    container ip_address {
      leaf address {
        type string;
      }

      leaf netmask {
        type string;
      }

    }
  }
}

and the following sample config

ntc# show running-config interface
interface color blue
interface ip_address address 8.40.99.11
interface ip_address netmask /21
ntc#
1 Like