shopify-junos-ez-stdlib 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +91 -0
- data/LICENSE +26 -0
- data/README.md +199 -0
- data/docs/Facts.md +192 -0
- data/docs/Providers/Group.md +61 -0
- data/docs/Providers/IPports.md +61 -0
- data/docs/Providers/L1ports.md +29 -0
- data/docs/Providers/L2ports.md +43 -0
- data/docs/Providers/LAGports.md +57 -0
- data/docs/Providers/StaticHosts.md +26 -0
- data/docs/Providers/StaticRoutes.md +37 -0
- data/docs/Providers/UserAuths.md +32 -0
- data/docs/Providers/Users.md +122 -0
- data/docs/Providers/Vlans.md +43 -0
- data/docs/Providers_Resources.md +353 -0
- data/docs/README_FIRST.md +27 -0
- data/docs/Utils/Config.md +160 -0
- data/docs/Utils/Filesystem.md +360 -0
- data/docs/Utils/Routing-Engine.md +379 -0
- data/docs/Utils/SCP.md +24 -0
- data/examples/config/config_file.rb +72 -0
- data/examples/config/config_template_object.rb +81 -0
- data/examples/config/config_template_simple.rb +76 -0
- data/examples/config/multi_config.rb +60 -0
- data/examples/fs_utils.rb +31 -0
- data/examples/lag_port.rb +27 -0
- data/examples/re_upgrade.rb +99 -0
- data/examples/re_utils.rb +33 -0
- data/examples/simple.rb +46 -0
- data/examples/st_hosts.rb +33 -0
- data/examples/user.rb +32 -0
- data/examples/vlans.rb +31 -0
- data/junos-ez-stdlib.gemspec +15 -0
- data/lib/junos-ez/exceptions.rb +3 -0
- data/lib/junos-ez/facts.rb +83 -0
- data/lib/junos-ez/facts/chassis.rb +51 -0
- data/lib/junos-ez/facts/ifd_style.rb +17 -0
- data/lib/junos-ez/facts/personality.rb +25 -0
- data/lib/junos-ez/facts/switch_style.rb +31 -0
- data/lib/junos-ez/facts/version.rb +58 -0
- data/lib/junos-ez/group.rb +206 -0
- data/lib/junos-ez/ip_ports.rb +30 -0
- data/lib/junos-ez/ip_ports/classic.rb +188 -0
- data/lib/junos-ez/l1_ports.rb +121 -0
- data/lib/junos-ez/l1_ports/classic.rb +87 -0
- data/lib/junos-ez/l1_ports/switch.rb +134 -0
- data/lib/junos-ez/l2_ports.rb +66 -0
- data/lib/junos-ez/l2_ports/bridge_domain.rb +499 -0
- data/lib/junos-ez/l2_ports/vlan.rb +433 -0
- data/lib/junos-ez/l2_ports/vlan_l2ng.rb +502 -0
- data/lib/junos-ez/lag_ports.rb +268 -0
- data/lib/junos-ez/provider.rb +619 -0
- data/lib/junos-ez/stdlib.rb +18 -0
- data/lib/junos-ez/system.rb +48 -0
- data/lib/junos-ez/system/st_hosts.rb +92 -0
- data/lib/junos-ez/system/st_routes.rb +159 -0
- data/lib/junos-ez/system/syscfg.rb +103 -0
- data/lib/junos-ez/system/userauths.rb +84 -0
- data/lib/junos-ez/system/users.rb +217 -0
- data/lib/junos-ez/utils/config.rb +236 -0
- data/lib/junos-ez/utils/fs.rb +385 -0
- data/lib/junos-ez/utils/re.rb +558 -0
- data/lib/junos-ez/version.rb +6 -0
- data/lib/junos-ez/vlans.rb +38 -0
- data/lib/junos-ez/vlans/bridge_domain.rb +89 -0
- data/lib/junos-ez/vlans/vlan.rb +119 -0
- data/lib/junos-ez/vlans/vlan_l2ng.rb +126 -0
- data/shipit.yml +4 -0
- data/tmp +7 -0
- metadata +129 -0
@@ -0,0 +1,360 @@
|
|
1
|
+
# `Junos::Ez::FS::Utils`
|
2
|
+
|
3
|
+
A collection of methods to access filesystem specific functions and information. These methods return data in
|
4
|
+
Hash / Array structures so the information can be programmatically accessible.
|
5
|
+
|
6
|
+
# METHODS
|
7
|
+
|
8
|
+
- [`cat`](#cat) - returns the String contents of a file
|
9
|
+
- [`checksum`](#checksum) - returns the checksum of a file (MD5, SHA1, SHA256 options)
|
10
|
+
- [`cleanup?`](#cleanup_check) - returns a Hash of files that *would be* removed from "request system storage cleanup"
|
11
|
+
- [`cleanup!`](#cleanup) - "request system storage cleanup" (!! NO CONFIRM !!)
|
12
|
+
- [`cp!`](#cp) - copies a file relative on the device filesystem
|
13
|
+
- [`cwd`](#cwd) - changes the current working directory
|
14
|
+
- [`pwd`](#pwd) - returns a String of the current working directory
|
15
|
+
- [`df`](#df) - "show system storage"
|
16
|
+
- [`ls`](#ls) - "file list", i.e. get a file / directory listing, returns a Hash
|
17
|
+
- [`mv!`](#mv) - "file move", i.e. move / rename files
|
18
|
+
- [`rm!`](#rm) - "file delete", i.e. deletes files
|
19
|
+
|
20
|
+
# USAGE
|
21
|
+
```ruby
|
22
|
+
|
23
|
+
# bind :fs to access the file-system utilities
|
24
|
+
|
25
|
+
Junos::Ez::FS::Utils( ndev, :fs )
|
26
|
+
|
27
|
+
# get a listing of my home directory files:
|
28
|
+
|
29
|
+
pp ndev.fs.ls '/var/home/jeremy', :detail => true
|
30
|
+
->
|
31
|
+
{"/var/home/jeremy"=>
|
32
|
+
{:fileblocks=>11244,
|
33
|
+
:files=>
|
34
|
+
"key1.pub"=>
|
35
|
+
{:owner=>"jeremy",
|
36
|
+
:group=>"staff",
|
37
|
+
:links=>1,
|
38
|
+
:size=>405,
|
39
|
+
:permissions_text=>"-rw-r--r--",
|
40
|
+
:permissions=>644,
|
41
|
+
:date=>"Apr 27 15:00",
|
42
|
+
:date_epoc=>1367074832},
|
43
|
+
"template-policy-options.conf"=>
|
44
|
+
{:owner=>"jeremy",
|
45
|
+
:group=>"staff",
|
46
|
+
:links=>1,
|
47
|
+
:size=>4320,
|
48
|
+
:permissions_text=>"-rw-r--r--",
|
49
|
+
:permissions=>644,
|
50
|
+
:date=>"Nov 6 2011",
|
51
|
+
:date_epoc=>1320564278}},
|
52
|
+
:dirs=>
|
53
|
+
{".ssh"=>
|
54
|
+
{:owner=>"jeremy",
|
55
|
+
:group=>"staff",
|
56
|
+
:links=>2,
|
57
|
+
:size=>512,
|
58
|
+
:permissions_text=>"drwxr-xr-x",
|
59
|
+
:permissions=>755,
|
60
|
+
:date=>"Apr 27 19:48",
|
61
|
+
:date_epoc=>1367092112},
|
62
|
+
"bak"=>
|
63
|
+
{:owner=>"jeremy",
|
64
|
+
:group=>"staff",
|
65
|
+
:links=>2,
|
66
|
+
:size=>512,
|
67
|
+
:permissions_text=>"drwxr-xr-x",
|
68
|
+
:permissions=>755,
|
69
|
+
:date=>"Apr 16 2010",
|
70
|
+
:date_epoc=>1271441068}}}}
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
# GORY DETAILS
|
76
|
+
|
77
|
+
## `cat( filename )` <a name="cat">
|
78
|
+
Returns the String contents of a file. If the file does not exist, an `IOError` with String error message is raised.
|
79
|
+
```ruby
|
80
|
+
puts ndev.fs.cat '/var/log/messages'
|
81
|
+
->
|
82
|
+
May 2 18:05:32 firefly newsyslog[1845]: logfile turned over due to -F request
|
83
|
+
|
84
|
+
puts ndev.fs.cat 'foober'
|
85
|
+
exception->
|
86
|
+
IOError: "could not resolve file: foober"
|
87
|
+
```
|
88
|
+
|
89
|
+
## `checksum( method, path )` <a name="checksum">
|
90
|
+
Returns the checksum of a file (MD5, SHA1, SHA256 options) located on the Junos target. The `method` idetifies the checksum method, and is one of `[:md5, :sha256, :sha1]`. The `path` argument specifies the file to run the checksum over. If the `path` file does not exist, then an `IOError` exception with String error-message will be raised.
|
91
|
+
|
92
|
+
The following runs an MD5 checksum over the file /var/tmp/junos-vsrx-domestic.tgz located on the Junos target:
|
93
|
+
```ruby
|
94
|
+
ndev.fs.checksum :md5, "/var/tmp/junos-vsrx-domestic.tgz"
|
95
|
+
->
|
96
|
+
"91132caf6030fa88a31c2b9db60ea54d"
|
97
|
+
|
98
|
+
# try to get a checksum on a non-existant file ...
|
99
|
+
|
100
|
+
ndev.fs.checksum :md5, "foober"
|
101
|
+
exception->
|
102
|
+
IOError: "md5: /cf/var/home/jeremy/foober: No such file or directory"
|
103
|
+
```
|
104
|
+
|
105
|
+
## `cleanup?` <a name="cleanup_check">
|
106
|
+
Returns a Hash of files that *would be* removed as a result of the command "request system storage cleanup".
|
107
|
+
```ruby
|
108
|
+
ndev.fs.cleanup?
|
109
|
+
->
|
110
|
+
{"/cf/var/crash/flowd_vsrx.log.firefly.0"=>
|
111
|
+
{:size_text=>"650B", :size=>650, :date=>"May 3 13:15"},
|
112
|
+
"/cf/var/crash/flowd_vsrx.log.firefly.1"=>
|
113
|
+
{:size_text=>"650B", :size=>650, :date=>"May 3 13:22"},
|
114
|
+
"/cf/var/crash/flowd_vsrx.log.firefly.2"=>
|
115
|
+
{:size_text=>"23B", :size=>23, :date=>"May 5 19:20"},
|
116
|
+
"/cf/var/crash/flowd_vsrx.log.firefly.3"=>
|
117
|
+
{:size_text=>"650B", :size=>650, :date=>"May 5 19:20"},
|
118
|
+
"/cf/var/tmp/vpn_tunnel_orig.id"=>
|
119
|
+
{:size_text=>"0B", :size=>0, :date=>"May 5 19:20"}}
|
120
|
+
```
|
121
|
+
|
122
|
+
## `cleanup!` <a name="cleanup">
|
123
|
+
Performs the command "request system storage cleanup" (!! NO CONFIRM !!), and returns a Hash of the files that were removed.
|
124
|
+
```ruby
|
125
|
+
ndev.fs.cleanup!
|
126
|
+
->
|
127
|
+
{"/cf/var/crash/flowd_vsrx.log.firefly.0"=>
|
128
|
+
{:size_text=>"650B", :size=>650, :date=>"May 3 13:15"},
|
129
|
+
"/cf/var/crash/flowd_vsrx.log.firefly.1"=>
|
130
|
+
{:size_text=>"650B", :size=>650, :date=>"May 3 13:22"},
|
131
|
+
"/cf/var/crash/flowd_vsrx.log.firefly.2"=>
|
132
|
+
{:size_text=>"23B", :size=>23, :date=>"May 5 19:20"},
|
133
|
+
"/cf/var/crash/flowd_vsrx.log.firefly.3"=>
|
134
|
+
{:size_text=>"650B", :size=>650, :date=>"May 5 19:20"},
|
135
|
+
"/cf/var/tmp/vpn_tunnel_orig.id"=>
|
136
|
+
{:size_text=>"0B", :size=>0, :date=>"May 5 19:20"}}
|
137
|
+
```
|
138
|
+
|
139
|
+
## `cp!( from_file, to_file )` <a name="cp">
|
140
|
+
Copies a file relative on the Junos filesystem. Returns `true` if the operations was successful, raises an `IOError` exceptions with error-message otherwise.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
# copy the vsrx.conf file from the temp directory to the current working directory
|
144
|
+
ndev.fs.cp! "/var/tmp/vsrx.conf","."
|
145
|
+
->
|
146
|
+
true
|
147
|
+
|
148
|
+
# try to copy a file that doesn't exist
|
149
|
+
ndev.fs.cp! "/var/tmp/vsrx.conf-bleck","."
|
150
|
+
(exception)->
|
151
|
+
IOError: "File does not exist: /var/tmp/vsrx.conf-bleck
|
152
|
+
File fetch failed"
|
153
|
+
```
|
154
|
+
|
155
|
+
## `cwd( directory )` <a name="cwd">
|
156
|
+
Changes the current working directory (String). Returns the working directory name if the operation was succesfful. If the requested `directory` does not exist, then an `IOError` with String error-message is raised.
|
157
|
+
```ruby
|
158
|
+
# change to the '/var/tmp' directory. What we see is that this directory is really a symlink to '/cf/var/tmp'
|
159
|
+
ndev.fs.cwd "/var/tmp"
|
160
|
+
->
|
161
|
+
"/cf/var/tmp"
|
162
|
+
|
163
|
+
# now try to change to a non-existant directory:
|
164
|
+
|
165
|
+
ndev.fs.cwd "/foober"
|
166
|
+
exception->
|
167
|
+
IOError: "invalid directory: /foober"
|
168
|
+
```
|
169
|
+
|
170
|
+
## `pwd`
|
171
|
+
Returns a String of the current working directory.
|
172
|
+
```ruby
|
173
|
+
ndev.fs.pwd
|
174
|
+
->
|
175
|
+
"/cf/var/home/jeremy"
|
176
|
+
```
|
177
|
+
|
178
|
+
# `df( opts = {} )` <a name="df">
|
179
|
+
Returns information about the filesystem storage, gathered from "show system storage". The following options are supported:
|
180
|
+
```
|
181
|
+
:format => [:hash, :xml, :text]
|
182
|
+
```
|
183
|
+
Determines the return format, the default is `:hash`. Format `:xml` returns the Junos XML result, and format `:text` returns the CLI text output.
|
184
|
+
```
|
185
|
+
:size_div => Fixnum
|
186
|
+
```
|
187
|
+
This option is only valid if `:format => :hash`. When a `:size_div` is provided, this method will change the reported size by dividing it down; handy if you want to covert the size in bytes to something like MB or GB reference. This option will change the values of the `:total_size`, `:used_size`, and `:avail_size` values.
|
188
|
+
```ruby
|
189
|
+
ndev.fs.df
|
190
|
+
->
|
191
|
+
{"/dev/ad0s1a"=>
|
192
|
+
{:mounted_on=>"/",
|
193
|
+
:total_blocks=>3313822,
|
194
|
+
:total_size=>"1.6G",
|
195
|
+
:used_blocks=>1431770,
|
196
|
+
:used_size=>"699M",
|
197
|
+
:used_percent=>47,
|
198
|
+
:avail_blocks=>1616948,
|
199
|
+
:avail_size=>"790M"},
|
200
|
+
"devfs"=>
|
201
|
+
{:mounted_on=>"/jail/dev",
|
202
|
+
:total_blocks=>2,
|
203
|
+
:total_size=>"1.0K",
|
204
|
+
:used_blocks=>2,
|
205
|
+
:used_size=>"1.0K",
|
206
|
+
:used_percent=>100,
|
207
|
+
:avail_blocks=>0,
|
208
|
+
:avail_size=>"0B"},
|
209
|
+
# <snip>
|
210
|
+
"/cf/var/log"=>
|
211
|
+
{:mounted_on=>"/jail/var/log",
|
212
|
+
:total_blocks=>3313822,
|
213
|
+
:total_size=>"1.6G",
|
214
|
+
:used_blocks=>1431770,
|
215
|
+
:used_size=>"699M",
|
216
|
+
:used_percent=>47,
|
217
|
+
:avail_blocks=>1616948,
|
218
|
+
:avail_size=>"790M"}}
|
219
|
+
```
|
220
|
+
Same example but dividing down the size by 1024 to put into MB.
|
221
|
+
```ruby
|
222
|
+
[7] pry(main)> ndev.fs.df :size_div => 1024
|
223
|
+
=> {"/dev/ad0s1a"=>
|
224
|
+
{:mounted_on=>"/",
|
225
|
+
:total_blocks=>3313822,
|
226
|
+
:total_size=>1618,
|
227
|
+
:used_blocks=>1431770,
|
228
|
+
:used_size=>699,
|
229
|
+
:used_percent=>47,
|
230
|
+
:avail_blocks=>1616948,
|
231
|
+
:avail_size=>789},
|
232
|
+
"devfs"=>
|
233
|
+
{:mounted_on=>"/jail/dev",
|
234
|
+
:total_blocks=>2,
|
235
|
+
:total_size=>0,
|
236
|
+
:used_blocks=>2,
|
237
|
+
:used_size=>0,
|
238
|
+
:used_percent=>100,
|
239
|
+
:avail_blocks=>0,
|
240
|
+
:avail_size=>0},
|
241
|
+
# <snip>
|
242
|
+
"/cf/var/log"=>
|
243
|
+
{:mounted_on=>"/jail/var/log",
|
244
|
+
:total_blocks=>3313822,
|
245
|
+
:total_size=>1618,
|
246
|
+
:used_blocks=>1431770,
|
247
|
+
:used_size=>699,
|
248
|
+
:used_percent=>47,
|
249
|
+
:avail_blocks=>1616948,
|
250
|
+
:avail_size=>789}}
|
251
|
+
```
|
252
|
+
|
253
|
+
## `ls( *args )` <a name="ls">
|
254
|
+
Returns a directory/file listing in a Hash structure. Each primary key is the name of the directory. If the required path is a file, then the key will be an empty string.
|
255
|
+
The `*args` determine what information is returned. The general format of use is:
|
256
|
+
```
|
257
|
+
ls <path>, <options>
|
258
|
+
```
|
259
|
+
Where `path` is a filesystem-path and `options` is a Hash of controls. The following options are supported:
|
260
|
+
```
|
261
|
+
:format => [:text, :xml, :hash]
|
262
|
+
```
|
263
|
+
Determines what format this method returns. By default this will be `:hash`. The `:xml` option will return the Junos XML result. The `:text` option will return the CLI text output.
|
264
|
+
```
|
265
|
+
:recurse => true
|
266
|
+
```
|
267
|
+
When this option is set, a complete recursive listing will be performed. This is only valid if the `path` is a directory. This option will return full informational detail on the files/directories as well.
|
268
|
+
```
|
269
|
+
:detail => true
|
270
|
+
```
|
271
|
+
When this option is set then detailed information, like file size, is provided.
|
272
|
+
|
273
|
+
If no `*args` are passed, then the file listing of the current working directory is provided:
|
274
|
+
```ruby
|
275
|
+
ndev.fs.ls
|
276
|
+
->
|
277
|
+
{"/cf/var/home/jeremy/"=>
|
278
|
+
{:fileblocks=>7370,
|
279
|
+
:files=>
|
280
|
+
{"FF-no-security.conf"=>{},
|
281
|
+
"key1.pub"=>{},
|
282
|
+
"vsrx.conf"=>{}},
|
283
|
+
:dirs=>{".ssh"=>{}}}}
|
284
|
+
|
285
|
+
```
|
286
|
+
Or if you want the details for the current directory listing
|
287
|
+
```ruby
|
288
|
+
[23] pry(main)> ndev.fs.ls :detail=>true
|
289
|
+
=> {"/cf/var/home/jeremy/"=>
|
290
|
+
{:fileblocks=>7370,
|
291
|
+
:files=>
|
292
|
+
{"FF-no-security.conf"=>
|
293
|
+
{:owner=>"jeremy",
|
294
|
+
:group=>"staff",
|
295
|
+
:links=>1,
|
296
|
+
:size=>366682,
|
297
|
+
:permissions_text=>"-rw-r--r--",
|
298
|
+
:permissions=>644,
|
299
|
+
:date=>"Apr 13 21:56",
|
300
|
+
:date_epoc=>1365890165},
|
301
|
+
"key1.pub"=>
|
302
|
+
{:owner=>"jeremy",
|
303
|
+
:group=>"staff",
|
304
|
+
:links=>1,
|
305
|
+
:size=>0,
|
306
|
+
:permissions_text=>"-rw-r--r--",
|
307
|
+
:permissions=>644,
|
308
|
+
:date=>"Apr 27 14:59",
|
309
|
+
:date_epoc=>1367074764},
|
310
|
+
"vsrx.conf"=>
|
311
|
+
{:owner=>"jeremy",
|
312
|
+
:group=>"staff",
|
313
|
+
:links=>1,
|
314
|
+
:size=>1559492,
|
315
|
+
:permissions_text=>"-rwxr-xr-x",
|
316
|
+
:permissions=>755,
|
317
|
+
:date=>"Dec 19 16:27",
|
318
|
+
:date_epoc=>1355934448}},
|
319
|
+
:dirs=>
|
320
|
+
{".ssh"=>
|
321
|
+
{:owner=>"jeremy",
|
322
|
+
:group=>"staff",
|
323
|
+
:links=>2,
|
324
|
+
:size=>512,
|
325
|
+
:permissions_text=>"drwxr-xr-x",
|
326
|
+
:permissions=>755,
|
327
|
+
:date=>"Apr 3 14:41",
|
328
|
+
:date_epoc=>1365000068}}}}
|
329
|
+
```
|
330
|
+
|
331
|
+
## `mv!( from_path, to_path )` <a name="mv">
|
332
|
+
Move / rename file(s). Returns `true` if the operation was successful, `IOError` exception with String error-message otherwise.
|
333
|
+
```ruby
|
334
|
+
# move the file "vsrx.conf" from the current working directory to the temp directory
|
335
|
+
ndev.fs.mv! "vsrx.conf","/var/tmp"
|
336
|
+
->
|
337
|
+
true
|
338
|
+
|
339
|
+
# Now do it again to generate an error message[26] pry(main)> ndev.fs.mv! "vsrx.conf","/var/tmp"
|
340
|
+
ndev.fs.mv! "vsrx.conf","/var/tmp"
|
341
|
+
exception->
|
342
|
+
IOError:
|
343
|
+
"mv: /cf/var/home/jeremy/vsrx.conf: No such file or directory"
|
344
|
+
```
|
345
|
+
|
346
|
+
## `rm!( path )` <a name="rm">
|
347
|
+
Removes the file(s) identified by `path`. Returns `true` if the file(s) are removed OK, `IOError` exception with String error-message otherwise.
|
348
|
+
```ruby
|
349
|
+
ndev.fs.rm! "/var/tmp/junos-vsrx-domestic.tgz"
|
350
|
+
->
|
351
|
+
true
|
352
|
+
|
353
|
+
# now try to remove the file again to generate an error ..
|
354
|
+
ndev.fs.rm! "/var/tmp/junos-vsrx-domestic.tgz"
|
355
|
+
exception->
|
356
|
+
IOError:
|
357
|
+
"rm: /var/tmp/junos-vsrx-domestic.tgz: No such file or directory"
|
358
|
+
```
|
359
|
+
|
360
|
+
|
@@ -0,0 +1,379 @@
|
|
1
|
+
# `Junos::Ez::RE::Utils`
|
2
|
+
|
3
|
+
A collection of methods to access routing-engine specific functions and information. These methods return data in Hash / Array structures so the information can be programmatically accessible.
|
4
|
+
|
5
|
+
# METHODS
|
6
|
+
|
7
|
+
## Informational
|
8
|
+
|
9
|
+
- [`status`](#status) - "show chassis routing-engine" information
|
10
|
+
- [`uptime`](#uptime) - "show system uptime" information
|
11
|
+
- [`system_alarms`](#system_alarms) - "show system alarms" information
|
12
|
+
- [`chassis_alarms`](#chassis_alarms) - "show chassis alarms" information
|
13
|
+
- [`memory`](#memory) - "show system memory" information
|
14
|
+
- [`users`](#users) - "show system users" information
|
15
|
+
|
16
|
+
## Software Image
|
17
|
+
|
18
|
+
- [`software_validate?`](#software_validate) - "request system software validate..."
|
19
|
+
- [`software_install!`](#software_install) - "request system software add ..."
|
20
|
+
- [`software_rollback!`](#software_rollback) - "request system software rollback"
|
21
|
+
- [`software_images`](#software_images) - indicates current/rollback image file names
|
22
|
+
|
23
|
+
## License Management
|
24
|
+
|
25
|
+
- [`license_install!`](#license_install) - "request system license add"
|
26
|
+
- [`license_rm!`](#license_rm) - "request system license delete"
|
27
|
+
- [`licenses`](#licenses) - "show system license"
|
28
|
+
|
29
|
+
## System Controls
|
30
|
+
|
31
|
+
- [`reboot!`](#reboot) - "request system reboot" (!! NO CONFIRM !!)
|
32
|
+
- [`shutdown!`](#shutdown) - "request system power-off" (!! NO CONFIRM !!)
|
33
|
+
|
34
|
+
## Miscellaneous
|
35
|
+
|
36
|
+
- [`ping`](#ping) - Perform a "ping" command
|
37
|
+
|
38
|
+
# USAGE
|
39
|
+
```ruby
|
40
|
+
|
41
|
+
# bind :re to access the routing-engine utitities
|
42
|
+
Junos::Ez::RE::Utils( ndev, :re )
|
43
|
+
|
44
|
+
# show the uptime information on this device
|
45
|
+
pp ndev.re.uptime
|
46
|
+
->
|
47
|
+
{"re0"=>
|
48
|
+
{:time_now=>"2013-04-27 22:28:24 UTC",
|
49
|
+
:active_users=>1,
|
50
|
+
:load_avg=>[0.08, 0.05, 0.01],
|
51
|
+
:uptime=>{:at=>"10:28PM", :ago=>"27 days, 2:58"},
|
52
|
+
:time_boot=>{:at=>"2013-03-31 19:30:47 UTC", :ago=>"3w6d 02:57"},
|
53
|
+
:protocols_started=>{:at=>"2013-03-31 19:34:53 UTC", :ago=>"3w6d 02:53"},
|
54
|
+
:last_config=>
|
55
|
+
{:at=>"2013-04-27 19:48:42 UTC", :ago=>"02:39:42", :by=>"jeremy"}}}
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
# GORY DETAILS
|
61
|
+
|
62
|
+
## `status`
|
63
|
+
|
64
|
+
Returns a Hash structure of "show chassis routing-engine" information. Each Hash key is the RE identifier. For example, on a target with a single RE:
|
65
|
+
```ruby
|
66
|
+
pp ndev.re.status
|
67
|
+
->
|
68
|
+
{"re0"=>
|
69
|
+
{:model=>"JUNOSV-FIREFLY RE",
|
70
|
+
:serialnumber=>"",
|
71
|
+
:temperature=>{:system=>"", :cpu=>""},
|
72
|
+
:memory=>{:total_size=>0, :buffer_util=>0},
|
73
|
+
:cpu_util=>{:user=>0, :background=>0, :system=>2, :interrupt=>0, :idle=>98},
|
74
|
+
:uptime=>
|
75
|
+
{:at=>"2013-05-02 17:37:51 UTC",
|
76
|
+
:ago=>"3 minutes, 4 seconds",
|
77
|
+
:reboot_reason=>"Router rebooted after a normal shutdown."},
|
78
|
+
:load_avg=>[0.06, 0.13, 0.07]}}
|
79
|
+
```
|
80
|
+
|
81
|
+
## `uptime`
|
82
|
+
|
83
|
+
Returns a Hash structure of "show system uptime" information. Each Hash key is the RE identifier. For example, on a target with a single RE:
|
84
|
+
```ruby
|
85
|
+
pp ndev.re.uptime
|
86
|
+
->
|
87
|
+
{"re0"=>
|
88
|
+
{:time_now=>"2013-05-02 17:42:09 UTC",
|
89
|
+
:active_users=>0,
|
90
|
+
:load_avg=>[0.02, 0.1, 0.06],
|
91
|
+
:uptime=>{:at=>"5:42PM", :ago=>"4 mins"},
|
92
|
+
:time_boot=>{:at=>"2013-05-02 17:37:51 UTC", :ago=>"00:04:18"},
|
93
|
+
:protocols_started=>{:at=>"2013-05-02 17:38:08 UTC", :ago=>"00:04:01"},
|
94
|
+
:last_config=>
|
95
|
+
{:at=>"2013-04-27 15:00:55 UTC", :ago=>"5d 02:41", :by=>"root"}}}
|
96
|
+
```
|
97
|
+
## `system_alarms`
|
98
|
+
|
99
|
+
Returns an Array of Hash structure of "show system alarms" information. If there are no alarms, this method returns `nil`. For example, a target with a single alarm:
|
100
|
+
```ruby
|
101
|
+
pp ndev.re.system_alarms
|
102
|
+
->
|
103
|
+
[{:at=>"2013-05-02 17:38:03 UTC",
|
104
|
+
:class=>"Minor",
|
105
|
+
:description=>"Rescue configuration is not set",
|
106
|
+
:type=>"Configuration"}]
|
107
|
+
```
|
108
|
+
|
109
|
+
## `chassis_alarms`
|
110
|
+
|
111
|
+
Returns an Array Hash structure of "show chassis alarms" information. If there are no alarms, this method returns `nil`. For example, a target with no chassis alarms:
|
112
|
+
```ruby
|
113
|
+
pp ndev.re.chassis_alarms
|
114
|
+
->
|
115
|
+
nil
|
116
|
+
```
|
117
|
+
|
118
|
+
## `memory`
|
119
|
+
|
120
|
+
Returns a Hash structure of "show system memory" information. Each key is the RE indentifier. A target with a single RE would look like the following. Note that the `:procs` Array is the process array, with each element as a Hash of process specific information.
|
121
|
+
```ruby
|
122
|
+
pp ndev.re.memory
|
123
|
+
->
|
124
|
+
{"re0"=>
|
125
|
+
{:memory_summary=>
|
126
|
+
{:total=>{:size=>1035668, :percentage=>100},
|
127
|
+
:reserved=>{:size=>18688, :percentage=>1},
|
128
|
+
:wired=>{:size=>492936, :percentage=>47},
|
129
|
+
:active=>{:size=>184152, :percentage=>17},
|
130
|
+
:inactive=>{:size=>65192, :percentage=>6},
|
131
|
+
:cache=>{:size=>261140, :percentage=>25},
|
132
|
+
:free=>{:size=>12660, :percentage=>1}},
|
133
|
+
:procs=>
|
134
|
+
[{:name=>"kernel",
|
135
|
+
:pid=>0,
|
136
|
+
:size=>569704,
|
137
|
+
:size_pct=>54.49,
|
138
|
+
:resident=>90304,
|
139
|
+
:resident_pct=>8.71},
|
140
|
+
{:name=>"/sbin/pmap",
|
141
|
+
:pid=>2768,
|
142
|
+
:size=>4764,
|
143
|
+
:size_pct=>0.15,
|
144
|
+
:resident=>1000,
|
145
|
+
:resident_pct=>0.09},
|
146
|
+
{:name=>"file: (mgd) /proc/2766/file (jeremy)",
|
147
|
+
:pid=>2765,
|
148
|
+
:size=>727896,
|
149
|
+
:size_pct=>23.16,
|
150
|
+
:resident=>18904,
|
151
|
+
:resident_pct=>1.82},
|
152
|
+
#
|
153
|
+
# snip, omitted full array for sake of sanity ...
|
154
|
+
#
|
155
|
+
]}}
|
156
|
+
```
|
157
|
+
|
158
|
+
## `users`
|
159
|
+
|
160
|
+
Returns a Array structure of "show system users" information. Each Array item is a Hash structure of user information. A target with a single user logged in would look like:
|
161
|
+
```ruby
|
162
|
+
pp ndev.re.users
|
163
|
+
->
|
164
|
+
[{:name=>"jeremy",
|
165
|
+
:tty=>"p0",
|
166
|
+
:from=>"192.168.56.1",
|
167
|
+
:login_time=>"5:45PM",
|
168
|
+
:idle_time=>"",
|
169
|
+
:command=>"-cli (cli)"}]
|
170
|
+
```
|
171
|
+
|
172
|
+
## `software_images`
|
173
|
+
Returns a Hash of the currnet and rollback image file-names.
|
174
|
+
```ruby
|
175
|
+
pp ndev.re.software_images
|
176
|
+
->
|
177
|
+
{:rollback=>"junos-12.1I20130415_junos_121_x44_d15.0-576602-domestic",
|
178
|
+
:current=>"junos-12.1I20130322_2104_slt-builder-domestic"}
|
179
|
+
```
|
180
|
+
|
181
|
+
## `software_validate?` <a name="software_validate">
|
182
|
+
|
183
|
+
Performs the equivalent of "request system software validate..." and returns `true` if the software passes validation or a String indicating the error message. The following is an example that simply checks for true:
|
184
|
+
```ruby
|
185
|
+
unless ndev.re.software_validate?( file_on_junos )
|
186
|
+
puts "The softare does not validate!"
|
187
|
+
ndev.close
|
188
|
+
exit 1
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
## `software_install!( opts = {} )` <a name="software_install">
|
193
|
+
|
194
|
+
Performs the equivalent of "request system software add ..." and returns `true` if the operation was successful or a String indicating the error message.
|
195
|
+
|
196
|
+
The following options are supported:
|
197
|
+
```
|
198
|
+
:no_validate => true
|
199
|
+
```
|
200
|
+
Instructs Junos not to validate the software image. You should use this option if your program explicity calls `software_validate?` first, since you don't want to do the validation twice.
|
201
|
+
```
|
202
|
+
:unlink => true
|
203
|
+
```
|
204
|
+
Instructs Junos to remove the software package file (.tgz) after the installation has completed.
|
205
|
+
```
|
206
|
+
:reboot => true
|
207
|
+
```
|
208
|
+
Instructs Junos to reboot the RE after the software has been installed successfully.
|
209
|
+
|
210
|
+
The following example illustrates an error message:
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
puts "Installing image ... please wait ..."
|
214
|
+
rc = ndev.re.software_install!( :package => file_on_junos, :no_validate => true )
|
215
|
+
if rc != true
|
216
|
+
puts rc
|
217
|
+
end
|
218
|
+
```
|
219
|
+
With the results of the `rc` String:
|
220
|
+
```
|
221
|
+
Verified junos-boot-vsrx-12.1I20130415_junos_121_x44_d15.0-576602.tgz signed by PackageDevelopment_12_1_0
|
222
|
+
Verified junos-vsrx-12.1I20130415_junos_121_x44_d15.0-576602-domestic signed by PackageDevelopment_12_1_0
|
223
|
+
|
224
|
+
WARNING: The software that is being installed has limited support.
|
225
|
+
WARNING: Run 'file show /etc/notices/unsupported.txt' for details.
|
226
|
+
|
227
|
+
Available space: -49868 require: 4641
|
228
|
+
|
229
|
+
WARNING: The /cf filesystem is low on free disk space.
|
230
|
+
WARNING: This package requires 4641k free, but there
|
231
|
+
WARNING: is only -49868k available.
|
232
|
+
|
233
|
+
WARNING: This installation attempt will be aborted.
|
234
|
+
WARNING: If you wish to force the installation despite these warnings
|
235
|
+
WARNING: you may use the 'force' option on the command line.
|
236
|
+
ERROR: junos-12.1I20130415_junos_121_x44_d15.0-576602-domestic fails requirements check
|
237
|
+
Installation failed for package '/var/tmp/junos-vsrx-domestic.tgz'
|
238
|
+
WARNING: Not enough space in /var/tmp to unpack junos-12.1I20130415_junos_121_x44_d15.0-576602.tgz
|
239
|
+
WARNING: Use 'request system storage cleanup' and
|
240
|
+
WARNING: the 'unlink' option to improve the chances of success
|
241
|
+
```
|
242
|
+
|
243
|
+
## `software_rollback!` <a name="software_rollback">
|
244
|
+
|
245
|
+
Performs the equivalent of "request system software rollback". The result of the operation is returned as a String. For example, a successful rollback would look like this:
|
246
|
+
```ruby
|
247
|
+
pp ndev.re.software_rollback!
|
248
|
+
->
|
249
|
+
"Restoring boot file package\njunos-12.1I20130415_junos_121_x44_d15.0-576602-domestic will become active at next reboot\nWARNING: A reboot is required to load this software correctly\nWARNING: Use the 'request system reboot' command\nWARNING: when software installation is complete"
|
250
|
+
```
|
251
|
+
An unsuccessful rollback would look like this:
|
252
|
+
```ruby
|
253
|
+
pp ndev.re.software_rollback!
|
254
|
+
->
|
255
|
+
"WARNING: Cannot rollback, /packages/junos is not valid"
|
256
|
+
```
|
257
|
+
|
258
|
+
## `reboot!( opts = {} )` <a name="reboot">
|
259
|
+
Performs the "request system reboot" action. There is **NO** confirmation prompt, so once you've executed this method, the action begins. Once this command executes the NETCONF session to the target will eventually terminate. You can trap the `Net::SSH::Disconnect` exception to detect this event.
|
260
|
+
|
261
|
+
The option Hash provides for the following controls:
|
262
|
+
```
|
263
|
+
:in => Fixnum
|
264
|
+
```
|
265
|
+
Instructs Junos to reboot after `:in` minutes from the time of calling `reboot!`
|
266
|
+
```
|
267
|
+
:at => String
|
268
|
+
```
|
269
|
+
Instructs Junos to reboot at a specific date and time. The format of `:at` is YYYYMMDDHHMM, where HH is the 24-hour (military) time. For example HH = 01 is 1am and HH=13 is 1pm. If you omit the YYYY, MM, or DD options the current values apply. For example `:at => 1730` is 1:30pm today.
|
270
|
+
|
271
|
+
## `shutdown!( opts = {} )` <a name="shutdown">
|
272
|
+
|
273
|
+
Performs the "request system power-off" action. There is **NO** confirmation prompt, so once you've executed this method, the action begins. Once this command executes the NETCONF session to the target will eventually terminate. You can trap the `Net::SSH::Disconnect` exception to detect this event.
|
274
|
+
|
275
|
+
The option Hash provides for the following controls:
|
276
|
+
```
|
277
|
+
:in => Fixnum
|
278
|
+
```
|
279
|
+
Instructs Junos to reboot after `:in` minutes from the time of calling `reboot!`
|
280
|
+
```
|
281
|
+
:at => String
|
282
|
+
```
|
283
|
+
Instructs Junos to reboot at a specific date and time. The format of `:at` is YYYYMMDDHHMM, where HH is the 24-hour (military) time. For example HH = 01 is 1am and HH=13 is 1pm. If you omit the YYYY, MM, or DD options the current values apply. For example `:at => 1730` is 1:30pm today.
|
284
|
+
|
285
|
+
## `license_install!( opts = {} )` <a name="license_install">
|
286
|
+
Installs the provided license. This method will return `true` if the key is installed correctly or a String message indicating the error.
|
287
|
+
|
288
|
+
The following options are supported, you **MUST** use either `:key` or `:filename` to provide the license ASCII-text.
|
289
|
+
```
|
290
|
+
:key
|
291
|
+
```
|
292
|
+
The ASCII-text of the key.
|
293
|
+
```
|
294
|
+
:filename
|
295
|
+
```
|
296
|
+
The path to the file on the server (not Junos) that contains the ASCII-text of the key.
|
297
|
+
|
298
|
+
The following illustates how to load a key from the server filesystem.
|
299
|
+
```ruby
|
300
|
+
ndev.re.license_install! :filename=>'/cygwin/home/jschulman/license.txt'
|
301
|
+
->
|
302
|
+
true
|
303
|
+
```
|
304
|
+
## `license_rm!( license_id )` <a name="license_rm">
|
305
|
+
Removes either a specific license or `:all` licenses from the target. This method will return `true` if the action was successful, or a String error-message otherwise.
|
306
|
+
|
307
|
+
Removing a specific license:
|
308
|
+
```ruby
|
309
|
+
ndev.re.license_rm! "JUNOS410496"
|
310
|
+
->
|
311
|
+
true
|
312
|
+
```
|
313
|
+
Removing all licenses
|
314
|
+
```ruby
|
315
|
+
ndev.re.license_rm! :all
|
316
|
+
->
|
317
|
+
true
|
318
|
+
```
|
319
|
+
|
320
|
+
## `licenses( opts = {} )` <a name="licenses">
|
321
|
+
|
322
|
+
Returns a Hash structure of information gathered from the "show system license" command.
|
323
|
+
|
324
|
+
The following options are supported:
|
325
|
+
```
|
326
|
+
:keys => true
|
327
|
+
```
|
328
|
+
Returns the license key value in ASCII text format.
|
329
|
+
|
330
|
+
Without the `:keys` option:
|
331
|
+
|
332
|
+
```ruby
|
333
|
+
pp ndev.re.licenses
|
334
|
+
->
|
335
|
+
{"JUNOS410496"=>
|
336
|
+
{:state=>"valid",
|
337
|
+
:version=>"2",
|
338
|
+
:serialnumber=>"91730A00092074",
|
339
|
+
:customer=>"LABVSRXJuniper-SEs",
|
340
|
+
:features=>
|
341
|
+
{"all"=>
|
342
|
+
{:description=>"All features",
|
343
|
+
:date_start=>"2013-02-05",
|
344
|
+
:date_end=>"2014-02-06"}}}}
|
345
|
+
```
|
346
|
+
With the `:keys` option:
|
347
|
+
```ruby
|
348
|
+
pp ndev.re.licenses :keys=>true
|
349
|
+
->
|
350
|
+
{"JUNOS410496"=>
|
351
|
+
{:state=>"valid",
|
352
|
+
:version=>"2",
|
353
|
+
:serialnumber=>"91730A00092074",
|
354
|
+
:customer=>"LABVSRXJuniper-SEs",
|
355
|
+
:features=>
|
356
|
+
{"all"=>
|
357
|
+
{:description=>"All features",
|
358
|
+
:date_start=>"2013-02-05",
|
359
|
+
:date_end=>"2014-02-06"}},
|
360
|
+
:key=>
|
361
|
+
"\nJUNOS410496 aeaqec agaia3 27n65m fq4ojr g4ztaq jqgayd\n smrqg4 2aye2m ifbfmu DEADBEF k3tjob sxelkt\n <snip>"}}
|
362
|
+
```
|
363
|
+
|
364
|
+
## `ping( host, opts = {} )` <a name="ping">
|
365
|
+
|
366
|
+
Issues a 'ping' from the Junos target, very handy for troubleshooting. This method will return `true` if the ping action was successful, or `false` otherwise.
|
367
|
+
|
368
|
+
The following options are supported, and they are the same as documented by the Junos techpubs:
|
369
|
+
```
|
370
|
+
:do_not_fragment, :inet, :inet6, :strict,
|
371
|
+
:count, :interface, :interval, :mac_address,
|
372
|
+
:routing_instance, :size, :source, :tos, :ttl, :wait
|
373
|
+
```
|
374
|
+
Here is a ping example that uses the 'do-no-fragment' and 'count' options:
|
375
|
+
```ruby
|
376
|
+
ndev.re.ping "192.168.56.1", :count => 5, :do_not_fragment => true
|
377
|
+
->
|
378
|
+
true
|
379
|
+
```
|