megam_api 0.17 → 0.18

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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 049495e50148060c8b58f16100dff5a6232aa63e
4
- data.tar.gz: 6c3a829fd7baa2121e70eaeae72e8dce1fbbc4e9
3
+ metadata.gz: 6626dcb2360e7260a1bddd92c57e1845345d2356
4
+ data.tar.gz: 7b1c22613192558107ebf6794e39b60061183bfc
5
5
  SHA512:
6
- metadata.gz: f87e02f88e6d63c5ad4fe63f40c3a67ec1842e45946ce6dedf68cf888143cbbabef538a2fbee4047c1e460eea7a9f24eda6eb8faff534d2768823b2dc17ff77d
7
- data.tar.gz: 82742a4c9a346161c626e082791d15861f7b55c45a5fb1f63bdcbe3f322c59daa85bcd6d0d8cc3e092cb6f7ae29b7dcad07bf4ad8a0bfdf26a2bb937b4ac1134
6
+ metadata.gz: 8f631bd0d105ba5859328c7ba165749ca66916fb09ed5e9f34eefc2d7ac35b674aee9bcc195931eab2b464dc6aec04db95d2d199ee5d3bb85544c08c08b80cda
7
+ data.tar.gz: e01d71f735758230e7e28c9f7f2b7abe50c8c2d707414f877d8e913bc406213e974e22ae8528e17a89f57206c57a48915c2c5b464c55f31d502749cbe734931f
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ task :default => :test
7
7
  Rake::TestTask.new do |task|
8
8
  task.name = :test
9
9
  task.test_files = FileList['test/test*.rb']
10
- end
10
+ end
data/lib/megam/api.rb CHANGED
@@ -18,54 +18,30 @@ require "megam/api/errors"
18
18
  require "megam/api/version"
19
19
  require "megam/api/login"
20
20
  require "megam/api/accounts"
21
- require "megam/api/nodes"
22
- require "megam/api/appdefns"
23
- require "megam/api/app_request"
24
- require "megam/api/bolt_request"
25
- require "megam/api/boltdefns"
26
21
  require "megam/api/requests"
27
- require "megam/api/predefs"
28
22
  require "megam/api/predef_clouds"
29
- require "megam/api/cloud_tools"
30
23
  require "megam/api/cloud_tool_settings"
31
24
  require "megam/api/sshkeys"
32
25
  require "megam/api/marketplaces"
33
26
  require "megam/api/marketplace_addons"
27
+ require "megam/api/organizations"
28
+ require "megam/api/domains"
34
29
  require "megam/api/csars"
30
+ require "megam/api/assemblies"
31
+
35
32
  require "megam/core/server_api"
36
33
  require "megam/core/config"
37
34
  require "megam/core/stuff"
38
35
  require "megam/core/text"
39
36
  require "megam/core/log"
40
37
  require "megam/core/json_compat"
41
- require "megam/builder/make_node"
42
- require "megam/builder/delete_node"
43
38
  require "megam/core/auth"
44
39
  require "megam/core/error"
45
40
  require "megam/core/account"
46
- require "megam/core/node"
47
- require "megam/core/appdefns"
48
- require "megam/core/app_request"
49
- require "megam/core/bolt_request"
50
- require "megam/core/boltdefns"
51
- require "megam/core/node_collection"
52
- require "megam/core/appdefns_collection"
53
- require "megam/core/app_request_collection"
54
- require "megam/core/bolt_request_collection"
55
- require "megam/core/boltdefns_collection"
56
41
  require "megam/core/request"
57
42
  require "megam/core/request_collection"
58
- require "megam/core/predef"
59
- require "megam/core/predef_collection"
60
43
  require "megam/core/predefcloud"
61
44
  require "megam/core/predefcloud_collection"
62
- require "megam/core/cloudtool"
63
- require "megam/core/cloudtool_collection"
64
- require "megam/core/cloudtemplate"
65
- require "megam/core/cloudtemplate_collection"
66
- require "megam/core/cloudinstruction_group"
67
- require "megam/core/cloudinstruction_collection"
68
- require "megam/core/cloudinstruction"
69
45
  require "megam/core/cloudtoolsetting"
70
46
  require "megam/core/cloudtoolsetting_collection"
71
47
  require "megam/core/sshkey"
@@ -74,11 +50,16 @@ require "megam/core/marketplace"
74
50
  require "megam/core/marketplace_collection"
75
51
  require "megam/core/marketplace_addon"
76
52
  require "megam/core/marketplace_addon_collection"
53
+ require "megam/core/organizations"
54
+ require "megam/core/domains"
55
+ require "megam/core/assemblies"
56
+ require "megam/core/assemblies_collection"
77
57
  require "megam/core/csar"
78
58
  require "megam/core/csar_collection"
79
59
  require "megam/core/konipai"
80
60
 
81
61
 
62
+
82
63
  module Megam
83
64
  class API
84
65
 
@@ -102,11 +83,14 @@ module Megam
102
83
 
103
84
  OPTIONS = {
104
85
  :headers => {},
105
- :host => API_MEGAM_CO,
86
+ :host => '127.0.0.1',
106
87
  :nonblock => false,
107
- :scheme => 'https'
88
+ :scheme => 'http'
108
89
  }
109
90
 
91
+ API_VERSION1 = "/v1"
92
+
93
+
110
94
 
111
95
  def text
112
96
  @text ||= Megam::Text.new(STDOUT, STDERR, STDIN, {})
@@ -210,17 +194,18 @@ module Megam
210
194
  end
211
195
 
212
196
 
213
-
214
197
  #Make a lazy connection.
215
198
  def connection
216
- @options[:path] =API_VERSION2+ @options[:path]
199
+ @options[:path] =API_VERSION2 + @options[:path]
217
200
  encoded_api_header = encode_header(@options)
218
201
  @options[:headers] = HEADERS.merge({
219
202
  X_Megam_HMAC => encoded_api_header[:hmac],
220
203
  X_Megam_DATE => encoded_api_header[:date],
221
204
  }).merge(@options[:headers])
222
205
 
206
+
223
207
  if @options[:scheme] == "https"
208
+
224
209
  if !File.exist?(File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")))
225
210
  text.warn("Certificate file does not exist. SSL_VERIFY_PEER set as false")
226
211
  Excon.defaults[:ssl_verify_peer] = false
@@ -232,7 +217,7 @@ module Megam
232
217
  else
233
218
  Megam::Log.debug("Certificate found")
234
219
  Excon.defaults[:ssl_verify_peer] = true
235
- Excon.defaults[:ssl_ca_file] = File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")) || File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem"))
220
+ Excon.defaults[:ssl_ca_file] = File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")) || File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem"))
236
221
  end
237
222
  end
238
223
 
@@ -257,7 +242,7 @@ module Megam
257
242
  # The output will have
258
243
  # :hmac
259
244
  # :date
260
- # (Refer https://Github.com/indykish/megamplay.git/test/AuthenticateSpec.scala)
245
+ # (Refer https://github.com/indykish/megamplay.git/test/AuthenticateSpec.scala)
261
246
  def encode_header(cmd_parms)
262
247
  header_params ={}
263
248
  body_digest = OpenSSL::Digest::MD5.digest(cmd_parms[:body])
@@ -273,7 +258,7 @@ module Megam
273
258
  final_hmac = @email+':' + hash
274
259
  header_params = { :hmac => final_hmac, :date => current_date}
275
260
  end
276
-
261
+
277
262
  end
278
263
 
279
264
  end
@@ -2,8 +2,8 @@ module Megam
2
2
  class API
3
3
 
4
4
  # GET /nodes
5
- def get_nodes
6
- @options = {:path => '/nodes',:body => ""}.merge(@options)
5
+ def get_assemblies
6
+ @options = {:path => '/assemblies',:body => ""}.merge(@options)
7
7
 
8
8
  request(
9
9
  :expects => 200,
@@ -12,8 +12,8 @@ module Megam
12
12
  )
13
13
  end
14
14
 
15
- def get_node(node_id)
16
- @options = {:path => "/nodes/#{node_id}",:body => ""}.merge(@options)
15
+ def get_assemblies(asm_id)
16
+ @options = {:path => "/assemblies/#{asm_id}",:body => ""}.merge(@options)
17
17
 
18
18
  request(
19
19
  :expects => 200,
@@ -22,9 +22,9 @@ module Megam
22
22
  )
23
23
  end
24
24
 
25
- def post_node(new_node)
26
- @options = {:path => '/nodes/content',
27
- :body => Megam::JSONCompat.to_json(new_node)}.merge(@options)
25
+ def post_assemblies(new_asm)
26
+ @options = {:path => '/assemblies/content',
27
+ :body => Megam::JSONCompat.to_json(new_asm)}.merge(@options)
28
28
 
29
29
  request(
30
30
  :expects => 201,
@@ -35,8 +35,8 @@ module Megam
35
35
 
36
36
  #Yet to be tested
37
37
  # DELETE /nodes/:node_id
38
- def delete_node(node_id)
39
- @options = {:path => '/nodes/#{node_id}',
38
+ def delete_assemblies(asm_id)
39
+ @options = {:path => '/nodes/#{asm_id}',
40
40
  :body => ""}.merge(@options)
41
41
 
42
42
  request(
@@ -0,0 +1,30 @@
1
+ module Megam
2
+ class API
3
+
4
+ def get_domains(name)
5
+
6
+ @options = {:path => "/domains/#{name}",
7
+ :body => ''}.merge(@options)
8
+
9
+ request(
10
+ :expects => 200,
11
+ :method => :get,
12
+ :body => @options[:body]
13
+ )
14
+ end
15
+
16
+
17
+ def post_domains(new_domain)
18
+
19
+ @options = {:path => '/domains/content',
20
+ :body => Megam::JSONCompat.to_json(new_domain)}.merge(@options)
21
+
22
+
23
+ request(
24
+ :expects => 201,
25
+ :method => :post,
26
+ :body => @options[:body]
27
+ )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Megam
2
+ class API
3
+
4
+ def get_organizations(name)
5
+
6
+ @options = {:path => "/organizations/#{name}",
7
+ :body => ''}.merge(@options)
8
+
9
+ request(
10
+ :expects => 200,
11
+ :method => :get,
12
+ :body => @options[:body]
13
+ )
14
+ end
15
+
16
+
17
+ def post_organizations(new_organization)
18
+
19
+ @options = {:path => '/organizations/content',
20
+ :body => Megam::JSONCompat.to_json(new_organization)}.merge(@options)
21
+
22
+
23
+ request(
24
+ :expects => 201,
25
+ :method => :post,
26
+ :body => @options[:body]
27
+ )
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.17"
3
+ VERSION = "0.18"
4
4
  end
5
5
  end
@@ -0,0 +1,180 @@
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
+
17
+ module Megam
18
+ class Assemblies < Megam::ServerAPI
19
+ def initialize(email=nil, api_key=nil)
20
+ @id = nil
21
+ @accounts_id = nil
22
+ @name = nil
23
+ @assemblies = []
24
+ @assemblies_type = []
25
+ @inputs = {}
26
+ @label = nil
27
+ @cloudsettings = []
28
+ @created_at = nil
29
+ super(email, api_key)
30
+ end
31
+
32
+ def assemblies
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 accounts_id(arg=nil)
46
+ if arg != nil
47
+ @accounts_id = arg
48
+ else
49
+ @accounts_id
50
+ end
51
+ end
52
+
53
+ def name(arg=nil)
54
+ if arg != nil
55
+ @name = arg
56
+ else
57
+ @name
58
+ end
59
+ end
60
+
61
+ def assemblies(arg=[])
62
+ if arg != []
63
+ @assemblies = arg
64
+ else
65
+ @assemblies
66
+ end
67
+ end
68
+
69
+
70
+ def inputs(arg=[])
71
+ if arg != []
72
+ @inputs = arg
73
+ else
74
+ @inputs
75
+ end
76
+ end
77
+
78
+ def created_at(arg=nil)
79
+ if arg != nil
80
+ @created_at = arg
81
+ else
82
+ @created_at
83
+ end
84
+ end
85
+
86
+ def error?
87
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
88
+ end
89
+
90
+ # Transform the ruby obj -> to a Hash
91
+ def to_hash
92
+ index_hash = Hash.new
93
+ index_hash["json_claz"] = self.class.name
94
+ index_hash["id"] = id
95
+ index_hash["name"] = name
96
+ index_hash["accounts_id"] = accounts_id
97
+ index_hash["inputs"] = inputs
98
+ index_hash["assemblies"] = assemblies
99
+ index_hash["created_at"] = created_at
100
+ index_hash
101
+ end
102
+
103
+ # Serialize this object as a hash: called from JsonCompat.
104
+ # Verify if this called from JsonCompat during testing.
105
+ def to_json(*a)
106
+ for_json.to_json(*a)
107
+ end
108
+
109
+ def for_json
110
+ result = {
111
+ "id" => id,
112
+ "name" => name,
113
+ "accounts_id" => accounts_id,
114
+ "assemblies" => assemblies,
115
+ "inputs" => inputs,
116
+ "created_at" => created_at
117
+ }
118
+ result
119
+ end
120
+
121
+ def self.json_create(o)
122
+ asm = new
123
+ asm.id(o["id"]) if o.has_key?("id")
124
+ asm.name(o["name"]) if o.has_key?("name")
125
+ asm.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
126
+ asm.assemblies(o["assemblies"]) if o.has_key?("assemblies") #this will be an array? can hash store array?
127
+
128
+ oq = o["inputs"]
129
+ asm.inputs[:id] = oq["id"] if oq && oq.has_key?("id")
130
+ asm.inputs[:assemblies_type] = oq["assemblies_type"] if oq && oq.has_key?("assemblies_type")
131
+ asm.inputs[:label] = oq["label"] if oq && oq.has_key?("label")
132
+ asm.inputs[:cloudsettings] = oq["cloudsettings"] if oq && oq.has_key?("cloudsettings")
133
+ asm.created_at(o["created_at"]) if o.has_key?("created_at")
134
+ asm
135
+ end
136
+
137
+ def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
138
+ asm = self.new(tmp_email, tmp_api_key)
139
+ asm.from_hash(o)
140
+ asm
141
+ end
142
+
143
+ def from_hash(o)
144
+ @id = o["id"] if o.has_key?("id")
145
+ @name = o["name"] if o.has_key?("name")
146
+ @accounts_id = o["accounts_id"] if o.has_key?("accounts_id")
147
+ @assemblies = o["assemblies"] if o.has_key?("assemblies")
148
+ @inputs = o["inputs"] if o.has_key?("inputs")
149
+ @label = o["label"] if o.has_key?("label")
150
+ @created_at = o["created_at"] if o.has_key?("created_at")
151
+ self
152
+ end
153
+
154
+ def self.create(o,tmp_email=nil, tmp_api_key=nil)
155
+ asm = from_hash(o, tmp_email, tmp_api_key)
156
+ asm.create
157
+ end
158
+
159
+ # Create the node via the REST API
160
+ def create
161
+ megam_rest.post_assemblies(to_hash)
162
+ end
163
+
164
+ # Load a account by email_p
165
+ def self.show(node_name, tmp_email=nil, tmp_api_key=nil)
166
+ asm = self.new(tmp_email, tmp_api_key)
167
+ asm.megam_rest.get_assemblies(node_name)
168
+ end
169
+
170
+ def self.list(tmp_email=nil, tmp_api_key=nil)
171
+ asm = self.new(tmp_email, tmp_api_key)
172
+ asm.megam_rest.get_assemblies
173
+ end
174
+
175
+ def to_s
176
+ Megam::Stuff.styled_hash(to_hash)
177
+ end
178
+
179
+ end
180
+ end