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,229 @@
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 PredefCloud
18
+ # Each notify entry is a resource/action pair, modeled as an
19
+ # Struct with a #resource and #action member
20
+ def initialize
21
+ @id = nil
22
+ @name = nil
23
+ @accounts_id = nil
24
+ @spec = {}
25
+ @access = {}
26
+ #@ideal=nil
27
+ #@performance = nil
28
+ @created_at = nil
29
+ @some_msg = {}
30
+ end
31
+
32
+ def predef_cloud
33
+ self
34
+ end
35
+
36
+ def megam_rest
37
+ options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
38
+ Megam::API.new(options)
39
+ end
40
+
41
+ def id(arg=nil)
42
+ if arg != nil
43
+ @id = arg
44
+ else
45
+ @id
46
+ end
47
+ end
48
+
49
+ def name(arg=nil)
50
+ if arg != nil
51
+ @name = arg
52
+ else
53
+ @name
54
+ end
55
+ end
56
+
57
+ def accounts_id(arg=nil)
58
+ if arg != nil
59
+ @accounts_id= arg
60
+ else
61
+ @accounts_id
62
+ end
63
+ end
64
+
65
+ def spec(arg=nil)
66
+ if arg != nil
67
+ @spec = arg
68
+ else
69
+ @spec
70
+ end
71
+ end
72
+
73
+ def access(arg=nil)
74
+ if arg != nil
75
+ @access = arg
76
+ else
77
+ @access
78
+ end
79
+ end
80
+
81
+ def ideal(arg=nil)
82
+ if arg != nil
83
+ @ideal= arg
84
+ else
85
+ @ideal
86
+ end
87
+ end
88
+
89
+ def performance(arg=nil)
90
+ if arg != nil
91
+ @performance= arg
92
+ else
93
+ @performance
94
+ end
95
+ end
96
+
97
+ def created_at(arg=nil)
98
+ if arg != nil
99
+ @created_at = arg
100
+ else
101
+ @created_at
102
+ end
103
+ end
104
+
105
+ def some_msg(arg=nil)
106
+ if arg != nil
107
+ @some_msg = arg
108
+ else
109
+ @some_msg
110
+ end
111
+ end
112
+
113
+ def error?
114
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
115
+ end
116
+
117
+ # Transform the ruby obj -> to a Hash
118
+ def to_hash
119
+ index_hash = Hash.new
120
+ index_hash["json_claz"] = self.class.name
121
+ index_hash["id"] = id
122
+ index_hash["name"] = name
123
+ index_hash["accounts_id"] = accounts_id
124
+ index_hash["spec"] = spec
125
+ index_hash["access"] = access
126
+ # index_hash["ideal"] = ideal
127
+ # index_hash["performance"] = performance
128
+ index_hash["created_at"] = created_at
129
+ index_hash
130
+ end
131
+
132
+ # Serialize this object as a hash: called from JsonCompat.
133
+ # Verify if this called from JsonCompat during testing.
134
+ def to_json(*a)
135
+ for_json.to_json(*a)
136
+ end
137
+
138
+ def for_json
139
+ result = {
140
+ "id" => id,
141
+ "name" => name,
142
+ "accounts_id" => accounts_id,
143
+ "spec" => spec,
144
+ "access" => access,
145
+ # "ideal" => ideal,
146
+ # "performance" => performance,
147
+ "created_at" => created_at
148
+ }
149
+ result
150
+ end
151
+
152
+ #
153
+ def self.json_create(o)
154
+ predefcd = new
155
+ predefcd.id(o["id"]) if o.has_key?("id")
156
+ predefcd.name(o["name"]) if o.has_key?("name")
157
+ #requests
158
+ oq = o["spec"]
159
+ predefcd.spec[:type_name] = oq["type_name"] if oq && oq.has_key?("type_name")
160
+ predefcd.spec[:groups] = oq["groups"] if oq && oq.has_key?("groups")
161
+ predefcd.spec[:image] = oq["image"] if oq && oq.has_key?("image")
162
+ predefcd.spec[:flavor] = oq["flavor"] if oq && oq.has_key?("flavor")
163
+ #predef
164
+ op = o["access"]
165
+ predefcd.access[:ssh_key] = op["ssh_key"] if op && op.has_key?("ssh_key")
166
+ predefcd.access[:identity_file] = op["identity_file"] if op && op.has_key?("identity_file")
167
+ predefcd.access[:ssh_user]= op["ssh_user"] if op && op.has_key?("ssh_user")
168
+ #access
169
+ # predefcd.ideal(o["ideal"]) if o.has_key?("ideal")
170
+ # predefcd.performance(o["performance"]) if o.has_key?("performance")
171
+ predefcd.created_at(o["created_at"]) if o.has_key?("created_at")
172
+ #success or error
173
+ predefcd.some_msg[:code] = o["code"] if o.has_key?("code")
174
+ predefcd.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
175
+ predefcd.some_msg[:msg]= o["msg"] if o.has_key?("msg")
176
+ predefcd.some_msg[:links] = o["links"] if o.has_key?("links")
177
+ predefcd
178
+ end
179
+
180
+ def self.from_hash(o)
181
+ predefcd = self.new()
182
+ predefcd.from_hash(o)
183
+ predefcd
184
+ end
185
+
186
+ def from_hash(o)
187
+ @id = o[:id] if o.has_key?(:id)
188
+ @name = o[:name] if o.has_key?(:name)
189
+ @spec = o[:spec] if o.has_key?(:spec)
190
+ @access = o[:access] if o.has_key?(:access)
191
+ # @ideal = o[:ideal] if o.has_key?(:ideal)
192
+ # @performance = o[:performance] if o.has_key?(:performance)
193
+ @created_at = o[:created_at] if o.has_key?(:created_at)
194
+ self
195
+ end
196
+
197
+ def self.create(o)
198
+ acct = from_hash(o)
199
+ acct.create
200
+ end
201
+
202
+ # Create the predef via the REST API
203
+ def create
204
+ megam_rest.post_predefcloud(to_hash)
205
+ end
206
+
207
+ # Load all predefs -
208
+ # returns a PredefsCollection
209
+ # don't return self. check if the Megam::PredefCollection is returned.
210
+ def self.list
211
+ predef = self.new()
212
+ predef.megam_rest.get_predefclouds
213
+ end
214
+
215
+ # Show a particular predef by name,
216
+ # Megam::Predef
217
+ def self.show(p_name)
218
+ pre = self.new()
219
+ pre.megam_rest.get_predefcloud(p_name)
220
+ self
221
+ end
222
+
223
+ def to_s
224
+ Megam::Stuff.styled_hash(to_hash)
225
+ #"---> Megam::Account:[error=#{error?}]\n"+
226
+ end
227
+
228
+ end
229
+ end
@@ -0,0 +1,168 @@
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 PredefCloudCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @predefclouds = Array.new
23
+ @predefclouds_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
26
+
27
+ def all_predefclouds
28
+ @predefclouds
29
+ end
30
+
31
+ def [](index)
32
+ @predefclouds[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_predefclouds(arg)
37
+ @predefclouds[index] = arg
38
+ @predefclouds_by_name[arg.name] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_predefclouds(a)
44
+ @predefclouds << a
45
+ @predefclouds_by_name[a.name] =@predefclouds.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(predefclouds)
54
+ is_megam_predefclouds(predefclouds)
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
+ # predefclouds
59
+ @predefclouds.insert(@insert_after_idx + 1, predefclouds)
60
+ # update name -> location mappings and register new predefclouds
61
+ @predefclouds_by_name.each_key do |key|
62
+ @predefclouds_by_name[key] += 1 if@predefclouds_by_name[key] > @insert_after_idx
63
+ end
64
+ @predefclouds_by_name[predefclouds.name] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @predefclouds << predefclouds
68
+ @predefclouds_by_name[predefclouds.name] =@predefclouds.length - 1
69
+ end
70
+ end
71
+
72
+ def each
73
+ @predefclouds.each do |predefclouds|
74
+ yield predefclouds
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @predefclouds.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @predefclouds.empty?
86
+ end
87
+
88
+ def lookup(predefclouds)
89
+ lookup_by = nil
90
+ if predefclouds.kind_of?(Megam::PredefCloud)
91
+ lookup_by = predefclouds.name
92
+ elsif predefclouds.kind_of?(String)
93
+ lookup_by = predefclouds
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::PredefClouds or String to lookup"
96
+ end
97
+ res =@predefclouds_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a predefclouds matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @predefclouds[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 |predefclouds|
108
+ index_hash[predefclouds.name] = predefclouds.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::PredefCloudCollection",
122
+ "results":[{
123
+ "id":"NOD362554470640386048",
124
+ "name":"ec2_rails",
125
+ "account_id":"ACT362544229488001024",
126
+ "json_claz":"Megam::PredefCloud",
127
+ "spec":{
128
+ "type_name":"sensor-type",
129
+ "groups":"sens-group",
130
+ "image":"sens-image",
131
+ "flavor":"sens-flvr"
132
+ },
133
+ "access":{
134
+ "ssh_key":"sens-ssh",
135
+ "identity_file":"sens-identity-file",
136
+ "ssh_user":"sens-sshuser"
137
+ },
138
+ "ideal":"",
139
+ "performance":""
140
+ }]
141
+ }
142
+ =end
143
+ def self.json_create(o)
144
+ collection = self.new()
145
+ o["results"].each do |predefclouds_list|
146
+ predefclouds_array = predefclouds_list.kind_of?(Array) ? predefclouds_list : [ predefclouds_list ]
147
+ predefclouds_array.each do |predefclouds|
148
+ collection.insert(predefclouds)
149
+ end
150
+ end
151
+ collection
152
+ end
153
+
154
+ private
155
+
156
+ def is_megam_predefclouds(arg)
157
+ unless arg.kind_of?(Megam::PredefCloud)
158
+ raise ArgumentError, "Members must be Megam::PredefClouds's"
159
+ end
160
+ true
161
+ end
162
+
163
+ def to_s
164
+ Megam::Stuff.styled_hash(to_hash)
165
+ end
166
+
167
+ end
168
+ end
@@ -0,0 +1,187 @@
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 Request
18
+ def initialize
19
+ @id = nil
20
+ @node_id = nil
21
+ @node_name = nil
22
+ @req_type = nil
23
+ @command =nil
24
+ @some_msg = {}
25
+ @created_at = nil
26
+ end
27
+
28
+ def request
29
+ self
30
+ end
31
+
32
+ def megam_rest
33
+ options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
34
+ Megam::API.new(options)
35
+ end
36
+
37
+ def id(arg=nil)
38
+ if arg != nil
39
+ @id = arg
40
+ else
41
+ @id
42
+ end
43
+ end
44
+
45
+ def node_id(arg=nil)
46
+ if arg != nil
47
+ @node_id = arg
48
+ else
49
+ @node_id
50
+ end
51
+ end
52
+
53
+ def node_name(arg=nil)
54
+ if arg != nil
55
+ @node_name = arg
56
+ else
57
+ @node_name
58
+ end
59
+ end
60
+ def req_type(arg=nil)
61
+ if arg != nil
62
+ @req_type = arg
63
+ else
64
+ @req_type
65
+ end
66
+ end
67
+ def created_at(arg=nil)
68
+ if arg != nil
69
+ @created_at = arg
70
+ else
71
+ @created_at
72
+ end
73
+ end
74
+
75
+ def command(arg=nil)
76
+ if arg != nil
77
+ @command = arg
78
+ else
79
+ @command
80
+ end
81
+ end
82
+
83
+ def some_msg(arg=nil)
84
+ if arg != nil
85
+ @some_msg = arg
86
+ else
87
+ @some_msg
88
+ end
89
+ end
90
+
91
+ def error?
92
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
93
+ end
94
+
95
+ # Transform the ruby obj -> to a Hash
96
+ def to_hash
97
+ index_hash = Hash.new
98
+ index_hash["json_claz"] = self.class.name
99
+ index_hash["id"] = id
100
+ index_hash["node_id"] = node_id
101
+ index_hash["node_name"] = node_name
102
+ index_hash["req_type"] = req_type
103
+ index_hash["command"] = command
104
+ index_hash["created_at"] = created_at
105
+ index_hash
106
+ end
107
+
108
+ # Serialize this object as a hash: called from JsonCompat.
109
+ # Verify if this called from JsonCompat during testing.
110
+ def to_json(*a)
111
+ for_json.to_json(*a)
112
+ end
113
+
114
+ def for_json
115
+ result = {
116
+ "id" => id,
117
+ "node_id" => node_id,
118
+ "node_name" => node_name,
119
+ "req_type" => req_type,
120
+ "command" => command,
121
+ "created_at" => created_at
122
+ }
123
+ result
124
+ end
125
+
126
+ #
127
+ def self.json_create(o)
128
+ node = new
129
+ node.id(o["id"]) if o.has_key?("id")
130
+ node.node_id(o["node_id"]) if o.has_key?("node_id")
131
+ node.node_name(o["node_name"]) if o.has_key?("node_name")
132
+ node.req_type(o["req_type"]) if o.has_key?("req_type")
133
+ node.command(o["command"]) if o.has_key?("command")
134
+ node.created_at(o["created_at"]) if o.has_key?("created_at")
135
+ #success or error
136
+ node.some_msg[:code] = o["code"] if o.has_key?("code")
137
+ node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
138
+ node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
139
+ node.some_msg[:links] = o["links"] if o.has_key?("links")
140
+ node
141
+ end
142
+
143
+ def self.from_hash(o)
144
+ node = self.new()
145
+ node.from_hash(o)
146
+ node
147
+ end
148
+
149
+ def from_hash(o)
150
+ @id = o["id"] if o.has_key?("id")
151
+ @node_id = o["node_id"] if o.has_key?("node_id")
152
+ @node_name = o["node_name"] if o.has_key?("node_name")
153
+ @req_type = o["req_type"] if o.has_key?("req_type")
154
+ @command = o["command"] if o.has_key?("command")
155
+ @created_at = o["created_at"] if o.has_key?("created_at")
156
+ self
157
+ end
158
+
159
+
160
+ def self.create(o)
161
+ acct = from_hash(o)
162
+ acct.create
163
+ end
164
+
165
+ # Create the node via the REST API
166
+ def create
167
+ megam_rest.post_request(to_hash)
168
+ end
169
+
170
+
171
+ def self.list
172
+ prede = self.new()
173
+ prede.megam_rest.get_requests
174
+ end
175
+
176
+ def self.show(n_name)
177
+ prede = self.new()
178
+ prede.megam_rest.get_request(n_name)
179
+ end
180
+
181
+ def to_s
182
+ Megam::Stuff.styled_hash(to_hash)
183
+ #"---> Megam::Account:[error=#{error?}]\n"+
184
+ end
185
+
186
+ end
187
+ end