megam_api 0.17 → 0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/megam/api.rb +20 -35
  4. data/lib/megam/api/{nodes.rb → assemblies.rb} +9 -9
  5. data/lib/megam/api/domains.rb +30 -0
  6. data/lib/megam/api/organizations.rb +30 -0
  7. data/lib/megam/api/version.rb +1 -1
  8. data/lib/megam/core/assemblies.rb +180 -0
  9. data/lib/megam/core/{node_collection.rb → assemblies_collection.rb} +44 -65
  10. data/lib/megam/core/csar.rb +0 -1
  11. data/lib/megam/core/domains.rb +129 -0
  12. data/lib/megam/core/json_compat.rb +17 -4
  13. data/lib/megam/core/organizations.rb +129 -0
  14. data/test/test_accounts.rb +1 -1
  15. data/test/test_assemblies.rb +10 -0
  16. data/test/test_domains.rb +27 -0
  17. data/test/test_helper.rb +25 -16
  18. data/test/test_organizations.rb +26 -0
  19. metadata +12 -38
  20. data/lib/megam/api/app_request.rb +0 -27
  21. data/lib/megam/api/appdefns.rb +0 -47
  22. data/lib/megam/api/bolt_request.rb +0 -27
  23. data/lib/megam/api/boltdefns.rb +0 -39
  24. data/lib/megam/api/cloud_tools.rb +0 -35
  25. data/lib/megam/api/logs.rb +0 -18
  26. data/lib/megam/api/predefs.rb +0 -35
  27. data/lib/megam/builder/delete_node.rb +0 -107
  28. data/lib/megam/builder/make_node.rb +0 -133
  29. data/lib/megam/core/app_request.rb +0 -227
  30. data/lib/megam/core/app_request_collection.rb +0 -148
  31. data/lib/megam/core/appdefns.rb +0 -182
  32. data/lib/megam/core/appdefns_collection.rb +0 -148
  33. data/lib/megam/core/bolt_request.rb +0 -225
  34. data/lib/megam/core/bolt_request_collection.rb +0 -148
  35. data/lib/megam/core/boltdefns.rb +0 -207
  36. data/lib/megam/core/boltdefns_collection.rb +0 -148
  37. data/lib/megam/core/cloudinstruction.rb +0 -110
  38. data/lib/megam/core/cloudinstruction_collection.rb +0 -145
  39. data/lib/megam/core/cloudinstruction_group.rb +0 -99
  40. data/lib/megam/core/cloudtemplate.rb +0 -127
  41. data/lib/megam/core/cloudtemplate_collection.rb +0 -145
  42. data/lib/megam/core/cloudtool.rb +0 -152
  43. data/lib/megam/core/cloudtool_collection.rb +0 -145
  44. data/lib/megam/core/node.rb +0 -366
  45. data/lib/megam/core/predef.rb +0 -201
  46. data/lib/megam/core/predef_collection.rb +0 -164
  47. data/test/test_appdefns.rb +0 -35
  48. data/test/test_appreqs.rb +0 -25
  49. data/test/test_boltdefns.rb +0 -32
  50. data/test/test_boltreqs.rb +0 -26
  51. data/test/test_cloudtools.rb +0 -22
  52. data/test/test_nodes.rb +0 -140
  53. data/test/test_predefs.rb +0 -72
@@ -1,18 +0,0 @@
1
- module Megam
2
- class API
3
- # PUT /logs/:node_id
4
- #empty body posted to get the logs
5
- #path having the node_id which is the key_name to fetch that particular log
6
- def get_logs(node_id)
7
- @options = {:path => "/logs/#{node_id}",
8
- :body => OkJson.encode({:nothing =>"nothing in body"})}.merge(@options)
9
-
10
- request(
11
- :expects => 200,
12
- :method => :post,
13
- :body => @options[:body]
14
- )
15
- end
16
-
17
- end
18
- end
@@ -1,35 +0,0 @@
1
- module Megam
2
- class API
3
- def get_predefs
4
- @options = {:path => '/predefs',:body => ""}.merge(@options)
5
-
6
- request(
7
- :expects => 200,
8
- :method => :get,
9
- :body => @options[:body]
10
- )
11
- end
12
-
13
- def get_predef(predef_name)
14
- @options = {:path => "/predefs/#{predef_name}",:body => ""}.merge(@options)
15
-
16
- request(
17
- :expects => 200,
18
- :method => :get,
19
- :body => @options[:body]
20
- )
21
- end
22
-
23
- def post_predef(new_predef)
24
- @options = {:path => '/predefs/content',
25
- :body => Megam::JSONCompat.to_json(new_predef)}.merge(@options)
26
-
27
- request(
28
- :expects => 201,
29
- :method => :post,
30
- :body => @options[:body]
31
- )
32
- end
33
-
34
- end
35
- end
@@ -1,107 +0,0 @@
1
- # Copyright:: Copyright (c) 2012, 2014 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 DeleteNode < Megam::ServerAPI
18
- def initialize(email=nil, api_key=nil)
19
- super(email, api_key)
20
- end
21
-
22
- def self.create(data, group, action, tmp_email=nil, tmp_api_key=nil)
23
- delete_command = self.new(tmp_email, tmp_api_key)
24
- begin
25
- node_collection = delete_command.megam_rest.get_node(data[:node_name])
26
- ct_collection = delete_command.megam_rest.get_cloudtools
27
- cts_collection = delete_command.megam_rest.get_cloudtoolsettings
28
- rescue ArgumentError => ae
29
- hash = {"msg" => ae.message, "msg_type" => "error"}
30
- re = Megam::Error.from_hash(hash)
31
- return re
32
- rescue Megam::API::Errors::ErrorWithResponse => ewr
33
- hash = {"msg" => ewr.message, "msg_type" => "error"}
34
- re = Megam::Error.from_hash(hash)
35
- return re
36
- rescue StandardError => se
37
- hash = {"msg" => se.message, "msg_type" => "error"}
38
- re = Megam::Error.from_hash(hash)
39
- return re
40
- end
41
- node = node_collection.data[:body].lookup(data[:node_name])
42
- tool = ct_collection.data[:body].lookup(node.request[:command]['systemprovider']['provider']['prov'])
43
- template = tool.cloudtemplates.lookup(node.request[:command]['compute']['cctype'])
44
- cloud_instruction = template.lookup_by_instruction(group, action)
45
- cts = cts_collection.data[:body].lookup(data[:repo])
46
- ci_command = "#{cloud_instruction.command}"
47
- if ci_command["<node_name>"].present?
48
- ci_command["<node_name>"] = "#{data[:node_name]}"
49
- end
50
- u = URI.parse(node.request[:command]['compute']['access']['vault_location'])
51
- u.path[0]=""
52
- if ci_command["-f"].present?
53
- ci_command["-f"] = "-f " + u.path + "/#{node.request[:command]['compute']['cctype']}.json"
54
- end
55
-
56
- if ci_command["-c"].present?
57
- ci_command["-c"] = "-c #{cts.conf_location}"
58
- end
59
- command_hash = {
60
- "systemprovider" => {
61
- "provider" => {
62
- "prov" => "#{node.request[:command]['systemprovider']['provider']['prov']}"
63
- }
64
- },
65
- "compute" => {
66
- "cctype" => "#{node.request[:command]['compute']['cctype']}",
67
- "cc" => {
68
- "groups" => "",
69
- "image" => "",
70
- "flavor" => "",
71
- "tenant_id" => "#{node.request[:command]['compute']['cc']['tenant_id']}"
72
- },
73
- "access" => {
74
- "ssh_key" => "",
75
- "identity_file" => "",
76
- "ssh_user" => "",
77
- "vault_location" => "#{node.request[:command]['compute']['access']['vault_location']}",
78
- "sshpub_location" => "#{node.request[:command]['compute']['access']['sshpub_location']}",
79
- "zone" => "#{node.request[:command]['compute']['access']['zone']}",
80
- "region" => "#{node.request[:command]['compute']['access']['region']}"
81
- }
82
- },
83
- "cloudtool" => {
84
- "chef" => {
85
- "command" => "#{node.request[:command]['cloudtool']['chef']['command']}",
86
- "plugin" => "#{node.request[:command]['compute']['cctype']} #{ci_command}", #ec2 server delete or create
87
- "run_list" => "",
88
- "name" => "-N #{data[:node_name]}"
89
- }
90
- }
91
- }
92
- node_hash = {
93
- "node_name" => "#{data[:node_name]}",
94
- "node_type" => "#{node.node_type}",
95
- "req_type" => "#{action}",
96
- "noofinstances" => "",
97
- "command" => command_hash,
98
- "predefs" => {},
99
- "appdefns" => {},
100
- "boltdefns" => {},
101
- "appreq" => {},
102
- "boltreq" => {}
103
- }
104
- node_hash
105
- end
106
- end
107
- end
@@ -1,133 +0,0 @@
1
- # Copyright:: Copyright (c) 2012, 2014 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 MakeNode < Megam::ServerAPI
18
-
19
- def initialize(email=nil, api_key=nil)
20
- super(email, api_key)
21
- end
22
-
23
-
24
-
25
- def self.create(data, group, action,tmp_email=nil, tmp_api_key=nil)
26
- make_command = self.new(tmp_email, tmp_api_key)
27
- begin
28
- pc_collection = make_command.megam_rest.get_predefclouds
29
- ct_collection = make_command.megam_rest.get_cloudtools
30
- cts_collection = make_command.megam_rest.get_cloudtoolsettings
31
- rescue ArgumentError => ae
32
- hash = {"msg" => ae.message, "msg_type" => "error"}
33
- re = Megam::Error.from_hash(hash)
34
- return re
35
- rescue Megam::API::Errors::ErrorWithResponse => ewr
36
- hash = {"msg" => ewr.message, "msg_type" => "error"}
37
- re = Megam::Error.from_hash(hash)
38
- return re
39
- rescue StandardError => se
40
- hash = {"msg" => se.message, "msg_type" => "error"}
41
- re = Megam::Error.from_hash(hash)
42
- return re
43
- end
44
- predef_cloud = pc_collection.data[:body].lookup("#{data[:predef_cloud_name]}")
45
- tool = ct_collection.data[:body].lookup(data[:provider])
46
- template = tool.cloudtemplates.lookup(predef_cloud.spec[:type_name])
47
- cloud_instruction = template.lookup_by_instruction(group, action)
48
- cts = cts_collection.data[:body].lookup(data[:repo])
49
- ci_command = "#{cloud_instruction.command}"
50
- if ci_command["<node_name>"].present?
51
- ci_command["<node_name>"] = "#{data[:book_name]}"
52
- end
53
- u = URI.parse(predef_cloud.access[:vault_location])
54
- u.path[0]=""
55
- if ci_command["-f"].present?
56
- ci_command["-f"] = "-f " + u.path + "/" + predef_cloud.spec[:type_name] + ".json"
57
- end
58
- if ci_command["-c"].present?
59
- ci_command["-c"] = "-c #{cts.conf_location}"
60
- end
61
- ci_name = cloud_instruction.name
62
- command_hash = {
63
- "systemprovider" => {
64
- "provider" => {
65
- "prov" => "#{data[:provider]}"
66
- }
67
- },
68
- "compute" => {
69
- "cctype" => "#{predef_cloud.spec[:type_name]}",
70
- "cc"=> {
71
- "groups" => "#{predef_cloud.spec[:groups]}",
72
- "image" => "#{predef_cloud.spec[:image]}",
73
- "flavor" => "#{predef_cloud.spec[:flavor]}",
74
- "tenant_id" => "#{predef_cloud.spec[:tenant_id]}"
75
- },
76
- "access" => {
77
- "ssh_key" => "#{predef_cloud.access[:ssh_key]}",
78
- "identity_file" => "#{predef_cloud.access[:identity_file]}",
79
- "ssh_user" => "#{predef_cloud.access[:ssh_user]}",
80
- "vault_location" => "#{predef_cloud.access[:vault_location]}",
81
- "sshpub_location" => "#{predef_cloud.access[:sshpub_location]}",
82
- "zone" => "#{predef_cloud.access[:zone]}",
83
- "region" => "#{predef_cloud.access[:region]}"
84
- }
85
- },
86
- "cloudtool" => {
87
- "chef" => {
88
- "command" => "#{tool.cli}",
89
- "plugin" => "#{template.cctype} #{ci_command}",
90
- "run_list" => "'role[#{data[:provider_role]}]'",
91
- "name" => "#{ci_name} #{data[:book_name]}"
92
- }
93
- }
94
- }
95
-
96
- node_hash = {
97
- "node_name" => "#{data[:book_name]}#{data[:domain_name]}",
98
- "node_type" => "#{data[:book_type]}",
99
- "req_type" => "#{action}",
100
- "noofinstances" => data[:no_of_instances],
101
- "command" => command_hash,
102
- "predefs" => {"name" => data[:predef_name], "scm" => "#{data[:deps_scm]}",
103
- "db" => "postgres@postgresql1.megam.com/morning.megam.co", "war" => "#{data[:deps_war]}", "queue" => "queue@queue1", "runtime_exec" => data[:runtime_exec]},
104
- "appdefns" => {"timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => "", "env_sh" => ""},
105
- "boltdefns" => {"username" => "", "apikey" => "", "store_name" => "", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => "", "env_sh" => ""},
106
- "appreq" => {},
107
- "boltreq" => {}
108
- }
109
-
110
- if data[:book_type] == "APP"
111
- if data[:deps_scm].length > 0
112
- data[:runtime_exec] = change_runtime(data[:deps_scm], data[:runtime_exec], action)
113
- end
114
- if data[:deps_war].length > 0
115
- data[:runtime_exec] = change_runtime(data[:deps_war], data[:runtime_exec], action)
116
- end
117
- node_hash["appdefns"] = {"timetokill" => "#{data[:timetokill]}", "metered" => "#{data[:metered]}", "logging" => "#{data[:logging]}", "runtime_exec" => "#{data[:runtime_exec]}", "env_sh" => "#{data[:env_sh]}"}
118
- end
119
- if data[:book_type] == "BOLT"
120
- node_hash["boltdefns"] = {"username" => "#{data['user_name']}", "apikey" => "#{data['password']}", "store_name" => "#{data['store_db_name']}", "url" => "#{data['url']}", "prime" => "#{data['prime']}", "timetokill" => "#{data['timetokill']}", "metered" => "#{data['monitoring']}", "logging" => "#{data['logging']}", "runtime_exec" => "#{data['runtime_exec']}", "env_sh" => "#{data[:env_sh]}" }
121
- end
122
- node_hash
123
- end
124
-
125
- def self.change_runtime(deps, runtime, action)
126
- project_name = File.basename(deps).split(".").first
127
- if /<projectname>/.match(runtime)
128
- runtime["unicorn_<projectname>"] = "unicorn_" + project_name
129
- end
130
- runtime
131
- end
132
- end
133
- end
@@ -1,227 +0,0 @@
1
- # Copyright:: Copyright (c) 2012, 2014 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 AppRequest< Megam::ServerAPI
18
-
19
- def initialize(email=nil, api_key=nil)
20
- @id = nil
21
- @req_type = nil
22
- @appdefns_id = nil
23
- @node_name = nil
24
- @lc_apply = nil
25
- @lc_additional = nil
26
- @lc_when = nil
27
- @created_at = nil
28
- @some_msg = {}
29
- super(email,api_key)
30
- end
31
-
32
- def appreq
33
- self
34
- end
35
-
36
-
37
- def id(arg=nil)
38
- if arg != nil
39
- @id = arg
40
- else
41
- @id
42
- end
43
- end
44
-
45
- def req_type(arg=nil)
46
- if arg != nil
47
- @req_type = arg
48
- else
49
- @req_type
50
- end
51
- end
52
-
53
- def appdefns_id(arg=nil)
54
- if arg != nil
55
- @appdefns_id = arg
56
- else
57
- @appdefns_id
58
- end
59
- end
60
-
61
- def node_name(arg=nil)
62
- if arg != nil
63
- @node_name = arg
64
- else
65
- @node_name
66
- end
67
- end
68
-
69
- def lc_apply(arg=nil)
70
- if arg != nil
71
- @lc_apply = arg
72
- else
73
- @lc_apply
74
- end
75
- end
76
-
77
- def lc_additional(arg=nil)
78
- if arg != nil
79
- @lc_additional = arg
80
- else
81
- @lc_additional
82
- end
83
- end
84
-
85
- def lc_when(arg=nil)
86
- if arg != nil
87
- @lc_when = arg
88
- else
89
- @lc_when
90
- end
91
- end
92
-
93
- def created_at(arg=nil)
94
- if arg != nil
95
- @created_at = arg
96
- else
97
- @created_at
98
- end
99
- end
100
- def some_msg(arg=nil)
101
- if arg != nil
102
- @some_msg = arg
103
- else
104
- @some_msg
105
- end
106
- end
107
-
108
- def error?
109
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
110
- end
111
-
112
- # Transform the ruby obj -> to a Hash
113
- def to_hash
114
- index_hash = Hash.new
115
- index_hash["json_claz"] = self.class.name
116
- index_hash["id"] = id
117
- index_hash["req_type"] = req_type
118
- index_hash["appdefns_id"] = appdefns_id
119
- index_hash["node_name"] = node_name
120
- index_hash["lc_apply"] = lc_apply
121
- index_hash["lc_additional"] = lc_additional
122
- index_hash["lc_when"] = lc_when
123
- index_hash["created_at"] = created_at
124
- index_hash["some_msg"] = some_msg
125
- index_hash
126
- end
127
-
128
- # Serialize this object as a hash: called from JsonCompat.
129
- # Verify if this called from JsonCompat during testing.
130
- def to_json(*a)
131
- for_json.to_json(*a)
132
- end
133
-
134
- def for_json
135
- result = {
136
- "id" => id,
137
- "req_type" => req_type,
138
- "appdefns_id" => appdefns_id,
139
- "node_name" => node_name,
140
- "lc_apply" => lc_apply,
141
- "lc_additional" => lc_additional,
142
- "lc_when" => lc_when,
143
- "created_at" => created_at
144
- }
145
- result
146
- end
147
-
148
-
149
- # Create a Megam::Node from NodeResult-JSON
150
- #
151
- #[{
152
- #"id":"NOD362212018897289216",
153
- #"accounts_id":"ACT362211962353876992",
154
- #"json_claz":"Megam::Node",
155
- #"request":{
156
- #"req_id":"NOD362212018897289216",
157
- #"command":"commands"
158
- #},
159
- #"predefs":{
160
- #"name":"",
161
- #"scm":"",
162
- #"war":"",
163
- #"db":"",
164
- #"queue":""
165
- #}
166
- #}]
167
- #
168
- def self.json_create(o)
169
- appreq = new
170
- appreq.id(o["id"]) if o.has_key?("id")
171
- appreq.req_type(o["req_type"]) if o.has_key?("req_type")
172
- appreq.appdefns_id(o["appdefns_id"]) if o.has_key?("appdefns_id")
173
- appreq.node_name(o["node_name"]) if o.has_key?("node_name")
174
- appreq.lc_apply(o["lc_apply"]) if o.has_key?("lc_apply")
175
- appreq.lc_additional(o["lc_additional"]) if o.has_key?("lc_additional")
176
- appreq.lc_when(o["lc_when"]) if o.has_key?("lc_when")
177
- appreq.created_at(o["created_at"]) if o.has_key?("created_at")
178
-
179
- appreq.some_msg[:code] = o["code"] if o.has_key?("code")
180
- appreq.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
181
- appreq.some_msg[:msg]= o["msg"] if o.has_key?("msg")
182
- appreq.some_msg[:links] = o["links"] if o.has_key?("links")
183
-
184
- appreq
185
- end
186
-
187
- def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
188
- appreq = self.new(tmp_email, tmp_api_key)
189
- appreq.from_hash(o)
190
- appreq
191
- end
192
-
193
- def from_hash(o)
194
- @id = o["id"] if o.has_key?("id")
195
- @req_type = o["req_type"] if o.has_key?("req_type")
196
- @appdefns_id = o["appdefns_id"] if o.has_key?("appdefns_id")
197
- @node_name = o["node_name"] if o.has_key?("node_name")
198
- @lc_apply = o["lc_apply"] if o.has_key?("lc_apply")
199
- @lc_additional = o["lc_additional"] if o.has_key?("lc_additional")
200
- @lc_when = o["lc_when"] if o.has_key?("lc_when")
201
- @created_at = o["created_at"] if o.has_key?("created_at")
202
- self
203
- end
204
-
205
- def self.create(o,tmp_email=nil, tmp_api_key=nil)
206
- acct = from_hash(o,tmp_email, tmp_api_key)
207
- acct.create
208
- end
209
-
210
- # Create the node via the REST API
211
- def create
212
- megam_rest.post_appreq(to_hash)
213
- end
214
-
215
- # Load a account by email_p
216
- def self.list(node_name,tmp_email=nil, tmp_api_key=nil)
217
- appreq = self.new(tmp_email, tmp_api_key)
218
- appreq.megam_rest.get_appreq(node_name)
219
- #self
220
- end
221
-
222
- def to_s
223
- Megam::Stuff.styled_hash(to_hash)
224
- end
225
-
226
- end
227
- end