Class: Megam::Components

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/megam/core/components.rb', line 19

def initialize(email=nil, api_key=nil)
  @id = nil
  @name =nil
  @tosca_type = nil
  @requirements = {}
  @host = nil
  @dummy = nil
  @inputs = {}
  @domain = nil
  @port = nil
  @username = nil
  @password = nil
  @version = nil
  @source = nil
  @design_inputs = nil
  @x = nil
  @y = nil
  @z = nil
  @wires = []
  @service_inputs = nil
  @ci_id = nil
  @dbname = nil
  @dbpassword = nil
  @external_management_resource = nil
  @artifacts = {}
  @artifact_type = nil
  @content = nil
  @artifact_requirements = nil
  @related_components = nil
  @operations = {}
  @operation_type = nil
  @target_resource = nil
  @others = []
  @created_at = nil

  super(email, api_key)
end

Class Method Details

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



439
440
441
442
# File 'lib/megam/core/components.rb', line 439

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

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



418
419
420
421
422
# File 'lib/megam/core/components.rb', line 418

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

.json_create(o) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/megam/core/components.rb', line 370

def self.json_create(o)
  asm = new
  asm.id(o["id"]) if o.has_key?("id")
  asm.name(o["name"]) if o.has_key?("name")
  asm.tosca_type(o["tosca_type"]) if o.has_key?("tosca_type")

  oq = o["requirements"]
  asm.requirements[:host] = oq["host"] if oq && oq.has_key?("host")
  asm.requirements[:dummy] = oq["dummy"] if oq && oq.has_key?("dummy")

  inp = o["inputs"]
  asm.inputs[:domain] = inp["domain"] if inp && inp.has_key?("domain")
  asm.inputs[:port] = inp["port"] if inp && inp.has_key?("port")
  asm.inputs[:username] = inp["username"] if inp && inp.has_key?("username")
  asm.inputs[:password] = inp["password"] if inp && inp.has_key?("password")
  asm.inputs[:version] = inp["version"] if inp && inp.has_key?("version")
  asm.inputs[:source] = inp["source"] if inp && inp.has_key?("source")
  asm.inputs[:design_inputs] = inp["design_inputs"] if inp && inp.has_key?("design_inputs")
  asm.inputs[:service_inputs] = inp["service_inputs"] if inp && inp.has_key?("service_inputs")
  asm.inputs[:ci_id] = inp["ci_id"] if inp && inp.has_key?("ci_id")
  # ind = inp["design_inputs"]
  #  asm.inputs["design_inputs"][:did] = ind["did"] if ind && ind.has_key?("did")
  # asm.inputs[:design_inputs][:x] = ind["x"] if ind && ind.has_key?("x")
  # asm.inputs[:design_inputs][:y] = ind["y"] if ind && ind.has_key?("y")
  #  asm.inputs[:design_inputs][:z] = ind["z"] if ind && ind.has_key?("z")
  #  asm.inputs[:design_inputs][:wires] = ind["wires"] if ind && ind.has_key?("wires")
  #  ins = o["inputs"]["service_inputs"]
  #  asm.inputs[:service_inputs][:dbname] = ins["dbname"] if ins && ins.has_key?("dbname")
  # asm.inputs[:service_inputs][:dbpassword] = ins["dbpassword"] if ins && ins.has_key?("dbpassword")

  asm.external_management_resource(o["external_management_resource"]) if o.has_key?("external_management_resource")

  ar = o["artifacts"]
  asm.artifacts[:artifact_type] = ar["artifact_type"] if ar && ar.has_key?("artifact_type")
  asm.artifacts[:content] = ar["content"] if ar && ar.has_key?("content")
  asm.artifacts[:artifact_requirements] = ar["artifact_requirements"] if ar && ar.has_key?("artifact_requirements")

  asm.related_components(o["related_components"]) if o.has_key?("related_components")

  ope = o["operations"]
  asm.operations[:operation_type] = ope["operation_type"] if ope && ope.has_key?("operation_type")
  asm.operations[:target_resource] = ope["target_resource"] if ope && ope.has_key?("target_resource")
  
  asm.others(o["others"]) if o.has_key?("others")
  asm.created_at(o["created_at"]) if o.has_key?("created_at")
  asm
end

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

Load a account by email_p



445
446
447
448
# File 'lib/megam/core/components.rb', line 445

def self.show(comp_id, tmp_email=nil, tmp_api_key=nil)
  asm = self.new(tmp_email, tmp_api_key)
  asm.megam_rest.get_components(comp_id)
end

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



450
451
452
453
# File 'lib/megam/core/components.rb', line 450

def self.update(o,tmp_email=nil, tmp_api_key=nil)
  asm = from_hash(o, tmp_email, tmp_api_key)
  asm.update
end

Instance Method Details

#artifact_requirements(arg = nil) ⇒ Object



269
270
271
272
273
274
275
# File 'lib/megam/core/components.rb', line 269

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

#artifact_type(arg = nil) ⇒ Object



253
254
255
256
257
258
259
# File 'lib/megam/core/components.rb', line 253

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

#artifacts(arg = nil) ⇒ Object



245
246
247
248
249
250
251
# File 'lib/megam/core/components.rb', line 245

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

#ci_id(arg = nil) ⇒ Object



213
214
215
216
217
218
219
# File 'lib/megam/core/components.rb', line 213

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

#componentsObject



57
58
59
# File 'lib/megam/core/components.rb', line 57

def components
  self
end

#content(arg = nil) ⇒ Object



261
262
263
264
265
266
267
# File 'lib/megam/core/components.rb', line 261

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

#created_at(arg = nil) ⇒ Object



317
318
319
320
321
322
323
# File 'lib/megam/core/components.rb', line 317

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

#dbname(arg = nil) ⇒ Object



221
222
223
224
225
226
227
# File 'lib/megam/core/components.rb', line 221

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

#dbpassword(arg = nil) ⇒ Object



229
230
231
232
233
234
235
# File 'lib/megam/core/components.rb', line 229

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

#design_inputs(arg = nil) ⇒ Object



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

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

#domain(arg = nil) ⇒ Object



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

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

#dummy(arg = nil) ⇒ Object



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

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

#error?Boolean



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

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

#external_management_resource(arg = nil) ⇒ Object



237
238
239
240
241
242
243
# File 'lib/megam/core/components.rb', line 237

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

#for_jsonObject



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/megam/core/components.rb', line 353

def for_json
  result = {
    "id" => id,
    "name" => name,
    "tosca_type" => tosca_type,
    "requirements" => requirements,
    "inputs" => inputs,
    "external_management_resource" => external_management_resource,
    "artifacts" => artifacts,
    "related_components" => related_components,
    "operations" => operations,
    "others" => others,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/megam/core/components.rb', line 424

def from_hash(o)
  @id                              = o["id"] if o.has_key?("id")
  @name                            = o["name"] if o.has_key?("name")
  @tosca_type                      = o["tosca_type"] if o.has_key?("tosca_type")
  @requirements                    = o["requirements"] if o.has_key?("requirements")
  @inputs                          = o["inputs"] if o.has_key?("inputs")
  @external_management_resource    = o["external_management_resource"] if o.has_key?("external_management_resource")
  @artifacts                       = o["artifacts"] if o.has_key?("artifacts")
  @related_components              = o["related_components"] if o.has_key?("related_components")
  @operations                      = o["operations"] if o.has_key?("operations")
  @others                          = o["others"] if o.has_key?("others")
  @created_at                      = o["created_at"] if o.has_key?("created_at")
  self
end

#host(arg = nil) ⇒ Object



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

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

#id(arg = nil) ⇒ Object



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

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

#inputs(arg = []) ⇒ Object



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

def inputs(arg=[])
  if arg != []
    @inputs = arg
  else
  @inputs
  end
end

#name(arg = nil) ⇒ Object



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

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

#operation_type(arg = nil) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/megam/core/components.rb', line 293

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

#operations(arg = nil) ⇒ Object



285
286
287
288
289
290
291
# File 'lib/megam/core/components.rb', line 285

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

#others(arg = nil) ⇒ Object



309
310
311
312
313
314
315
# File 'lib/megam/core/components.rb', line 309

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

#password(arg = nil) ⇒ Object



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

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

#port(arg = nil) ⇒ Object



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

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


277
278
279
280
281
282
283
# File 'lib/megam/core/components.rb', line 277

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

#requirements(arg = nil) ⇒ Object



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

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

#service_inputs(arg = nil) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/megam/core/components.rb', line 205

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

#source(arg = nil) ⇒ Object



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

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

#target_resource(arg = nil) ⇒ Object



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

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

#to_hashObject

Transform the ruby obj -> to a Hash



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

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["name"] = name
  index_hash["tosca_type"] = tosca_type
  index_hash["requirements"] = requirements
  index_hash["inputs"] = inputs
  index_hash["external_management_resource"] = external_management_resource
  index_hash["artifacts"] = artifacts
  index_hash["related_components"] = related_components
  index_hash["operations"] = operations
  index_hash["others"] = others
  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.



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

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

#to_sObject



460
461
462
# File 'lib/megam/core/components.rb', line 460

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

#tosca_type(arg = nil) ⇒ Object



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

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

#updateObject

Create the node via the REST API



456
457
458
# File 'lib/megam/core/components.rb', line 456

def update
  megam_rest.update_component(to_hash)
end

#username(arg = nil) ⇒ Object



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

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

#version(arg = nil) ⇒ Object



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

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

#wires(arg = nil) ⇒ Object



197
198
199
200
201
202
203
# File 'lib/megam/core/components.rb', line 197

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

#x(arg = nil) ⇒ Object



173
174
175
176
177
178
179
# File 'lib/megam/core/components.rb', line 173

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

#y(arg = nil) ⇒ Object



181
182
183
184
185
186
187
# File 'lib/megam/core/components.rb', line 181

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

#z(arg = nil) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/megam/core/components.rb', line 189

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