Class: LMC::DeviceConfig
- Inherits:
-
Object
- Object
- LMC::DeviceConfig
- Defined in:
- lib/lmc/config/device_config.rb
Overview
Represents a device config in LMC
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #confighash ⇒ Object
- #configjson ⇒ Object
- #current_device_type ⇒ Object
-
#descriptive_confighash ⇒ Object
Returns a hash similar to #confighash but with the OIDs replaced with more meaningful descriptions.
- #dscui ⇒ Object
- #feature_mask_lower32_hex ⇒ String
-
#initialize(cloud, account, device) ⇒ DeviceConfig
constructor
def url_stringtable [‘cloud-service-config’, ‘configdsc’, ‘stringtable’, dscui] end.
- #items ⇒ Object
- #lcf ⇒ Object
- #lcf_device_version ⇒ Object
-
#lcf_feature_id_string ⇒ String
Gives the feature IDs as a string like this: “IDs:2,3,f”.
- #url_configbuilder ⇒ Object
- #url_state ⇒ Object
- #url_ticket ⇒ Object
Constructor Details
#initialize(cloud, account, device) ⇒ DeviceConfig
def url_stringtable
['cloud-service-config', 'configdsc', 'stringtable', dscui['stringtableId']]
end
32 33 34 35 36 37 38 39 40 |
# File 'lib/lmc/config/device_config.rb', line 32 def initialize(cloud, account, device) @cloud = cloud @account = account @device = device @response = nil @ticket_id = nil # state returns an object with each requested device id pointing to a state object. @state = @cloud.get(url_state, deviceIds: @device.id.to_s).body[@device.id] end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/lmc/config/device_config.rb', line 6 def state @state end |
Instance Method Details
#confighash ⇒ Object
46 47 48 |
# File 'lib/lmc/config/device_config.rb', line 46 def confighash items.to_h end |
#configjson ⇒ Object
42 43 44 |
# File 'lib/lmc/config/device_config.rb', line 42 def configjson confighash.to_json end |
#current_device_type ⇒ Object
98 99 100 |
# File 'lib/lmc/config/device_config.rb', line 98 def current_device_type OpenStruct.new JSON.parse state['currentDeviceType'] end |
#descriptive_confighash ⇒ Object
Returns a hash similar to #confighash but with the OIDs replaced with more meaningful descriptions.
54 55 56 57 58 59 |
# File 'lib/lmc/config/device_config.rb', line 54 def descriptive_confighash item_map = dscui.item_by_id_map confighash.map { |k, v| [item_map[k].description, v] }.to_h end |
#dscui ⇒ Object
65 66 67 |
# File 'lib/lmc/config/device_config.rb', line 65 def dscui @dscui ||= DeviceDSCUi.new @device end |
#feature_mask_lower32_hex ⇒ String
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/lmc/config/device_config.rb', line 104 def feature_mask_lower32_hex feature_mask = 0 lower_features = current_device_type.features.select { |feature| feature < 32 } lower_features.each do |feature_pos| feature = 2**feature_pos feature_mask = feature_mask | feature end if feature_mask == 0 '0x00000000' else format '%#010x', feature_mask end end |
#items ⇒ Object
61 62 63 |
# File 'lib/lmc/config/device_config.rb', line 61 def items response.items end |
#lcf ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/lmc/config/device_config.rb', line 69 def lcf # lfc format findings: # group headings in {} do not matter # indentation does not matter # table oids need to be enclosed in <> # table cell oids need to be enclosed in () and should follow table oids result = '' result += lcf_header items.each do |key, value| if value.instance_of? String result += "#{key} = #{value}\n" elsif value.instance_of? Hash rows = value['rows'] col_ids = value['colIds'] if rows.length > 0 result += "<#{key}>\n" rows.each_with_index { |row, index| row.each_with_index { |col, col_index| result += "(#{key}.#{index + 1}.#{col_ids[col_index]}) = #{col}\n"} } end else raise 'Unexpected value in config items: ' + value.class.to_s end end result += end |
#lcf_device_version ⇒ Object
118 119 120 121 122 123 |
# File 'lib/lmc/config/device_config.rb', line 118 def lcf_device_version v = 'v' v += "#{@device.status['fwMajor']}." v += "#{@device.status['fwMinor']}." v + format('%04d', @device.status['fwBuild']) end |
#lcf_feature_id_string ⇒ String
Gives the feature IDs as a string like this: “IDs:2,3,f”
128 129 130 131 |
# File 'lib/lmc/config/device_config.rb', line 128 def lcf_feature_id_string hex_features = current_device_type.features.map { |feature| feature.to_s 16 } "IDs:#{hex_features.join(',')}" end |
#url_configbuilder ⇒ Object
8 9 10 11 |
# File 'lib/lmc/config/device_config.rb', line 8 def url_configbuilder ['cloud-service-config', 'configbuilder', 'accounts', @account.id, 'devices', @device.id, 'ui'] end |
#url_state ⇒ Object
24 25 26 |
# File 'lib/lmc/config/device_config.rb', line 24 def url_state %W(cloud-service-config configdevice accounts #{@account.id} state) end |
#url_ticket ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lmc/config/device_config.rb', line 13 def url_ticket ['cloud-service-config', 'configbuilder', 'accounts', @account.id, 'devices', @device.id, 'tickets', @ticket_id] end |