class Innologix::Supervisor

Attributes

client[RW]
created_at[RW]
device_types[RW]
error[RW]
groups[RW]
id[RW]
ip[RW]
name[RW]
status[RW]
storage[RW]
storage_id[RW]
updated_at[RW]

Public Class Methods

new(h = {}) click to toggle source
# File lib/innologix/supervisor.rb, line 18
def initialize(h = {})
  h.each { |k, v| public_send("#{k}=", v) }
  @client = Client.default
end

Public Instance Methods

check_status(callback = nil) click to toggle source
# File lib/innologix/supervisor.rb, line 136
def check_status(callback = nil)
  path = '/supervisors/' + id.to_s + '/check_status'
  method = 'patch'
  form_params = {callback: callback}
  options = {form_params: form_params}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    result[:message]
  else
    RequestError.new(result)
  end
end
create() click to toggle source
# File lib/innologix/supervisor.rb, line 70
def create
  path = '/supervisors'
  method = 'post'
  form_params = {name: name, ip: ip, storage_id: storage_id}
  options = {form_params: {supervisor: form_params}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end
delete() click to toggle source
# File lib/innologix/supervisor.rb, line 96
def delete
  path = '/supervisors/' + id.to_s
  method = 'delete'
  result = client.call_api(path, method)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end
from_hash(attributes) click to toggle source
# File lib/innologix/supervisor.rb, line 149
def from_hash(attributes)
  supervisor = Innologix::Supervisor.new
  supervisor.id = attributes[:id]
  supervisor.name = attributes[:name]
  supervisor.ip = attributes[:ip]
  supervisor.status = attributes[:status]
  supervisor.storage_id = attributes[:storage_id]
  supervisor.created_at = attributes[:created_at]
  supervisor.updated_at = attributes[:updated_at]

  if attributes[:storage] != nil
    supervisor.storage = Innologix::Storage.new(attributes[:storage])
  end

  supervisor.groups = []
  if attributes[:groups] != nil
    attributes[:groups].each do |group|
      supervisor.groups.push(Innologix::Group.new(group))
    end
  end

  supervisor.device_types = []
  if attributes[:device_types] != nil
    attributes[:device_types].each do |device_type|
      supervisor.device_types.push(Innologix::DeviceType.new(device_type))
    end
  end

  supervisor
end
get(id) click to toggle source
# File lib/innologix/supervisor.rb, line 59
def get(id)
  path = '/supervisors/' + id.to_s
  method = 'get'
  result = client.call_api(path, method)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end
list(offset = 0, limit = 10) click to toggle source
# File lib/innologix/supervisor.rb, line 23
def list(offset = 0, limit = 10)
  path = '/supervisors'
  method = 'get'
  options = {query_params: {offset: offset, limit: limit}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    list =[]
    result[:supervisors].each do |device|
      list.push(from_hash(device))
    end
    meta = OpenStruct.new
    meta.offset = result[:meta][:offset]
    meta.limit = result[:meta][:limit]
    meta.total = result[:meta][:total]

    result = OpenStruct.new
    result.supervisors = list
    result.meta = meta
    result
  else
    RequestError.new(result)
  end
end
restart(callback = nil) click to toggle source
# File lib/innologix/supervisor.rb, line 123
def restart(callback = nil)
  path = '/supervisors/' + id.to_s + '/restart'
  method = 'patch'
  form_params = {callback: callback}
  options = {form_params: form_params}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    result[:message]
  else
    RequestError.new(result)
  end
end
total() click to toggle source
# File lib/innologix/supervisor.rb, line 47
def total
  path = '/supervisors/total'
  method = 'get'
  options = {}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    result
  else
    nil
  end
end
update() click to toggle source
# File lib/innologix/supervisor.rb, line 83
def update
  path = '/supervisors/' + id.to_s
  method = 'put'
  form_params = {name: name, ip: ip, storage_id: storage_id}
  options = {form_params: {supervisor: form_params}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end
update_configs() click to toggle source
# File lib/innologix/supervisor.rb, line 107
def update_configs
  path = '/supervisors/' + id.to_s + '/update_configs'
  method = 'patch'
  result = client.call_api(path, method)
  if result[:error].nil?
    supervisor = from_hash(result[:supervisor])
    meta = result[:meta]
    result = OpenStruct.new
    result.supervisor = supervisor
    result.meta = meta
    result
  else
    RequestError.new(result)
  end
end