Note that there are some explanatory texts on larger screens.

plurals
  1. POAnonymous class inheritance
    primarykey
    data
    text
    <p>I am building a python automation API around a device configuration that looks like this...</p> <pre><code>root@EX4200-24T# show interfaces ge-0/0/6 mtu 9216; unit 0 { family ethernet-switching { port-mode trunk; vlan { members [ v100 v101 v102 ]; } } } root@EX4200-24T# </code></pre> <p>I am defining python classes for certain actions (like SET), as well as classes for the keywords for the action... The idea is that SET would iterate through the keyword classes and attach the class objects to the interfaces.</p> <p>The problem is that the configuration of this device is quite hierarchical... for instance if there are many <code>ethernet-switching</code> instances, I don't want API users to have to use:</p> <pre><code># Note that each keyword corresponds to a python class that is appended # to an InterfaceList object behind the scenes... SET(Interface='ge-0/0/6.0', Family='ethernet-switching', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) SET(Interface='ge-0/0/7.0', Family='ethernet-switching', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) SET(Interface='ge-0/0/8.0', Family='ethernet-switching', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) </code></pre> <p>Instead I would like to be able to use:</p> <pre><code>Family('ethernet-switching') SET(Interface='ge-0/0/6.0', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) SET(Interface='ge-0/0/7.0', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) SET(Interface='ge-0/0/8.0', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) Family(None) # API usage continues... </code></pre> <p>However, I can't figure out a way to code this in python without resorting to something like this...</p> <pre><code>f = Family('ethernet-switching') f.SET(Interface='ge-0/0/6.0', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) f.SET(Interface='ge-0/0/7.0', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) f.SET(Interface='ge-0/0/8.0', PortMode='trunk', Vlan=['v100', 'v101', 'v102']) </code></pre> <p>Which is not so bad until I need <code>SET()</code> to inherit from multiple classes... such as...</p> <p><em>PREFERRED API</em></p> <pre><code># Note: there could be many combinations of classes to inherit from Family('ethernet-switching') PortMode('trunk') SET(Interface='ge-0/0/6.0', Vlan=['v100', 'v101', 'v102']) SET(Interface='ge-0/0/7.0', Vlan=['v100', 'v101', 'v102']) PortMode('access') SET(Interface='ge-0/0/8.0', Vlan=['v100']) SET(Interface='ge-0/0/9.0', Vlan=['v100']) Family(None) PortMode(None) </code></pre> <p>Is there a pythonic way to achieve the last API example I have? If not, can you share some ideas for how to code the hierarchy of classes?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload