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 = hash_tree end end



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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
  @appdefns = {}
  @boltdefns = {}
  @created_at = nil
end

Class Method Details

.create(o) ⇒ Object



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

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

.from_hash(o) ⇒ Object



303
304
305
306
307
# File 'lib/megam/core/node.rb', line 303

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":"" } }]



235
236
237
238
239
240
241
242
243
244
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
# File 'lib/megam/core/node.rb', line 235

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.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
  oc = o["command"]
  node.command = node.command(oc) if oc && oc.has_key?("systemprovider")
=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



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

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

.show(node_name) ⇒ Object

Load a account by email_p



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

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

Instance Method Details

#accounts_id(arg = nil) ⇒ Object



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

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

#appdefns(arg = nil) ⇒ Object



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

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

#boltdefns(arg = nil) ⇒ Object



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

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

#command(arg = nil) ⇒ Object



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

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

#createObject

Create the node via the REST API



331
332
333
# File 'lib/megam/core/node.rb', line 331

def create
  megam_rest.post_node(to_hash)
end

#created_at(arg = nil) ⇒ Object



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

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

#error?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/megam/core/node.rb', line 167

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

#for_jsonObject



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/megam/core/node.rb', line 198

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,
    "noofinstances" => noofinstances,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/megam/core/node.rb', line 309

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")
  @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



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

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

#megam_restObject



50
51
52
53
# File 'lib/megam/core/node.rb', line 50

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

#nodeObject



46
47
48
# File 'lib/megam/core/node.rb', line 46

def node
  self
end

#node_name(arg = nil) ⇒ Object



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

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

#node_type(arg = nil) ⇒ Object



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

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

#noofinstances(arg = nil) ⇒ Object



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

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

#predefs(arg = nil) ⇒ Object



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

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

#req_type(arg = nil) ⇒ Object



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

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

#request(arg = nil) ⇒ Object



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

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

#some_msg(arg = nil) ⇒ Object



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

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

#status(arg = nil) ⇒ Object



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

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

#to_hashObject

Transform the ruby obj -> to a Hash



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/megam/core/node.rb', line 172

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["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.



194
195
196
# File 'lib/megam/core/node.rb', line 194

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

#to_sObject



346
347
348
349
# File 'lib/megam/core/node.rb', line 346

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