enfcli 3.7.0.pre.alpha → 3.8.0.pre.alpha

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db8db881fd3ddf2776c8b0d4f0eac562fe296866c7a5c4ceb36dd3a0f1f5bf43
4
- data.tar.gz: 85d26d33f9d9019dd5f37a894d1ff748f2c1162b2ff2eb25fe8547fda7165248
3
+ metadata.gz: fef441dacffa981c271943ac40b3e5f51578398af87480e38ce66b3c1e4e1ecb
4
+ data.tar.gz: a4a9cf8bf7744a3c531acd0b8910486e77d48c1ee20d07d5bdb21eb6640560e2
5
5
  SHA512:
6
- metadata.gz: 02c0690082f3a6457f7e33a3ec053a5cec315bc7a61fef59ffc3c72a650a4b6bf4fec2b0e237acc775928e9717a64dca536cc543ec06a7dde5853bd96b6f17a0
7
- data.tar.gz: deaaa92d2a9ec1b57f628ac10fa0390fc1530e425b698f87ea1a36d0f679414a3682eeb8bc278cc7ee6bd9da3012fa2791fc04dd5d89b65e27ae801165805459
6
+ metadata.gz: 12a28d52907530654463ecb3aa8a836ea5e09fcadb255ca4b1ea39c53e7990d227db5a679baf40fe125d8a7bd1cbc7bf7acd9588a90763bc3f6ac71b3136009e
7
+ data.tar.gz: ceb7a1bea95832a792842fda3307d5fc9dfe86b73ba39d7b4756fe2f4a6dc41df306ccd3b553c13db92f3b3186443ab077779cb0facab08a1cd94a5eeb7dfbcc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enfcli (3.7.0.pre.alpha)
4
+ enfcli (3.8.0.pre.alpha)
5
5
  rest-client (~> 2.0)
6
6
  terminal-table
7
7
  thor (~> 0.20.0)
data/lib/enfapi.rb CHANGED
@@ -241,6 +241,14 @@ module EnfApi
241
241
  EnfApi::API.instance.get "/api/captive/v1/device/#{dev_id}"
242
242
  end
243
243
 
244
+ # Update a device
245
+ ## NO_TEST
246
+ def update_device(id, dev_updates)
247
+ json = EnfApi.to_json(dev_updates)
248
+ EnfApi::API.instance.put "/api/captive/v1/device/#{id}", json
249
+ end
250
+
251
+
244
252
  # Get the status of a device
245
253
  ## NO_TEST
246
254
  def get_device_status(dev_id)
@@ -158,9 +158,13 @@ module EnfCli
158
158
  }
159
159
  }
160
160
  dev_name = options[:'device-name']
161
- profile = options[:profile_id]
161
+ profile_id = options[:profile_id]
162
162
  new_device_hash[:device_name] = dev_name if dev_name
163
- new_device_hash[:profile] = profile if profile
163
+ if profile_id
164
+ profile_hash = {}
165
+ profile_hash[:id] = profile_id
166
+ new_device_hash[:profile] = profile_hash
167
+ end
164
168
 
165
169
  # send the new device request
166
170
  device_data = EnfApi::Captive.instance.create_device new_device_hash
@@ -197,6 +201,34 @@ module EnfCli
197
201
  end
198
202
  end
199
203
 
204
+ desc 'update-device',
205
+ 'Update an existing device record with the values specified.'
206
+ method_option :'device-id', type: :string, required: true, banner: 'DEVICE-ID',
207
+ desc: 'DEVICE-ID is either the device serial number or its ipv6 address.'
208
+ method_option :'device-name', type: :string, default: nil, banner: 'DEVICE-NAME',
209
+ desc: 'User-defined name for the device.'
210
+ method_option :'profile-id', type: :string, default: nil, banner: 'PROFILE_ID',
211
+ desc: 'UUID of the profile that the device will use. The profile must already exist.'
212
+ def update_device
213
+ try_with_rescue_in_session do
214
+ id = options[:'device-id']
215
+ name = options[:'device-name']
216
+ profile_id = options[:'profile-id']
217
+
218
+ raise "At least one option needs to change." if name == nil && profile_id == nil
219
+
220
+ update_hash = {}
221
+ update_hash[:device_name] = name if name
222
+ if profile_id
223
+ update_hash[:profile] = {}
224
+ update_hash[:profile][:id] = profile_id
225
+ end
226
+
227
+ data = EnfApi::Captive.instance.update_device id, update_hash
228
+ display_device data
229
+ end
230
+ end
231
+
200
232
  desc 'get-device-status',
201
233
  'Get the latest status of the specified device.'
202
234
  method_option :'device-id', required: true, type: :string,
@@ -419,10 +451,8 @@ module EnfCli
419
451
  mac_addrs = device_data[:mac_address]
420
452
  firmware = device_data[:firmware_version]
421
453
  firmware = '< not available >' unless firmware
422
- profile_id = device_data[:profile]
423
- profile_id = '< not available >' unless profile_id
454
+ profile = device_data[:profile]
424
455
  status = device_data[:status]
425
- status = '< not available >' unless status
426
456
 
427
457
  say "Serial Number : #{device_data[:serial_number]}"
428
458
  say "Device Name : #{name}"
@@ -436,11 +466,43 @@ module EnfCli
436
466
  say " 4 : #{mac_addrs[:'4']}"
437
467
  end
438
468
  say "Firmware Version : #{firmware}"
439
- say "Profile ID : #{profile_id}"
440
- say "Status : #{status}"
469
+ if profile
470
+ say "Profile :"
471
+ display_profile profile, true
472
+ else
473
+ say "Profile : < not available >"
474
+ end
475
+ display_device_status_summary status
441
476
  say ''
442
477
  end
443
478
 
479
+ #
480
+ # display the status summary
481
+ #
482
+ def display_device_status_summary (device_status)
483
+ if device_status
484
+ sn = device_status[:serial_number]
485
+ mode = device_status[:router_mode]
486
+ mode = device_status[:mode] unless mode
487
+ mode = "\n" unless mode
488
+ wifi = device_status[:wifi]
489
+
490
+ say 'Status :'
491
+ say " Serial Number : #{sn}" if sn
492
+ say " Router Mode : #{mode}"
493
+
494
+ if wifi
495
+ connected = wifi[:connected]
496
+ connected = " < unknown >" unless connected
497
+ ssid = wifi[:SSID]
498
+ say " wifi connected: #{connected}"
499
+ say " SSID : #{ssid}" if ssid
500
+ end
501
+ else
502
+ say "Status : < not available >"
503
+ end
504
+ end
505
+
444
506
  #
445
507
  # display the status of the device.
446
508
  # status is a hash matching the json structure
@@ -518,26 +580,39 @@ module EnfCli
518
580
  #
519
581
  # Display profile detail
520
582
  #
521
- def display_profile (profile)
522
- say "Name :#{profile[:name]}"
523
- say "Profile ID :#{profile[:id]}"
524
- say "Configuration version :#{profile[:config][:version]}"
525
- say "Mode :#{profile[:config][:mode]}"
526
- display_wifi_summary profile[:config][:wifi]
583
+ def display_profile (profile, summary = false)
584
+ if summary
585
+ indent = ' '
586
+ else
587
+ indent = ''
588
+ end
589
+
590
+ say indent + "Name : #{profile[:name]}"
591
+ say indent + "Profile ID : #{profile[:id]}"
592
+ say indent + "Configuration version : #{profile[:config][:version]}"
593
+ unless summary
594
+ say "Mode :#{profile[:config][:mode]}"
595
+ display_wifi_summary profile[:config][:wifi]
596
+ end
527
597
  end
528
598
 
529
599
  #
530
600
  # Display summary of the WIFI configuration info
531
601
  #
532
602
  def display_wifi_summary (wifi)
533
- say "Wifi config :"
534
- say " id :#{wifi[:id]}"
535
- # TODO - make accessible only to Xaptum admins
536
- say " domain :#{wifi[:domain]}"
537
- say " name :#{wifi[:name]}"
538
- desc = wifi[:description]
539
- say " description :#{desc}" if desc
540
- say " config version :#{wifi[:version]}"
603
+ if wifi
604
+ say "Wifi config :"
605
+ say " id :#{wifi[:id]}"
606
+ # TODO - make accessible only to Xaptum admins
607
+ say " domain :#{wifi[:domain]}"
608
+ say " name :#{wifi[:name]}"
609
+ desc = wifi[:description]
610
+ say " description :#{desc}" if desc
611
+ say " config version :#{wifi[:version]}"
612
+ else
613
+ say "Wifi config : < not configured >"
614
+ end
615
+
541
616
  end
542
617
 
543
618
  #
@@ -14,5 +14,5 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module EnfCli
17
- VERSION = '3.7.0-alpha'
17
+ VERSION = '3.8.0-alpha'
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enfcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0.pre.alpha
4
+ version: 3.8.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Venkatakumar Srinivasan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor