junos-ez-stdlib 0.0.17 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/docs/Facts.md +92 -6
- data/docs/Providers_Resources.md +28 -1
- data/docs/Utils/SCP.md +24 -0
- data/examples/re_upgrade.rb +1 -1
- data/lib/junos-ez/exceptions.rb +1 -1
- data/lib/junos-ez/facts/personality.rb +4 -1
- data/lib/junos-ez/provider.rb +15 -5
- data/lib/junos-ez/vlans.rb +1 -1
- metadata +3 -2
data/CHANGELOG.md
CHANGED
@@ -21,6 +21,8 @@
|
|
21
21
|
|
22
22
|
Completed initial documentation. Still more work to be done with these files
|
23
23
|
but the "enough to get started" information is now available
|
24
|
+
|
25
|
+
# 2013-May
|
24
26
|
|
25
27
|
0.0.15: 2013-05-02
|
26
28
|
|
@@ -37,4 +39,8 @@
|
|
37
39
|
RE::Utils - added support for license-key management. Renamed "software" methods from "xxx_software"
|
38
40
|
to "software_xxx" to be consistent with other naming usage. Updated docs.
|
39
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
|
+
|
40
46
|
|
data/docs/Facts.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# FACT KEEPING
|
2
2
|
|
3
3
|
This framework is *fact based*, meaning that the provider libraries will have access to information about each
|
4
4
|
target. Facts enable the framework to abstract the physical differences of the underlying hardware.
|
@@ -9,12 +9,11 @@ There are collection of standard facts that are always read by the framework. Y
|
|
9
9
|
|
10
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
11
|
|
12
|
-
#
|
12
|
+
# USAGE
|
13
13
|
|
14
14
|
Usage rule: you **MUST** call `Junos::Ez::Provider` on your netconf object:
|
15
15
|
|
16
16
|
- **AFTER** the object has connected to the target, since it will read facts
|
17
|
-
|
18
17
|
- **BEFORE** you add any other providers, since these may use the facts
|
19
18
|
|
20
19
|
Here is a basic example:
|
@@ -59,17 +58,104 @@ pp ndev.facts.catalog
|
|
59
58
|
:version=>"12.1X44-D10.4"}
|
60
59
|
```
|
61
60
|
|
62
|
-
#
|
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
|
63
149
|
|
64
150
|
- `read!` - reloads the facts from the target
|
65
|
-
- `[]` - retrieve a specific fact from the keeper
|
151
|
+
- `facts[]` - retrieve a specific fact from the keeper
|
66
152
|
- `fact` - alternative method to retrieve a specific fact from the keeper
|
67
153
|
- `list`, `list!` - returns an Array of fact names (symbols)
|
68
154
|
- `catalog`, `catalog!` - returns a Hash of fact names and values
|
69
155
|
|
70
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]`
|
71
157
|
|
72
|
-
#
|
158
|
+
# CREATING CUSTOM FACTS
|
73
159
|
|
74
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!
|
75
161
|
|
data/docs/Providers_Resources.md
CHANGED
@@ -314,7 +314,7 @@ port.write!
|
|
314
314
|
|
315
315
|
### Interating Resources
|
316
316
|
|
317
|
-
You can use the `each` method to
|
317
|
+
You can use the `each` method to iterate through each managed resource, as provided by the `list` provider instance variable. For example:
|
318
318
|
|
319
319
|
```ruby
|
320
320
|
ndev.l1_ports.each do |port|
|
@@ -324,3 +324,30 @@ ndev.l1_ports.each do |port|
|
|
324
324
|
end
|
325
325
|
end
|
326
326
|
```
|
327
|
+
|
328
|
+
You can use the `with` method to iterate through a given list of managed resources. For example:
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
# dump the status for just these two IP ports ...
|
332
|
+
|
333
|
+
ip_list = ["ge-0/0/1.719","ge-0/0/1.335"]
|
334
|
+
|
335
|
+
ndev.ip_ports.with(ip_list) do |ip|
|
336
|
+
pp ip.name
|
337
|
+
pp ip.status
|
338
|
+
end
|
339
|
+
|
340
|
+
->
|
341
|
+
"ge-0/0/1.719"
|
342
|
+
{:l1_oper_status=>:up,
|
343
|
+
:oper_status=>:down,
|
344
|
+
:snmp_index=>616,
|
345
|
+
:packets_rx=>0,
|
346
|
+
:packets_tx=>0}
|
347
|
+
"ge-0/0/1.335"
|
348
|
+
{:l1_oper_status=>:up,
|
349
|
+
:oper_status=>:up,
|
350
|
+
:snmp_index=>613,
|
351
|
+
:packets_rx=>0,
|
352
|
+
:packets_tx=>0}
|
353
|
+
```
|
data/docs/Utils/SCP.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# `Net::SCP`
|
2
|
+
|
3
|
+
The NETCONF object already provides a mechanism to use secure-copy (SCP), so technically this is _not_ part of the `Junos::EZ` framework. That being said, this is some quick documentation and URLs so you can copy files to and from Junos devices.
|
4
|
+
|
5
|
+
# DOCS
|
6
|
+
|
7
|
+
For documentation on `Net::SCP`, please refer to this website: http://net-ssh.github.io/scp/v1/api/index.html
|
8
|
+
|
9
|
+
# USAGE
|
10
|
+
|
11
|
+
The NETCONF object includes an instance variable `scp` that is class `Net::SCP`.
|
12
|
+
|
13
|
+
To copy a file from the server to the Junos target, you use the `upload` or `upload!` method. The bang(!) version is blocking, meaning the code execution will resume only after the file has been completely transfered.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
file_on_server = "/cygwin/junos/junos-ex4200-image.tgz"
|
17
|
+
location_on_junos = "/var/tmp"
|
18
|
+
|
19
|
+
ndev.scp.upload!( from_on_server, location_on_junos )
|
20
|
+
```
|
21
|
+
|
22
|
+
To copy a file from the Junos target to the server, you use the `download` or `download!` method.
|
23
|
+
|
24
|
+
Both upload and download methods can take a Ruby block which is used to provide progress updates on the transfer. There is a complete "software upgrade" example that illustrates this technique in the _examples_ directory.
|
data/examples/re_upgrade.rb
CHANGED
@@ -23,7 +23,7 @@ puts "OK!"
|
|
23
23
|
## attach our private & utils that we need ...
|
24
24
|
|
25
25
|
Junos::Ez::Provider( ndev )
|
26
|
-
Junos::Ez::RE::Utils( ndev, :re ) #
|
26
|
+
Junos::Ez::RE::Utils( ndev, :re ) # routing-engine utils
|
27
27
|
Junos::Ez::FS::Utils( ndev, :fs ) # filesystem utils
|
28
28
|
|
29
29
|
## upload the software image to the target device
|
data/lib/junos-ez/exceptions.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
Junos::Ez::Facts::Keeper.define( :personality ) do |ndev, facts|
|
2
2
|
|
3
3
|
model = uses :hardwaremodel
|
4
|
+
uses :routingengines
|
5
|
+
|
6
|
+
examine = ( model != "Virtual Chassis" ) ? model : facts[:RE0][:model]
|
4
7
|
|
5
|
-
facts[:personality] = case
|
8
|
+
facts[:personality] = case examine
|
6
9
|
when /^(EX)|(QFX)/
|
7
10
|
:SWITCH
|
8
11
|
when /^MX/
|
data/lib/junos-ez/provider.rb
CHANGED
@@ -14,7 +14,7 @@ require 'junos-ez/exceptions.rb'
|
|
14
14
|
|
15
15
|
module Junos::Ez
|
16
16
|
|
17
|
-
VERSION = "0.0
|
17
|
+
VERSION = "0.1.0"
|
18
18
|
|
19
19
|
### ---------------------------------------------------------------
|
20
20
|
### rpc_errors - decodes the XML into an array of error/Hash
|
@@ -361,16 +361,26 @@ class Junos::Ez::Provider::Parent
|
|
361
361
|
end
|
362
362
|
|
363
363
|
### ---------------------------------------------------------------
|
364
|
-
### Provider each
|
365
|
-
###
|
366
|
-
###
|
367
|
-
### management, yo!
|
364
|
+
### Provider `each` - iterate through each managed resource
|
365
|
+
### as obtained from the `list` instance variable. select the
|
366
|
+
### object and pass it to the provided block
|
368
367
|
### ---------------------------------------------------------------
|
369
368
|
|
370
369
|
def each( &block )
|
371
370
|
raise ArgumentError, "not a provider" unless is_provider?
|
372
371
|
list.each{ |name| yield select(name ) }
|
373
372
|
end
|
373
|
+
|
374
|
+
### ---------------------------------------------------------------
|
375
|
+
### Provider `with` - iterate through each managed resource
|
376
|
+
### as obtained from the `given_list` instance variable.
|
377
|
+
### select the object and pass it to the provided block
|
378
|
+
### ---------------------------------------------------------------
|
379
|
+
|
380
|
+
def with( given_list, &block )
|
381
|
+
raise ArgumentError, "not a provider" unless is_provider?
|
382
|
+
given_list.each{ |name| yield select( name ) }
|
383
|
+
end
|
374
384
|
|
375
385
|
### ---------------------------------------------------------------
|
376
386
|
### Provider reader methods
|
data/lib/junos-ez/vlans.rb
CHANGED
@@ -16,7 +16,7 @@ module Junos::Ez::Vlans
|
|
16
16
|
when :BRIDGE_DOMAIN
|
17
17
|
Junos::Ez::Vlans::Provider::BRIDGE_DOMAIN.new( ndev )
|
18
18
|
else
|
19
|
-
raise Junos::Ez::
|
19
|
+
raise Junos::Ez::NoProviderError, "target does not support vlan bridges"
|
20
20
|
end
|
21
21
|
newbie.properties = Junos::Ez::Provider::PROPERTIES + PROPERTIES
|
22
22
|
Junos::Ez::Provider.attach_instance_variable( ndev, varsym, newbie )
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: junos-ez-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: netconf
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- docs/Utils/Config.md
|
93
93
|
- docs/Utils/Filesystem.md
|
94
94
|
- docs/Utils/Routing-Engine.md
|
95
|
+
- docs/Utils/SCP.md
|
95
96
|
homepage: https://github.com/jeremyschulman/ruby-junos-ez-stdlib
|
96
97
|
licenses: []
|
97
98
|
post_install_message:
|