Class: Innologix::Supervisor
- Inherits:
-
Object
- Object
- Innologix::Supervisor
- Defined in:
- lib/innologix/supervisor.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#device_types ⇒ Object
Returns the value of attribute device_types.
-
#error ⇒ Object
Returns the value of attribute error.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#storage ⇒ Object
Returns the value of attribute storage.
-
#storage_id ⇒ Object
Returns the value of attribute storage_id.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #check_status(callback = nil) ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #from_hash(attributes) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(h = {}) ⇒ Supervisor
constructor
A new instance of Supervisor.
- #list(offset = 0, limit = 10) ⇒ Object
- #restart(callback = nil) ⇒ Object
- #total ⇒ Object
- #update ⇒ Object
- #update_configs ⇒ Object
Constructor Details
#initialize(h = {}) ⇒ Supervisor
Returns a new instance of Supervisor.
18 19 20 21 |
# File 'lib/innologix/supervisor.rb', line 18 def initialize(h = {}) h.each { |k, v| public_send("#{k}=", v) } @client = Client.default end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
15 16 17 |
# File 'lib/innologix/supervisor.rb', line 15 def client @client end |
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/innologix/supervisor.rb', line 8 def created_at @created_at end |
#device_types ⇒ Object
Returns the value of attribute device_types.
13 14 15 |
# File 'lib/innologix/supervisor.rb', line 13 def device_types @device_types end |
#error ⇒ Object
Returns the value of attribute error.
16 17 18 |
# File 'lib/innologix/supervisor.rb', line 16 def error @error end |
#groups ⇒ Object
Returns the value of attribute groups.
12 13 14 |
# File 'lib/innologix/supervisor.rb', line 12 def groups @groups end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/innologix/supervisor.rb', line 3 def id @id end |
#ip ⇒ Object
Returns the value of attribute ip.
5 6 7 |
# File 'lib/innologix/supervisor.rb', line 5 def ip @ip end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/innologix/supervisor.rb', line 4 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/innologix/supervisor.rb', line 6 def status @status end |
#storage ⇒ Object
Returns the value of attribute storage.
11 12 13 |
# File 'lib/innologix/supervisor.rb', line 11 def storage @storage end |
#storage_id ⇒ Object
Returns the value of attribute storage_id.
7 8 9 |
# File 'lib/innologix/supervisor.rb', line 7 def storage_id @storage_id end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
9 10 11 |
# File 'lib/innologix/supervisor.rb', line 9 def updated_at @updated_at end |
Instance Method Details
#check_status(callback = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# 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} = {form_params: form_params} result = client.call_api(path, method, ) if result[:error].nil? result[:message] else RequestError.new(result) end end |
#create ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/innologix/supervisor.rb', line 70 def create path = '/supervisors' method = 'post' form_params = {name: name, ip: ip, storage_id: storage_id} = {form_params: {supervisor: form_params}} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#delete ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# 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) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# 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) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/innologix/supervisor.rb', line 23 def list(offset = 0, limit = 10) path = '/supervisors' method = 'get' = {query_params: {offset: offset, limit: limit}} result = client.call_api(path, method, ) if result[:error].nil? list =[] result[:supervisors].each do |device| list.push(from_hash(device)) end = OpenStruct.new .offset = result[:meta][:offset] .limit = result[:meta][:limit] .total = result[:meta][:total] result = OpenStruct.new result.supervisors = list result. = result else RequestError.new(result) end end |
#restart(callback = nil) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/innologix/supervisor.rb', line 123 def restart(callback = nil) path = '/supervisors/' + id.to_s + '/restart' method = 'patch' form_params = {callback: callback} = {form_params: form_params} result = client.call_api(path, method, ) if result[:error].nil? result[:message] else RequestError.new(result) end end |
#total ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/innologix/supervisor.rb', line 47 def total path = '/supervisors/total' method = 'get' = {} result = client.call_api(path, method, ) if result[:error].nil? result else nil end end |
#update ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# 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} = {form_params: {supervisor: form_params}} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#update_configs ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# 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]) = result[:meta] result = OpenStruct.new result.supervisor = supervisor result. = result else RequestError.new(result) end end |