junos-ez-stdlib 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -31,3 +31,10 @@
31
31
  runtime status information about the port
32
32
 
33
33
  RE::Utils - misc updates, and documentation
34
+
35
+ 0.0.16: 2013-05-03
36
+
37
+ RE::Utils - added support for license-key management. Renamed "software" methods from "xxx_software"
38
+ to "software_xxx" to be consistent with other naming usage. Updated docs.
39
+
40
+
data/docs/Facts.md CHANGED
@@ -46,8 +46,8 @@ pp ndev.facts.catalog
46
46
  {:hardwaremodel=>"SRX210H",
47
47
  :serialnumber=>"AD2909AA0096",
48
48
  :hostname=>"srx210",
49
- :domain=>"",
50
- :fqdn=>"srx210",
49
+ :domain=>"workflowsherpas.com",
50
+ :fqdn=>"srx210.workflowsherpas.com",
51
51
  :RE=>
52
52
  {:status=>"OK",
53
53
  :model=>"RE-SRX210H",
@@ -1,4 +1,4 @@
1
- # Junos::Ez::RE::Utils
1
+ # `Junos::Ez::RE::Utils`
2
2
 
3
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, rather than scraping CLI or navigating Junos XML.
4
4
 
@@ -25,29 +25,40 @@ pp ndev.re.uptime
25
25
 
26
26
  # METHODS
27
27
 
28
- ## Information
28
+ ## Informational
29
29
 
30
- - `status` - "show chassis routing-engine" information
31
- - `uptime` - "show system uptime" information
32
- - `system_alarms` - "show system alarms" information
33
- - `chassis_alarms` - "show chassis alarms" information
34
- - `memory` - "show system memory" information
35
- - `users` - "show system users" information
30
+ - [`status`](#status) - "show chassis routing-engine" information
31
+ - [`uptime`](#uptime) - "show system uptime" information
32
+ - [`system_alarms`](#system_alarms) - "show system alarms" information
33
+ - [`chassis_alarms`](#chassis_alarms) - "show chassis alarms" information
34
+ - [`memory`](#memory) - "show system memory" information
35
+ - [`users`](#users) - "show system users" information
36
36
 
37
37
  ## Software Image
38
38
 
39
- - `validate_software?` - "request system software validate..."
40
- - `install_software!` - "request system software add ..."
41
- - `rollback_software!` - "request system software rollback"
39
+ - [`software_validate?`](#software_validate) - "request system software validate..."
40
+ - [`software_install!`](#software_install) - "request system software add ..."
41
+ - [`software_rollback!`](#software_rollback) - "request system software rollback"
42
+ - [`software_images`](#software_images) - indicates current/rollback image file names
43
+
44
+ ## License Management
45
+
46
+ - [`license_install!`](#license_install) - "request system license add"
47
+ - [`license_rm!`](#license_rm) - "request system license delete"
48
+ - [`licenses`](#licenses) - "show system license"
42
49
 
43
50
  ## System Controls
44
51
 
45
- - `reboot!` - "request system reboot" (!! NO CONFIRM !!)
46
- - `shutdown!` - "request system power-off" (!! NO CONFIRM !!)
52
+ - [`reboot!`](#reboot) - "request system reboot" (!! NO CONFIRM !!)
53
+ - [`shutdown!`](#shutdown) - "request system power-off" (!! NO CONFIRM !!)
54
+
55
+ ## Miscellaneous
56
+
57
+ - [`ping`](#ping) - Perform a "ping" command
47
58
 
48
59
  # GORY DETAILS
49
60
 
50
- ## status
61
+ ## `status`
51
62
 
52
63
  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:
53
64
  ```ruby
@@ -66,7 +77,7 @@ pp ndev.re.status
66
77
  :load_avg=>[0.06, 0.13, 0.07]}}
67
78
  ```
68
79
 
69
- ## uptime
80
+ ## `uptime`
70
81
 
71
82
  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:
72
83
  ```ruby
@@ -82,7 +93,7 @@ pp ndev.re.uptime
82
93
  :last_config=>
83
94
  {:at=>"2013-04-27 15:00:55 UTC", :ago=>"5d 02:41", :by=>"root"}}}
84
95
  ```
85
- ## system_alarms
96
+ ## `system_alarms`
86
97
 
87
98
  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:
88
99
  ```ruby
@@ -94,7 +105,7 @@ pp ndev.re.system_alarms
94
105
  :type=>"Configuration"}]
95
106
  ```
96
107
 
97
- ## chassis_alarms
108
+ ## `chassis_alarms`
98
109
 
99
110
  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:
100
111
  ```ruby
@@ -103,7 +114,7 @@ pp ndev.re.chassis_alarms
103
114
  nil
104
115
  ```
105
116
 
106
- ## memory
117
+ ## `memory`
107
118
 
108
119
  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.
109
120
  ```ruby
@@ -143,7 +154,7 @@ pp ndev.re.memory
143
154
  ]}}
144
155
  ```
145
156
 
146
- ## users
157
+ ## `users`
147
158
 
148
159
  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:
149
160
  ```ruby
@@ -157,24 +168,49 @@ pp ndev.re.users
157
168
  :command=>"-cli (cli)"}]
158
169
  ```
159
170
 
160
- ## validate_software?
171
+ ## `software_images`
172
+ Returns a Hash of the currnet and rollback image file-names.
173
+ ```ruby
174
+ pp ndev.re.software_images
175
+ ->
176
+ {:rollback=>"junos-12.1I20130415_junos_121_x44_d15.0-576602-domestic",
177
+ :current=>"junos-12.1I20130322_2104_slt-builder-domestic"}
178
+ ```
179
+
180
+ ## `software_validate?` <a name="software_validate">
161
181
 
162
182
  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:
163
183
  ```ruby
164
- unless ndev.re.validate_software?( file_on_junos )
184
+ unless ndev.re.software_validate?( file_on_junos )
165
185
  puts "The softare does not validate!"
166
186
  ndev.close
167
187
  exit 1
168
188
  end
169
189
  ```
170
190
 
171
- ## install_software!
191
+ ## `software_install!( opts = {} )` <a name="software_install">
172
192
 
173
- Performs the equivalent of "request system software add ..." and returns `true` if the operation was successful or a String indicating the error message. The following example illustrates an error message:
193
+ Performs the equivalent of "request system software add ..." and returns `true` if the operation was successful or a String indicating the error message.
194
+
195
+ The following options are supported:
196
+ ```
197
+ :no_validate => true
198
+ ```
199
+ 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.
200
+ ```
201
+ :unlink => true
202
+ ```
203
+ Instructs Junos to remove the software package file (.tgz) after the installation has completed.
204
+ ```
205
+ :reboot => true
206
+ ```
207
+ Instructs Junos to reboot the RE after the software has been installed successfully.
208
+
209
+ The following example illustrates an error message:
174
210
 
175
211
  ```ruby
176
212
  puts "Installing image ... please wait ..."
177
- rc = ndev.re.install_software!( :package => file_on_junos, :no_validate => true )
213
+ rc = ndev.re.software_install!( :package => file_on_junos, :no_validate => true )
178
214
  if rc != true
179
215
  puts rc
180
216
  end
@@ -203,23 +239,22 @@ WARNING: Use 'request system storage cleanup' and
203
239
  WARNING: the 'unlink' option to improve the chances of success
204
240
  ```
205
241
 
206
- ## rollback_software!
242
+ ## `software_rollback!` <a name="software_rollback">
207
243
 
208
244
  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:
209
245
  ```ruby
210
- pp ndev.re.rollback_software!
246
+ pp ndev.re.software_rollback!
211
247
  ->
212
- "Restoring boot file package\njunos-12.1I20130422_2129_jni-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"
248
+ "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"
213
249
  ```
214
250
  An unsuccessful rollback would look like this:
215
251
  ```ruby
216
- pp ndev.re.rollback_software!
252
+ pp ndev.re.software_rollback!
217
253
  ->
218
254
  "WARNING: Cannot rollback, /packages/junos is not valid"
219
255
  ```
220
256
 
221
- ## reboot!( opts = {} )
222
-
257
+ ## `reboot!( opts = {} )` <a name="reboot">
223
258
  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.
224
259
 
225
260
  The option Hash provides for the following controls:
@@ -232,7 +267,7 @@ Instructs Junos to reboot after `:in` minutes from the time of calling `reboot!`
232
267
  ```
233
268
  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.
234
269
 
235
- ## shutdown!( opts = {} )
270
+ ## `shutdown!( opts = {} )` <a name="shutdown">
236
271
 
237
272
  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.
238
273
 
@@ -246,3 +281,98 @@ Instructs Junos to reboot after `:in` minutes from the time of calling `reboot!`
246
281
  ```
247
282
  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.
248
283
 
284
+ ## `license_install!( opts = {} )` <a name="license_install">
285
+ Installs the provided license. This method will return `true` if the key is installed correctly or a String message indicating the error.
286
+
287
+ The following options are supported, you **MUST** use either `:key` or `:filename` to provide the license ASCII-text.
288
+ ```
289
+ :key
290
+ ```
291
+ The ASCII-text of the key.
292
+ ```
293
+ :filename
294
+ ```
295
+ The path to the file on the server (not Junos) that contains the ASCII-text of the key.
296
+
297
+ The following illustates how to load a key from the server filesystem.
298
+ ```ruby
299
+ ndev.re.license_install! :filename=>'/cygwin/home/jschulman/license.txt'
300
+ ->
301
+ true
302
+ ```
303
+ ## `license_rm!( license_id )` <a name="license_rm">
304
+ 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.
305
+
306
+ Removing a specific license:
307
+ ```ruby
308
+ ndev.re.license_rm! "JUNOS410496"
309
+ ->
310
+ true
311
+ ```
312
+ Removing all licenses
313
+ ```ruby
314
+ ndev.re.license_rm! :all
315
+ ->
316
+ true
317
+ ```
318
+
319
+ ## `licenses( opts = {} )` <a name="licenses">
320
+
321
+ Returns a Hash structure of information gathered from the "show system license" command.
322
+
323
+ The following options are supported:
324
+ ```
325
+ :keys => true
326
+ ```
327
+ Returns the license key value in ASCII text format.
328
+
329
+ Without the `:keys` option:
330
+
331
+ ```ruby
332
+ pp ndev.re.licenses
333
+ ->
334
+ {"JUNOS410496"=>
335
+ {:state=>"valid",
336
+ :version=>"2",
337
+ :serialnumber=>"91730A00092074",
338
+ :customer=>"LABVSRXJuniper-SEs",
339
+ :features=>
340
+ {"all"=>
341
+ {:description=>"All features",
342
+ :date_start=>"2013-02-05",
343
+ :date_end=>"2014-02-06"}}}}
344
+ ```
345
+ With the `:keys` option:
346
+ ```ruby
347
+ pp ndev.re.licenses :keys=>true
348
+ ->
349
+ {"JUNOS410496"=>
350
+ {:state=>"valid",
351
+ :version=>"2",
352
+ :serialnumber=>"91730A00092074",
353
+ :customer=>"LABVSRXJuniper-SEs",
354
+ :features=>
355
+ {"all"=>
356
+ {:description=>"All features",
357
+ :date_start=>"2013-02-05",
358
+ :date_end=>"2014-02-06"}},
359
+ :key=>
360
+ "\nJUNOS410496 aeaqec agaia3 27n65m fq4ojr g4ztaq jqgayd\n smrqg4 2aye2m ifbfmu DEADBEF k3tjob sxelkt\n <snip>"}}
361
+ ```
362
+
363
+ ## `ping( host, opts = {} )` <a name="ping">
364
+
365
+ 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.
366
+
367
+ The following options are supported, and they are the same as documented by the Junos techpubs:
368
+ ```
369
+ :do_not_fragment, :inet, :inet6, :strict,
370
+ :count, :interface, :interval, :mac_address,
371
+ :routing_instance, :size, :source, :tos, :ttl, :wait
372
+ ```
373
+ Here is a ping example that uses the 'do-no-fragment' and 'count' options:
374
+ ```ruby
375
+ ndev.re.ping "192.168.56.1", :count => 5, :do_not_fragment => true
376
+ ->
377
+ true
378
+ ```
@@ -38,23 +38,27 @@ file_on_junos = '/var/tmp/' + file_name
38
38
 
39
39
  def copy_file_to_junos( ndev, file_on_server, file_on_junos )
40
40
  mgr_i = cur_i = 0
41
+ backitup = 8.chr * 4
41
42
  ndev.scp.upload!( file_on_server, file_on_junos ) do |ch, name, sent, total|
42
43
  pct = (sent.to_f / total.to_f) * 100
43
44
  mgr_i = pct.to_i
44
45
  if mgr_i != cur_i
45
46
  cur_i = mgr_i
46
- puts cur_i.to_s + "%"
47
+ printf "%4s", cur_i.to_s + "%"
48
+ print backitup
47
49
  end
48
50
  end
49
51
  end
50
52
 
51
- puts "Copying file to Junos ..."
53
+ print "Copying file to Junos ... "
52
54
  copy_file_to_junos( ndev, file_on_server, file_on_junos )
55
+ puts "OK! "
53
56
 
54
57
  ###
55
58
  ### check the MD5 checksum values
56
59
  ###
57
60
 
61
+ print "Validating MD5 checksum ... "
58
62
  md5_on_s = Digest::MD5.file( file_on_server ).to_s
59
63
  md5_on_j = ndev.fs.checksum( :md5, file_on_junos )
60
64
 
@@ -64,27 +68,32 @@ if md5_on_s != md5_on_j
64
68
  exit 1
65
69
  end
66
70
 
67
- puts "MD5 checksum matches ... proceeding ..."
68
- puts "Validating image ... please wait ..."
71
+ puts "OK!"
72
+
73
+ print "Validating image ... please wait ... "
69
74
 
70
- unless ndev.re.validate_software?( file_on_junos )
75
+ unless ndev.re.software_validate?( file_on_junos )
71
76
  puts "The softare does not validate!"
72
77
  ndev.close
73
78
  exit 1
74
79
  end
75
80
 
76
- puts "Installing image ... please wait ..."
77
- rc = ndev.re.install_software!( :package => file_on_junos, :no_validate => true )
81
+ puts "OK!"
82
+
83
+ print "Installing image ... please wait ... "
84
+ rc = ndev.re.software_install!( :package => file_on_junos, :no_validate => true )
78
85
  if rc != true
79
86
  puts rc
80
87
  end
81
88
 
89
+ puts "OK!"
90
+
82
91
  ### use pry if you want to 'look around'
83
92
  ## -> binding.pry
84
93
 
85
- ### if you wanted to reboot the system now, you coud
86
- ### do the following ...
87
-
88
- ## -> ndev.re.reboot!
94
+ if ARGV[1] == 'reboot'
95
+ puts "Rebooting!"
96
+ ndev.re.reboot!
97
+ end
89
98
 
90
99
  ndev.close
@@ -11,7 +11,7 @@ module Junos; end
11
11
 
12
12
  module Junos::Ez
13
13
 
14
- VERSION = "0.0.15"
14
+ VERSION = "0.0.16"
15
15
 
16
16
  ### ---------------------------------------------------------------
17
17
  ### rpc_errors - decodes the XML into an array of error/Hash
@@ -6,15 +6,23 @@ a misc. collection of methods that perform basic automation tasks
6
6
  like upgrading software or getting process information. The
7
7
  following lists the methods and the equivalent Junos CLI commands
8
8
 
9
- - status: show chassis routing-engine
10
- - uptime: show system uptime
11
- - system_alarms: show system alarms
12
- - chassis_alarms: show chassis alarms
13
- - memory: show system memeory
14
- - users: show system users
15
- - validate_software?: request system software validate
16
- - install_software!: request system software add
17
- - rollback_software!: request system software rollback
9
+ - status show chassis routing-engine
10
+ - uptime show system uptime
11
+ - system_alarms show system alarms
12
+ - chassis_alarms show chassis alarms
13
+ - memory show system memeory
14
+ - users show system users
15
+
16
+ - software_install! request system software add
17
+ - software_rollback! request system software rollback
18
+ - software_validate? request system software validate
19
+ - software_images - provides image file names for current/rollback
20
+
21
+ - license_install! request system license add !! TBD !!
22
+ - license_rm! request system license delete
23
+ - license_save request system license save !! TBD !!
24
+ - licenses show system license
25
+
18
26
  - reboot!: request system reboot (no confirm!!)
19
27
  - shutdown!: request system power-off (no confirm!!)
20
28
 
@@ -179,11 +187,17 @@ class Junos::Ez::RE::Provider < Junos::Ez::Provider::Parent
179
187
  users_a
180
188
  end
181
189
 
190
+ ### ===============================================================
191
+ ###
192
+ ### Software related methods
193
+ ###
194
+ ### ===============================================================
195
+
182
196
  ### ---------------------------------------------------------------
183
- ### validate_software? - request system software validate ...
197
+ ### software_validate? - request system software validate ...
184
198
  ### ---------------------------------------------------------------
185
199
 
186
- def validate_software?( package )
200
+ def software_validate?( package )
187
201
  got = @ndev.rpc.request_package_validate(:package_name => package).parent
188
202
  errcode = got.xpath('package-result').text.to_i
189
203
  return true if errcode == 0
@@ -193,15 +207,16 @@ class Junos::Ez::RE::Provider < Junos::Ez::Provider::Parent
193
207
  end
194
208
 
195
209
  ### ---------------------------------------------------------------
196
- ### install_software! - request system software add ...
210
+ ### software_install! - request system software add ...
197
211
  ### ---------------------------------------------------------------
198
212
 
199
- def install_software!( opts = {} )
213
+ def software_install!( opts = {} )
200
214
  raise ArgumentError "missing :package" unless opts[:package]
201
215
 
202
216
  args = { :package_name => opts[:package] }
203
217
  args[:no_validate] = true if opts[:no_validate]
204
218
  args[:unlink] = true if opts[:unlink]
219
+ args[:reboot] = true if opts[:reboot]
205
220
 
206
221
  got = @ndev.rpc.request_package_add( args ).parent
207
222
  errcode = got.xpath('package-result').text.to_i
@@ -212,14 +227,37 @@ class Junos::Ez::RE::Provider < Junos::Ez::Provider::Parent
212
227
  end
213
228
 
214
229
  ### ---------------------------------------------------------------
215
- ### rollback_software! - request system software rollback
230
+ ### software_rollback! - request system software rollback
216
231
  ### ---------------------------------------------------------------
217
232
 
218
- def rollback_software!
233
+ def software_rollback!
219
234
  got = @ndev.rpc.request_package_rollback
220
235
  got.text.strip
221
236
  end
237
+
238
+ def software_images
239
+ ls_pkgs = @ndev.rpc.file_list(:path=>'/packages')
240
+ symlink = ls_pkgs.xpath('//file-symlink-target')[0]
241
+ if symlink
242
+ ls_pkgs = @ndev.rpc.file_list(:path => symlink.text.strip)
243
+ end
244
+
245
+ junos_symlink = ls_pkgs.xpath('//file-information[normalize-space(file-name) = "junos"]')[0]
246
+ junos_old_symlink = ls_pkgs.xpath('//file-information[normalize-space(file-name) = "junos.old"]')[0]
247
+
248
+ ret_h = {}
249
+ ret_h[:rollback] = (junos_old_symlink) ? junos_old_symlink.xpath('file-symlink-target').text.strip : nil
250
+ ret_h[:current] = (junos_symlink) ? junos_symlink.xpath('file-symlink-target').text.strip : ret_h[:rollback]
251
+
252
+ ret_h
253
+ end
222
254
 
255
+ ### ===============================================================
256
+ ###
257
+ ### Misc Routing Engine Commands & Controls
258
+ ###
259
+ ### ===============================================================
260
+
223
261
  ### ---------------------------------------------------------------
224
262
  ### reboot! - request system reboot (no confirm!!)
225
263
  ### ---------------------------------------------------------------
@@ -263,15 +301,14 @@ class Junos::Ez::RE::Provider < Junos::Ez::Provider::Parent
263
301
  got.xpath('//request-reboot-status').text.strip
264
302
  end
265
303
 
266
- def ping( opts = {} )
304
+ def ping( host, opts = {} )
267
305
  arg_options = [
268
- :host,
269
306
  :do_not_fragment, :inet, :inet6, :strict,
270
307
  :count, :interface, :interval, :mac_address,
271
308
  :routing_instance, :size, :source, :tos, :ttl, :wait
272
309
  ]
273
310
 
274
- args = {}
311
+ args = {:host => host}
275
312
  opts.each do |k,v|
276
313
  if arg_options.include? k
277
314
  args[k] = v
@@ -290,6 +327,132 @@ class Junos::Ez::RE::Provider < Junos::Ez::Provider::Parent
290
327
 
291
328
  return (block_given?) ? yield(got) : false
292
329
  end
330
+
331
+ ### ===============================================================
332
+ ###
333
+ ### License related methods
334
+ ###
335
+ ### ===============================================================
336
+
337
+ ## ----------------------------------------------------------------
338
+ ## - retrieve Hash of license information.
339
+ ##
340
+ ## By default this will provide the license installed
341
+ ## information.
342
+ ##
343
+ ## --- returns ---
344
+ ## - Hash of data if there are licenses
345
+ ## - nil if no licenses
346
+ ##
347
+ ## --- options ---
348
+ ## :keys => true
349
+ ## Will include the key-text for the license
350
+ ##
351
+ ## ----------------------------------------------------------------
352
+
353
+ def licenses( opts = {} )
354
+
355
+ got = @ndev.rpc.get_license_summary_information
356
+ licenses = got.xpath('license-information/license')
357
+ return nil if licenses.empty?
358
+
359
+ ret_h = {}
360
+ licenses.each do |lic|
361
+ lic_h = {}
362
+ ret_h[lic.xpath('name').text.strip] = lic_h
363
+
364
+ lic_h[:state] = lic.xpath('license-state').text.strip
365
+ lic_h[:version] = lic.xpath('license-version').text.strip
366
+ lic_h[:serialnumber] = lic.xpath('software-sn').text.strip
367
+ lic_h[:customer] = lic.xpath('customer-reference').text.strip
368
+
369
+ features = lic.xpath('feature-block/feature')
370
+ unless features.empty?
371
+ feats_h = {}
372
+ lic_h[:features] = feats_h
373
+ features.each do |feat|
374
+ feat_h = {}
375
+ feats_h[feat.xpath('name').text.strip] = feat_h
376
+ feat_h[:description] = feat.xpath('description').text.strip
377
+ v_info = feat.xpath('validity-information')[0]
378
+ case v_info.xpath('validity-type').text.strip
379
+ when 'date-based'
380
+ feat_h[:date_start] = v_info.xpath('start-date').text.strip
381
+ feat_h[:date_end] = v_info.xpath('end-date').text.strip
382
+ end
383
+ end # each features
384
+ end # if features
385
+ end # each license
386
+
387
+ ## now check to see if the :keys have been requested. if so
388
+ ## then get that data, and store back into the return Hash.
389
+
390
+ if opts[:keys]
391
+ got = @ndev.rpc.get_license_key_information
392
+ got.xpath('license-key').each do |key|
393
+ name = key.xpath('name').text.strip
394
+ ret_h[name][:key] = key.xpath('key-data').text
395
+ end
396
+ end
397
+
398
+ ret_h
399
+ end
400
+
401
+ ## ----------------------------------------------------------------
402
+ ## add a license
403
+ ##
404
+ ## --- returns ---
405
+ ## true - key added OK
406
+ ## String - error message otherwise
407
+ ##
408
+ ## --- options ---
409
+ ## :key => String
410
+ ## The key text
411
+ ##
412
+ ## :filename => String
413
+ ## Path to licence-file on server
414
+ ## ----------------------------------------------------------------
415
+
416
+ def license_install!( opts = {} )
417
+ args = {}
418
+ if opts[:key]
419
+ args[:key_data] = opts[:key]
420
+ elsif opts[:filename]
421
+ args[:key_data] = File.read(opts[:filename]).strip
422
+ end
423
+ got = @ndev.rpc.request_license_add( args )
424
+ success = got.xpath('add-success')[0]
425
+ return true if success
426
+ got.xpath('//message').text.strip
427
+ end
428
+
429
+ ## ----------------------------------------------------------------
430
+ ## remove a license
431
+ ##
432
+ ## license_id is the String license-id or the special name :all
433
+ ## ----------------------------------------------------------------
434
+
435
+ def license_rm!( license_id )
436
+ args = {}
437
+ if license_id == :all
438
+ args[:all] = true
439
+ else
440
+ args[:license_identifier] = license_id
441
+ end
442
+ got = @ndev.rpc.request_license_delete( args )
443
+ ### @@@ need to test return cases ... for now, just return
444
+ ### the 'got' XML
445
+ got
446
+ end
447
+
448
+ ## ----------------------------------------------------------------
449
+ ## save licenses (plr!) to a file
450
+ ## ----------------------------------------------------------------
451
+
452
+ def license_save( opts = {} )
453
+ raise StandardError, "not implemented yet"
454
+ end
455
+
293
456
  end
294
457
 
295
458
  ### -----------------------------------------------------------------
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.15
4
+ version: 0.0.16
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-02 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: netconf