Class: LMC::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/lmc/Device.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Device

Returns a new instance of Device.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lmc/Device.rb', line 7

def initialize(data)
  @id = data['id']
  @comment = data['comment']
  @name = data['status']['name']
  @serial = data['status']['serial']
  @model = data['status']['model']
  @heartbeatstate = data['status']['heartbeatState']
  @status = data['status']
  @account = data['account']
  @cloud = @account.cloud
  @cloud ||= Cloud.instance
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def 
  @account
end

#cloudObject (readonly)

Returns the value of attribute cloud.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def cloud
  @cloud
end

#heartbeatstateObject (readonly)

Returns the value of attribute heartbeatstate.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def heartbeatstate
  @heartbeatstate
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def id
  @id
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def name
  @name
end

#serialObject (readonly)

Returns the value of attribute serial.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def serial
  @serial
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/lmc/Device.rb', line 5

def status
  @status
end

Class Method Details

.get_for_account(account) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lmc/Device.rb', line 28

def self.()
  cloud = Cloud.instance
  cloud.auth_for_accounts [.id]
  list = cloud.get ['cloud-service-devices', 'accounts', .id, 'devices']
  if list.code != 200
    puts "Error getting devices: #{list.body.message}"
    exit 1
  end
  devices = list.map do |data|
    data['account'] = 
    LMC::Device.new(data)
  end
  devices
end

.get_for_account_id(account_id) ⇒ Object



43
44
45
# File 'lib/lmc/Device.rb', line 43

def self.()
   Account.get()
end

Instance Method Details

#configObject



51
52
53
# File 'lib/lmc/Device.rb', line 51

def config
  LMC::DeviceConfig.new(@cloud, @account, self)
end

#config_stateObject



47
48
49
# File 'lib/lmc/Device.rb', line 47

def config_state
  @config_state ||= get_config_state
end

#get_monitor_widgets(widget_item_ids) ⇒ Object



24
25
26
# File 'lib/lmc/Device.rb', line 24

def get_monitor_widgets(widget_item_ids)
  @cloud.get ['cloud-service-monitoring', @account.id, 'devices', @id, 'monitordata'], :widgetItemIds => widget_item_ids.join(',')
end

#hwmask_hexObject



63
64
65
# File 'lib/lmc/Device.rb', line 63

def hwmask_hex
  format format '%#010x', status['hwMask']
end

#monitor_record_groupObject



59
60
61
# File 'lib/lmc/Device.rb', line 59

def monitor_record_group
  'DEVICE'
end

#record(name) ⇒ Object



55
56
57
# File 'lib/lmc/Device.rb', line 55

def record(name)
  MonitoringRecord.new(@cloud, @account, self, name)
end

#set_config_for_account(config, account) ⇒ Object



20
21
22
# File 'lib/lmc/Device.rb', line 20

def (config, )
  @cloud.put ['cloud-service-config', 'configbuilder', 'accounts', .id, 'devices', @id, 'ui'], config
end