简体   繁体   English

Cisco IOS将“ show conf”转换为XML?

[英]Cisco IOS “show conf” to XML?

Is there either: 是否有:

A freely available program that can convert the output of a Cisco's "show conf" to some sensible XML, like this (probably not very sensible) block form: 一个免费的程序,可以将Cisco的“ show conf”的输出转换为一些明智的XML,例如以下(可能不是很明智)的块形式:

<aaa>
  <new-model/>
  <authentication>
    <login>
      <default>
        <group id="tacacs+">enable</group>
      </defult>
    </login>

    <!-- ...etc... -->

  </authentication>
</aaa>

...or, if not, at an XML schema that I could look to implement? ...或者(如果没有的话)在我可以实现的XML模式上? Without a deep understanding of the IOS syntax, building up the schema is proving to be tricky. 在没有对IOS语法的深入了解的情况下,建立架构被证明是棘手的。

Cisco provides no schema for IOS configurations. 思科不为IOS配置提供任何架构。 However, you may have two options: 但是,您可能有两个选择:

  • Cisco's IOS XR has built-in XML support. 思科的IOS XR具有内置的XML支持。 Depending on the model of your router you may be able to upgrade. 根据路由器的型号,您可能可以升级。 You'll have to enable the "xml-agent" feature for this to work. 您必须启用“ xml-agent”功能才能正常工作。 Be aware that this feature is not always deemed reliable yet (last we checked there were some bugs that prevented us from using it), but it should be good enough for many people. 请注意,此功能并不总是可靠的(最后,我们检查了一些阻止我们使用该功能的错误),但是对于许多人来说,它应该已经足够好了。

  • If upgrading is not an option, there is this horrible ugly hack (that's my fault): 如果无法升级,那么这个可怕的丑陋骇客(这是我的错):

http://code.google.com/p/text2xml/ http://code.google.com/p/text2xml/

It comes with a syntax for IOS (syntax/ios.def in the repository) that supports translating a significant number of commands to XML, but is in no way complete. 它带有用于IOS的语法(存储库中的语法/ios.def),该语法支持将大量命令转换为XML,但绝不是完整的。 Still, it works for a large number of very complex configurations here, and extending it to support new IOS commands should merely be a matter of adding the new commands to the (painfully unreadable and hard to understand) syntax definition. 尽管如此,它仍然可以在这里用于大量非常复杂的配置,并且将其扩展以支持新的IOS命令仅是将新命令添加到(非常难以理解且难以理解的)语法定义中的问题。

You'll still want to convert the resulting XML to something more stable, but XML transformations are way easier than parsing IOS (which is a royal PITA). 您仍然需要将生成的XML转换为更稳定的格式,但是XML转换比解析IOS(这是一种皇家PITA)要容易得多。

[edit] The above answer is now largely obsolete : I have written Gelatin , which lets you convert IOS and IOS XR configurations to XML, JSON, or YAML - whichever you prefer. [edit] 上面的答案现在已经过时了 :我写了Gelatin ,它使您可以将IOS和IOS XR配置转换为XML,JSON或YAML-随便哪个。 This is essentially a replacement for afore mentioned ugly hack, with the following differences: 这本质上是上述丑陋黑客的替代品,具有以下区别:

  • I no longer call it an ugly hack. 我不再称其为丑陋的骇客。 I am actually pretty proud of it, so don't disillusion me! 我真的为此感到骄傲,所以不要让我失望! More seriously, if you find any problem with it, please let me know and I will fix it. 更严重的是,如果您发现任何问题,请告诉我,我们会解决。
  • Written in pure Python, and it no longer compiles to C, which makes it a lot easier to use and install. 用纯Python编写,并且不再编译为C,这使得它的使用和安装变得更加容易。 (Also, the performance gain from generating C code wasn't essential anyway.) (此外,通过生成C代码获得的性能提升也不是必需的。)
  • The syntax is way easier to understand. 语法的方式更容易理解。 There is also some documentation. 也有一些文档。
  • The parser is much more stable. 解析器要稳定得多。

A short how-to: 简短的操作方法:

  • Download and install Gelatin: 下载并安装明胶:

     git clone git://github.com/knipknap/Gelatin.git cd Gelatin sudo python setup.py install 
  • The package contains a syntax for IOS (syntax/ios/show_running_config/syntax.gel) and another one for IOS XR (syntax/ios_xr/show_running_config/syntax.gel). 该软件包包含一个用于IOS的语法(syntax / ios / show_running_config / syntax.gel)和另一个用于IOS XR的语法(syntax / ios_xr / show_running_config / syntax.gel)。

  • Transform a config to XML using the following command: 使用以下命令将配置转换为XML:

     gel -s syntax.gel config.txt 

If that fails, please file a bug with the configuration that does not work. 如果失败,请提交配置无效的错误 (Or better yet, attach a patch for the syntax.) I fully expect that a lot of IOS commands are still missing, so don't be shy. (或者更好的是,附加一个语法补丁。)我完全希望仍然缺少许多IOS命令,所以请不要害羞。

Gelatin may be used to transform pretty much anything to XML, and if you happen to create your own syntax files (further instructions are here ), please send them in. I'll gladly accept any feedback. 明胶可用于将几乎所有内容转换为XML,如果您碰巧创建了自己的语法文件(更多说明在此处 ),请发送它们。我很乐意接受任何反馈。

我在12.4(20)T,12.2(33)SRE,12.2(54)SG及更高版本上遇到了XML-PI ,它处理了这样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM