junos-ez-stdlib 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/LICENSE +26 -0
  2. data/README.md +181 -0
  3. data/docs/Config_Utils.md +3 -0
  4. data/docs/Facts.md +106 -0
  5. data/docs/Filesys_Utils.md +3 -0
  6. data/docs/IPports.md +3 -0
  7. data/docs/L1ports.md +3 -0
  8. data/docs/L2ports.md +3 -0
  9. data/docs/Providers_Resources.md +304 -0
  10. data/docs/RE_utils.md +3 -0
  11. data/docs/StaticHosts.md +3 -0
  12. data/docs/StaticRoutes.md +3 -0
  13. data/docs/Vlans.md +3 -0
  14. data/examples/config/config_file.rb +72 -0
  15. data/examples/config/config_template_object.rb +81 -0
  16. data/examples/config/config_template_simple.rb +76 -0
  17. data/examples/config/multi_config.rb +60 -0
  18. data/examples/fs_utils.rb +31 -0
  19. data/examples/re_upgrade.rb +90 -0
  20. data/examples/re_utils.rb +30 -0
  21. data/examples/simple.rb +47 -0
  22. data/examples/st_hosts.rb +33 -0
  23. data/examples/vlans.rb +25 -0
  24. data/junos-ez-stdlib.gemspec +15 -0
  25. data/lib/junos-ez/facts/chassis.rb +45 -0
  26. data/lib/junos-ez/facts/ifd_style.rb +14 -0
  27. data/lib/junos-ez/facts/personality.rb +22 -0
  28. data/lib/junos-ez/facts/switch_style.rb +22 -0
  29. data/lib/junos-ez/facts/version.rb +32 -0
  30. data/lib/junos-ez/facts.rb +85 -0
  31. data/lib/junos-ez/ip_ports/classic.rb +149 -0
  32. data/lib/junos-ez/ip_ports.rb +28 -0
  33. data/lib/junos-ez/l1_ports/classic.rb +87 -0
  34. data/lib/junos-ez/l1_ports/switch.rb +134 -0
  35. data/lib/junos-ez/l1_ports.rb +81 -0
  36. data/lib/junos-ez/l2_ports/bridge_domain.rb +0 -0
  37. data/lib/junos-ez/l2_ports/vlan.rb +317 -0
  38. data/lib/junos-ez/l2_ports/vlan_l2ng.rb +0 -0
  39. data/lib/junos-ez/l2_ports.rb +57 -0
  40. data/lib/junos-ez/provider.rb +608 -0
  41. data/lib/junos-ez/stdlib.rb +16 -0
  42. data/lib/junos-ez/system/st_hosts.rb +74 -0
  43. data/lib/junos-ez/system/st_routes.rb +135 -0
  44. data/lib/junos-ez/system/syscfg.rb +103 -0
  45. data/lib/junos-ez/system.rb +98 -0
  46. data/lib/junos-ez/utils/config.rb +205 -0
  47. data/lib/junos-ez/utils/fs.rb +376 -0
  48. data/lib/junos-ez/utils/re.rb +371 -0
  49. data/lib/junos-ez/vlans/bridge_domain.rb +85 -0
  50. data/lib/junos-ez/vlans/vlan.rb +112 -0
  51. data/lib/junos-ez/vlans.rb +31 -0
  52. metadata +111 -0
@@ -0,0 +1,72 @@
1
+ =begin
2
+
3
+ This exmaple illustrates the use of the Junos::Ez::Config::Utils library. The code will load the contents
4
+ of a configuration file and save the diff output to the file "diffs.txt". Error checking/exception
5
+ handling is also demonstrated. If there are any errors, the "pretty-print" (pp) function will dump the
6
+ contents of the result structure to stderr so you can see what it looks like.
7
+
8
+ =end
9
+
10
+ require 'net/netconf/jnpr'
11
+ require 'junos-ez/stdlib'
12
+
13
+ # login information for NETCONF session
14
+
15
+ login = { :target => 'vsrx', :username => 'jeremy', :password => 'jeremy1', }
16
+
17
+ ## create a NETCONF object to manage the device and open the connection ...
18
+
19
+ ndev = Netconf::SSH.new( login )
20
+ $stdout.print "Connecting to device #{login[:target]} ... "
21
+ ndev.open
22
+ $stdout.puts "OK!"
23
+
24
+ # attach the junos-ez objects to the ndev object ...
25
+
26
+ Junos::Ez::Provider( ndev )
27
+ Junos::Ez::Config::Utils( ndev, :cfg )
28
+
29
+ # begin a block to trap any raised expections ...
30
+ begin
31
+
32
+ # lock the candidate config
33
+ ndev.cfg.lock!
34
+
35
+ # load the contents of the 'load_sample.conf' file
36
+ # into the device.
37
+
38
+ $stdout.puts "Loading changes ..."
39
+ ndev.cfg.load! :filename => 'load_sample.conf'
40
+
41
+ # check to see if commit-check passes. if it doesn't
42
+ # it will return a structure of errors
43
+
44
+ unless (errs = ndev.cfg.commit?) == true
45
+ $stderr.puts "Commit check failed"
46
+ pp errs
47
+ ndev.close # will auto-rollback changes
48
+ exit 1
49
+ end
50
+
51
+ # save the cnfig diff to a file ...
52
+ File.open( "diffs.txt", "w") {|f| f.write ndev.cfg.diff? }
53
+
54
+ # commit the changes and unlock the config
55
+
56
+ $stdout.puts "Commiting changes ..."
57
+ ndev.cfg.commit!
58
+ ndev.cfg.unlock!
59
+
60
+ $stdout.puts "Done!"
61
+
62
+ rescue Netconf::LockError
63
+ $stderr.puts "Unable to lock config"
64
+ rescue Netconf::EditError => e
65
+ $stderr.puts "Unable to load configuration"
66
+ pp Junos::Ez::rpc_errors( e.rsp )
67
+ rescue Netconf::CommitError => e
68
+ $stderr.puts "Unable to commit configuration"
69
+ pp Junos::Ez::rpc_errors( e.rpc )
70
+ end
71
+
72
+ ndev.close
@@ -0,0 +1,81 @@
1
+ =begin
2
+
3
+ This exmaple illustrates the use of the Junos::Ez::Config::Utils library. The code will load the contents
4
+ of a template (ERB) file and use an object to contain the variables used in scope (binding).
5
+
6
+ Error checking/exception handling is also demonstrated. If there are any errors, the "pretty-print"
7
+ (pp) function will dump the contents of the result structure to stderr so you can see what it looks like.
8
+
9
+ =end
10
+
11
+ require 'net/netconf/jnpr'
12
+ require 'junos-ez/stdlib'
13
+
14
+ # login information for NETCONF session
15
+
16
+ login = { :target => 'vsrx', :username => 'jeremy', :password => 'jeremy1', }
17
+
18
+ ## create a NETCONF object to manage the device and open the connection ...
19
+
20
+ ndev = Netconf::SSH.new( login )
21
+ $stdout.print "Connecting to device #{login[:target]} ... "
22
+ ndev.open
23
+ $stdout.puts "OK!"
24
+
25
+ # attach the junos-ez objects to the ndev object ...
26
+
27
+ Junos::Ez::Provider( ndev )
28
+ Junos::Ez::Config::Utils( ndev, :cfg )
29
+
30
+ # begin a block to trap any raised expections ...
31
+ begin
32
+
33
+ # lock the candidate config
34
+ ndev.cfg.lock!
35
+
36
+ # load the template (ERB) file and use an object to contains the variables
37
+ # in scope durning the ERB result evaluation, so declare that now just for demo purposes ...
38
+
39
+ class MyClass
40
+ def initialize
41
+ @interfaces = ['ge-0/0/1','ge-0/0/2','ge-0/0/3']
42
+ end
43
+ end
44
+
45
+ myobj = MyClass.new
46
+
47
+ $stdout.puts "Loading changes ..."
48
+ ndev.cfg.load! :filename => 'load_template_object.conf', :binding => myobj
49
+
50
+ # check to see if commit-check passes. if it doesn't
51
+ # it will return a structure of errors
52
+
53
+ unless (errs = ndev.cfg.commit?) == true
54
+ $stderr.puts "Commit check failed"
55
+ pp errs
56
+ ndev.close # will auto-rollback changes
57
+ exit 1
58
+ end
59
+
60
+ # save the cnfig diff to a file ...
61
+ File.open( "diffs.txt", "w") {|f| f.write ndev.cfg.diff? }
62
+
63
+ # commit the changes and unlock the config
64
+
65
+ $stdout.puts "Commiting changes ..."
66
+ ndev.cfg.commit!
67
+ ndev.cfg.unlock!
68
+
69
+ $stdout.puts "Done!"
70
+
71
+ rescue Netconf::LockError
72
+ $stderr.puts "Unable to lock config"
73
+ rescue Netconf::EditError => e
74
+ $stderr.puts "Unable to load configuration"
75
+ pp Junos::Ez::rpc_errors( e.rsp )
76
+ rescue Netconf::CommitError => e
77
+ $stderr.puts "Unable to commit configuration"
78
+ pp Junos::Ez::rpc_errors( e.rpc )
79
+ end
80
+
81
+ ndev.close
@@ -0,0 +1,76 @@
1
+ =begin
2
+
3
+ This exmaple illustrates the use of the Junos::Ez::Config::Utils library. The code will load the contents
4
+ of a template (ERB) file and use the current variables in the main scope (binding) to fill in the details.
5
+
6
+ Error checking/exception handling is also demonstrated. If there are any errors, the "pretty-print"
7
+ (pp) function will dump the contents of the result structure to stderr so you can see what it looks like.
8
+
9
+ =end
10
+
11
+ require 'net/netconf/jnpr'
12
+ require 'junos-ez/stdlib'
13
+
14
+ # login information for NETCONF session
15
+
16
+ login = { :target => 'vsrx', :username => 'jeremy', :password => 'jeremy1', }
17
+
18
+ ## create a NETCONF object to manage the device and open the connection ...
19
+
20
+ ndev = Netconf::SSH.new( login )
21
+ $stdout.print "Connecting to device #{login[:target]} ... "
22
+ ndev.open
23
+ $stdout.puts "OK!"
24
+
25
+ # attach the junos-ez objects to the ndev object ...
26
+
27
+ Junos::Ez::Provider( ndev )
28
+ Junos::Ez::Config::Utils( ndev, :cfg )
29
+
30
+ # begin a block to trap any raised expections ...
31
+ begin
32
+
33
+ # lock the candidate config
34
+ ndev.cfg.lock!
35
+
36
+ # load the template (ERB) file and use the current variables in scope (binding)
37
+ # when evaluating the results of the template. The template references a
38
+ # veriable called 'interfaces', so declare that now ...
39
+
40
+ interfaces = ['ge-0/0/1','ge-0/0/2','ge-0/0/3']
41
+
42
+ $stdout.puts "Loading changes ..."
43
+ ndev.cfg.load! :filename => 'load_template_main.conf', :binding => binding
44
+
45
+ # check to see if commit-check passes. if it doesn't
46
+ # it will return a structure of errors
47
+
48
+ unless (errs = ndev.cfg.commit?) == true
49
+ $stderr.puts "Commit check failed"
50
+ pp errs
51
+ ndev.close # will auto-rollback changes
52
+ exit 1
53
+ end
54
+
55
+ # save the cnfig diff to a file ...
56
+ File.open( "diffs.txt", "w") {|f| f.write ndev.cfg.diff? }
57
+
58
+ # commit the changes and unlock the config
59
+
60
+ $stdout.puts "Commiting changes ..."
61
+ ndev.cfg.commit!
62
+ ndev.cfg.unlock!
63
+
64
+ $stdout.puts "Done!"
65
+
66
+ rescue Netconf::LockError
67
+ $stderr.puts "Unable to lock config"
68
+ rescue Netconf::EditError => e
69
+ $stderr.puts "Unable to load configuration"
70
+ pp Junos::Ez::rpc_errors( e.rsp )
71
+ rescue Netconf::CommitError => e
72
+ $stderr.puts "Unable to commit configuration"
73
+ pp Junos::Ez::rpc_errors( e.rpc )
74
+ end
75
+
76
+ ndev.close
@@ -0,0 +1,60 @@
1
+ require 'pry'
2
+ require 'net/netconf/jnpr'
3
+ require 'junos-ez/stdlib'
4
+
5
+ # list of targets to make the change. Hardcoding these as array
6
+ # but you could load them from a file, etc.
7
+
8
+ targets = [ 'vsrx', 'ex-10', 'ex-20', 'ex-33' ]
9
+
10
+ # let's assume that all targets use the same login/password ...
11
+
12
+ login = { :username => 'jeremy', :password => 'jeremy1', }
13
+
14
+
15
+ # -------------------------------------------------------------------
16
+ # define a function to do the configuration actions
17
+ # -------------------------------------------------------------------
18
+
19
+ def load_stuff( login )
20
+
21
+ ## create a NETCONF object to manage the device and open the connection ...
22
+ ndev = Netconf::SSH.new( login )
23
+ $stdout.print "Connecting to device #{login[:target]} ... "
24
+ ndev.open
25
+ $stdout.puts "OK!"
26
+
27
+ Junos::Ez::Provider( ndev )
28
+ Junos::Ez::Config::Utils( ndev, :cfg )
29
+
30
+ # lock the candidate config
31
+ # ndev.cfg.lock!
32
+
33
+ # examples of loading ...
34
+ # ndev.cfg.load! :filename => 'load_sample.conf'
35
+ # ndev.cfg.load! :content => File.read( 'load_sample.conf' ), :format => :text
36
+ # ndev.cfg.load! :filename => 'load_sample.set'
37
+
38
+ binding.pry
39
+
40
+ # check to see if the config is OK to commit
41
+ # ndev.cfg.commit?
42
+
43
+ # perform the commit
44
+ # ndev.cfg.commit!
45
+
46
+ # unlock the config
47
+ # ndev.cfg.unlock!
48
+
49
+ ndev.close
50
+ end
51
+
52
+ ### -----------------------------------------------------------------
53
+ ### run through each of the target names and load configs ..
54
+ ### -----------------------------------------------------------------
55
+
56
+ targets.each do |target|
57
+ login[:target] = target
58
+ load_stuff( login )
59
+ end
60
+
@@ -0,0 +1,31 @@
1
+ require 'pry'
2
+ require 'pp'
3
+ require 'yaml'
4
+ require 'net/netconf/jnpr'
5
+ require 'junos-ez/stdlib'
6
+
7
+ # login information for NETCONF session
8
+
9
+ login = { :target => 'vsrx', :username => 'jeremy', :password => 'jeremy1', }
10
+
11
+ ## create a NETCONF object to manage the device and open the connection ...
12
+
13
+ ndev = Netconf::SSH.new( login )
14
+ $stdout.print "Connecting to device #{login[:target]} ... "
15
+ ndev.open
16
+ $stdout.puts "OK!"
17
+
18
+ ## Now bind providers to the device object.
19
+ ## the 'Junos::Ez::Provider' must be first before all others
20
+ ## this provider will setup the device 'facts'. The other providers
21
+ ## allow you to define the instance variables; so this example
22
+ ## is using 'l1_ports' and 'ip_ports', but you could name them
23
+ ## what you like, yo!
24
+
25
+ Junos::Ez::Provider( ndev )
26
+ Junos::Ez::Fs::Utils( ndev, :fs )
27
+
28
+
29
+ binding.pry
30
+
31
+ ndev.close
@@ -0,0 +1,90 @@
1
+ require 'pry'
2
+ require 'pp'
3
+ require 'net/scp'
4
+ require 'net/netconf/jnpr'
5
+ require 'junos-ez/stdlib'
6
+
7
+ unless ARGV[0]
8
+ puts "You must specify a target"
9
+ exit 1
10
+ end
11
+
12
+ # login information for NETCONF session
13
+
14
+ login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
15
+
16
+ ## create a NETCONF object to manage the device and open the connection ...
17
+
18
+ ndev = Netconf::SSH.new( login )
19
+ print "Connecting to device #{login[:target]} ... "
20
+ ndev.open
21
+ puts "OK!"
22
+
23
+ ## attach our private & utils that we need ...
24
+
25
+ Junos::Ez::Provider( ndev )
26
+ Junos::Ez::RE::Utils( ndev, :re ) # routine-engine utils
27
+ Junos::Ez::FS::Utils( ndev, :fs ) # filesystem utils
28
+
29
+ ## upload the software image to the target device
30
+ ## http://net-ssh.github.io/net-scp/
31
+
32
+ file_name = 'junos-vsrx-domestic.tgz'
33
+ file_on_server = '/home/jschulman/junos-images/vsrx/' + file_name
34
+ file_on_junos = '/var/tmp/' + file_name
35
+
36
+ ## simple function to use the Netconf::SSH SCP functionality to
37
+ ## upload a file to the device and watch the percetage tick by ...
38
+
39
+ def copy_file_to_junos( ndev, file_on_server, file_on_junos )
40
+ mgr_i = cur_i = 0
41
+ ndev.scp.upload!( file_on_server, file_on_junos ) do |ch, name, sent, total|
42
+ pct = (sent.to_f / total.to_f) * 100
43
+ mgr_i = pct.to_i
44
+ if mgr_i != cur_i
45
+ cur_i = mgr_i
46
+ puts cur_i.to_s + "%"
47
+ end
48
+ end
49
+ end
50
+
51
+ puts "Copying file to Junos ..."
52
+ copy_file_to_junos( ndev, file_on_server, file_on_junos )
53
+
54
+ ###
55
+ ### check the MD5 checksum values
56
+ ###
57
+
58
+ md5_on_s = Digest::MD5.file( file_on_server ).to_s
59
+ md5_on_j = ndev.fs.checksum( :md5, file_on_junos )
60
+
61
+ if md5_on_s != md5_on_j
62
+ puts "The MD5 checksum values do not match!"
63
+ ndev.close
64
+ exit 1
65
+ end
66
+
67
+ puts "MD5 checksum matches ... proceeding ..."
68
+ puts "Validating image ... please wait ..."
69
+
70
+ unless ndev.re.validate_software?( file_on_junos )
71
+ puts "The softare does not validate!"
72
+ ndev.close
73
+ exit 1
74
+ end
75
+
76
+ puts "Installing image ... place wait ..."
77
+ rc = ndev.re.install_software!( :package => file_on_junos, :no_validate => true )
78
+ if rc != true
79
+ puts rc
80
+ end
81
+
82
+ ### use pry if you want to 'look around'
83
+ ## -> binding.pry
84
+
85
+ ### if you wanted to reboot the system now, you coud
86
+ ### do the following ...
87
+
88
+ ## -> ndev.re.reboot!
89
+
90
+ ndev.close
@@ -0,0 +1,30 @@
1
+ require 'pry'
2
+ require 'pp'
3
+ require 'net/scp'
4
+ require 'net/netconf/jnpr'
5
+ require 'junos-ez/stdlib'
6
+
7
+ # login information for NETCONF session
8
+ unless ARGV[0]
9
+ puts "You must specify a target"
10
+ exit 1
11
+ end
12
+
13
+ login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
14
+
15
+ ## create a NETCONF object to manage the device and open the connection ...
16
+
17
+ ndev = Netconf::SSH.new( login )
18
+ print "Connecting to device #{login[:target]} ... "
19
+ ndev.open
20
+ puts "OK!"
21
+
22
+ ## attach our private & utils that we need ...
23
+
24
+ Junos::Ez::Provider( ndev )
25
+ Junos::Ez::RE::Utils( ndev, :re )
26
+ Junos::Ez::FS::Utils( ndev, :fs )
27
+
28
+ binding.pry
29
+
30
+ ndev.close
@@ -0,0 +1,47 @@
1
+ require 'pry'
2
+ require 'yaml'
3
+ require 'net/netconf/jnpr'
4
+ require 'junos-ez/stdlib'
5
+ require 'junos-ez/srx'
6
+
7
+ unless ARGV[0]
8
+ puts "You must specify a target"
9
+ exit 1
10
+ end
11
+
12
+ # login information for NETCONF session
13
+ login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
14
+
15
+ ## create a NETCONF object to manage the device and open the connection ...
16
+
17
+ ndev = Netconf::SSH.new( login )
18
+ $stdout.print "Connecting to device #{login[:target]} ... "
19
+ ndev.open
20
+ $stdout.puts "OK!"
21
+
22
+ ## Now bind providers to the device object.
23
+ ## the 'Junos::Ez::Provider' must be first before all others
24
+ ## this provider will setup the device 'facts'. The other providers
25
+ ## allow you to define the instance variables; so this example
26
+ ## is using 'l1_ports' and 'ip_ports', but you could name them
27
+ ## what you like, yo!
28
+
29
+ Junos::Ez::Provider( ndev )
30
+ Junos::Ez::L1ports::Provider( ndev, :l1_ports )
31
+ Junos::Ez::IPports::Provider( ndev, :ip_ports )
32
+
33
+ ## drop into interactive mode to play around ... let's look
34
+ ## at what the device has for facts ...
35
+
36
+ #-> ndev.facts.list
37
+ #-> ndev.facts.catalog
38
+ #-> ndev.fact :version
39
+
40
+ ## now look at specific providers like the physical (l1) ports ...
41
+
42
+ #-> ndev.l1_ports.list
43
+ #-> ndev.l1_ports.catalog
44
+
45
+ binding.pry
46
+
47
+ ndev.close
@@ -0,0 +1,33 @@
1
+ require 'pry'
2
+ require 'pp'
3
+ require 'yaml'
4
+ require 'net/netconf/jnpr'
5
+ require 'junos-ez/stdlib'
6
+
7
+ # login information for NETCONF session
8
+
9
+ login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
10
+
11
+ ## create a NETCONF object to manage the device and open the connection ...
12
+
13
+ ndev = Netconf::SSH.new( login )
14
+ $stdout.print "Connecting to device #{login[:target]} ... "
15
+ ndev.open
16
+ $stdout.puts "OK!"
17
+
18
+ ## Now bind providers to the device object.
19
+ ## the 'Junos::Ez::Provider' must be first before all others
20
+ ## this provider will setup the device 'facts'. The other providers
21
+ ## allow you to define the instance variables; so this example
22
+ ## is using 'l1_ports' and 'ip_ports', but you could name them
23
+ ## what you like, yo!
24
+
25
+ Junos::Ez::Provider( ndev )
26
+ Junos::Ez::StaticHosts::Provider( ndev, :hosts )
27
+
28
+ pp ndev.hosts.list
29
+ pp ndev.hosts.catalog
30
+
31
+ binding.pry
32
+
33
+ ndev.close
data/examples/vlans.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'net/netconf/jnpr'
2
+ require 'junos-ez/stdlib'
3
+
4
+ # login information for NETCONF session
5
+
6
+ login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
7
+
8
+ ## create a NETCONF object to manage the device and open the connection ...
9
+
10
+ ndev = Netconf::SSH.new( login )
11
+ $stdout.print "Connecting to device #{login[:target]} ... "
12
+ ndev.open
13
+ $stdout.puts "OK!"
14
+
15
+ Junos::Ez::Provider( ndev )
16
+ Junos::Ez::Config::Utils( ndev, :cu )
17
+ Junos::Ez::Vlans::Provider( ndev, :vlans )
18
+ Junos::Ez::L2ports::Provider( ndev, :l2_ports )
19
+
20
+ pp ndev.vlans.list
21
+ pp ndev.vlans.catalog
22
+
23
+ binding.pry
24
+
25
+ ndev.close
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift 'lib'
2
+ require 'rake'
3
+ require 'junos-ez/provider'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'junos-ez-stdlib'
7
+ s.version = Junos::Ez::VERSION
8
+ s.summary = "Junos EZ Framework - Standard Libraries"
9
+ s.description = "Automation Framework for Junos/NETCONF: Facts, Providers, and Utils"
10
+ s.homepage = 'https://github.com/jeremyschulman/ruby-junos-ez-stdlib'
11
+ s.authors = ["Jeremy Schulman"]
12
+ s.email = 'jschulman@juniper.net'
13
+ s.files = FileList[ '*', 'lib/**/*.rb', 'examples/**/*.rb', 'docs/**/*.md' ]
14
+ s.add_dependency('netconf')
15
+ end
@@ -0,0 +1,45 @@
1
+ Junos::Ez::Facts::Keeper.define( :chassis ) do |ndev, facts|
2
+
3
+ inv_info = ndev.rpc.get_chassis_inventory
4
+ chassis = inv_info.xpath('chassis')
5
+
6
+ facts[:hardwaremodel] = chassis.xpath('description').text
7
+ facts[:serialnumber] = chassis.xpath('serial-number').text
8
+
9
+ cfg = ndev.rpc.get_configuration{|xml|
10
+ xml.system {
11
+ xml.send(:'host-name')
12
+ xml.send(:'domain-name')
13
+ }
14
+ }
15
+
16
+ facts[:hostname] = cfg.xpath('//host-name').text
17
+ facts[:domain] = cfg.xpath('//domain-name').text
18
+ facts[:fqdn] = facts[:hostname]
19
+ facts[:fqdn] += ".#{facts[:domain]}" unless facts[:domain].empty?
20
+
21
+ end
22
+
23
+ Junos::Ez::Facts::Keeper.define( :master ) do |ndev, facts|
24
+ uses :routingengines
25
+ end
26
+
27
+ Junos::Ez::Facts::Keeper.define( :routingengines ) do |ndev, facts|
28
+
29
+ re_facts = ['mastership-state','status','model','up-time','last-reboot-reason']
30
+ re_info = ndev.rpc.get_route_engine_information
31
+ re_info.xpath('//route-engine').each do |re|
32
+ slot_id = re.xpath('slot').text || "0"
33
+ slot = ("RE" + slot_id).to_sym
34
+ facts[slot] = Hash[ re_facts.collect{ |ele| [ ele.tr('-','_').to_sym, re.xpath(ele).text ] } ]
35
+ if facts[slot][:mastership_state].empty?
36
+ facts[slot].delete :mastership_state
37
+ else
38
+ facts[:master] = slot_id if facts[slot][:mastership_state] == 'master'
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+
45
+
@@ -0,0 +1,14 @@
1
+
2
+ Junos::Ez::Facts::Keeper.define( :ifd_style ) do |ndev, facts|
3
+ persona = uses :personality
4
+
5
+ facts[:ifd_style] = case persona
6
+ when :SWITCH
7
+ :SWITCH
8
+ else
9
+ :CLASSIC
10
+ end
11
+
12
+ end
13
+
14
+
@@ -0,0 +1,22 @@
1
+ Junos::Ez::Facts::Keeper.define( :personality ) do |ndev, facts|
2
+
3
+ model = uses :hardwaremodel
4
+
5
+ facts[:personality] = case model
6
+ when /^(EX)|(QFX)/
7
+ :SWITCH
8
+ when /^MX/
9
+ :MX
10
+ when /^vMX/
11
+ facts[:virtual] = true
12
+ :MX
13
+ when /SRX(\d){3}/
14
+ :SRX_BRANCH
15
+ when /junosv-firefly/i
16
+ facts[:virtual] = true
17
+ :SRX_BRANCH
18
+ when /SRX(\d){4}/
19
+ :SRX_HIGHEND
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ Junos::Ez::Facts::Keeper.define( :switch_style ) do |ndev, facts|
2
+ f_persona = uses :personality
3
+
4
+ facts[:switch_style] = case f_persona
5
+ when :SWITCH, :SRX_BRANCH
6
+ case facts[:hardwaremodel]
7
+ when /junosv-firefly/i
8
+ :NONE
9
+ when /^(ex9)|(ex43)/i
10
+ :VLAN_L2NG
11
+ else
12
+ :VLAN
13
+ end
14
+ when :MX, :SRX_HIGHEND
15
+ :BRIDGE_DOMAIN
16
+ else
17
+ :NONE
18
+ end
19
+
20
+ end
21
+
22
+