Class: Megam::Node

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/node.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ Node

Returns a new instance of Node.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/megam/core/node.rb', line 20

def initialize(email=nil, api_key=nil)
  @id = nil
  @node_name = nil
  @accounts_id = nil
  @node_type = nil
  @req_type = nil
  @status=nil
  @noofinstances=0
  @request ={}
  @predefs={}
  @some_msg = {}
  @command = Hashie::Mash.new
  @appdefnsid = nil
  @boltdefnsid = nil
  @appdefns = {}
  @boltdefns = {}
  @created_at = nil
  super(email, api_key)
end

Class Method Details

.create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



337
338
339
340
# File 'lib/megam/core/node.rb', line 337

def self.create(o,tmp_email=nil, tmp_api_key=nil)
  acct = from_hash(o, tmp_email, tmp_api_key)
  acct.create
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



313
314
315
316
317
# File 'lib/megam/core/node.rb', line 313

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  node = self.new(tmp_email, tmp_api_key)
  node.from_hash(o)
  node
end

.json_create(o) ⇒ Object

Create a Megam::Node from NodeResult-JSON

[{ “id”:“NOD362212018897289216”, “accounts_id”:“ACT362211962353876992”, “json_claz”:“Megam::Node”, “request”:{ “req_id”:“NOD362212018897289216”, “command”:“commands” }, “predefs”:{ “name”:“”, “scm”:“”, “war”:“”, “db”:“”, “queue”:“” } }]



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/megam/core/node.rb', line 245

def self.json_create(o)
  node = new
  node.id(o["id"]) if o.has_key?("id")
  node.node_name(o["node_name"]) if o.has_key?("node_name")
  node.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
  node.node_type(o["node_type"]) if o.has_key?("node_type")
  node.req_type(o["req_type"]) if o.has_key?("req_type")
  node.status(o["status"]) if o.has_key?("status")
  node.appdefnsid(o["appdefnsid"]) if o.has_key?("appdefnsid")
  node.boltdefnsid(o["boltdefnsid"]) if o.has_key?("boltdefnsid")
  node.noofinstances(o["noofinstances"]) if o.has_key?("noofinstances")
  node.created_at(o["created_at"]) if o.has_key?("created_at")
  #requests
  oq = o["request"]
  node.request[:req_id] = oq["req_id"] if oq && oq.has_key?("req_id")
  node.request[:req_type] = oq["req_type"] if oq && oq.has_key?("req_type")
  node.request[:command] = oq["command"] if oq && oq.has_key?("command")

  #Command
=begin
node.command[:systemprovider][:provider][:prov] = oc["systemprovider"]["provider"]["prov"]
node.command[:compute][:cctype] = oc["compute"]["cctype"]
node.command[:compute][:cc][:groups] = oc["compute"]["cc"]["groups"]
node.command[:compute][:cc][:image] = oc["compute"]["cc"]["image"]
node.command[:compute][:cc][:flavor] = oc["compute"]["cc"]["flavor"]
node.command[:compute][:access][:ssh_key] = oc["compute"]["access"]["ssh_key"]
node.command[:compute][:access][:identity_file] = oc["compute"]["access"]["identity_file"]
node.command[:compute][:access][:ssh_user] = oc["compute"]["access"]["ssh_user"]
node.command[:cloudtool][:chef][:command] = oc["cloudtool"]["chef"]["command"]
node.command[:cloudtool][:chef][:plugin] = oc["cloudtool"]["chef"]["plugin"]
node.command[:cloudtool][:chef][:run_list] = oc["cloudtool"]["chef"]["run_list"]
node.command[:cloudtool][:chef][:name] = oc["cloudtool"]["chef"]["name"]
=end
  #predef
  op = o["predefs"]
  node.predefs[:name] = op["name"] if op && op.has_key?("name")
  node.predefs[:scm] = op["scm"] if op && op.has_key?("scm")
  node.predefs[:war]= op["war"] if op && op.has_key?("war")
  node.predefs[:db] = op["db"] if op && op.has_key?("db")
  node.predefs[:queue] = op["queue"] if op && op.has_key?("queue")

  #APP DEFINITIONS
  op = o["appdefns"]
  node.appdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
  node.appdefns[:metered] = op["metered"] if op && op.has_key?("metered")
  node.appdefns[:logging]= op["logging"] if op && op.has_key?("logging")
  node.appdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")

  #BOLT DEFINITIONS
  op = o["boltdefns"]
  node.boltdefns[:username] = op["username"] if op && op.has_key?("username")
  node.boltdefns[:apikey] = op["apikey"] if op && op.has_key?("apikey")
  node.boltdefns[:store_name]= op["store_name"] if op && op.has_key?("store_name")
  node.boltdefns[:url] = op["url"] if op && op.has_key?("url")
  node.boltdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
  node.boltdefns[:metered] = op["metered"] if op && op.has_key?("metered")
  node.boltdefns[:logging]= op["logging"] if op && op.has_key?("logging")
  node.boltdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")

  #success or error
  node.some_msg[:code] = o["code"] if o.has_key?("code")
  node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  node.some_msg[:links] = o["links"] if o.has_key?("links")

  node
end

.list(tmp_email = nil, tmp_api_key = nil) ⇒ Object



353
354
355
356
# File 'lib/megam/core/node.rb', line 353

def self.list(tmp_email=nil, tmp_api_key=nil)
  node = self.new(tmp_email, tmp_api_key)
  node.megam_rest.get_nodes
end

.show(node_name, tmp_email = nil, tmp_api_key = nil) ⇒ Object

Load a account by email_p



348
349
350
351
# File 'lib/megam/core/node.rb', line 348

def self.show(node_name, tmp_email=nil, tmp_api_key=nil)
  node = self.new(tmp_email, tmp_api_key)
  node.megam_rest.get_node(node_name)
end

Instance Method Details

#accounts_id(arg = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/megam/core/node.rb', line 77

def accounts_id(arg=nil)
  if arg != nil
    @accounts_id = arg
  else
  @accounts_id
  end
end

#appdefns(arg = nil) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/megam/core/node.rb', line 125

def appdefns(arg=nil)
  if arg != nil
    @appdefns = arg
  else
  @appdefns
  end
end

#appdefnsid(arg = nil) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/megam/core/node.rb', line 141

def appdefnsid(arg=nil)
  if arg != nil
    @appdefnsid = arg
  else
  @appdefnsid
  end
end

#boltdefns(arg = nil) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/megam/core/node.rb', line 133

def boltdefns(arg=nil)
  if arg != nil
    @boltdefns = arg
  else
  @boltdefns
  end
end

#boltdefnsid(arg = nil) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/megam/core/node.rb', line 149

def boltdefnsid(arg=nil)
  if arg != nil
    @boltdefnsid = arg
  else
  @boltdefnsid
  end
end

#command(arg = nil) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/megam/core/node.rb', line 61

def command(arg=nil)
  if arg != nil
    @command = arg
  else
  @command
  end
end

#createObject

Create the node via the REST API



343
344
345
# File 'lib/megam/core/node.rb', line 343

def create
  megam_rest.post_node(to_hash)
end

#created_at(arg = nil) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/megam/core/node.rb', line 157

def created_at(arg=nil)
  if arg != nil
    @created_at = arg
  else
  @created_at
  end
end

#error?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/megam/core/node.rb', line 173

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/megam/core/node.rb', line 206

def for_json
  result = {
    "id" => id,
    "node_name" => node_name,
    "accounts_id" => accounts_id,
    "node_type" => node_type,
    "req_type" => req_type,
    "status" => status,
    "request" => request,
    "predefs" => predefs,
    "appdefns" => appdefns,
    "boltdefns" => boltdefns,
    "appdefnsid" => appdefnsid,
    "boltdefnsid" => boltdefnsid,
    "noofinstances" => noofinstances,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/megam/core/node.rb', line 319

def from_hash(o)
  @node_name = o["node_name"] if o.has_key?("node_name")
  @command   = o["command"] if o.has_key?("command")
  @id        = o["id"] if o.has_key?("id")
  @accounts_id    = o["accounts_id"] if o.has_key?("accounts_id")
  @node_type    = o["node_type"] if o.has_key?("node_type")
  @req_type    = o["req_type"] if o.has_key?("req_type")
  @request   = o["request"] if o.has_key?("request")
  @predefs   = o["predefs"] if o.has_key?("predefs")
  @appdefns   = o["appdefns"] if o.has_key?("appdefns")
  @boltdefns   = o["boltdefns"] if o.has_key?("boltdefns")
  @appdefnsid   = o["appdefnsid"] if o.has_key?("appdefnsid")
  @boltdefnsid   = o["boltdefnsid"] if o.has_key?("boltdefnsid")
  @noofinstances        = o["noofinstances"] if o.has_key?("noofinstances")
  @created_at        = o["created_at"] if o.has_key?("created_at")
  self
end

#id(arg = nil) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/megam/core/node.rb', line 69

def id(arg=nil)
  if arg != nil
    @id = arg
  else
  @id
  end
end

#nodeObject



40
41
42
# File 'lib/megam/core/node.rb', line 40

def node
  self
end

#node_name(arg = nil) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/megam/core/node.rb', line 45

def node_name(arg=nil)
  if arg != nil
    @node_name = arg
  else
  @node_name
  end
end

#node_type(arg = nil) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/megam/core/node.rb', line 85

def node_type(arg=nil)
  if arg != nil
    @node_type = arg
  else
  @node_type
  end
end

#noofinstances(arg = nil) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/megam/core/node.rb', line 53

def noofinstances(arg=nil)
  if arg != nil
    @noofinstances = arg
  else
  @noofinstances
  end
end

#predefs(arg = nil) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/megam/core/node.rb', line 117

def predefs(arg=nil)
  if arg != nil
    @predefs = arg
  else
  @predefs
  end
end

#req_type(arg = nil) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/megam/core/node.rb', line 93

def req_type(arg=nil)
  if arg != nil
    @req_type = arg
  else
  @req_type
  end
end

#request(arg = nil) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/megam/core/node.rb', line 109

def request(arg=nil)
  if arg != nil
    @request = arg
  else
  @request
  end
end

#some_msg(arg = nil) ⇒ Object



165
166
167
168
169
170
171
# File 'lib/megam/core/node.rb', line 165

def some_msg(arg=nil)
  if arg != nil
    @some_msg = arg
  else
  @some_msg
  end
end

#status(arg = nil) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/megam/core/node.rb', line 101

def status(arg=nil)
  if arg != nil
    @status = arg
  else
  @status
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/megam/core/node.rb', line 178

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["node_name"] = node_name
  index_hash["accounts_id"] = accounts_id
  index_hash["node_type"] = node_type
  index_hash["req_type"] = req_type
  index_hash["status"] = status
  index_hash["command"] = command
  index_hash["request"] = request
  index_hash["predefs"] = predefs
  index_hash["appdefns"] = appdefns
  index_hash["boltdefns"] = boltdefns
  index_hash["some_msg"] = some_msg
  index_hash["noofinstances"] = noofinstances.to_i
  index_hash["appdefnsid"] = appdefnsid
  index_hash["boltdefnsid"] = boltdefnsid
  index_hash["created_at"] = created_at
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



202
203
204
# File 'lib/megam/core/node.rb', line 202

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



358
359
360
361
# File 'lib/megam/core/node.rb', line 358

def to_s
  Megam::Stuff.styled_hash(to_hash)
#"---> Megam::Account:[error=#{error?}]\n"+
end