shopify-junos-ez-stdlib 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +91 -0
  3. data/LICENSE +26 -0
  4. data/README.md +199 -0
  5. data/docs/Facts.md +192 -0
  6. data/docs/Providers/Group.md +61 -0
  7. data/docs/Providers/IPports.md +61 -0
  8. data/docs/Providers/L1ports.md +29 -0
  9. data/docs/Providers/L2ports.md +43 -0
  10. data/docs/Providers/LAGports.md +57 -0
  11. data/docs/Providers/StaticHosts.md +26 -0
  12. data/docs/Providers/StaticRoutes.md +37 -0
  13. data/docs/Providers/UserAuths.md +32 -0
  14. data/docs/Providers/Users.md +122 -0
  15. data/docs/Providers/Vlans.md +43 -0
  16. data/docs/Providers_Resources.md +353 -0
  17. data/docs/README_FIRST.md +27 -0
  18. data/docs/Utils/Config.md +160 -0
  19. data/docs/Utils/Filesystem.md +360 -0
  20. data/docs/Utils/Routing-Engine.md +379 -0
  21. data/docs/Utils/SCP.md +24 -0
  22. data/examples/config/config_file.rb +72 -0
  23. data/examples/config/config_template_object.rb +81 -0
  24. data/examples/config/config_template_simple.rb +76 -0
  25. data/examples/config/multi_config.rb +60 -0
  26. data/examples/fs_utils.rb +31 -0
  27. data/examples/lag_port.rb +27 -0
  28. data/examples/re_upgrade.rb +99 -0
  29. data/examples/re_utils.rb +33 -0
  30. data/examples/simple.rb +46 -0
  31. data/examples/st_hosts.rb +33 -0
  32. data/examples/user.rb +32 -0
  33. data/examples/vlans.rb +31 -0
  34. data/junos-ez-stdlib.gemspec +15 -0
  35. data/lib/junos-ez/exceptions.rb +3 -0
  36. data/lib/junos-ez/facts.rb +83 -0
  37. data/lib/junos-ez/facts/chassis.rb +51 -0
  38. data/lib/junos-ez/facts/ifd_style.rb +17 -0
  39. data/lib/junos-ez/facts/personality.rb +25 -0
  40. data/lib/junos-ez/facts/switch_style.rb +31 -0
  41. data/lib/junos-ez/facts/version.rb +58 -0
  42. data/lib/junos-ez/group.rb +206 -0
  43. data/lib/junos-ez/ip_ports.rb +30 -0
  44. data/lib/junos-ez/ip_ports/classic.rb +188 -0
  45. data/lib/junos-ez/l1_ports.rb +121 -0
  46. data/lib/junos-ez/l1_ports/classic.rb +87 -0
  47. data/lib/junos-ez/l1_ports/switch.rb +134 -0
  48. data/lib/junos-ez/l2_ports.rb +66 -0
  49. data/lib/junos-ez/l2_ports/bridge_domain.rb +499 -0
  50. data/lib/junos-ez/l2_ports/vlan.rb +433 -0
  51. data/lib/junos-ez/l2_ports/vlan_l2ng.rb +502 -0
  52. data/lib/junos-ez/lag_ports.rb +268 -0
  53. data/lib/junos-ez/provider.rb +619 -0
  54. data/lib/junos-ez/stdlib.rb +18 -0
  55. data/lib/junos-ez/system.rb +48 -0
  56. data/lib/junos-ez/system/st_hosts.rb +92 -0
  57. data/lib/junos-ez/system/st_routes.rb +159 -0
  58. data/lib/junos-ez/system/syscfg.rb +103 -0
  59. data/lib/junos-ez/system/userauths.rb +84 -0
  60. data/lib/junos-ez/system/users.rb +217 -0
  61. data/lib/junos-ez/utils/config.rb +236 -0
  62. data/lib/junos-ez/utils/fs.rb +385 -0
  63. data/lib/junos-ez/utils/re.rb +558 -0
  64. data/lib/junos-ez/version.rb +6 -0
  65. data/lib/junos-ez/vlans.rb +38 -0
  66. data/lib/junos-ez/vlans/bridge_domain.rb +89 -0
  67. data/lib/junos-ez/vlans/vlan.rb +119 -0
  68. data/lib/junos-ez/vlans/vlan_l2ng.rb +126 -0
  69. data/shipit.yml +4 -0
  70. data/tmp +7 -0
  71. metadata +129 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35f03b58ce9cfea7aee6a2bf7cb00f69721692d8
4
+ data.tar.gz: a38199a944c32a844c185d01508d9e704de28744
5
+ SHA512:
6
+ metadata.gz: 032c27f113348d914b8441470bf784efdb34acbbea615d5d7d5612fd7620b72c7273dc88414aac38a39d1356f7ac45412bbbf3ab7c8511aa75b0b4f08936aff9
7
+ data.tar.gz: 3a947882c3ca848b08daea12cbe66ab104536ebbec5ac0473db3f26d737f63025e12e3d72e0080927c3f5fe63694b2a6ca5a54734f8af598fa62d805f53dec66
data/CHANGELOG.md ADDED
@@ -0,0 +1,91 @@
1
+ # 2013-April
2
+
3
+ 0.0.10: 2013-04-26
4
+
5
+ Initial release of code into RubyGems. Code tested on EX and SRX-branch. Consider this code
6
+ as "early-adopter". Comments/feedback is welcome and appreciated.
7
+
8
+ 0.0.11: 2013-04-26
9
+
10
+ Updated Junos::Ez::RE::Utils
11
+ #memory changed :procs from Hash to Array
12
+ #users changed return from Hash to Array
13
+
14
+ 0.0.12: 2013-04-26
15
+
16
+ Updated Junos::Ez::FS:Utils#ls to include :symlink information
17
+ Adding Junos::Ez::Users::Provider for login management
18
+ Adding Junos::Ez::UserAuths::Provider for SSH-key management
19
+
20
+ 0.0.14: 2013-04-28
21
+
22
+ Completed initial documentation. Still more work to be done with these files
23
+ but the "enough to get started" information is now available
24
+
25
+ # 2013-May
26
+
27
+ 0.0.15: 2013-05-02
28
+
29
+ L2ports - added support for framework to read [edit vlans] stanza to recognize interfaces configured
30
+ there vs. under [edit interfaces]
31
+
32
+ IPports - added :acl_in and :acl_out for stateless ACL filtering. added .status method to return
33
+ runtime status information about the port
34
+
35
+ RE::Utils - misc updates, and documentation
36
+
37
+ 0.0.16: 2013-05-03
38
+
39
+ RE::Utils - added support for license-key management. Renamed "software" methods from "xxx_software"
40
+ to "software_xxx" to be consistent with other naming usage. Updated docs.
41
+
42
+ 0.0.17: 2013-05-05
43
+
44
+ FS::Utils - updated docs. fixed methods so that all "error" scenarios raise IOError excaptions.
45
+
46
+ 0.1.0: 2013-05-06
47
+
48
+ All docs and code _finished_ for the inital release of code. Always more to do, but at this
49
+ point, declaring the framework "good for early adopter testing". Looking forward to bug-reports,
50
+ please open issues against this repo. Thank you!
51
+
52
+ 0.1.1: 2013-05-29
53
+
54
+ Fixed a small bug in fact gathering for hardwaremodel
55
+
56
+ # 2013-July
57
+
58
+ 0.1.2: 2013-07-04
59
+
60
+ Fixed issue#3. Previously this gem would not work with non-VC capable EX switches. Updated
61
+ the `facts/version.rb` file to handle these devices. Also added a new fact `:vc_capable` that
62
+ is set to `true` if the EX can support virtual-chassis, and `false` if it cannot.
63
+
64
+ # 2013-Aug
65
+
66
+ 0.2.0:
67
+
68
+ Fixed issue #6. Added support for EX4300 platform. Added new provider for Link Aggregation Group
69
+ resources (LAGports)
70
+
71
+ # 2016-March
72
+
73
+ 1.0.0:
74
+
75
+ Fixed issues
76
+ Issue #17 Add support for OCX device.
77
+ Issue #20 "under development" error is thrown while importing the interface_create recipe from the Chef-Server.
78
+ Issue #22 "netdev_vlan" resource action delete is not working fine while invoking from the JUNOS Chef-Client.
79
+ Issue #23 RPC command error: commit-configuration is getting thrown on Invoking the "netdev_lag" resource from
80
+ JUNOS Chef Client.
81
+ Issue #27 Duplicate declaration of lag configuration in a recipe is giving NoMethodError: undefined method
82
+ `properties' for nil:NilClass.
83
+ Issue #30 Error in rerunning netdev_lag interface.
84
+ Issue #33 undefined method `properties' for nil:NilClass error is thrown if the backup RE is unreachable.
85
+ Issue #35 Error in running chef client from Backup RE.
86
+ Issue #39 Getting 'Junos::Ez::NoProviderError' error on qfx device.
87
+ Issue #42 Raise exception to handle warnings in <error-severity>.
88
+
89
+ Enhancement
90
+ * Add support for configuring l2_interface on MX device.
91
+ * Add support for provider 'group' for configuring JUNOS groups.
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ LICENSE (BSD-2)
2
+ ===============
3
+ Copyright (c) 2013, Jeremy Schulman, Juniper Networks
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in
14
+ the documentation and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,199 @@
1
+ # OVERVIEW
2
+
3
+ Ruby framework to support Junos OS based device management automation.
4
+
5
+ This is the "standard library" or "core" set of functionality that should work on most/all Junos OS based devices.
6
+
7
+ This framework is build on top of the NETCONF gem which uses XML as the fundamental data-exchange. So no
8
+ "automating the CLI" or using SNMP. The purpose of this framework is to **enable automation development
9
+ without requiring specific Junos XML knowledge**.
10
+
11
+ Further documentation can be found in the *docs* subdirectory.
12
+
13
+ # FRAMEWORK
14
+
15
+ The framework is comprised of these basic eloements:
16
+
17
+ - Facts:
18
+
19
+ A Hash of name/value pairs of information auto-collected. Fact values can be Hash structures as well
20
+ so you can have deeply nested fact data. You can also define your own facts in addition to the "stdlib" facts.
21
+ The facts are used by the framework to create a platform indepent layer of abstraction. This means
22
+ that managing a VLAN, for example, is the same regardless of the underlying hardware platofrm (EX, QFX,
23
+ MX, SRX, ...)
24
+
25
+ - Resources:
26
+
27
+ Resources allow you to easily configure and perform operational functions on specific items within Junos,
28
+ for example VLANs, or switch ports. A resource has *properties* that you manipuate as Hash. You can
29
+ interact with Junos using resource methods like `read!`, `write!`, `delete!`, `activate!`, `deactivate!`, etc.
30
+ For a complete listing of resource methods, refer to the *docs* directory
31
+
32
+ - Providers:
33
+
34
+ Providers allow you to manage a collection of resource, and most commonly, select a resource.
35
+ The purpose of a provider/resource is to automate the life-cycle of common changes, like adding
36
+ VLANs, or ports to a VLAN. A provider also allows you to obtain a `list` of resources
37
+ (Array of *names*) or a `catalog` (Hash of resource properties). Providers may include resource
38
+ specific functionality, like using complex YAML/Hash data for easy import/export and provisioning
39
+ with Junos. If you need the ability to simply apply config-snippets that you do not need to model
40
+ as resources (as you might for initial device commissioning), the Utilities library is where you
41
+ want to start.
42
+
43
+ - Utilities:
44
+
45
+ Utilities are simply collections of functions. The **configuration** utilities, for example, will
46
+ allow you to easily push config snippets in "curly-brace", "set", or XML formats. Very useful
47
+ for unmanaged provider/resources (like initial configuration of the device). The
48
+ **routing-engine** utilities, for example, will allow you to easily upgrade software, check
49
+ memory usage, and do `ping` operations.
50
+
51
+ # EXAMPLE USAGE
52
+
53
+ ```ruby
54
+ require 'pp'
55
+ require 'net/netconf/jnpr'
56
+ require 'junos-ez/stdlib'
57
+
58
+ unless ARGV[0]
59
+ puts "You must specify a target"
60
+ exit 1
61
+ end
62
+
63
+ # login information for NETCONF session
64
+ login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
65
+
66
+ ## create a NETCONF object to manage the device and open the connection ...
67
+
68
+ ndev = Netconf::SSH.new( login )
69
+ print "Connecting to device #{login[:target]} ... "
70
+ ndev.open
71
+ puts "OK!"
72
+
73
+ ## Now bind providers to the device object. The 'Junos::Ez::Provider' must be first.
74
+ ## This will retrieve the device 'facts'. The other providers allow you to define the
75
+ ## provider variables; so this example is using 'l1_ports' and 'ip_ports', but you could name
76
+ ## them what you like, yo!
77
+
78
+ Junos::Ez::Provider( ndev )
79
+ Junos::Ez::L1ports::Provider( ndev, :l1_ports )
80
+ Junos::Ez::IPports::Provider( ndev, :ip_ports )
81
+ Junos::Ez::Config::Utils( ndev, :cu )
82
+
83
+ # -----------------------------------------------------------
84
+ # Facts ...
85
+ # -----------------------------------------------------------
86
+
87
+ # show the device softare version fact
88
+ pp ndev.fact :version
89
+
90
+ # show the device serial-number face
91
+ pp ndev.fact :serialnumber
92
+
93
+ # get a list of all available facts (Array)
94
+ pp ndev.facts.list
95
+
96
+ # get a hash of all facts and their associated values
97
+ pp ndev.facts.catalog
98
+
99
+ # -----------------------------------------------------------
100
+ # Layer 1 (physical ports) Resources ...
101
+ # -----------------------------------------------------------
102
+
103
+ pp ndev.l1_ports.list
104
+ pp ndev.l1_ports.catalog
105
+
106
+ # select port 'ge-0/0/0' and display the contents
107
+ # of the properties (like port, speed, description)
108
+
109
+ ge_0 = ndev.l1_ports['ge-0/0/0']
110
+ pp ge_0.to_h
111
+
112
+ # change port to disable, this will write the change
113
+ # but not commit it.
114
+
115
+ ge_0[:admin] = :down
116
+ ge_0.write!
117
+
118
+ # show the diff of the change to the screen
119
+
120
+ puts ndev.cu.diff?
121
+
122
+ # now rollback the change, since we don't want to save it.
123
+
124
+ ndev.cu.rollback!
125
+
126
+ ndev.close
127
+ ```
128
+
129
+ # PROVIDERS
130
+
131
+ Providers manage access to individual resources and their associated properties. Providers/resources exists
132
+ for managing life-cycle common changes that you generally need as part of a larger workflow process. For more
133
+ documentation on Providers/Resources, see the *docs* directory.
134
+
135
+ - L1ports: Physical port management
136
+ - L2ports: Ethernet port (VLAN) management
137
+ - Vlans: VLAN resource management
138
+ - IPports: IP v4 port management
139
+ - StaticHosts: Static Hosts [system static-host-mapping ...]
140
+ - StaticRoutes: Static Routes [routing-options static ...]
141
+ - Group: JUNOS groups management
142
+
143
+ # UTILITIES
144
+
145
+ - Config:
146
+
147
+ These functions allow you to load config snippets, do commit checks, look at config diffs, etc.
148
+ Generally speaking, you would want to use the Providers/Resources framework to manage specific
149
+ items in the config. This utility library is very useful when doing the initial commissioning
150
+ process, where you do not (cannot) model every aspect of Junos. These utilities can also be
151
+ used in conjunction with Providers/Resources, specifically around locking/unlocking and committing
152
+ the configuration.
153
+
154
+ - Filesystem:
155
+
156
+ These functions provide you "unix-like" commands that return data in Hash forms rather than
157
+ as string output you'd normally have to screen-scraps. These methods include `ls`, `df`, `pwd`,
158
+ `cwd`, `cleanup`, and `cleanup!`
159
+
160
+ - Routing-Engine:
161
+
162
+ These functions provide a general collection to information and functioanlity for handling
163
+ routing-engine (RE) processes. These functions `reboot!`, `shutdown!`, `install_software!`,
164
+ `ping`. Information gathering such as memory-usage, current users, and RE status information
165
+ is also made available through this collection.
166
+
167
+ # DEPENDENCIES
168
+
169
+ * gem netconf
170
+ * Junos OS based products
171
+
172
+ # INSTALLATION
173
+
174
+ * gem install junos-ez-stdlib
175
+
176
+ # CONTRIBUTORS
177
+ Juniper Networks is actively contributing to and maintaining this repo. Please contact jnpr-community-netdev@juniper.net
178
+ for any queries.
179
+
180
+ Contributors:
181
+ [John Deatherage](https://github.com/routelastresort), [Nitin Kumar](https://github.com/vnitinv),
182
+ [Priyal Jain](https://github.com/jainpriyal), [Ganesh Nalawade](https://github.com/ganeshnalawade)
183
+
184
+ Former Contributors:
185
+ [Jeremy Schulman](https://github.com/jeremyschulman)
186
+
187
+ # LICENSES
188
+
189
+ BSD-2, See LICENSE file
190
+
191
+ # SUPPORT
192
+
193
+ Support for this software is made available exclusively through Github repo issue tracking. You are also welcome to contact the CONTRIBUTORS directly via their provided contact information.
194
+
195
+ If you find a bug, please open an issue against this repo.
196
+
197
+ If you have suggestions or ideas, please write them up and add them to the "SUGGESTION-BOX" folder of this repo (via pull request). This way we can share the ideas with the community and crowdsource for feature delivery.
198
+
199
+ Thank you!
data/docs/Facts.md ADDED
@@ -0,0 +1,192 @@
1
+ # FACT KEEPING
2
+
3
+ This framework is *fact based*, meaning that the provider libraries will have access to information about each
4
+ target. Facts enable the framework to abstract the physical differences of the underlying hardware.
5
+
6
+ For example,the `Junos::Ez::Vlans::Provider` allows you to manage vlans without having to worry about the differences between the EX product family and the MX product family. To you, the programmer, you simply obtain a resource and manage the associated properties.
7
+
8
+ There are collection of standard facts that are always read by the framework. You can find a list of these and the assocaited code in the *libs/../facts* subdirectory. These facts are also avaialble to your program as well. So you can make programmatic decisions based on the facts of the device.
9
+
10
+ You can also define your own facts, and then go on to building your own provider libraries (but we're getting ahead of ourselfs here ...)
11
+
12
+ # USAGE
13
+
14
+ Usage rule: you **MUST** call `Junos::Ez::Provider` on your netconf object:
15
+
16
+ - **AFTER** the object has connected to the target, since it will read facts
17
+ - **BEFORE** you add any other providers, since these may use the facts
18
+
19
+ Here is a basic example:
20
+
21
+ ```ruby
22
+ require 'pp'
23
+ require 'net/netconf/jnpr'
24
+ require 'junos-ez/stdlib'
25
+
26
+ login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
27
+
28
+ # create a NETCONF object to manage the device
29
+
30
+ ndev = Netconf::SSH.new( login )
31
+
32
+ # open the NETCONF connetion, if this fails, the object will throw an exception
33
+ ndev.open
34
+
35
+ # now that the netconf session has been established, initialize the object for the
36
+ # Junos::Ez framework. This will add an instance variable called `@facts` and
37
+ # retrieve all known facts from the target
38
+
39
+ Junos::Ez::Provider( ndev )
40
+
41
+ # do a quick dump of all facts
42
+
43
+ pp ndev.facts.catalog
44
+ ->
45
+ {:hardwaremodel=>"SRX210H",
46
+ :serialnumber=>"AD2909AA0096",
47
+ :hostname=>"srx210",
48
+ :domain=>"workflowsherpas.com",
49
+ :fqdn=>"srx210.workflowsherpas.com",
50
+ :RE=>
51
+ {:status=>"OK",
52
+ :model=>"RE-SRX210H",
53
+ :up_time=>"26 days, 15 hours, 46 minutes, 4 seconds",
54
+ :last_reboot_reason=>"0x200:normal shutdown"},
55
+ :personality=>:SRX_BRANCH,
56
+ :ifd_style=>:CLASSIC,
57
+ :switch_style=>:VLAN,
58
+ :version=>"12.1X44-D10.4"}
59
+ ```
60
+
61
+ # STANDARD FACTS
62
+
63
+ The following facts are provided by the `Junos::Ez::Provider` framework:
64
+ ```
65
+ :hardwaremodel => String
66
+ ```
67
+ Identifies the target hardware model as obtained from the chassis inventory information
68
+ ```
69
+ :serialnumber => String
70
+ ```
71
+ Identifies the target chassis serial-number as obtained from the chassis inventory information
72
+ ```
73
+ :hostname => String
74
+ ```
75
+ Identifies the target host-name as obtained from the system configuration
76
+ ```
77
+ :domain => String
78
+ ```
79
+ Identifies the target domain-name as obtained from the system configuration
80
+ ```
81
+ :fqdn => String
82
+ ```
83
+ Identifies the target Fully-Qualified-Domain-Name (FQDN), which is the composite of the `:hostname` and `:domain` facts.
84
+ ```
85
+ :version => String
86
+ ```
87
+ Identifies the Junos version string, e.g. "12.3R2.5" running on the master routing-engine.
88
+ ```
89
+ :version_<RE | FPC + ID> => String
90
+ ```
91
+ When the target is a multi-routing-engine or virtual-chassis system, the version loaded on each control processor is provided as a separate version fact. All version facts begin with `version_`. So and MX router with two routing-engines would have `:version_RE0` and `:version_RE1` in additon to the `:version` fact. An EX vritual chassis with two members would have `:version_FPC0` and `:version_FPC1` facts in additon to the `:version` fact.
92
+ ```
93
+ :master => String
94
+ ```
95
+ If the target is a multi-routing-engine capabile, this fact will identify the master RE, for example "0".
96
+ ```
97
+ :RE<SLOD_ID> => Hash
98
+ ```
99
+ For each routing-engine, a Hash structure of information is obtained.
100
+ The following illustrates an EX virtual-chassis:
101
+ ```ruby
102
+ ndev.facts.catalog
103
+ ->
104
+ {:hardwaremodel=>"Virtual Chassis",
105
+ :serialnumber=>"BP0208207236",
106
+ :hostname=>"jex",
107
+ :domain=>"workflowsherpas.com",
108
+ :fqdn=>"jex.workflowsherpas.com",
109
+ :RE0=>
110
+ {:mastership_state=>"master",
111
+ :status=>"OK",
112
+ :model=>"EX4200-48T, 8 POE",
113
+ :up_time=>"14 minutes, 12 seconds",
114
+ :last_reboot_reason=>"0x2:watchdog "},
115
+ :master=>"0",
116
+ :RE1=>
117
+ {:mastership_state=>"backup",
118
+ :status=>"OK",
119
+ :model=>"EX4200-48T, 8 POE",
120
+ :up_time=>"14 minutes, 12 seconds",
121
+ :last_reboot_reason=>"0x2:watchdog "},
122
+ :personality=>:SWITCH,
123
+ :ifd_style=>:SWITCH,
124
+ :switch_style=>:VLAN,
125
+ :version_FPC0=>"12.2R3.5",
126
+ :version_FPC1=>"12.2R3.5",
127
+ :version_FPC2=>"12.2R3.5",
128
+ :version=>"12.2R3.5"}
129
+ ```
130
+ Note the presense of`:RE0` and `:RE1` facts, each contains the Hash information for each routing-engine. If a target does not support multiple routing-engnies, then there will be a `:RE` fact (no slot-id).
131
+ ```
132
+ :switch_style => [:VLAN, :BRIDGE_DOMAIN, :VLAN_ELS, :NONE]
133
+ ```
134
+ Identifies the target style for handing vlan configurations. If the target does not support vlan briding (for example the vSRX), then the style will be set to `:NONE`.
135
+ ```
136
+ :personality => [:SWITCH, :MX, :SRX_BRANCH, :SRX_HIGHEND]
137
+ ```
138
+ Identifies the personality of the target.
139
+ ```
140
+ :ifd_style => [:CLASSIC, :SWITCH]
141
+ ```
142
+ Identifies the target style for handling interface configuration differences.
143
+ ```
144
+ :virtual => true
145
+ ```
146
+ Set if the target is a virtual-machine, like the vSRX
147
+
148
+ # METHODS
149
+
150
+ - `read!` - reloads the facts from the target
151
+ - `facts[]` - retrieve a specific fact from the keeper
152
+ - `fact` - alternative method to retrieve a specific fact from the keeper
153
+ - `list`, `list!` - returns an Array of fact names (symbols)
154
+ - `catalog`, `catalog!` - returns a Hash of fact names and values
155
+
156
+ The bang (!) indicates that the method will re-read the value from the target, which the non-bang method uses the values cached in memory. If the cache does not exist, the framework will read the values. The use of the bang-methods are handy if/when you have facts whose values change at runtime, like the `ndev.fact(:RE)[:up_time]`
157
+
158
+ # CREATING CUSTOM FACTS
159
+
160
+ You can define your own facts using `Junos::Ez::Facts::Keeper.define`. You can review the stdlib facts by looking the *libs/../facts* subdirectory of this repo. Here is the code for the `:chassis` fact. What is interesting about this example, is this code will actually create multiple facts about the chassis. So there is not a required one-to-one relationship between createing a custom fact and the actual number of facts it creates, yo!
161
+
162
+ When you define your fact, you must give it a unique "fact name*, and a block. The block takee two arguments: the first is the netconf object, which will provide you access to the underlying Junos XML netconf, an a Hash that allows you to write your facts into the Keeper:
163
+
164
+ ```ruby
165
+ Junos::Ez::Facts::Keeper.define( :chassis ) do |ndev, facts|
166
+
167
+ inv_info = ndev.rpc.get_chassis_inventory
168
+ chassis = inv_info.xpath('chassis')
169
+
170
+ facts[:hardwaremodel] = chassis.xpath('description').text
171
+ facts[:serialnumber] = chassis.xpath('serial-number').text
172
+
173
+ cfg = ndev.rpc.get_configuration{|xml|
174
+ xml.system {
175
+ xml.send(:'host-name')
176
+ xml.send(:'domain-name')
177
+ }
178
+ }
179
+
180
+ facts[:hostname] = cfg.xpath('//host-name').text
181
+ facts[:domain] = cfg.xpath('//domain-name').text
182
+ facts[:fqdn] = facts[:hostname]
183
+ facts[:fqdn] += ".#{facts[:domain]}" unless facts[:domain].empty?
184
+
185
+ end
186
+ ```
187
+
188
+
189
+
190
+
191
+
192
+