megam_api 0.15 → 0.16
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.
- checksums.yaml +4 -4
- data/README.md +8 -10
- data/lib/megam/api.rb +34 -20
- data/lib/megam/api/csars.rb +50 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/builder/delete_node.rb +1 -1
- data/lib/megam/builder/make_node.rb +1 -1
- data/lib/megam/core/app_request.rb +1 -1
- data/lib/megam/core/app_request_collection.rb +1 -1
- data/lib/megam/core/appdefns.rb +1 -1
- data/lib/megam/core/appdefns_collection.rb +1 -1
- data/lib/megam/core/bolt_request.rb +1 -1
- data/lib/megam/core/bolt_request_collection.rb +1 -1
- data/lib/megam/core/boltdefns.rb +1 -1
- data/lib/megam/core/boltdefns_collection.rb +1 -1
- data/lib/megam/core/cloudinstruction.rb +1 -1
- data/lib/megam/core/cloudinstruction_collection.rb +1 -1
- data/lib/megam/core/cloudinstruction_group.rb +1 -1
- data/lib/megam/core/cloudtemplate.rb +1 -1
- data/lib/megam/core/cloudtemplate_collection.rb +1 -1
- data/lib/megam/core/cloudtool.rb +1 -1
- data/lib/megam/core/cloudtool_collection.rb +1 -1
- data/lib/megam/core/cloudtoolsetting.rb +1 -1
- data/lib/megam/core/cloudtoolsetting_collection.rb +1 -1
- data/lib/megam/core/config.rb +3 -3
- data/lib/megam/core/csar.rb +165 -0
- data/lib/megam/core/csar_collection.rb +148 -0
- data/lib/megam/core/json_compat.rb +12 -3
- data/lib/megam/core/konipai.rb +57 -0
- data/lib/megam/core/marketplace.rb +20 -20
- data/lib/megam/core/marketplace_addon.rb +8 -8
- data/lib/megam/core/marketplace_addon_collection.rb +1 -1
- data/lib/megam/core/marketplace_collection.rb +1 -1
- data/lib/megam/core/node.rb +1 -1
- data/lib/megam/core/node_collection.rb +1 -1
- data/lib/megam/core/predef.rb +1 -1
- data/lib/megam/core/predef_collection.rb +1 -1
- data/lib/megam/core/predefcloud.rb +1 -1
- data/lib/megam/core/predefcloud_collection.rb +1 -1
- data/lib/megam/core/request.rb +1 -1
- data/lib/megam/core/request_collection.rb +1 -1
- data/lib/megam/core/server_api.rb +4 -5
- data/lib/megam/core/sshkey.rb +1 -1
- data/lib/megam/core/sshkey_collection.rb +1 -1
- data/megam_api.gemspec +7 -7
- data/test/test_cloudtoolsettings.rb +3 -3
- data/test/test_csars.rb +21 -0
- data/test/test_helper.rb +1 -1
- data/test/test_marketplaces.rb +8 -8
- data/test/test_nodes.rb +4 -4
- data/test/test_predefclouds.rb +4 -4
- data/test/test_requests.rb +1 -1
- data/test/test_sshkeys.rb +1 -1
- metadata +19 -13
@@ -0,0 +1,148 @@
|
|
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 csarlicable 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 CSARCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
|
21
|
+
attr_reader :iterator
|
22
|
+
def initialize
|
23
|
+
@csars = Array.new
|
24
|
+
@csars_by_name = Hash.new
|
25
|
+
@insert_after_idx = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def all_csars
|
29
|
+
@csars
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](index)
|
33
|
+
@csars[index]
|
34
|
+
end
|
35
|
+
|
36
|
+
def []=(index, arg)
|
37
|
+
is_megam_csar(arg)
|
38
|
+
@csars[index] = arg
|
39
|
+
@csars_by_name[arg.name] = index
|
40
|
+
end
|
41
|
+
|
42
|
+
def <<(*args)
|
43
|
+
args.flatten.each do |a|
|
44
|
+
is_megam_csar(a)
|
45
|
+
@csars << a
|
46
|
+
@csars_by_name[a.name] = @csars.length - 1
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# 'push' is an alias method to <<
|
52
|
+
alias_method :push, :<<
|
53
|
+
|
54
|
+
def insert(csar)
|
55
|
+
is_megam_csar(csar)
|
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
|
+
@csars.insert(@insert_after_idx + 1, csar)
|
61
|
+
# update name -> location mcsarings and register new node
|
62
|
+
@csars_by_name.each_key do |key|
|
63
|
+
@csars_by_name[key] += 1 if @csars_by_name[key] > @insert_after_idx
|
64
|
+
end
|
65
|
+
@csars_by_name[csar.link] = @insert_after_idx + 1
|
66
|
+
@insert_after_idx += 1
|
67
|
+
else
|
68
|
+
@csars << csar
|
69
|
+
@csars_by_name[csar.link] = @csars.length - 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def each
|
74
|
+
@csars.each do |csar|
|
75
|
+
yield csar
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def each_index
|
80
|
+
@csars.each_index do |i|
|
81
|
+
yield i
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def empty?
|
86
|
+
@csars.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
def lookup(csar)
|
90
|
+
lookup_by = nil
|
91
|
+
if csar.kind_of?(Megam::CSAR)
|
92
|
+
lookup_by = csar.link
|
93
|
+
elsif csar.kind_of?(String)
|
94
|
+
lookup_by = csar
|
95
|
+
else
|
96
|
+
raise ArgumentError, "Must pass a Megam::CSAR or String to lookup"
|
97
|
+
end
|
98
|
+
res = @csars_by_name[lookup_by]
|
99
|
+
unless res
|
100
|
+
raise ArgumentError, "Cannot find a csar matching #{lookup_by} (did you define it first?)"
|
101
|
+
end
|
102
|
+
@csars[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 |csar|
|
109
|
+
index_hash[csar.link] = csar.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 |csars_list|
|
124
|
+
csars_array = csars_list.kind_of?(Array) ? csars_list : [ csars_list ]
|
125
|
+
csars_array.each do |csar|
|
126
|
+
collection.insert(csar)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
collection
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
def is_megam_csar(arg)
|
137
|
+
unless arg.kind_of?(Megam::CSAR)
|
138
|
+
raise ArgumentError, "Members must be Megam::CSAR'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
|
@@ -57,6 +57,11 @@ module Megam
|
|
57
57
|
MEGAM_MARKETPLACECOLLECTION = "Megam::MarketPlaceCollection".freeze
|
58
58
|
MEGAM_MARKETPLACEADDON = "Megam::MarketPlaceAddons".freeze
|
59
59
|
MEGAM_MARKETPLACEADDONCOLLECTION = "Megam::MarketPlaceAddonsCollection".freeze
|
60
|
+
MEGAM_CSAR = "Megam::CSAR".freeze
|
61
|
+
MEGAM_CSARCOLLECTION = "Megam::CSARCollection".freeze
|
62
|
+
|
63
|
+
|
64
|
+
|
60
65
|
class <<self
|
61
66
|
# Increase the max nesting for JSON, which defaults
|
62
67
|
# to 19, and isn't enough for some (for example, a Node within a Node)
|
@@ -65,12 +70,12 @@ module Megam
|
|
65
70
|
if opts.nil? || !opts.has_key?(:max_nesting)
|
66
71
|
opts = opts.nil? ? Hash.new : opts.clone
|
67
72
|
opts[:max_nesting] = JSON_MAX_NESTING
|
68
|
-
end
|
73
|
+
end
|
69
74
|
opts
|
70
75
|
end
|
71
76
|
|
72
77
|
# Just call the JSON gem's parse method with a modified :max_nesting field
|
73
|
-
def from_json(source, opts = {})
|
78
|
+
def from_json(source, opts = {})
|
74
79
|
obj = ::Yajl::Parser.parse(source)
|
75
80
|
# JSON gem requires top level object to be a Hash or Array (otherwise
|
76
81
|
# you get the "must contain two octets" error). Yajl doesn't impose the
|
@@ -115,7 +120,7 @@ module Megam
|
|
115
120
|
json_hash
|
116
121
|
end
|
117
122
|
|
118
|
-
def to_json(obj, opts = nil)
|
123
|
+
def to_json(obj, opts = nil)
|
119
124
|
obj.to_json(opts_add_max_nesting(opts))
|
120
125
|
end
|
121
126
|
|
@@ -197,6 +202,10 @@ module Megam
|
|
197
202
|
Megam::MarketPlaceAddons
|
198
203
|
when MEGAM_MARKETPLACEADDONCOLLECTION
|
199
204
|
Megam::MarketPlaceAddonsCollection
|
205
|
+
when MEGAM_CSAR
|
206
|
+
Megam::CSAR
|
207
|
+
when MEGAM_CSARCOLLECTION
|
208
|
+
Megam::CSARCollection
|
200
209
|
else
|
201
210
|
raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
|
202
211
|
end
|
@@ -0,0 +1,57 @@
|
|
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 KoniPai
|
18
|
+
|
19
|
+
def initialize()
|
20
|
+
@koni = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def konipai
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def koni(arg=nil)
|
28
|
+
if arg != nil
|
29
|
+
@koni = arg
|
30
|
+
else
|
31
|
+
@koni
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Transform the ruby obj -> to a Hash
|
37
|
+
def to_hash
|
38
|
+
index_hash = Hash.new
|
39
|
+
index_hash["json_claz"] = self.class.name
|
40
|
+
index_hash["koni"] = koni
|
41
|
+
index_hash
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def self.json_create(o)
|
46
|
+
kp = new
|
47
|
+
kp.koni(o) if o != null
|
48
|
+
kp
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
Megam::Stuff.styled_hash(to_hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2012,
|
1
|
+
# Copyright:: Copyright (c) 2012, 2014 Megam Systems
|
2
2
|
# License:: Apache License, Version 2.0
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -20,14 +20,14 @@ module Megam
|
|
20
20
|
def initialize(email=nil, api_key=nil)
|
21
21
|
@id = nil
|
22
22
|
@name = nil
|
23
|
-
@appdetails = {}
|
23
|
+
@appdetails = {}
|
24
24
|
@features={}
|
25
25
|
@plans=nil
|
26
26
|
@applinks={}
|
27
27
|
@attach =nil
|
28
28
|
@predefnode=nil
|
29
|
-
@some_msg = {}
|
30
|
-
@approved = nil
|
29
|
+
@some_msg = {}
|
30
|
+
@approved = nil
|
31
31
|
@created_at = nil
|
32
32
|
super(email, api_key)
|
33
33
|
end
|
@@ -36,7 +36,7 @@ module Megam
|
|
36
36
|
self
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
|
40
40
|
def name(arg=nil)
|
41
41
|
if arg != nil
|
42
42
|
@name = arg
|
@@ -51,7 +51,7 @@ module Megam
|
|
51
51
|
else
|
52
52
|
@appdetails
|
53
53
|
end
|
54
|
-
end
|
54
|
+
end
|
55
55
|
|
56
56
|
def id(arg=nil)
|
57
57
|
if arg != nil
|
@@ -59,7 +59,7 @@ module Megam
|
|
59
59
|
else
|
60
60
|
@id
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end
|
63
63
|
|
64
64
|
def features(arg=nil)
|
65
65
|
if arg != nil
|
@@ -76,7 +76,7 @@ module Megam
|
|
76
76
|
@plans
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def applinks(arg=nil)
|
81
81
|
if arg != nil
|
82
82
|
@applinks = arg
|
@@ -108,7 +108,7 @@ module Megam
|
|
108
108
|
@approved
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def created_at(arg=nil)
|
113
113
|
if arg != nil
|
114
114
|
@created_at = arg
|
@@ -141,8 +141,8 @@ module Megam
|
|
141
141
|
index_hash["applinks"] = applinks
|
142
142
|
index_hash["attach"] = attach
|
143
143
|
index_hash["predefnode"] = predefnode
|
144
|
-
index_hash["approved"] = approved
|
145
|
-
index_hash["some_msg"] = some_msg
|
144
|
+
index_hash["approved"] = approved
|
145
|
+
index_hash["some_msg"] = some_msg
|
146
146
|
index_hash["created_at"] = created_at
|
147
147
|
index_hash
|
148
148
|
end
|
@@ -163,12 +163,12 @@ module Megam
|
|
163
163
|
"applinks" => applinks,
|
164
164
|
"attach" => attach,
|
165
165
|
"predefnode" => predefnode,
|
166
|
-
"approved" => approved,
|
166
|
+
"approved" => approved,
|
167
167
|
"created_at" => created_at
|
168
168
|
}
|
169
169
|
result
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
def self.json_create(o)
|
173
173
|
app = new
|
174
174
|
app.id(o["id"]) if o.has_key?("id")
|
@@ -186,17 +186,17 @@ module Megam
|
|
186
186
|
app.features[:feature2] = oq["feature2"] if oq && oq.has_key?("feature2")
|
187
187
|
app.features[:feature3] = oq["feature3"] if oq && oq.has_key?("feature3")
|
188
188
|
app.features[:feature4] = oq["feature4"] if oq && oq.has_key?("feature4")
|
189
|
-
|
189
|
+
|
190
190
|
oa = o["appdetails"]
|
191
191
|
app.appdetails[:logo] = oa["logo"] if oa && oa.has_key?("logo")
|
192
192
|
app.appdetails[:category] = oa["category"] if oa && oa.has_key?("category")
|
193
|
-
app.appdetails[:description] = oa["description"] if oa && oa.has_key?("description")
|
194
|
-
|
193
|
+
app.appdetails[:description] = oa["description"] if oa && oa.has_key?("description")
|
194
|
+
|
195
195
|
#op = o["plan"]
|
196
196
|
#app.plan[:price] = op["price"] if op && op.has_key?("price")
|
197
197
|
#app.plan[:description] = op["description"] if op && op.has_key?("description")
|
198
|
-
#app.plan[:plantype]= op["plantype"] if op && op.has_key?("plantype")
|
199
|
-
|
198
|
+
#app.plan[:plantype]= op["plantype"] if op && op.has_key?("plantype")
|
199
|
+
|
200
200
|
ol = o["applinks"]
|
201
201
|
app.applinks[:free_support] = ol["free_support"] if ol && ol.has_key?("free_support")
|
202
202
|
app.applinks[:paid_support] = ol["paid_support"] if ol && ol.has_key?("paid_support")
|
@@ -205,7 +205,7 @@ module Megam
|
|
205
205
|
app.applinks[:content_link] = ol["content_link"] if ol && ol.has_key?("content_link")
|
206
206
|
app.applinks[:wiki_link] = ol["wiki_link"] if ol && ol.has_key?("wiki_link")
|
207
207
|
app.applinks[:source_link] = ol["source_link"] if ol && ol.has_key?("source_link")
|
208
|
-
|
208
|
+
|
209
209
|
#success or error
|
210
210
|
app.some_msg[:code] = o["code"] if o.has_key?("code")
|
211
211
|
app.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
@@ -230,7 +230,7 @@ module Megam
|
|
230
230
|
@applinks = o["applinks"] if o.has_key?("applinks")
|
231
231
|
@attach = o["attach"] if o.has_key?("attach")
|
232
232
|
@predefnode = o["predefnode"] if o.has_key?("predefnode")
|
233
|
-
@approved = o["approved"] if o.has_key?("approved")
|
233
|
+
@approved = o["approved"] if o.has_key?("approved")
|
234
234
|
@created_at = o["created_at"] if o.has_key?("created_at")
|
235
235
|
self
|
236
236
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2012,
|
1
|
+
# Copyright:: Copyright (c) 2012, 2014 Megam Systems
|
2
2
|
# License:: Apache License, Version 2.0
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,7 +15,7 @@
|
|
15
15
|
#
|
16
16
|
module Megam
|
17
17
|
class MarketPlaceAddons< Megam::ServerAPI
|
18
|
-
|
18
|
+
|
19
19
|
def initialize(email=nil, api_key=nil)
|
20
20
|
@id = nil
|
21
21
|
@node_id = nil
|
@@ -27,11 +27,11 @@ module Megam
|
|
27
27
|
@some_msg = {}
|
28
28
|
super(email,api_key)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def market_place_addons
|
32
32
|
self
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
|
36
36
|
def id(arg=nil)
|
37
37
|
if arg != nil
|
@@ -117,7 +117,7 @@ module Megam
|
|
117
117
|
|
118
118
|
# Serialize this object as a hash: called from JsonCompat.
|
119
119
|
# Verify if this called from JsonCompat during testing.
|
120
|
-
def to_json(*a)
|
120
|
+
def to_json(*a)
|
121
121
|
for_json.to_json(*a)
|
122
122
|
end
|
123
123
|
|
@@ -130,7 +130,7 @@ module Megam
|
|
130
130
|
"config" => {},
|
131
131
|
"config_id" => config_id,
|
132
132
|
"created_at" => created_at
|
133
|
-
}
|
133
|
+
}
|
134
134
|
result
|
135
135
|
end
|
136
136
|
|
@@ -143,8 +143,8 @@ module Megam
|
|
143
143
|
addon.marketplace_id(o["marketplace_id"]) if o.has_key?("marketplace_id")
|
144
144
|
addon.config(o["config"]) if o.has_key?("config")
|
145
145
|
addon.config_id(o["config_id"]) if o.has_key?("config_id")
|
146
|
-
addon.created_at(o["created_at"]) if o.has_key?("created_at")
|
147
|
-
|
146
|
+
addon.created_at(o["created_at"]) if o.has_key?("created_at")
|
147
|
+
|
148
148
|
addon.some_msg[:code] = o["code"] if o.has_key?("code")
|
149
149
|
addon.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
150
150
|
addon.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|