Created
December 10, 2015 12:06
-
-
Save ytti/ae5f15b514c3ae7f82e1 to your computer and use it in GitHub Desktop.
builds IGP topology off JNPR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'ntt/junos/xmlssh' | |
require 'pry' | |
class GetTopology | |
HOST = 'r00.testtx09.us.bb' | |
COMMAND = 'show isis database detail' | |
attr_reader :nodes, :edges | |
def initialize | |
xml = NTT::JunOS::XMLSSH.run host: HOST, command: COMMAND | |
@nodes, @edges = parse_xml xml | |
end | |
private | |
def parse_xml xml | |
nodes, edges = [], [] | |
xml.xpath('///isis-database-entry').each do |node| | |
name = clean_name node.at_xpath('lsp-id').content | |
nodes << name | |
node.xpath('isis-neighbor').each do |neighbor| | |
peer = clean_name neighbor.at_xpath('is-neighbor-id').content | |
metric = neighbor.at_xpath('metric').content.to_i | |
edges << { | |
src: name, | |
dst: peer, | |
metric: metric, | |
} | |
end | |
end | |
[nodes, edges] | |
end | |
def clean_name name | |
name = name.split('.')[0..-2].join('.') | |
name = name[0..-5] if name[-4..-2] == '-re' | |
name | |
end | |
end | |
if $0 == __FILE__ | |
topo = GetTopology.new | |
binding.pry | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment