megam_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.project +17 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +5 -0
  6. data/README.md +83 -0
  7. data/Rakefile +10 -0
  8. data/lib/certs/cacert.pem +3554 -0
  9. data/lib/megam/api.rb +244 -0
  10. data/lib/megam/api/accounts.rb +29 -0
  11. data/lib/megam/api/appdefns.rb +26 -0
  12. data/lib/megam/api/appreqs.rb +27 -0
  13. data/lib/megam/api/boltdefns.rb +27 -0
  14. data/lib/megam/api/boltreqs.rb +27 -0
  15. data/lib/megam/api/cloud_tools.rb +35 -0
  16. data/lib/megam/api/errors.rb +27 -0
  17. data/lib/megam/api/login.rb +14 -0
  18. data/lib/megam/api/logs.rb +18 -0
  19. data/lib/megam/api/nodes.rb +50 -0
  20. data/lib/megam/api/predef_clouds.rb +35 -0
  21. data/lib/megam/api/predefs.rb +35 -0
  22. data/lib/megam/api/requests.rb +37 -0
  23. data/lib/megam/api/version.rb +5 -0
  24. data/lib/megam/core/account.rb +170 -0
  25. data/lib/megam/core/appdefns.rb +192 -0
  26. data/lib/megam/core/appdefns_collection.rb +148 -0
  27. data/lib/megam/core/appreqs.rb +224 -0
  28. data/lib/megam/core/appreqs_collection.rb +148 -0
  29. data/lib/megam/core/auth.rb +91 -0
  30. data/lib/megam/core/boltdefns.rb +198 -0
  31. data/lib/megam/core/boltdefns_collection.rb +148 -0
  32. data/lib/megam/core/boltreqs.rb +224 -0
  33. data/lib/megam/core/boltreqs_collection.rb +148 -0
  34. data/lib/megam/core/cloudinstruction.rb +110 -0
  35. data/lib/megam/core/cloudinstruction_collection.rb +145 -0
  36. data/lib/megam/core/cloudinstruction_group.rb +99 -0
  37. data/lib/megam/core/cloudtemplate.rb +127 -0
  38. data/lib/megam/core/cloudtemplate_collection.rb +145 -0
  39. data/lib/megam/core/cloudtool.rb +153 -0
  40. data/lib/megam/core/cloudtool_collection.rb +145 -0
  41. data/lib/megam/core/config.rb +44 -0
  42. data/lib/megam/core/error.rb +99 -0
  43. data/lib/megam/core/json_compat.rb +183 -0
  44. data/lib/megam/core/log.rb +33 -0
  45. data/lib/megam/core/node.rb +347 -0
  46. data/lib/megam/core/node_collection.rb +166 -0
  47. data/lib/megam/core/predef.rb +208 -0
  48. data/lib/megam/core/predef_collection.rb +164 -0
  49. data/lib/megam/core/predefcloud.rb +229 -0
  50. data/lib/megam/core/predefcloud_collection.rb +168 -0
  51. data/lib/megam/core/request.rb +187 -0
  52. data/lib/megam/core/request_collection.rb +145 -0
  53. data/lib/megam/core/stuff.rb +69 -0
  54. data/lib/megam/core/text.rb +88 -0
  55. data/lib/megam_api.rb +1 -0
  56. data/megam_api.gemspec +26 -0
  57. data/test/test_accounts.rb +46 -0
  58. data/test/test_appdefns.rb +23 -0
  59. data/test/test_appreqs.rb +28 -0
  60. data/test/test_boltdefns.rb +23 -0
  61. data/test/test_boltreqs.rb +28 -0
  62. data/test/test_cloudtools.rb +22 -0
  63. data/test/test_helper.rb +67 -0
  64. data/test/test_login.rb +12 -0
  65. data/test/test_logs.rb +15 -0
  66. data/test/test_nodes.rb +141 -0
  67. data/test/test_predefclouds.rb +67 -0
  68. data/test/test_predefs.rb +72 -0
  69. data/test/test_requests.rb +85 -0
  70. metadata +213 -0
@@ -0,0 +1,148 @@
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 AppdefnsCollection
18
+ include Enumerable
19
+
20
+
21
+ attr_reader :iterator
22
+ def initialize
23
+ @appdefns = Array.new
24
+ @appdefns_by_name = Hash.new
25
+ @insert_after_idx = nil
26
+ end
27
+
28
+ def all_appdefns
29
+ @appdefns
30
+ end
31
+
32
+ def [](index)
33
+ @appdefns[index]
34
+ end
35
+
36
+ def []=(index, arg)
37
+ is_megam_appdefn(arg)
38
+ @appdefns[index] = arg
39
+ @appdefns_by_name[arg.id] = index
40
+ end
41
+
42
+ def <<(*args)
43
+ args.flatten.each do |a|
44
+ is_megam_appdefn(a)
45
+ @appdefns << a
46
+ @appdefns_by_name[a.id] = @appdefns.length - 1
47
+ end
48
+ self
49
+ end
50
+
51
+ # 'push' is an alias method to <<
52
+ alias_method :push, :<<
53
+
54
+ def insert(appdefn)
55
+ is_megam_appdefn(appdefn)
56
+ if @insert_after_idx
57
+ # in the middle of executing a run, so any Appdefnss inserted now should
58
+ # be placed after the most recent addition done by the currently executing
59
+ # appdefns
60
+ @appdefns.insert(@insert_after_idx + 1, appdefn)
61
+ # update name -> location mappings and register new appdefns
62
+ @appdefns_by_name.each_key do |key|
63
+ @appdefns_by_name[key] += 1 if @appdefns_by_name[key] > @insert_after_idx
64
+ end
65
+ @appdefns_by_name[appdefn.id] = @insert_after_idx + 1
66
+ @insert_after_idx += 1
67
+ else
68
+ @appdefns << appdefn
69
+ @appdefns_by_name[appdefn.id] = @appdefns.length - 1
70
+ end
71
+ end
72
+
73
+ def each
74
+ @appdefns.each do |appdefn|
75
+ yield appdefn
76
+ end
77
+ end
78
+
79
+ def each_index
80
+ @appdefns.each_index do |i|
81
+ yield i
82
+ end
83
+ end
84
+
85
+ def empty?
86
+ @appdefns.empty?
87
+ end
88
+
89
+ def lookup(appdefn)
90
+ lookup_by = nil
91
+ if appdefn.kind_of?(Megam::Appdefns)
92
+ lookup_by = appdefn.id
93
+ elsif appdefn.kind_of?(String)
94
+ lookup_by = appdefn
95
+ else
96
+ raise ArgumentError, "Must pass a Megam::Appdefns or String to lookup"
97
+ end
98
+ res = @appdefns_by_name[lookup_by]
99
+ unless res
100
+ raise ArgumentError, "Cannot find a appdefn matching #{lookup_by} (did you define it first?)"
101
+ end
102
+ @appdefns[res]
103
+ end
104
+
105
+ # Transform the ruby obj -> to a Hash
106
+ def to_hash
107
+ index_hash = Hash.new
108
+ self.each do |appdefn|
109
+ index_hash[appdefn.id] = appdefn.to_s
110
+ end
111
+ index_hash
112
+ end
113
+
114
+ # Serialize this object as a hash: called from JsonCompat.
115
+ # Verify if this called from JsonCompat during testing.
116
+ def to_json(*a)
117
+ for_json.to_json(*a)
118
+ end
119
+
120
+
121
+ def self.json_create(o)
122
+ collection = self.new()
123
+ o["results"].each do |appdefns_list|
124
+ appdefns_array = appdefns_list.kind_of?(Array) ? appdefns_list : [ appdefns_list ]
125
+ appdefns_array.each do |appdefn|
126
+ collection.insert(appdefn)
127
+ end
128
+ end
129
+ collection
130
+ end
131
+
132
+ private
133
+
134
+
135
+
136
+ def is_megam_appdefn(arg)
137
+ unless arg.kind_of?(Megam::Appdefns)
138
+ raise ArgumentError, "Members must be Megam::Appdefn's"
139
+ end
140
+ true
141
+ end
142
+
143
+ def to_s
144
+ Megam::Stuff.styled_hash(to_hash)
145
+ end
146
+
147
+ end
148
+ end
@@ -0,0 +1,224 @@
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 Appreqs
18
+ # Each notify entry is a resource/action pair, modeled as an
19
+ # Struct with a #resource and #action member
20
+ =begin
21
+ def self.hash_tree
22
+ Hash.new do |hash, key|
23
+ hash[key] = hash_tree
24
+ end
25
+ end
26
+ =end
27
+
28
+ def initialize
29
+ @id = nil
30
+ @req_type = nil
31
+ @appdefns_id = nil
32
+ @node_name = nil
33
+ @lc_apply = nil
34
+ @lc_additional = nil
35
+ @lc_when = nil
36
+ @created_at = nil
37
+ end
38
+ def node
39
+ self
40
+ end
41
+
42
+ def megam_rest
43
+ options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
44
+ Megam::API.new(options)
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 req_type(arg=nil)
56
+ if arg != nil
57
+ @req_type = arg
58
+ else
59
+ @req_type
60
+ end
61
+ end
62
+
63
+ def appdefns_id(arg=nil)
64
+ if arg != nil
65
+ @appdefns_id = arg
66
+ else
67
+ @appdefns_id
68
+ end
69
+ end
70
+
71
+ def node_name(arg=nil)
72
+ if arg != nil
73
+ @node_name = arg
74
+ else
75
+ @node_name
76
+ end
77
+ end
78
+
79
+ def lc_apply(arg=nil)
80
+ if arg != nil
81
+ @lc_apply = arg
82
+ else
83
+ @lc_apply
84
+ end
85
+ end
86
+
87
+ def lc_additional(arg=nil)
88
+ if arg != nil
89
+ @lc_additional = arg
90
+ else
91
+ @lc_additional
92
+ end
93
+ end
94
+
95
+ def lc_when(arg=nil)
96
+ if arg != nil
97
+ @lc_when = arg
98
+ else
99
+ @lc_when
100
+ end
101
+ end
102
+
103
+ def created_at(arg=nil)
104
+ if arg != nil
105
+ @created_at = arg
106
+ else
107
+ @created_at
108
+ end
109
+ end
110
+
111
+ def error?
112
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
113
+ end
114
+
115
+ # Transform the ruby obj -> to a Hash
116
+ def to_hash
117
+ index_hash = Hash.new
118
+ index_hash["json_claz"] = self.class.name
119
+ index_hash["id"] = id
120
+ index_hash["req_type"] = req_type
121
+ index_hash["appdefns_id"] = appdefns_id
122
+ index_hash["node_name"] = node_name
123
+ index_hash["lc_apply"] = lc_apply
124
+ index_hash["lc_additional"] = lc_additional
125
+ index_hash["lc_when"] = lc_when
126
+ index_hash["created_at"] = created_at
127
+ index_hash
128
+ end
129
+
130
+ # Serialize this object as a hash: called from JsonCompat.
131
+ # Verify if this called from JsonCompat during testing.
132
+ def to_json(*a)
133
+ for_json.to_json(*a)
134
+ end
135
+
136
+ def for_json
137
+ result = {
138
+ "id" => id,
139
+ "req_type" => req_type,
140
+ "appdefns_id" => appdefns_id,
141
+ "node_name" => node_name,
142
+ "lc_apply" => lc_apply,
143
+ "lc_additional" => lc_additional,
144
+ "lc_when" => lc_when,
145
+ "created_at" => created_at
146
+ }
147
+ result
148
+ end
149
+
150
+
151
+ # Create a Megam::Node from NodeResult-JSON
152
+ #
153
+ #[{
154
+ #"id":"NOD362212018897289216",
155
+ #"accounts_id":"ACT362211962353876992",
156
+ #"json_claz":"Megam::Node",
157
+ #"request":{
158
+ #"req_id":"NOD362212018897289216",
159
+ #"command":"commands"
160
+ #},
161
+ #"predefs":{
162
+ #"name":"",
163
+ #"scm":"",
164
+ #"war":"",
165
+ #"db":"",
166
+ #"queue":""
167
+ #}
168
+ #}]
169
+ #
170
+ def self.json_create(o)
171
+ node = new
172
+ node.id(o["id"]) if o.has_key?("id")
173
+ node.req_type(o["req_type"]) if o.has_key?("req_type")
174
+ node.appdefns_id(o["appdefns_id"]) if o.has_key?("appdefns_id")
175
+ node.node_name(o["node_name"]) if o.has_key?("node_name")
176
+ node.lc_apply(o["lc_apply"]) if o.has_key?("lc_apply")
177
+ node.lc_additional(o["lc_additional"]) if o.has_key?("lc_additional")
178
+ node.lc_when(o["lc_when"]) if o.has_key?("lc_when")
179
+ node.created_at(o["created_at"]) if o.has_key?("created_at")
180
+
181
+ node
182
+ end
183
+
184
+ def self.from_hash(o)
185
+ node = self.new()
186
+ node.from_hash(o)
187
+ node
188
+ end
189
+
190
+ def from_hash(o)
191
+ @id = o["id"] if o.has_key?("id")
192
+ @req_type = o["req_type"] if o.has_key?("req_type")
193
+ @appdefns_id = o["appdefns_id"] if o.has_key?("appdefns_id")
194
+ @node_name = o["node_name"] if o.has_key?("node_name")
195
+ @lc_apply = o["lc_apply"] if o.has_key?("lc_apply")
196
+ @lc_additional = o["lc_additional"] if o.has_key?("lc_additional")
197
+ @lc_when = o["lc_when"] if o.has_key?("lc_when")
198
+ @created_at = o["created_at"] if o.has_key?("created_at")
199
+ self
200
+ end
201
+
202
+ def self.create(o)
203
+ acct = from_hash(o)
204
+ acct.create
205
+ end
206
+
207
+ # Create the node via the REST API
208
+ def create
209
+ megam_rest.post_node(to_hash)
210
+ end
211
+
212
+ # Load a account by email_p
213
+ def self.show(node_name)
214
+ megam_rest.get_node(node_name)
215
+ self
216
+ end
217
+
218
+ def to_s
219
+ Megam::Stuff.styled_hash(to_hash)
220
+ #"---> Megam::Account:[error=#{error?}]\n"+
221
+ end
222
+
223
+ end
224
+ end
@@ -0,0 +1,148 @@
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 AppreqsCollection
18
+ include Enumerable
19
+
20
+
21
+ attr_reader :iterator
22
+ def initialize
23
+ @appreqs = Array.new
24
+ @appreqs_by_name = Hash.new
25
+ @insert_after_idx = nil
26
+ end
27
+
28
+ def all_appreqs
29
+ @appreqs
30
+ end
31
+
32
+ def [](index)
33
+ @appreqs[index]
34
+ end
35
+
36
+ def []=(index, arg)
37
+ is_megam_appreq(arg)
38
+ @appreqs[index] = arg
39
+ @appreqs_by_name[arg.id] = index
40
+ end
41
+
42
+ def <<(*args)
43
+ args.flatten.each do |a|
44
+ is_megam_appreq(a)
45
+ @appreqs << a
46
+ @appreqs_by_name[a.id] = @appreqs.length - 1
47
+ end
48
+ self
49
+ end
50
+
51
+ # 'push' is an alias method to <<
52
+ alias_method :push, :<<
53
+
54
+ def insert(appreq)
55
+ is_megam_appreq(appreq)
56
+ if @insert_after_idx
57
+ # in the middle of executing a run, so any Appreqss inserted now should
58
+ # be placed after the most recent addition done by the currently executing
59
+ # appreqs
60
+ @appreqs.insert(@insert_after_idx + 1, appreq)
61
+ # update name -> location mappings and register new appreqs
62
+ @appreqs_by_name.each_key do |key|
63
+ @appreqs_by_name[key] += 1 if @appreqs_by_name[key] > @insert_after_idx
64
+ end
65
+ @appreqs_by_name[appreq.id] = @insert_after_idx + 1
66
+ @insert_after_idx += 1
67
+ else
68
+ @appreqs << appreq
69
+ @appreqs_by_name[appreq.id] = @appreqs.length - 1
70
+ end
71
+ end
72
+
73
+ def each
74
+ @appreqs.each do |appreq|
75
+ yield appreq
76
+ end
77
+ end
78
+
79
+ def each_index
80
+ @appreqs.each_index do |i|
81
+ yield i
82
+ end
83
+ end
84
+
85
+ def empty?
86
+ @appreqs.empty?
87
+ end
88
+
89
+ def lookup(appreq)
90
+ lookup_by = nil
91
+ if appreq.kind_of?(Megam::Appreqs)
92
+ lookup_by = appreq.id
93
+ elsif appreq.kind_of?(String)
94
+ lookup_by = appreq
95
+ else
96
+ raise ArgumentError, "Must pass a Megam::Appreqs or String to lookup"
97
+ end
98
+ res = @appreqs_by_name[lookup_by]
99
+ unless res
100
+ raise ArgumentError, "Cannot find a appreq matching #{lookup_by} (did you define it first?)"
101
+ end
102
+ @appreqs[res]
103
+ end
104
+
105
+ # Transform the ruby obj -> to a Hash
106
+ def to_hash
107
+ index_hash = Hash.new
108
+ self.each do |appreq|
109
+ index_hash[appreq.id] = appreq.to_s
110
+ end
111
+ index_hash
112
+ end
113
+
114
+ # Serialize this object as a hash: called from JsonCompat.
115
+ # Verify if this called from JsonCompat during testing.
116
+ def to_json(*a)
117
+ for_json.to_json(*a)
118
+ end
119
+
120
+
121
+ def self.json_create(o)
122
+ collection = self.new()
123
+ o["results"].each do |appreqs_list|
124
+ appreqs_array = appreqs_list.kind_of?(Array) ? appreqs_list : [ appreqs_list ]
125
+ appreqs_array.each do |appreq|
126
+ collection.insert(appreq)
127
+ end
128
+ end
129
+ collection
130
+ end
131
+
132
+ private
133
+
134
+
135
+
136
+ def is_megam_appreq(arg)
137
+ unless arg.kind_of?(Megam::Appreqs)
138
+ raise ArgumentError, "Members must be Megam::Appreq's"
139
+ end
140
+ true
141
+ end
142
+
143
+ def to_s
144
+ Megam::Stuff.styled_hash(to_hash)
145
+ end
146
+
147
+ end
148
+ end