cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1070
Views
0
Helpful
1
Replies

Get all configuration below interface using python maapi

nso20
Level 1
Level 1

Hello,

I can get the value of description on device interface using python maapi as below:

import ncs.maapi as maapi

with ncs.maapi.single_read_trans('admin', 'system', db=ncs.OPERATIONAL) as m:
    root = ncs.maagic.get_root(m)

    print(root.devices.device['mydevice'].config.ios__interface.GigabitEthernet['1'].description)

my_interface_desc

Instead of getting a single value, can I get the output of all configuration below the interface (e.g. description, ip address, negotiation, ...) using python maapi, something like:
root.ncs__devices.device['mydevice'].config.ios__interface.GigabitEthernet['1'].?

1 Reply 1

rogaglia
Cisco Employee
Cisco Employee

I do not believe you can get what you want in Python. What I can think about is the encodeXML() method in Java. This will return you the full sub-tree structure from your object that you can print in XML format (or decode at your wish). Please remember that a "config" in CDB is a tree and not a "string".

 

  • encodeXML

    public List<ConfXMLParam> encodeXML()
                                 throws NavuException
    Description copied from class: NavuNode
    Encoding the sub-tree including the current NavuNode as the topmost NavuNode to a ConfXMLParam array.

    The returning ConfXMLParam array contains no values except for list keys. The leaf elements are encoded as ConfXMLParamLeaf therefore the returning array could be used as a input parameter to NavuNode.getValues(ConfXMLParam[]) on the current elements parent.

      NavuNode node = ...;
       //cxa contains structure that does not contains values except for
      //keys in list elements
       ConfXMLParam[] cxa = node.encodeXML().toArray(new ConfXMLParam[0]);
       NavuNode parent = node.getParent();
    
       //contains sub-tree with all the values
       ConfXMLParam[] cxb = parent.getValues(cxa);
     
    Specified by:
    encodeXML in class NavuNode
    Returns:
    An array of ConfXMLParam of the sub-tree (including key values) with key values.
    Throws:
    NavuException - If the operation could not be performed for some reasons
    See Also:
    ConfXMLParam, ConfXMLParamValue