Class: Megam::Node

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

def self.hash_tree

  Hash.new do |hash, key|
    hash[key] = hash_tree
  end
end


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/core/node.rb', line 29

def initialize
  @id = nil
  @node_name = nil
  @accounts_id = nil
  @node_type = nil
  @req_type = nil
  @status=nil
  @noofinstances=0
  @request ={}
  @predefs={}
  @some_msg = {}
  #@command = self.class.hash_tree
	@command = Hashie::Mash.new
	@appdefnsid = nil
	@boltdefnsid = nil
	@appdefns = {}
	@boltdefns = {}
  @created_at = nil
end

Class Method Details

.create(o) ⇒ Object



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

def self.create(o)
  acct = from_hash(o)
  acct.create
end

.from_hash(o) ⇒ Object



324
325
326
327
328
# File 'lib/megam/core/node.rb', line 324

def self.from_hash(o)
  node = self.new()
  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”:“” } }]



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
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/megam/core/node.rb', line 256

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

.listObject



364
365
366
367
# File 'lib/megam/core/node.rb', line 364

def self.list
  node = self.new()
  node.megam_rest.get_nodes
end

.show(node_name) ⇒ Object

Load a account by email_p



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

def self.show(node_name)
  node = self.new()
  node.megam_rest.get_node(node_name)
end

Instance Method Details

#accounts_id(arg = nil) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/megam/core/node.rb', line 89

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

#appdefns(arg = nil) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/megam/core/node.rb', line 137

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

#appdefnsid(arg = nil) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/megam/core/node.rb', line 152

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

#boltdefns(arg = nil) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/megam/core/node.rb', line 145

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

#boltdefnsid(arg = nil) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/megam/core/node.rb', line 160

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

#command(arg = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/megam/core/node.rb', line 73

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

#createObject

Create the node via the REST API



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

def create
  megam_rest.post_node(to_hash)
end

#created_at(arg = nil) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/megam/core/node.rb', line 168

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

#error?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/megam/core/node.rb', line 184

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

#for_jsonObject



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/megam/core/node.rb', line 217

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



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/megam/core/node.rb', line 330

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



81
82
83
84
85
86
87
# File 'lib/megam/core/node.rb', line 81

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

#megam_restObject



52
53
54
55
# File 'lib/megam/core/node.rb', line 52

def megam_rest
  options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
  Megam::API.new(options)
end

#nodeObject



48
49
50
# File 'lib/megam/core/node.rb', line 48

def node
  self
end

#node_name(arg = nil) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/megam/core/node.rb', line 57

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

#node_type(arg = nil) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/megam/core/node.rb', line 97

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

#noofinstances(arg = nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/megam/core/node.rb', line 65

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

#predefs(arg = nil) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/megam/core/node.rb', line 129

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

#req_type(arg = nil) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/megam/core/node.rb', line 105

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

#request(arg = nil) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/megam/core/node.rb', line 121

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

#some_msg(arg = nil) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/megam/core/node.rb', line 176

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

#status(arg = nil) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/megam/core/node.rb', line 113

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

#to_hashObject

Transform the ruby obj -> to a Hash



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/megam/core/node.rb', line 189

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.



213
214
215
# File 'lib/megam/core/node.rb', line 213

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

#to_sObject



369
370
371
372
# File 'lib/megam/core/node.rb', line 369

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