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,166 @@
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 NodeCollection
18
+ include Enumerable
19
+
20
+
21
+ attr_reader :iterator
22
+ def initialize
23
+ @nodes = Array.new
24
+ @nodes_by_name = Hash.new
25
+ @insert_after_idx = nil
26
+ end
27
+
28
+ def all_nodes
29
+ @nodes
30
+ end
31
+
32
+ def [](index)
33
+ @nodes[index]
34
+ end
35
+
36
+ def []=(index, arg)
37
+ is_megam_node(arg)
38
+ @nodes[index] = arg
39
+ @nodes_by_name[arg.node_name] = index
40
+ end
41
+
42
+ def <<(*args)
43
+ args.flatten.each do |a|
44
+ is_megam_node(a)
45
+ @nodes << a
46
+ @nodes_by_name[a.node_name] = @nodes.length - 1
47
+ end
48
+ self
49
+ end
50
+
51
+ # 'push' is an alias method to <<
52
+ alias_method :push, :<<
53
+
54
+ def insert(node)
55
+ is_megam_node(node)
56
+ if @insert_after_idx
57
+ # in the middle of executing a run, so any nodes inserted now should
58
+ # be placed after the most recent addition done by the currently executing
59
+ # node
60
+ @nodes.insert(@insert_after_idx + 1, node)
61
+ # update name -> location mappings and register new node
62
+ @nodes_by_name.each_key do |key|
63
+ @nodes_by_name[key] += 1 if @nodes_by_name[key] > @insert_after_idx
64
+ end
65
+ @nodes_by_name[node.node_name] = @insert_after_idx + 1
66
+ @insert_after_idx += 1
67
+ else
68
+ @nodes << node
69
+ @nodes_by_name[node.node_name] = @nodes.length - 1
70
+ end
71
+ end
72
+
73
+ def each
74
+ @nodes.each do |node|
75
+ yield node
76
+ end
77
+ end
78
+
79
+ def each_index
80
+ @nodes.each_index do |i|
81
+ yield i
82
+ end
83
+ end
84
+
85
+ def empty?
86
+ @nodes.empty?
87
+ end
88
+
89
+ def lookup(node)
90
+ lookup_by = nil
91
+ if node.kind_of?(Megam::Node)
92
+ lookup_by = node.node_name
93
+ elsif node.kind_of?(String)
94
+ lookup_by = node
95
+ else
96
+ raise ArgumentError, "Must pass a Megam::Node or String to lookup"
97
+ end
98
+ res = @nodes_by_name[lookup_by]
99
+ unless res
100
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
101
+ end
102
+ @nodes[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 |node|
109
+ index_hash[node.node_name] = node.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
+ =begin
122
+ ["json_claz":"Megam::NodeCollection",{
123
+ "id":"NOD362428315933343744",
124
+ "accounts_id":"ACT362211963352121344",
125
+ "json_claz":"Megam::Node",
126
+ "request":{
127
+ "req_id":"NOD362428315933343744",
128
+ "command":"commands"
129
+ },
130
+ "predefs":{
131
+ "name":"",
132
+ "scm":"",
133
+ "war":"",
134
+ "db":"",
135
+ "queue":""
136
+ }
137
+ }]
138
+ =end
139
+ def self.json_create(o)
140
+ collection = self.new()
141
+ o["results"].each do |nodes_list|
142
+ nodes_array = nodes_list.kind_of?(Array) ? nodes_list : [ nodes_list ]
143
+ nodes_array.each do |node|
144
+ collection.insert(node)
145
+ end
146
+ end
147
+ collection
148
+ end
149
+
150
+ private
151
+
152
+
153
+
154
+ def is_megam_node(arg)
155
+ unless arg.kind_of?(Megam::Node)
156
+ raise ArgumentError, "Members must be Megam::Node's"
157
+ end
158
+ true
159
+ end
160
+
161
+ def to_s
162
+ Megam::Stuff.styled_hash(to_hash)
163
+ end
164
+
165
+ end
166
+ end
@@ -0,0 +1,208 @@
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 Predef
18
+
19
+ def initialize
20
+ @id = nil
21
+ @name = nil
22
+ @provider = nil
23
+ @provider_role =nil
24
+ @build_monkey=nil
25
+ @runtime_exec = nil
26
+ @created_at = nil
27
+ @some_msg = {}
28
+ end
29
+
30
+ def predef
31
+ self
32
+ end
33
+
34
+ def megam_rest
35
+ options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
36
+ Megam::API.new(options)
37
+ end
38
+
39
+ def id(arg=nil)
40
+ if arg != nil
41
+ @id = arg
42
+ else
43
+ @id
44
+ end
45
+ end
46
+
47
+ def name(arg=nil)
48
+ if arg != nil
49
+ @name = arg
50
+ else
51
+ @name
52
+ end
53
+ end
54
+
55
+ def runtime_exec(arg=nil)
56
+ if arg != nil
57
+ @runtime_exec = arg
58
+ else
59
+ @runtime_exec
60
+ end
61
+ end
62
+
63
+ def provider(arg=nil)
64
+ if arg != nil
65
+ @provider = arg
66
+ else
67
+ @provider
68
+ end
69
+ end
70
+
71
+ def provider_role(arg=nil)
72
+ if arg != nil
73
+ @provider_role = arg
74
+ else
75
+ @provider_role
76
+ end
77
+ end
78
+
79
+ def build_monkey(arg=nil)
80
+ if arg != nil
81
+ @build_monkey = arg
82
+ else
83
+ @build_monkey
84
+ end
85
+ end
86
+
87
+ def created_at(arg=nil)
88
+ if arg != nil
89
+ @created_at = arg
90
+ else
91
+ @created_at
92
+ end
93
+ end
94
+
95
+ def some_msg(arg=nil)
96
+ if arg != nil
97
+ @some_msg = arg
98
+ else
99
+ @some_msg
100
+ end
101
+ end
102
+
103
+ def error?
104
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
105
+ end
106
+
107
+ # Transform the ruby obj -> to a Hash
108
+ def to_hash
109
+ index_hash = Hash.new
110
+ index_hash["json_claz"] = self.class.name
111
+ index_hash["id"] = id
112
+ index_hash["name"] = name
113
+ index_hash["provider"] = provider
114
+ index_hash["provider_role"] = provider_role
115
+ index_hash["build_monkey"] = build_monkey
116
+ index_hash["runtime_exec"] = runtime_exec
117
+ index_hash["created_at"] = created_at
118
+ index_hash
119
+ end
120
+
121
+ # Serialize this object as a hash: called from JsonCompat.
122
+ # Verify if this called from JsonCompat during testing.
123
+ def to_json(*a)
124
+ for_json.to_json(*a)
125
+ end
126
+
127
+ def for_json
128
+ result = {
129
+ "id" => id,
130
+ "name" => name,
131
+ "provider" => provider,
132
+ "provider_role" => provider_role,
133
+ "build_monkey" => build_monkey,
134
+ "runtime_exec" => runtime_exec,
135
+ "created_at" => created_at
136
+ }
137
+ result
138
+ end
139
+
140
+ #
141
+ def self.json_create(o)
142
+ node = new
143
+ node.id(o["id"]) if o.has_key?("id")
144
+ node.name(o["name"]) if o.has_key?("name")
145
+ node.provider(o["provider"]) if o.has_key?("provider")
146
+ node.provider_role(o["provider_role"]) if o.has_key?("provider_role")
147
+ node.build_monkey(o["build_monkey"]) if o.has_key?("build_monkey")
148
+ node.runtime_exec(o["runtime_exec"]) if o.has_key?("runtime_exec")
149
+ node.created_at(o["created_at"]) if o.has_key?("created_at")
150
+ #success or error
151
+ node.some_msg[:code] = o["code"] if o.has_key?("code")
152
+ node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
153
+ node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
154
+ node.some_msg[:links] = o["links"] if o.has_key?("links")
155
+ node
156
+ end
157
+
158
+ def self.from_hash(o)
159
+ node = self.new()
160
+ node.from_hash(o)
161
+ node
162
+ end
163
+
164
+ def from_hash(o)
165
+ @id = o[:id] if o.has_key?(:id)
166
+ @name = o[:name] if o.has_key?(:name)
167
+ @provider = o[:provider] if o.has_key?(:provider)
168
+ @provider_role = o[:provider_role] if o.has_key?(:provider_role)
169
+ @build_monkey = o[:build_monkey] if o.has_key?(:build_monkey)
170
+ @runtime_exec = o[:runtime_exec] if o.has_key?(:runtime_exec)
171
+ @created_at = o[:created_at] if o.has_key?(:created_at)
172
+ self
173
+ end
174
+
175
+ def self.create
176
+ predef = build
177
+ predef.create
178
+ end
179
+
180
+
181
+ # Create the predef via the REST API
182
+ def create(predef_input)
183
+ megam_rest.post_predef(predef_input)
184
+ self
185
+ end
186
+
187
+ # Load all predefs -
188
+ # returns a PredefsCollection
189
+ # don't return self. check if the Megam::PredefCollection is returned.
190
+ def self.list
191
+ prede = self.new()
192
+ prede.megam_rest.get_predefs
193
+ end
194
+
195
+ # Show a particular predef by name,
196
+ # Megam::Predef
197
+ def self.show(p_name)
198
+ prede = self.new()
199
+ prede.megam_rest.get_predef(p_name)
200
+ end
201
+
202
+ def to_s
203
+ Megam::Stuff.styled_hash(to_hash)
204
+ #"---> Megam::Account:[error=#{error?}]\n"+
205
+ end
206
+
207
+ end
208
+ end
@@ -0,0 +1,164 @@
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 PredefCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @predefs = Array.new
23
+ @predefs_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
26
+
27
+ def all_predefs
28
+ @predefs
29
+ end
30
+
31
+ def [](index)
32
+ @predefs[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_predef(arg)
37
+ @predefs[index] = arg
38
+ @predefs_by_name[arg.name] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_predef(a)
44
+ @predefs << a
45
+ @predefs_by_name[a.name] = @predefs.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(predef)
54
+ is_megam_predef(predef)
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
+ # predef
59
+ @predefs.insert(@insert_after_idx + 1, predef)
60
+ # update name -> location mappings and register new predef
61
+ @predefs_by_name.each_key do |key|
62
+ @predefs_by_name[key] += 1 if @predefs_by_name[key] > @insert_after_idx
63
+ end
64
+ @predefs_by_name[predef.name] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @predefs << predef
68
+ @predefs_by_name[predef.name] = @predefs.length - 1
69
+ end
70
+ end
71
+
72
+ def each
73
+ @predefs.each do |predef|
74
+ yield predef
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @predefs.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @predefs.empty?
86
+ end
87
+
88
+ def lookup(predef)
89
+ lookup_by = nil
90
+ if predef.kind_of?(Megam::Predef)
91
+ lookup_by = predef.name
92
+ elsif predef.kind_of?(String)
93
+ lookup_by = predef
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::Predef or String to lookup"
96
+ end
97
+ res = @predefs_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a predef matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @predefs[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 |predef|
108
+ index_hash[predef.name] = predef.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
+ =begin
120
+ {
121
+ "json_claz":"Megam::PredefCollection",
122
+ "results":[{
123
+ "id":"PRE362554468593565696",
124
+ "name":"rabbitmq",
125
+ "provider":"chef",
126
+ "provider_role":"rabbitmq",
127
+ "build_monkey":"none",
128
+ "json_claz":"Megam::Predef"
129
+ },{
130
+ "id":"PRE362554470090932224",
131
+ "name":"mobhtml5",
132
+ "provider":"chef",
133
+ "provider_role":"sencha",
134
+ "build_monkey":"none",
135
+ "json_claz":"Megam::Predef"
136
+ }]
137
+ }
138
+ =end
139
+ def self.json_create(o)
140
+ collection = self.new()
141
+ o["results"].each do |predefs_list|
142
+ predefs_array = predefs_list.kind_of?(Array) ? predefs_list : [ predefs_list ]
143
+ predefs_array.each do |predef|
144
+ collection.insert(predef)
145
+ end
146
+ end
147
+ collection
148
+ end
149
+
150
+ private
151
+
152
+ def is_megam_predef(arg)
153
+ unless arg.kind_of?(Megam::Predef)
154
+ raise ArgumentError, "Members must be Megam::Predef's"
155
+ end
156
+ true
157
+ end
158
+
159
+ def to_s
160
+ Megam::Stuff.styled_hash(to_hash)
161
+ end
162
+
163
+ end
164
+ end