wangke1970 / yang_parser Goto Github PK
View Code? Open in Web Editor NEWyang parser rfc7950
yang parser rfc7950
1. run python3 yang_rfc.py ./bgp/ (generate yang_modules file) or python3 yang_rfc.py (If there are yang_modules file in the directory) 2. out Choice Modeule Name: ['ietf-netconf', 'openconfig-bgp-policy', 'openconfig-inet-types', 'openconfig-bgp-types', 'openconfig-policy-types', 'openconfig-types', 'openconfig-yang-types', 'ietf-inet-types', 'ietf-yang-types', 'ietf-interfaces', 'openconfig-interfaces', 'openconfig-extensions', 'openconfig-bgp', 'openconfig-routing-policy'] module >openconfig-bgp (yang contianer,list,leaf,leaf-list,... tree) openconfig-bgp>* 3、openconfig-bgp>* ....... ....... ├ container use-multiple-paths ->-6438312242391315966 ├ container config ->4874438011303423425 ├ leaf enabled ->-8644924308082446906 ├ container state ├ config false ├ leaf enabled ├ container ebgp ->-73683027755021457 ├ container config ->6271267819966798184 ├ leaf allow-multiple-as ->201404358886246952 ├ leaf maximum-paths ->-7024144332218161246 ├ container state ├ config false ├ leaf allow-multiple-as ├ leaf maximum-paths ├ container ibgp ->-2251363372557777736 ├ container config ->2237497577408369645 ├ leaf maximum-paths ->8891077290169949704 ├ container state ├ config false ├ leaf maximum-paths ├ container apply-policy ->-3688259472857241272 ├ container config ->-542825605681862353 ├ leaf-list import-policy ->202389048834029177 ├ leaf default-import-policy ->1581993182980904389 ├ leaf-list export-policy ->-2822994043534005579 ├ leaf default-export-policy ->8128682493600742992 ├ container state ├ config false ├ leaf-list import-policy ├ leaf default-import-policy ├ leaf-list export-policy ├ leaf default-export-policy ...... (copy paste -3688259472857241272) openconfig-bgp>-3688259472857241272 /openconfig-bgp>-3688259472857241272 ├ container apply-policy ->-3688259472857241272 ├ container config ->-542825605681862353 ├ leaf-list import-policy(path /openconfig-routing-policy:routing-policy/openconfig-routing-policy:policy-definitions/openconfig-routing-policy:policy-definition/openconfig-routing-policy:name) ->202389048834029177 ├ path_point (/openconfig-routing-policy:routing-policy/openconfig-routing-policy:policy-definitions/openconfig-routing-policy:policy-definition[{}]/openconfig-routing-policy:config/openconfig-routing-policy:name) ├ type string ├ ordered-by user ├ leaf default-import-policy ->1581993182980904389 ├ type default-policy-type ├ type enumeration ├ enum ACCEPT_ROUTE ├ enum REJECT_ROUTE ├ default REJECT_ROUTE ├ leaf-list export-policy(path /openconfig-routing-policy:routing-policy/openconfig-routing-policy:policy-definitions/openconfig-routing-policy:policy-definition/openconfig-routing-policy:name) ->-2822994043534005579 ├ path_point (/openconfig-routing-policy:routing-policy/openconfig-routing-policy:policy-definitions/openconfig-routing-policy:policy-definition[{}]/openconfig-routing-policy:config/openconfig-routing-policy:name) ├ type string ├ ordered-by user ├ leaf default-export-policy ->8128682493600742992 ├ type default-policy-type ├ type enumeration ├ enum ACCEPT_ROUTE ├ enum REJECT_ROUTE ├ default REJECT_ROUTE <Node>: oc-bgp:bgp/oc-bgp:peer-groups/oc-bgp:peer-group[{}]/oc-bgp:apply-policy <SubNode>: oc-bgp:config/oc-bgp:import-policy[{}] oc-bgp:config/oc-bgp:default-import-policy oc-bgp:config/oc-bgp:export-policy[{}] oc-bgp:config/oc-bgp:default-export-policy /openconfig-bgp> ([{}] is list or leaf-list) 4、input namespaces /openconfig-bgp>namespaces Show Module Prefix : ['openconfig-bgp'] Namespaces in yang module : {'openconfig-bgp': 'http://openconfig.net/yang/bgp'} Module name to prefix : {'openconfig-bgp': 'oc-bgp'} Add namespace yang nc if need : {'yang':'urn:ietf:params:xml:ns:yang:ietf-yang-types','nc':'urn:ietf:params:xml:ns:netconf:base:1.0'} 5、now use xpath2xml build xml (wangke1970/xpath2xml) #example from xpath2xml import xpath2xml ns = {'yang':'urn:ietf:params:xml:ns:yang:ietf-yang-types','nc':'urn:ietf:params:xml:ns:netconf:base:1.0','oc-bgp':'http://openconfig.net/yang/bgp'} bgp_x = xpath2xml(ns,'nc:rpc') example_str_1 = 'nc:edit-config/nc:config/' + 'oc-bgp:bgp/oc-bgp:peer-groups/oc-bgp:peer-group[0]/oc-bgp:apply-policy/oc-bgp:config' example_str_2 = 'nc:edit-config/nc:config/' + 'oc-bgp:bgp/oc-bgp:peer-groups/oc-bgp:peer-group[1]/oc-bgp:apply-policy/oc-bgp:config' bgp_x.add(example_str_1) bgp_x.add(example_str_2) #注意 oc-bgp:default-import-policy','oc-bgp:export-policy[0]','oc-bgp:export-policy[1]','oc-bgp:default-export-policy' 次序先入的node先生成xml bgp_x.insert(example_str_1,'oc-bgp:import-policy[0]') bgp_x.insert(example_str_1,'oc-bgp:import-policy[1]') bgp_x.inserts(example_str_1,['oc-bgp:default-import-policy','oc-bgp:export-policy[0]','oc-bgp:export-policy[1]','oc-bgp:default-export-policy']) bgp_x.insert(example_str_2,'oc-bgp:import-policy[0]') bgp_x.inserts(example_str_2,['oc-bgp:default-import-policy','oc-bgp:export-policy[0]','oc-bgp:default-export-policy']) print(bgp_x.xml) tree = bgp_x.tree ss = tree.dump print(ss) ######################out############################ <?xml version='1.0' encoding='utf-8'?> <nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:oc-bgp="http://openconfig.net/yang/bgp"><nc:edit-config><nc:config><oc-bgp:bgp><oc-bgp:peer-groups><oc-bgp:peer-group><oc-bgp:apply-policy><oc-bgp:config><oc-bgp:import-policy /><oc-bgp:import-policy /><oc-bgp:default-import-policy /><oc-bgp:export-policy /><oc-bgp:export-policy /><oc-bgp:default-export-policy /></oc-bgp:config></oc-bgp:apply-policy></oc-bgp:peer-group><oc-bgp:peer-group><oc-bgp:apply-policy><oc-bgp:config><oc-bgp:import-policy /><oc-bgp:default-import-policy /><oc-bgp:export-policy /><oc-bgp:default-export-policy /></oc-bgp:config></oc-bgp:apply-policy></oc-bgp:peer-group></oc-bgp:peer-groups></oc-bgp:bgp></nc:config></nc:edit-config></nc:rpc> nc:rpc ├ nc:edit-config ├ nc:config ├ oc-bgp:bgp ├ oc-bgp:peer-groups ├ oc-bgp:peer-group[0] ├ oc-bgp:apply-policy ├ oc-bgp:config ├ oc-bgp:import-policy[0] ├ oc-bgp:import-policy[1] ├ oc-bgp:default-import-policy ├ oc-bgp:export-policy[0] ├ oc-bgp:export-policy[1] ├ oc-bgp:default-export-policy ├ oc-bgp:peer-group[1] ├ oc-bgp:apply-policy ├ oc-bgp:config ├ oc-bgp:import-policy ├ oc-bgp:default-import-policy ├ oc-bgp:export-policy ├ oc-bgp:default-export-policy 6、find node /huawei-mac>find(container global-attribute) H:-5640491272284131244 ➔ P:/huawei-mac:mac/huawei-mac:global-attribute /huawei-mac>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.