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

Returns a new instance of 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
# 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
  @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
  @created_at = nil    

  super(email, api_key)
end

Class Method Details

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



415
416
417
418
# File 'lib/megam/core/components.rb', line 415

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



396
397
398
399
400
# File 'lib/megam/core/components.rb', line 396

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



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
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
# File 'lib/megam/core/components.rb', line 350

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")
 # 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.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



422
423
424
425
# File 'lib/megam/core/components.rb', line 422

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

Instance Method Details

#artifact_requirements(arg = nil) ⇒ Object



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

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

#artifact_type(arg = nil) ⇒ Object



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

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

#artifacts(arg = nil) ⇒ Object



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

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

#componentsObject



55
56
57
# File 'lib/megam/core/components.rb', line 55

def components
  self
end

#content(arg = nil) ⇒ Object



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

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

#created_at(arg = nil) ⇒ Object



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

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

#dbname(arg = nil) ⇒ Object



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

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

#dbpassword(arg = nil) ⇒ Object



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

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

#design_inputs(arg = nil) ⇒ Object



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

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

#domain(arg = nil) ⇒ Object



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

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

#dummy(arg = nil) ⇒ Object



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

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

#error?Boolean

Returns:

  • (Boolean)


307
308
309
# File 'lib/megam/core/components.rb', line 307

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

#external_management_resource(arg = nil) ⇒ Object



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

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

#for_jsonObject



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/megam/core/components.rb', line 334

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

#from_hash(o) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/megam/core/components.rb', line 402

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")
  @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")
  @created_at                      = o["created_at"] if o.has_key?("created_at")
  self
end

#host(arg = nil) ⇒ Object



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

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

#id(arg = nil) ⇒ Object



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

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

#inputs(arg = []) ⇒ Object



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

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

#name(arg = nil) ⇒ Object



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

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

#operation_type(arg = nil) ⇒ Object



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

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

#operations(arg = nil) ⇒ Object



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

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

#password(arg = nil) ⇒ Object



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

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

#port(arg = nil) ⇒ Object



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

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


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

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

#requirements(arg = nil) ⇒ Object



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

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

#service_inputs(arg = nil) ⇒ Object



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

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

#source(arg = nil) ⇒ Object



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

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

#target_resource(arg = nil) ⇒ Object



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

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



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/megam/core/components.rb', line 312

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



330
331
332
# File 'lib/megam/core/components.rb', line 330

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

#to_sObject



428
429
430
# File 'lib/megam/core/components.rb', line 428

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

#tosca_type(arg = nil) ⇒ Object



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

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

#username(arg = nil) ⇒ Object



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

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

#version(arg = nil) ⇒ Object



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

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

#wires(arg = nil) ⇒ Object



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

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

#x(arg = nil) ⇒ Object



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

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

#y(arg = nil) ⇒ Object



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

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

#z(arg = nil) ⇒ Object



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

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