megam_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.project +17 -0
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/README.md +83 -0
- data/Rakefile +10 -0
- data/lib/certs/cacert.pem +3554 -0
- data/lib/megam/api.rb +244 -0
- data/lib/megam/api/accounts.rb +29 -0
- data/lib/megam/api/appdefns.rb +26 -0
- data/lib/megam/api/appreqs.rb +27 -0
- data/lib/megam/api/boltdefns.rb +27 -0
- data/lib/megam/api/boltreqs.rb +27 -0
- data/lib/megam/api/cloud_tools.rb +35 -0
- data/lib/megam/api/errors.rb +27 -0
- data/lib/megam/api/login.rb +14 -0
- data/lib/megam/api/logs.rb +18 -0
- data/lib/megam/api/nodes.rb +50 -0
- data/lib/megam/api/predef_clouds.rb +35 -0
- data/lib/megam/api/predefs.rb +35 -0
- data/lib/megam/api/requests.rb +37 -0
- data/lib/megam/api/version.rb +5 -0
- data/lib/megam/core/account.rb +170 -0
- data/lib/megam/core/appdefns.rb +192 -0
- data/lib/megam/core/appdefns_collection.rb +148 -0
- data/lib/megam/core/appreqs.rb +224 -0
- data/lib/megam/core/appreqs_collection.rb +148 -0
- data/lib/megam/core/auth.rb +91 -0
- data/lib/megam/core/boltdefns.rb +198 -0
- data/lib/megam/core/boltdefns_collection.rb +148 -0
- data/lib/megam/core/boltreqs.rb +224 -0
- data/lib/megam/core/boltreqs_collection.rb +148 -0
- data/lib/megam/core/cloudinstruction.rb +110 -0
- data/lib/megam/core/cloudinstruction_collection.rb +145 -0
- data/lib/megam/core/cloudinstruction_group.rb +99 -0
- data/lib/megam/core/cloudtemplate.rb +127 -0
- data/lib/megam/core/cloudtemplate_collection.rb +145 -0
- data/lib/megam/core/cloudtool.rb +153 -0
- data/lib/megam/core/cloudtool_collection.rb +145 -0
- data/lib/megam/core/config.rb +44 -0
- data/lib/megam/core/error.rb +99 -0
- data/lib/megam/core/json_compat.rb +183 -0
- data/lib/megam/core/log.rb +33 -0
- data/lib/megam/core/node.rb +347 -0
- data/lib/megam/core/node_collection.rb +166 -0
- data/lib/megam/core/predef.rb +208 -0
- data/lib/megam/core/predef_collection.rb +164 -0
- data/lib/megam/core/predefcloud.rb +229 -0
- data/lib/megam/core/predefcloud_collection.rb +168 -0
- data/lib/megam/core/request.rb +187 -0
- data/lib/megam/core/request_collection.rb +145 -0
- data/lib/megam/core/stuff.rb +69 -0
- data/lib/megam/core/text.rb +88 -0
- data/lib/megam_api.rb +1 -0
- data/megam_api.gemspec +26 -0
- data/test/test_accounts.rb +46 -0
- data/test/test_appdefns.rb +23 -0
- data/test/test_appreqs.rb +28 -0
- data/test/test_boltdefns.rb +23 -0
- data/test/test_boltreqs.rb +28 -0
- data/test/test_cloudtools.rb +22 -0
- data/test/test_helper.rb +67 -0
- data/test/test_login.rb +12 -0
- data/test/test_logs.rb +15 -0
- data/test/test_nodes.rb +141 -0
- data/test/test_predefclouds.rb +67 -0
- data/test/test_predefs.rb +72 -0
- data/test/test_requests.rb +85 -0
- metadata +213 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2013 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
|
+
module Megam
|
17
|
+
class CloudTemplate
|
18
|
+
def initialize
|
19
|
+
@cctype = nil
|
20
|
+
@cloud_instruction_group = nil
|
21
|
+
@cloud_instruction_group_by_name = Hash.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def cloud_template
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def cctype(arg=nil)
|
29
|
+
if arg != nil
|
30
|
+
@cctype = arg
|
31
|
+
else
|
32
|
+
@cctype
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def cloud_instruction_group(arg=nil)
|
37
|
+
if arg != nil
|
38
|
+
@cloud_instruction_group = arg
|
39
|
+
else
|
40
|
+
@cloud_instruction_group
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def cloud_instruction_group_by_name(arg=nil)
|
45
|
+
if arg != nil
|
46
|
+
@cloud_instruction_group_by_name = arg
|
47
|
+
else
|
48
|
+
@cloud_instruction_group_by_name
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#returns a cloud instruction for a particular group
|
53
|
+
def lookup_by_group_name(group)
|
54
|
+
res =@cloud_instruction_group_by_name[group]
|
55
|
+
unless res
|
56
|
+
raise ArgumentError, "Cannot find a cloudgroup matching #{group} (did you define it first?)"
|
57
|
+
end
|
58
|
+
res
|
59
|
+
end
|
60
|
+
|
61
|
+
#returns a cloud instruction for a particular group, action
|
62
|
+
def lookup_by_instruction(group,action)
|
63
|
+
single_cig = lookup_by_group_name(group)
|
64
|
+
#single_cig.cloud_instructions_array.select { |cloudinstructions| cloudinstructions.lookup(action) }
|
65
|
+
single_cig.cloud_instructions_array.each do |cia|
|
66
|
+
@ci= cia.lookup(action)
|
67
|
+
end
|
68
|
+
@ci
|
69
|
+
end
|
70
|
+
|
71
|
+
def error?
|
72
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
73
|
+
end
|
74
|
+
|
75
|
+
# Transform the ruby obj -> to a Hash
|
76
|
+
def to_hash
|
77
|
+
index_hash = Hash.new
|
78
|
+
index_hash["json_claz"] = self.class.name
|
79
|
+
index_hash["cctype"] = cctype
|
80
|
+
cloud_instruction_group.each do |single_cig|
|
81
|
+
index_hash[single_cig.group] = single_cig
|
82
|
+
end
|
83
|
+
index_hash
|
84
|
+
end
|
85
|
+
|
86
|
+
# Serialize this object as a hash: called from JsonCompat.
|
87
|
+
# Verify if this called from JsonCompat during testing.
|
88
|
+
def to_json(*a)
|
89
|
+
for_json.to_json(*a)
|
90
|
+
end
|
91
|
+
|
92
|
+
def for_json
|
93
|
+
result = {
|
94
|
+
"cctype" => cctype,
|
95
|
+
"cloud_instruction_group" => cloud_instruction_group
|
96
|
+
}
|
97
|
+
result
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
def self.json_create(o)
|
102
|
+
cloudtemplate = new
|
103
|
+
cloudtemplate.cctype(o["cctype"]) if o.has_key?("cctype")
|
104
|
+
cloudtemplate.cloud_instruction_group(o["cloud_instruction_group"]) if o.has_key?("cloud_instruction_group")
|
105
|
+
cloudtemplate.cloud_instruction_group.each do |single_cig|
|
106
|
+
cloudtemplate.cloud_instruction_group_by_name[single_cig.group] = single_cig
|
107
|
+
end
|
108
|
+
cloudtemplate
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.from_hash(o)
|
112
|
+
cloudtemplate = self.new()
|
113
|
+
cloudtemplate.from_hash(o)
|
114
|
+
cloudtemplate
|
115
|
+
end
|
116
|
+
|
117
|
+
def from_hash(o)
|
118
|
+
@cctype = o[:cctype] if o.has_key?(:cctype)
|
119
|
+
self
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_s
|
123
|
+
Megam::Stuff.styled_hash(to_hash)
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2013 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
|
+
module Megam
|
17
|
+
class CloudTemplateCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@cloudtemplates = Array.new
|
23
|
+
@cloudtemplates_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_cloudtemplates
|
28
|
+
@cloudtemplates
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@cloudtemplates[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_cloudtemplate(arg)
|
37
|
+
@cloudtemplates[index] = arg
|
38
|
+
@cloudtemplates_by_name[arg.cctype] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_cloudtemplate(a)
|
44
|
+
@cloudtemplates << a
|
45
|
+
@cloudtemplates_by_name[a.cctype] =@cloudtemplates.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(cloudtemplate)
|
54
|
+
is_megam_cloudtemplate(cloudtemplate)
|
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
|
+
# cloudtemplates
|
59
|
+
@cloudtemplates.insert(@insert_after_idx + 1, cloudtemplate)
|
60
|
+
# update name -> location mappings and register new cloudtemplates
|
61
|
+
@cloudtemplates_by_name.each_key do |key|
|
62
|
+
@cloudtemplates_by_name[key] += 1 if@cloudtemplates_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@cloudtemplates_by_name[cloudtemplate.cctype] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@cloudtemplates << cloudtemplate
|
68
|
+
@cloudtemplates_by_name[cloudtemplate.cctype] =@cloudtemplates.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@cloudtemplates.each do |cloudtemplate|
|
74
|
+
yield cloudtemplate
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@cloudtemplates.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@cloudtemplates.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(cloudtemplate)
|
89
|
+
lookup_by = nil
|
90
|
+
if cloudtemplate.kind_of?(Megam::CloudTemplate)
|
91
|
+
lookup_by = cloudtemplate.cctype
|
92
|
+
elsif cloudtemplate.kind_of?(String)
|
93
|
+
lookup_by = cloudtemplate
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::CloudTemplates or String to lookup"
|
96
|
+
end
|
97
|
+
res =@cloudtemplates_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a cloudtemplates matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@cloudtemplates[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Transform the ruby obj -> to a Hash
|
105
|
+
def to_hash
|
106
|
+
index_hash = Hash.new
|
107
|
+
self.each do |cloudtemplate|
|
108
|
+
index_hash[cloudtemplate.cctype] = cloudtemplate.to_s
|
109
|
+
end
|
110
|
+
index_hash
|
111
|
+
end
|
112
|
+
|
113
|
+
# Serialize this object as a hash: called from JsonCompat.
|
114
|
+
# Verify if this called from JsonCompat during testing.
|
115
|
+
def to_json(*a)
|
116
|
+
for_json.to_json(*a)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def self.json_create(o)
|
121
|
+
collection = self.new()
|
122
|
+
o["results"].each do |cloudtemplates_list|
|
123
|
+
cloudtemplates_array = cloudtemplates_list.kind_of?(Array) ? cloudtemplates_list : [ cloudtemplates_list ]
|
124
|
+
cloudtemplates_array.each do |cloudtemplate|
|
125
|
+
collection.insert(cloudtemplate)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
collection
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def is_megam_cloudtemplate(arg)
|
134
|
+
unless arg.kind_of?(Megam::CloudTemplate)
|
135
|
+
raise ArgumentError, "Members must be Megam::CloudTemplate's"
|
136
|
+
end
|
137
|
+
true
|
138
|
+
end
|
139
|
+
|
140
|
+
def to_s
|
141
|
+
Megam::Stuff.styled_hash(to_hash)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2013 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
|
+
module Megam
|
17
|
+
class CloudTool
|
18
|
+
def initialize
|
19
|
+
@id = nil
|
20
|
+
@name = nil
|
21
|
+
@cli = nil
|
22
|
+
@cloudtemplates = nil
|
23
|
+
@some_msg = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def cloud_tool
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def megam_rest
|
31
|
+
options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
|
32
|
+
Megam::API.new(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def id(arg=nil)
|
36
|
+
if arg != nil
|
37
|
+
@id = arg
|
38
|
+
else
|
39
|
+
@id
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def cli(arg=nil)
|
44
|
+
if arg != nil
|
45
|
+
@cli = arg
|
46
|
+
else
|
47
|
+
@cli
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def name(arg=nil)
|
52
|
+
if arg != nil
|
53
|
+
@name = arg
|
54
|
+
else
|
55
|
+
@name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def cloudtemplates(arg=nil)
|
60
|
+
if arg != nil
|
61
|
+
@cloudtemplates = arg
|
62
|
+
else
|
63
|
+
@cloudtemplates
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def some_msg(arg=nil)
|
68
|
+
if arg != nil
|
69
|
+
@some_msg = arg
|
70
|
+
else
|
71
|
+
@some_msg
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def error?
|
76
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
77
|
+
end
|
78
|
+
|
79
|
+
# Transform the ruby obj -> to a Hash
|
80
|
+
def to_hash
|
81
|
+
index_hash = Hash.new
|
82
|
+
index_hash["json_claz"] = self.class.name
|
83
|
+
index_hash["id"] = id
|
84
|
+
index_hash["name"] = name
|
85
|
+
index_hash["cli"] = cli
|
86
|
+
index_hash["cloudtemplates"] = cloudtemplates
|
87
|
+
index_hash["some_msg"] = some_msg
|
88
|
+
index_hash
|
89
|
+
end
|
90
|
+
|
91
|
+
# Serialize this object as a hash: called from JsonCompat.
|
92
|
+
# Verify if this called from JsonCompat during testing.
|
93
|
+
def to_json(*a)
|
94
|
+
for_json.to_json(*a)
|
95
|
+
end
|
96
|
+
|
97
|
+
def for_json
|
98
|
+
result = {
|
99
|
+
"id" => id,
|
100
|
+
"name" => name,
|
101
|
+
"cli" => cli,
|
102
|
+
"cloudtemplates" => cloudtemplates
|
103
|
+
}
|
104
|
+
result
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
def self.json_create(o)
|
109
|
+
cloudtool = new
|
110
|
+
cloudtool.id(o["id"]) if o.has_key?("id")
|
111
|
+
cloudtool.name(o["name"]) if o.has_key?("name")
|
112
|
+
cloudtool.cli(o["cli"]) if o.has_key?("cli")
|
113
|
+
cloudtool.cloudtemplates(o["cloudtemplates"]) if o.has_key?("cloudtemplates")
|
114
|
+
|
115
|
+
#success or error
|
116
|
+
cloudtool.some_msg[:code] = o["code"] if o.has_key?("code")
|
117
|
+
cloudtool.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
118
|
+
cloudtool.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
119
|
+
cloudtool.some_msg[:links] = o["links"] if o.has_key?("links")
|
120
|
+
cloudtool
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.from_hash(o)
|
124
|
+
cloudtool = self.new()
|
125
|
+
cloudtool.from_hash(o)
|
126
|
+
cloudtool
|
127
|
+
end
|
128
|
+
|
129
|
+
def from_hash(o)
|
130
|
+
@provider = o[:provider] if o.has_key?(:provider)
|
131
|
+
self
|
132
|
+
end
|
133
|
+
|
134
|
+
# Load all cloudtools -
|
135
|
+
# returns a CloudToolsCollection
|
136
|
+
def self.list
|
137
|
+
ct = self.new()
|
138
|
+
ct.megam_rest.get_cloudtools
|
139
|
+
end
|
140
|
+
|
141
|
+
# Show a particular cloudtool by name,
|
142
|
+
# Megam::CloudTool
|
143
|
+
def self.show(p_name)
|
144
|
+
megam_rest.get_cloudtool(p_name)
|
145
|
+
self
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_s
|
149
|
+
Megam::Stuff.styled_hash(to_hash)
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2013 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
|
+
module Megam
|
17
|
+
class CloudToolCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@cloudtools = Array.new
|
23
|
+
@cloudtools_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_cloudtools
|
28
|
+
@cloudtools
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@cloudtools[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_cloudtool(arg)
|
37
|
+
@cloudtools[index] = arg
|
38
|
+
@cloudtools_by_name[arg.name] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_cloudtool(a)
|
44
|
+
@cloudtools << a
|
45
|
+
@cloudtools_by_name[a.name] =@cloudtools.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(cloudtool)
|
54
|
+
is_megam_cloudtool(cloudtool)
|
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
|
+
# cloudtools
|
59
|
+
@cloudtools.insert(@insert_after_idx + 1, cloudtool)
|
60
|
+
# update name -> location mappings and register new cloudtools
|
61
|
+
@cloudtools_by_name.each_key do |key|
|
62
|
+
@cloudtools_by_name[key] += 1 if@cloudtools_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@cloudtools_by_name[cloudtool.name] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@cloudtools << cloudtool
|
68
|
+
@cloudtools_by_name[cloudtool.name] =@cloudtools.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@cloudtools.each do |cloudtool|
|
74
|
+
yield cloudtool
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@cloudtools.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@cloudtools.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(cloudtool)
|
89
|
+
lookup_by = nil
|
90
|
+
if cloudtool.kind_of?(Megam::CloudTool)
|
91
|
+
lookup_by = cloudtool.name
|
92
|
+
elsif cloudtool.kind_of?(String)
|
93
|
+
lookup_by = cloudtool
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::CloudTools or String to lookup"
|
96
|
+
end
|
97
|
+
res =@cloudtools_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a cloudtools matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@cloudtools[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Transform the ruby obj -> to a Hash
|
105
|
+
def to_hash
|
106
|
+
index_hash = Hash.new
|
107
|
+
self.each do |cloudtool|
|
108
|
+
index_hash[cloudtool.name] = cloudtool.to_s
|
109
|
+
end
|
110
|
+
index_hash
|
111
|
+
end
|
112
|
+
|
113
|
+
# Serialize this object as a hash: called from JsonCompat.
|
114
|
+
# Verify if this called from JsonCompat during testing.
|
115
|
+
def to_json(*a)
|
116
|
+
for_json.to_json(*a)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def self.json_create(o)
|
121
|
+
collection = self.new()
|
122
|
+
o["results"].each do |cloudtools_list|
|
123
|
+
cloudtools_array = cloudtools_list.kind_of?(Array) ? cloudtools_list : [ cloudtools_list ]
|
124
|
+
cloudtools_array.each do |cloudtool|
|
125
|
+
collection.insert(cloudtool)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
collection
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def is_megam_cloudtool(arg)
|
134
|
+
unless arg.kind_of?(Megam::CloudTool)
|
135
|
+
raise ArgumentError, "Members must be Megam::CloudTool's"
|
136
|
+
end
|
137
|
+
true
|
138
|
+
end
|
139
|
+
|
140
|
+
def to_s
|
141
|
+
Megam::Stuff.styled_hash(to_hash)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|