Class: Megam::Boltdefns

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/boltdefns.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) ⇒ Boltdefns

Returns a new instance of Boltdefns.



19
20
21
22
23
24
25
26
27
# File 'lib/megam/core/boltdefns.rb', line 19

def initialize(email=nil, api_key=nil)
  @id = nil
  @node_id = nil
  @node_name = nil
  @boltdefns ={}
  @created_at = nil
  @some_msg = {}
  super(email,api_key)
end

Class Method Details

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



179
180
181
182
# File 'lib/megam/core/boltdefns.rb', line 179

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



164
165
166
167
168
# File 'lib/megam/core/boltdefns.rb', line 164

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  boltdefns = self.new(tmp_email, tmp_api_key)
  boltdefns.from_hash(o)
  boltdefns
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”:“” } }]



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/megam/core/boltdefns.rb', line 136

def self.json_create(o)
  boltdefns = new
  boltdefns.id(o["id"]) if o.has_key?("id")
  boltdefns.node_id(o["node_id"]) if o.has_key?("node_id")
  boltdefns.node_name(o["node_name"]) if o.has_key?("node_name")
  boltdefns.created_at(o["created_at"]) if o.has_key?("created_at")

  #APP DEFINITIONS
  op = o["boltdefns"]
  boltdefns.boltdefns[:username] = op["username"] if op && op.has_key?("username")
  boltdefns.boltdefns[:apikey] = op["apikey"] if op && op.has_key?("apikey")
  boltdefns.boltdefns[:store_name]= op["store_name"] if op && op.has_key?("store_name")
  boltdefns.boltdefns[:url] = op["url"] if op && op.has_key?("url")
  boltdefns.boltdefns[:prime] = op["prime"] if op && op.has_key?("prime")

  boltdefns.boltdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
  boltdefns.boltdefns[:metered] = op["metered"] if op && op.has_key?("metered")
  boltdefns.boltdefns[:logging]= op["logging"] if op && op.has_key?("logging")
  boltdefns.boltdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")

  boltdefns.some_msg[:code] = o["code"] if o.has_key?("code")
  boltdefns.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  boltdefns.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  boltdefns.some_msg[:links] = o["links"] if o.has_key?("links")

  boltdefns
end

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

Show all bolt defns by [node_name]/email



190
191
192
193
# File 'lib/megam/core/boltdefns.rb', line 190

def self.show(node_name,tmp_email=nil, tmp_api_key=nil)
  boltdefns = self.new(tmp_email, tmp_api_key)
  boltdefns.megam_rest.get_boltdefn(node_name)
end

.show_by_node(node_name, id, tmp_email = nil, tmp_api_key = nil) ⇒ Object

Show a bolt defn by [node_name, defn id] for an email



196
197
198
199
# File 'lib/megam/core/boltdefns.rb', line 196

def self.show_by_node(node_name,id,tmp_email=nil, tmp_api_key=nil)
  boltdefns = self.new(tmp_email, tmp_api_key)
  boltdefns.megam_rest.get_boltdefn(node_name,id)
end

Instance Method Details

#boltdefns(arg = nil) ⇒ Object



29
30
31
# File 'lib/megam/core/boltdefns.rb', line 29

def boltdefns
  self
end

#createObject

Create the node via the REST API



185
186
187
# File 'lib/megam/core/boltdefns.rb', line 185

def create
  megam_rest.post_boltdefn(to_hash)
end

#created_at(arg = nil) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/megam/core/boltdefns.rb', line 67

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

#error?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/megam/core/boltdefns.rb', line 83

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

#for_jsonObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/megam/core/boltdefns.rb', line 106

def for_json
  result = {
    "id" => id,
    "node_id" => node_id,
    "node_name" => node_name,
    "boltdefns" => boltdefns,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



170
171
172
173
174
175
176
177
# File 'lib/megam/core/boltdefns.rb', line 170

def from_hash(o)
  @id        = o["id"] if o.has_key?("id")
  @node_id    = o["node_id"] if o.has_key?("node_id")
  @node_name = o["node_name"] if o.has_key?("node_name")
  @boltdefns   = o["boltdefns"] if o.has_key?("boltdefns")
  @created_at        = o["created_at"] if o.has_key?("created_at")
  self
end

#id(arg = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/megam/core/boltdefns.rb', line 35

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

#node_id(arg = nil) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/megam/core/boltdefns.rb', line 43

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

#node_name(arg = nil) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/megam/core/boltdefns.rb', line 51

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

#some_msg(arg = nil) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/megam/core/boltdefns.rb', line 75

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

#to_hashObject

Transform the ruby obj -> to a Hash



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/megam/core/boltdefns.rb', line 88

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["node_id"] = node_id
  index_hash["node_name"] = node_name
  index_hash["boltdefns"] = boltdefns
  index_hash["created_at"] = created_at
  index_hash["some_msg"] = some_msg
  index_hash
end

#to_json(*a) ⇒ Object

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



102
103
104
# File 'lib/megam/core/boltdefns.rb', line 102

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

#to_sObject



201
202
203
# File 'lib/megam/core/boltdefns.rb', line 201

def to_s
  Megam::Stuff.styled_hash(to_hash)
end