megam_api 1.5.rc5 → 1.5.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/LICENSE +21 -202
  4. data/README.md +3 -20
  5. data/lib/megam/api.rb +154 -169
  6. data/lib/megam/api/accounts.rb +0 -15
  7. data/lib/megam/api/assemblies.rb +0 -15
  8. data/lib/megam/api/assembly.rb +0 -15
  9. data/lib/megam/api/balances.rb +0 -15
  10. data/lib/megam/api/billedhistories.rb +0 -15
  11. data/lib/megam/api/billingtransactions.rb +0 -15
  12. data/lib/megam/api/components.rb +0 -15
  13. data/lib/megam/api/domains.rb +0 -15
  14. data/lib/megam/api/errors.rb +0 -15
  15. data/lib/megam/api/eventsbilling.rb +0 -15
  16. data/lib/megam/api/eventscontainer.rb +0 -15
  17. data/lib/megam/api/eventsstorage.rb +0 -15
  18. data/lib/megam/api/eventsvm.rb +0 -15
  19. data/lib/megam/api/marketplaces.rb +0 -15
  20. data/lib/megam/api/organizations.rb +0 -15
  21. data/lib/megam/api/promos.rb +0 -15
  22. data/lib/megam/api/requests.rb +0 -15
  23. data/lib/megam/api/sensors.rb +0 -15
  24. data/lib/megam/api/snapshots.rb +0 -15
  25. data/lib/megam/api/sshkeys.rb +0 -15
  26. data/lib/megam/api/version.rb +1 -16
  27. data/lib/megam/core/account.rb +241 -60
  28. data/lib/megam/core/assemblies.rb +0 -16
  29. data/lib/megam/core/assemblies_collection.rb +101 -116
  30. data/lib/megam/core/assembly.rb +201 -218
  31. data/lib/megam/core/assembly_collection.rb +101 -116
  32. data/lib/megam/core/balances.rb +182 -197
  33. data/lib/megam/core/balances_collection.rb +101 -116
  34. data/lib/megam/core/billedhistories.rb +186 -201
  35. data/lib/megam/core/billedhistories_collection.rb +101 -116
  36. data/lib/megam/core/billingtransactions.rb +0 -15
  37. data/lib/megam/core/billingtransactions_collection.rb +0 -15
  38. data/lib/megam/core/components.rb +300 -316
  39. data/lib/megam/core/components_collection.rb +0 -15
  40. data/lib/megam/core/domain_collection.rb +1 -16
  41. data/lib/megam/core/domains.rb +115 -131
  42. data/lib/megam/core/error.rb +55 -70
  43. data/lib/megam/core/eventsbilling.rb +0 -16
  44. data/lib/megam/core/eventsbilling_collection.rb +101 -116
  45. data/lib/megam/core/eventscontainer.rb +0 -16
  46. data/lib/megam/core/eventscontainer_collection.rb +101 -116
  47. data/lib/megam/core/eventsstorage.rb +0 -16
  48. data/lib/megam/core/eventsstorage_collection.rb +0 -15
  49. data/lib/megam/core/eventsvm.rb +0 -16
  50. data/lib/megam/core/eventsvm_collection.rb +101 -116
  51. data/lib/megam/core/json_compat.rb +0 -12
  52. data/lib/megam/core/konipai.rb +0 -15
  53. data/lib/megam/core/log.rb +0 -15
  54. data/lib/megam/core/marketplace.rb +224 -241
  55. data/lib/megam/core/marketplace_collection.rb +0 -15
  56. data/lib/megam/core/organizations.rb +0 -16
  57. data/lib/megam/core/organizations_collection.rb +0 -15
  58. data/lib/megam/core/promos.rb +0 -15
  59. data/lib/megam/core/request.rb +0 -15
  60. data/lib/megam/core/request_collection.rb +0 -15
  61. data/lib/megam/core/rest_adapter.rb +0 -15
  62. data/lib/megam/core/sensors.rb +138 -154
  63. data/lib/megam/core/sensors_collection.rb +0 -15
  64. data/lib/megam/core/snapshots.rb +0 -16
  65. data/lib/megam/core/snapshots_collection.rb +0 -15
  66. data/lib/megam/core/sshkey.rb +169 -184
  67. data/lib/megam/core/sshkey_collection.rb +0 -15
  68. data/lib/megam/core/stuff.rb +17 -32
  69. data/lib/megam/core/text.rb +82 -97
  70. data/lib/megam/mixins/assemblies.rb +10 -25
  71. data/lib/megam/mixins/assembly.rb +33 -49
  72. data/lib/megam/mixins/common_deployable.rb +64 -79
  73. data/lib/megam/mixins/components.rb +160 -175
  74. data/lib/megam/mixins/megam_attributes.rb +22 -37
  75. data/lib/megam/mixins/outputs.rb +14 -29
  76. data/lib/megam/mixins/policies.rb +21 -36
  77. data/lib/megam_api.rb +0 -15
  78. data/test/mixins/test_assemblies.rb +1 -2
  79. data/test/test_accounts.rb +84 -29
  80. data/test/test_billingtranscations.rb +17 -21
  81. data/test/test_eventscontainer.rb +19 -23
  82. data/test/test_eventsstorage.rb +8 -10
  83. data/test/test_eventsvm.rb +19 -23
  84. data/test/test_helper.rb +30 -30
  85. data/test/test_snapshots.rb +16 -22
  86. metadata +2 -2
@@ -1,136 +1,121 @@
1
- ##
2
- ## Copyright 2013-2016 Megam Systems
3
- ##
4
- ## Licensed under the Apache License, Version 2.0 (the "License");
5
- ## you may not use this file except in compliance with the License.
6
- ## You may obtain a copy of the License at
7
- ##
8
- ## http://www.apache.org/licenses/LICENSE-2.0
9
- ##
10
- ## Unless required by applicable law or agreed to in writing, software
11
- ## distributed under the License is distributed on an "AS IS" BASIS,
12
- ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- ## See the License for the specific language governing permissions and
14
- ## limitations under the License.
15
- ##
16
1
  module Megam
17
- class BilledhistoriesCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @billedhistories = Array.new
23
- @billedhistories_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
2
+ class BilledhistoriesCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @billedhistories = Array.new
8
+ @billedhistories_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
26
11
 
27
- def all_billedhistories
28
- @billedhistories
29
- end
12
+ def all_billedhistories
13
+ @billedhistories
14
+ end
30
15
 
31
- def [](index)
32
- @billedhistories[index]
33
- end
16
+ def [](index)
17
+ @billedhistories[index]
18
+ end
34
19
 
35
- def []=(index, arg)
36
- is_megam_billedhistories(arg)
37
- @billedhistories[index] = arg
38
- @billedhistories_by_name[arg.accounts_id] = index
39
- end
20
+ def []=(index, arg)
21
+ is_megam_billedhistories(arg)
22
+ @billedhistories[index] = arg
23
+ @billedhistories_by_name[arg.accounts_id] = index
24
+ end
40
25
 
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_billedhistories(a)
44
- @billedhistories << a
45
- @billedhistories_by_name[a.accounts_id] =@billedhistories.length - 1
46
- end
47
- self
48
- end
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_billedhistories(a)
29
+ @billedhistories << a
30
+ @billedhistories_by_name[a.accounts_id] =@billedhistories.length - 1
31
+ end
32
+ self
33
+ end
49
34
 
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(billedhistories)
54
- is_megam_billedhistories(billedhistories)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any predefs inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # billedhistories
59
- @billedhistories.insert(@insert_after_idx + 1, billedhistories)
60
- # update name -> location mappings and register new billedhistories
61
- @billedhistories_by_name.each_key do |key|
62
- @billedhistories_by_name[key] += 1 if@billedhistories_by_name[key] > @insert_after_idx
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(billedhistories)
39
+ is_megam_billedhistories(billedhistories)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any predefs inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # billedhistories
44
+ @billedhistories.insert(@insert_after_idx + 1, billedhistories)
45
+ # update name -> location mappings and register new billedhistories
46
+ @billedhistories_by_name.each_key do |key|
47
+ @billedhistories_by_name[key] += 1 if@billedhistories_by_name[key] > @insert_after_idx
48
+ end
49
+ @billedhistories_by_name[billedhistories.accounts_id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @billedhistories << billedhistories
53
+ @billedhistories_by_name[billedhistories.accounts_id] =@billedhistories.length - 1
54
+ end
63
55
  end
64
- @billedhistories_by_name[billedhistories.accounts_id] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @billedhistories << billedhistories
68
- @billedhistories_by_name[billedhistories.accounts_id] =@billedhistories.length - 1
69
- end
70
- end
71
56
 
72
- def each
73
- @billedhistories.each do |billedhistories|
74
- yield billedhistories
75
- end
76
- end
57
+ def each
58
+ @billedhistories.each do |billedhistories|
59
+ yield billedhistories
60
+ end
61
+ end
77
62
 
78
- def each_index
79
- @billedhistories.each_index do |i|
80
- yield i
81
- end
82
- end
63
+ def each_index
64
+ @billedhistories.each_index do |i|
65
+ yield i
66
+ end
67
+ end
83
68
 
84
- def empty?
85
- @billedhistories.empty?
86
- end
69
+ def empty?
70
+ @billedhistories.empty?
71
+ end
87
72
 
88
- def lookup(billedhistories)
89
- lookup_by = nil
90
- if Billedhistories.kind_of?(Megam::Billedhistories)
91
- lookup_by = billedhistories.accounts_id
92
- elsif billedhistories.kind_of?(String)
93
- lookup_by = billedhistories
94
- else
95
- raise ArgumentError, "Must pass a Megam::billedhistories or String to lookup"
96
- end
97
- res =@billedhistories_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a billedhistories matching #{lookup_by} (did you define it first?)"
100
- end
101
- @billedhistories[res]
102
- end
73
+ def lookup(billedhistories)
74
+ lookup_by = nil
75
+ if Billedhistories.kind_of?(Megam::Billedhistories)
76
+ lookup_by = billedhistories.accounts_id
77
+ elsif billedhistories.kind_of?(String)
78
+ lookup_by = billedhistories
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::billedhistories or String to lookup"
81
+ end
82
+ res =@billedhistories_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a billedhistories matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @billedhistories[res]
87
+ end
103
88
 
104
- def to_s
105
- @billedhistories.join(", ")
106
- end
89
+ def to_s
90
+ @billedhistories.join(", ")
91
+ end
107
92
 
108
- def for_json
109
- to_a.map { |item| item.to_s }
110
- end
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
111
96
 
112
- def to_json(*a)
113
- Megam::JSONCompat.to_json(for_json, *a)
114
- end
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
115
100
 
116
- def self.json_create(o)
117
- collection = self.new()
118
- o["results"].each do |billedhistories_list|
119
- billedhistories_array = billedhistories_list.kind_of?(Array) ? billedhistories_list : [ billedhistories_list ]
120
- billedhistories_array.each do |billedhistories|
121
- collection.insert(billedhistories)
101
+ def self.json_create(o)
102
+ collection = self.new()
103
+ o["results"].each do |billedhistories_list|
104
+ billedhistories_array = billedhistories_list.kind_of?(Array) ? billedhistories_list : [ billedhistories_list ]
105
+ billedhistories_array.each do |billedhistories|
106
+ collection.insert(billedhistories)
107
+ end
108
+ end
109
+ collection
122
110
  end
123
- end
124
- collection
125
- end
126
111
 
127
- private
112
+ private
128
113
 
129
- def is_megam_billedhistories(arg)
130
- unless arg.kind_of?(Megam::Billedhistories)
131
- raise ArgumentError, "Members must be Megam::billedhistories's"
132
- end
133
- true
114
+ def is_megam_billedhistories(arg)
115
+ unless arg.kind_of?(Megam::Billedhistories)
116
+ raise ArgumentError, "Members must be Megam::billedhistories's"
117
+ end
118
+ true
119
+ end
134
120
  end
135
- end
136
121
  end
@@ -1,18 +1,3 @@
1
- ##
2
- ## Copyright 2013-2016 Megam Systems
3
- ##
4
- ## Licensed under the Apache License, Version 2.0 (the "License");
5
- ## you may not use this file except in compliance with the License.
6
- ## You may obtain a copy of the License at
7
- ##
8
- ## http://www.apache.org/licenses/LICENSE-2.0
9
- ##
10
- ## Unless required by applicable law or agreed to in writing, software
11
- ## distributed under the License is distributed on an "AS IS" BASIS,
12
- ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- ## See the License for the specific language governing permissions and
14
- ## limitations under the License.
15
- ##
16
1
  module Megam
17
2
  class Billingtransactions < Megam::RestAdapter
18
3
  def initialize(o)
@@ -1,18 +1,3 @@
1
- ##
2
- ## Copyright 2013-2016 Megam Systems
3
- ##
4
- ## Licensed under the Apache License, Version 2.0 (the "License");
5
- ## you may not use this file except in compliance with the License.
6
- ## You may obtain a copy of the License at
7
- ##
8
- ## http://www.apache.org/licenses/LICENSE-2.0
9
- ##
10
- ## Unless required by applicable law or agreed to in writing, software
11
- ## distributed under the License is distributed on an "AS IS" BASIS,
12
- ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- ## See the License for the specific language governing permissions and
14
- ## limitations under the License.
15
- ##
16
1
  module Megam
17
2
  class BillingtransactionsCollection
18
3
  include Enumerable
@@ -1,319 +1,303 @@
1
- # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
- # License:: Apache License, Version 2.0
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- #
16
-
17
1
  module Megam
18
- class Components < Megam::RestAdapter
19
- def initialize(o)
20
- @id = nil
21
- @name = nil
22
- @tosca_type = nil
23
- @inputs = []
24
- @outputs = []
25
- @envs = []
26
- @artifacts = {}
27
- @artifact_type = nil
28
- @content = nil
29
- @artifact_requirements = []
30
- @related_components = []
31
- @operations = []
32
- @status = nil
33
- @repo = {}
34
- @rtype = nil
35
- @source = nil
36
- @oneclick = nil
37
- @url = nil
38
- @created_at = nil
39
-
40
- super(o)
41
- end
42
-
43
- def components
44
- self
45
- end
46
-
47
- def id(arg = nil)
48
- if !arg.nil?
49
- @id = arg
50
- else
51
- @id
52
- end
53
- end
54
-
55
- def name(arg = nil)
56
- if !arg.nil?
57
- @name = arg
58
- else
59
- @name
60
- end
61
- end
62
-
63
- def tosca_type(arg = nil)
64
- if !arg.nil?
65
- @tosca_type = arg
66
- else
67
- @tosca_type
68
- end
69
- end
70
-
71
- def inputs(arg = [])
72
- if arg != []
73
- @inputs = arg
74
- else
75
- @inputs
76
- end
77
- end
78
-
79
- def outputs(arg = [])
80
- if arg != []
81
- @outputs = arg
82
- else
83
- @outputs
84
- end
85
- end
86
-
87
- def envs(arg = [])
88
- if arg != []
89
- @envs = arg
90
- else
91
- @envs
92
- end
93
- end
94
-
95
- def artifacts(arg = nil)
96
- if !arg.nil?
97
- @artifacts = arg
98
- else
99
- @artifacts
100
- end
101
- end
102
-
103
- def artifact_type(arg = nil)
104
- if !arg.nil?
105
- @artifact_type = arg
106
- else
107
- @artifact_type
108
- end
109
- end
110
-
111
- def content(arg = nil)
112
- if !arg.nil?
113
- @content = arg
114
- else
115
- @content
116
- end
117
- end
118
-
119
- def artifact_requirements(arg = [])
120
- if arg != []
121
- @artifact_requirements = arg
122
- else
123
- @artifact_requirements
124
- end
125
- end
126
-
127
- def related_components(arg = [])
128
- if arg != []
129
- @related_components = arg
130
- else
131
- @related_components
132
- end
133
- end
134
-
135
- def operations(arg = [])
136
- if arg != []
137
- @operations = arg
138
- else
139
- @operations
140
- end
141
- end
142
-
143
- def status(arg = nil)
144
- if !arg.nil?
145
- @status = arg
146
- else
147
- @status
148
- end
149
- end
150
-
151
- def repo(arg = nil)
152
- if !arg.nil?
153
- @repo = arg
154
- else
155
- @repo
156
- end
157
- end
158
-
159
- def rtype(arg = nil)
160
- if !arg.nil?
161
- @rtype = arg
162
- else
163
- @rtype
164
- end
165
- end
166
-
167
- def source(arg = nil)
168
- if !arg.nil?
169
- @source = arg
170
- else
171
- @source
172
- end
173
- end
174
-
175
- def oneclick(arg = nil)
176
- if !arg.nil?
177
- @oneclick = arg
178
- else
179
- @oneclick
180
- end
181
- end
182
-
183
- def url(arg = nil)
184
- if !arg.nil?
185
- @url = arg
186
- else
187
- @url
188
- end
189
- end
190
-
191
- def created_at(arg = nil)
192
- if !arg.nil?
193
- @created_at = arg
194
- else
195
- @created_at
196
- end
197
- end
198
-
199
- def error?
200
- crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
201
- end
202
-
203
- # Transform the ruby obj -> to a Hash
204
- def to_hash
205
- index_hash = {}
206
- index_hash['json_claz'] = self.class.name
207
- index_hash['id'] = id
208
- index_hash['name'] = name
209
- index_hash['tosca_type'] = tosca_type
210
- index_hash['inputs'] = inputs
211
- index_hash['outputs'] = outputs
212
- index_hash['envs'] = envs
213
- index_hash['artifacts'] = artifacts
214
- index_hash['related_components'] = related_components
215
- index_hash['operations'] = operations
216
- index_hash['status'] = status
217
- index_hash['repo'] = repo
218
- index_hash['created_at'] = created_at
219
- index_hash
220
- end
221
-
222
- # Serialize this object as a hash: called from JsonCompat.
223
- # Verify if this called from JsonCompat during testing.
224
- def to_json(*a)
225
- for_json.to_json(*a)
226
- end
227
-
228
- def for_json
229
- result = {
230
- 'id' => id,
231
- 'name' => name,
232
- 'tosca_type' => tosca_type,
233
- 'inputs' => inputs,
234
- 'outputs' => outputs,
235
- 'envs' => envs,
236
- 'artifacts' => artifacts,
237
- 'related_components' => related_components,
238
- 'operations' => operations,
239
- 'status' => status,
240
- 'repo' => repo,
241
- 'created_at' => created_at
242
- }
243
- result
244
- end
245
-
246
- def self.json_create(o)
247
- asm = new({})
248
- asm.id(o['id']) if o.key?('id')
249
- asm.name(o['name']) if o.key?('name')
250
- asm.tosca_type(o['tosca_type']) if o.key?('tosca_type')
251
- asm.inputs(o['inputs']) if o.key?('inputs')
252
- asm.outputs(o['outputs']) if o.key?('outputs')
253
- asm.envs(o['envs']) if o.key?('envs')
254
- ar = o['artifacts']
255
- asm.artifacts[:artifact_type] = ar['artifact_type'] if ar && ar.key?('artifact_type')
256
- asm.artifacts[:content] = ar['content'] if ar && ar.key?('content')
257
- asm.artifacts[:artifact_requirements] = ar['artifact_requirements'] if ar && ar.key?('artifact_requirements')
258
-
259
- asm.related_components(o['related_components']) if o.key?('related_components')
260
- asm.operations(o['operations']) if o.key?('operations')
261
- asm.status(o['status']) if o.key?('status')
262
-
263
- ro = o['repo']
264
- asm.repo[:rtype] = ro['rtype'] if ro && ro.key?('rtype')
265
- asm.repo[:source] = ro['source'] if ro && ro.key?('source')
266
- asm.repo[:oneclick] = ro['oneclick'] if ro && ro.key?('oneclick')
267
- asm.repo[:url] = ro['url'] if ro && ro.key?('url')
268
- asm.created_at(o['created_at']) if o.key?('created_at')
269
- asm
270
- end
271
-
272
- def self.from_hash(o)
273
- asm = new(o)
274
- asm.from_hash(o)
275
- asm
276
- end
277
-
278
- def from_hash(o)
279
- @id = o['id'] if o.key?('id')
280
- @name = o['name'] if o.key?('name')
281
- @tosca_type = o['tosca_type'] if o.key?('tosca_type')
282
- @inputs = o['inputs'] if o.key?('inputs')
283
- @outputs = o['outputs'] if o.key?('outputs')
284
- @envs = o['envs'] if o.key?('envs')
285
- @artifacts = o['artifacts'] if o.key?('artifacts')
286
- @related_components = o['related_components'] if o.key?('related_components')
287
- @operations = o['operations'] if o.key?('operations')
288
- @status = o['status'] if o.key?('status')
289
- @repo = o['repo'] if o.key?('repo')
290
- @created_at = o['created_at'] if o.key?('created_at')
291
- self
292
- end
293
-
294
- def self.create(params)
295
- asm = from_hash(params)
296
- asm.create
297
- end
298
-
299
- # Load a account by email_p
300
- def self.show(params)
301
- asm = new(params)
302
- asm.megam_rest.get_components(params['id'])
303
- end
304
-
305
- def self.update(params)
306
- asm = from_hash(params)
307
- asm.update
308
- end
309
-
310
- # Create the node via the REST API
311
- def update
312
- megam_rest.update_component(to_hash)
313
- end
314
-
315
- def to_s
316
- Megam::Stuff.styled_hash(to_hash)
2
+ class Components < Megam::RestAdapter
3
+ def initialize(o)
4
+ @id = nil
5
+ @name = nil
6
+ @tosca_type = nil
7
+ @inputs = []
8
+ @outputs = []
9
+ @envs = []
10
+ @artifacts = {}
11
+ @artifact_type = nil
12
+ @content = nil
13
+ @artifact_requirements = []
14
+ @related_components = []
15
+ @operations = []
16
+ @status = nil
17
+ @repo = {}
18
+ @rtype = nil
19
+ @source = nil
20
+ @oneclick = nil
21
+ @url = nil
22
+ @created_at = nil
23
+
24
+ super(o)
25
+ end
26
+
27
+ def components
28
+ self
29
+ end
30
+
31
+ def id(arg = nil)
32
+ if !arg.nil?
33
+ @id = arg
34
+ else
35
+ @id
36
+ end
37
+ end
38
+
39
+ def name(arg = nil)
40
+ if !arg.nil?
41
+ @name = arg
42
+ else
43
+ @name
44
+ end
45
+ end
46
+
47
+ def tosca_type(arg = nil)
48
+ if !arg.nil?
49
+ @tosca_type = arg
50
+ else
51
+ @tosca_type
52
+ end
53
+ end
54
+
55
+ def inputs(arg = [])
56
+ if arg != []
57
+ @inputs = arg
58
+ else
59
+ @inputs
60
+ end
61
+ end
62
+
63
+ def outputs(arg = [])
64
+ if arg != []
65
+ @outputs = arg
66
+ else
67
+ @outputs
68
+ end
69
+ end
70
+
71
+ def envs(arg = [])
72
+ if arg != []
73
+ @envs = arg
74
+ else
75
+ @envs
76
+ end
77
+ end
78
+
79
+ def artifacts(arg = nil)
80
+ if !arg.nil?
81
+ @artifacts = arg
82
+ else
83
+ @artifacts
84
+ end
85
+ end
86
+
87
+ def artifact_type(arg = nil)
88
+ if !arg.nil?
89
+ @artifact_type = arg
90
+ else
91
+ @artifact_type
92
+ end
93
+ end
94
+
95
+ def content(arg = nil)
96
+ if !arg.nil?
97
+ @content = arg
98
+ else
99
+ @content
100
+ end
101
+ end
102
+
103
+ def artifact_requirements(arg = [])
104
+ if arg != []
105
+ @artifact_requirements = arg
106
+ else
107
+ @artifact_requirements
108
+ end
109
+ end
110
+
111
+ def related_components(arg = [])
112
+ if arg != []
113
+ @related_components = arg
114
+ else
115
+ @related_components
116
+ end
117
+ end
118
+
119
+ def operations(arg = [])
120
+ if arg != []
121
+ @operations = arg
122
+ else
123
+ @operations
124
+ end
125
+ end
126
+
127
+ def status(arg = nil)
128
+ if !arg.nil?
129
+ @status = arg
130
+ else
131
+ @status
132
+ end
133
+ end
134
+
135
+ def repo(arg = nil)
136
+ if !arg.nil?
137
+ @repo = arg
138
+ else
139
+ @repo
140
+ end
141
+ end
142
+
143
+ def rtype(arg = nil)
144
+ if !arg.nil?
145
+ @rtype = arg
146
+ else
147
+ @rtype
148
+ end
149
+ end
150
+
151
+ def source(arg = nil)
152
+ if !arg.nil?
153
+ @source = arg
154
+ else
155
+ @source
156
+ end
157
+ end
158
+
159
+ def oneclick(arg = nil)
160
+ if !arg.nil?
161
+ @oneclick = arg
162
+ else
163
+ @oneclick
164
+ end
165
+ end
166
+
167
+ def url(arg = nil)
168
+ if !arg.nil?
169
+ @url = arg
170
+ else
171
+ @url
172
+ end
173
+ end
174
+
175
+ def created_at(arg = nil)
176
+ if !arg.nil?
177
+ @created_at = arg
178
+ else
179
+ @created_at
180
+ end
181
+ end
182
+
183
+ def error?
184
+ crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
185
+ end
186
+
187
+ # Transform the ruby obj -> to a Hash
188
+ def to_hash
189
+ index_hash = {}
190
+ index_hash['json_claz'] = self.class.name
191
+ index_hash['id'] = id
192
+ index_hash['name'] = name
193
+ index_hash['tosca_type'] = tosca_type
194
+ index_hash['inputs'] = inputs
195
+ index_hash['outputs'] = outputs
196
+ index_hash['envs'] = envs
197
+ index_hash['artifacts'] = artifacts
198
+ index_hash['related_components'] = related_components
199
+ index_hash['operations'] = operations
200
+ index_hash['status'] = status
201
+ index_hash['repo'] = repo
202
+ index_hash['created_at'] = created_at
203
+ index_hash
204
+ end
205
+
206
+ # Serialize this object as a hash: called from JsonCompat.
207
+ # Verify if this called from JsonCompat during testing.
208
+ def to_json(*a)
209
+ for_json.to_json(*a)
210
+ end
211
+
212
+ def for_json
213
+ result = {
214
+ 'id' => id,
215
+ 'name' => name,
216
+ 'tosca_type' => tosca_type,
217
+ 'inputs' => inputs,
218
+ 'outputs' => outputs,
219
+ 'envs' => envs,
220
+ 'artifacts' => artifacts,
221
+ 'related_components' => related_components,
222
+ 'operations' => operations,
223
+ 'status' => status,
224
+ 'repo' => repo,
225
+ 'created_at' => created_at
226
+ }
227
+ result
228
+ end
229
+
230
+ def self.json_create(o)
231
+ asm = new({})
232
+ asm.id(o['id']) if o.key?('id')
233
+ asm.name(o['name']) if o.key?('name')
234
+ asm.tosca_type(o['tosca_type']) if o.key?('tosca_type')
235
+ asm.inputs(o['inputs']) if o.key?('inputs')
236
+ asm.outputs(o['outputs']) if o.key?('outputs')
237
+ asm.envs(o['envs']) if o.key?('envs')
238
+ ar = o['artifacts']
239
+ asm.artifacts[:artifact_type] = ar['artifact_type'] if ar && ar.key?('artifact_type')
240
+ asm.artifacts[:content] = ar['content'] if ar && ar.key?('content')
241
+ asm.artifacts[:artifact_requirements] = ar['artifact_requirements'] if ar && ar.key?('artifact_requirements')
242
+
243
+ asm.related_components(o['related_components']) if o.key?('related_components')
244
+ asm.operations(o['operations']) if o.key?('operations')
245
+ asm.status(o['status']) if o.key?('status')
246
+
247
+ ro = o['repo']
248
+ asm.repo[:rtype] = ro['rtype'] if ro && ro.key?('rtype')
249
+ asm.repo[:source] = ro['source'] if ro && ro.key?('source')
250
+ asm.repo[:oneclick] = ro['oneclick'] if ro && ro.key?('oneclick')
251
+ asm.repo[:url] = ro['url'] if ro && ro.key?('url')
252
+ asm.created_at(o['created_at']) if o.key?('created_at')
253
+ asm
254
+ end
255
+
256
+ def self.from_hash(o)
257
+ asm = new(o)
258
+ asm.from_hash(o)
259
+ asm
260
+ end
261
+
262
+ def from_hash(o)
263
+ @id = o['id'] if o.key?('id')
264
+ @name = o['name'] if o.key?('name')
265
+ @tosca_type = o['tosca_type'] if o.key?('tosca_type')
266
+ @inputs = o['inputs'] if o.key?('inputs')
267
+ @outputs = o['outputs'] if o.key?('outputs')
268
+ @envs = o['envs'] if o.key?('envs')
269
+ @artifacts = o['artifacts'] if o.key?('artifacts')
270
+ @related_components = o['related_components'] if o.key?('related_components')
271
+ @operations = o['operations'] if o.key?('operations')
272
+ @status = o['status'] if o.key?('status')
273
+ @repo = o['repo'] if o.key?('repo')
274
+ @created_at = o['created_at'] if o.key?('created_at')
275
+ self
276
+ end
277
+
278
+ def self.create(params)
279
+ asm = from_hash(params)
280
+ asm.create
281
+ end
282
+
283
+ # Load a account by email_p
284
+ def self.show(params)
285
+ asm = new(params)
286
+ asm.megam_rest.get_components(params['id'])
287
+ end
288
+
289
+ def self.update(params)
290
+ asm = from_hash(params)
291
+ asm.update
292
+ end
293
+
294
+ # Create the node via the REST API
295
+ def update
296
+ megam_rest.update_component(to_hash)
297
+ end
298
+
299
+ def to_s
300
+ Megam::Stuff.styled_hash(to_hash)
301
+ end
317
302
  end
318
- end
319
303
  end