megam_api 0.11 → 0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b596f43aff236e1f432583c681e9207d351b9fac
4
- data.tar.gz: 2244e795603cb0752b936777810e781edea5011c
3
+ metadata.gz: 1e565c5f554f3b29604419c0f51758171a97444a
4
+ data.tar.gz: 8c915ad1bb5d1ff93225e5816a2c27b97dbc9f00
5
5
  SHA512:
6
- metadata.gz: cb6ed13dfb045eb9135737559d1b8e655aef6e2c7ef891ce16f778ccda137dd63d8178d05a4d8a7de4313195786862afbc59dd5ef4c125b369e9b3ae0fa388c3
7
- data.tar.gz: 78ed5f63995b668796d052c9be4f0611aea7e1b26a9f513a07da1ef8141626ca497e64caa8aba43062234158bb2416039ce397cb8d392b769286568408a2d550
6
+ metadata.gz: 8fc940ba8296de0aacfbab4df73d2c5cd5c9e15e80f0c47f4de6cac11e8bd9638255fa765fd835b1471acebac84ea6698e9a03b07d141296dfef3a2cf4cea7fa
7
+ data.tar.gz: b22382100b343abc033e667ab8659f6a125ce6f3f8d4c6bd23ba637fe2edc4e3bd0171cb9c305ca595f6b7427ca53add134957bb2a7d22a564a4ac775d8e3de6
data/lib/megam/api.rb CHANGED
@@ -29,6 +29,7 @@ require "megam/api/cloud_tools"
29
29
  require "megam/api/cloud_tool_settings"
30
30
  require "megam/api/sshkeys"
31
31
  require "megam/api/marketplaces"
32
+ require "megam/api/marketplace_addons"
32
33
  require "megam/core/server_api"
33
34
  require "megam/core/config"
34
35
  require "megam/core/stuff"
@@ -69,6 +70,8 @@ require "megam/core/sshkey"
69
70
  require "megam/core/sshkey_collection"
70
71
  require "megam/core/marketplace"
71
72
  require "megam/core/marketplace_collection"
73
+ require "megam/core/marketplace_addon"
74
+ require "megam/core/marketplace_addon_collection"
72
75
 
73
76
  #we may nuke logs out of the api
74
77
  #require "megam/api/logs"
@@ -128,8 +131,8 @@ module Megam
128
131
  Megam::Log.debug("> #{pkey}: #{pvalue}")
129
132
  end
130
133
 
131
- begin
132
- response = connection.request(params, &block)
134
+ begin
135
+ response = connection.request(params, &block)
133
136
  rescue Excon::Errors::HTTPStatusError => error
134
137
  klass = case error.response.status
135
138
 
@@ -0,0 +1,27 @@
1
+ module Megam
2
+ class API
3
+
4
+ #=begin
5
+ def get_addons(node_name)
6
+ @options = {:path => "/marketplaceaddons/#{node_name}",:body => ""}.merge(@options)
7
+
8
+ request(
9
+ :expects => 200,
10
+ :method => :get,
11
+ :body => @options[:body]
12
+ )
13
+ end
14
+ #=end
15
+ def post_addon(new_addon)
16
+ @options = {:path => '/marketplaceaddons/content',
17
+ :body => Megam::JSONCompat.to_json(new_addon)}.merge(@options)
18
+
19
+ request(
20
+ :expects => 201,
21
+ :method => :post,
22
+ :body => @options[:body]
23
+ )
24
+ end
25
+
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.11"
3
+ VERSION = "0.12"
4
4
  end
5
5
  end
@@ -25,7 +25,7 @@ module Megam
25
25
  MEGAM_AUTH = "Megam::Auth".freeze
26
26
  MEGAM_ERROR = "Megam::Error".freeze
27
27
  MEGAM_ACCOUNT = "Megam::Account".freeze
28
- MEGAM_NODE = "Megam::Node".freeze
28
+ MEGAM_NODE = "Megam::Node".freeze
29
29
  MEGAM_NODECOLLECTION = "Megam::NodeCollection".freeze
30
30
  MEGAM_APPDEFNS = "Megam::AppDefns".freeze
31
31
  MEGAM_APPREQUEST = "Megam::AppRequest".freeze
@@ -55,7 +55,8 @@ module Megam
55
55
  MEGAM_SSHKEYCOLLECTION = "Megam::SshKeyCollection".freeze
56
56
  MEGAM_MARKETPLACE = "Megam::MarketPlace".freeze
57
57
  MEGAM_MARKETPLACECOLLECTION = "Megam::MarketPlaceCollection".freeze
58
-
58
+ MEGAM_MARKETPLACEADDON = "Megam::MarketPlaceAddons".freeze
59
+ MEGAM_MARKETPLACEADDONCOLLECTION = "Megam::MarketPlaceAddonsCollection".freeze
59
60
  class <<self
60
61
  # Increase the max nesting for JSON, which defaults
61
62
  # to 19, and isn't enough for some (for example, a Node within a Node)
@@ -64,12 +65,12 @@ module Megam
64
65
  if opts.nil? || !opts.has_key?(:max_nesting)
65
66
  opts = opts.nil? ? Hash.new : opts.clone
66
67
  opts[:max_nesting] = JSON_MAX_NESTING
67
- end
68
+ end
68
69
  opts
69
70
  end
70
71
 
71
72
  # Just call the JSON gem's parse method with a modified :max_nesting field
72
- def from_json(source, opts = {})
73
+ def from_json(source, opts = {})
73
74
  obj = ::Yajl::Parser.parse(source)
74
75
  # JSON gem requires top level object to be a Hash or Array (otherwise
75
76
  # you get the "must contain two octets" error). Yajl doesn't impose the
@@ -114,7 +115,7 @@ module Megam
114
115
  json_hash
115
116
  end
116
117
 
117
- def to_json(obj, opts = nil)
118
+ def to_json(obj, opts = nil)
118
119
  obj.to_json(opts_add_max_nesting(opts))
119
120
  end
120
121
 
@@ -192,6 +193,10 @@ module Megam
192
193
  Megam::MarketPlace
193
194
  when MEGAM_MARKETPLACECOLLECTION
194
195
  Megam::MarketPlaceCollection
196
+ when MEGAM_MARKETPLACEADDON
197
+ Megam::MarketPlaceAddons
198
+ when MEGAM_MARKETPLACEADDONCOLLECTION
199
+ Megam::MarketPlaceAddonsCollection
195
200
  else
196
201
  raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
197
202
  end
@@ -0,0 +1,195 @@
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 MarketPlaceAddons< Megam::ServerAPI
18
+
19
+ def initialize(email=nil, api_key=nil)
20
+ @id = nil
21
+ @node_id = nil
22
+ @node_name = nil
23
+ @marketplace_id = nil
24
+ @config = {}
25
+ @config_id = nil
26
+ @created_at = nil
27
+ @some_msg = {}
28
+ super(email,api_key)
29
+ end
30
+
31
+ def market_place_addons
32
+ self
33
+ end
34
+
35
+
36
+ def id(arg=nil)
37
+ if arg != nil
38
+ @id = arg
39
+ else
40
+ @id
41
+ end
42
+ end
43
+
44
+ def node_id(arg=nil)
45
+ if arg != nil
46
+ @node_id = arg
47
+ else
48
+ @node_id
49
+ end
50
+ end
51
+
52
+ def node_name(arg=nil)
53
+ if arg != nil
54
+ @node_name = arg
55
+ else
56
+ @node_name
57
+ end
58
+ end
59
+
60
+ def marketplace_id(arg=nil)
61
+ if arg != nil
62
+ @marketplace_id = arg
63
+ else
64
+ @marketplace_id
65
+ end
66
+ end
67
+
68
+ def config_id(arg=nil)
69
+ if arg != nil
70
+ @config_id = arg
71
+ else
72
+ @config_id
73
+ end
74
+ end
75
+
76
+ def config(arg=nil)
77
+ if arg != nil
78
+ @config = arg
79
+ else
80
+ @config
81
+ end
82
+ end
83
+
84
+ def created_at(arg=nil)
85
+ if arg != nil
86
+ @created_at = arg
87
+ else
88
+ @created_at
89
+ end
90
+ end
91
+ def some_msg(arg=nil)
92
+ if arg != nil
93
+ @some_msg = arg
94
+ else
95
+ @some_msg
96
+ end
97
+ end
98
+
99
+ def error?
100
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
101
+ end
102
+
103
+ # Transform the ruby obj -> to a Hash
104
+ def to_hash
105
+ index_hash = Hash.new
106
+ index_hash["json_claz"] = self.class.name
107
+ index_hash["id"] = id
108
+ index_hash["node_id"] = node_id
109
+ index_hash["node_name"] = node_name
110
+ index_hash["marketplace_id"] = marketplace_id
111
+ index_hash["config"] = config
112
+ index_hash["config_id"] = config_id
113
+ index_hash["created_at"] = created_at
114
+ index_hash["some_msg"] = some_msg
115
+ index_hash
116
+ end
117
+
118
+ # Serialize this object as a hash: called from JsonCompat.
119
+ # Verify if this called from JsonCompat during testing.
120
+ def to_json(*a)
121
+ for_json.to_json(*a)
122
+ end
123
+
124
+ def for_json
125
+ result = {
126
+ "id" => id,
127
+ "node_id" => node_id,
128
+ "node_name" => node_name,
129
+ "marketplace_id" => marketplace_id,
130
+ "config" => config,
131
+ "config_id" => config_id,
132
+ "created_at" => created_at
133
+ }
134
+ result
135
+ end
136
+
137
+
138
+ def self.json_create(o)
139
+ addon = new
140
+ addon.id(o["id"]) if o.has_key?("id")
141
+ addon.node_id(o["node_id"]) if o.has_key?("node_id")
142
+ addon.node_name(o["node_name"]) if o.has_key?("node_name")
143
+ addon.marketplace_id(o["marketplace_id"]) if o.has_key?("marketplace_id")
144
+ addon.config(o["config"]) if o.has_key?("config")
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
+
148
+ addon.some_msg[:code] = o["code"] if o.has_key?("code")
149
+ addon.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
150
+ addon.some_msg[:msg]= o["msg"] if o.has_key?("msg")
151
+ addon.some_msg[:links] = o["links"] if o.has_key?("links")
152
+
153
+ addon
154
+ end
155
+
156
+ def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
157
+ addon = self.new(tmp_email, tmp_api_key)
158
+ addon.from_hash(o)
159
+ addon
160
+ end
161
+
162
+ def from_hash(o)
163
+ @id = o["id"] if o.has_key?("id")
164
+ @node_id = o["node_id"] if o.has_key?("node_id")
165
+ @node_name = o["node_name"] if o.has_key?("node_name")
166
+ @marketplace_id = o["marketplace_id"] if o.has_key?("marketplace_id")
167
+ @config = o["config"] if o.has_key?("config")
168
+ @config_id = o["config_id"] if o.has_key?("config_id")
169
+ @created_at = o["created_at"] if o.has_key?("created_at")
170
+ self
171
+ end
172
+
173
+ def self.create(o,tmp_email=nil, tmp_api_key=nil)
174
+ acct = from_hash(o,tmp_email, tmp_api_key)
175
+ acct.create
176
+ end
177
+
178
+ # Create the addon via the REST API
179
+ def create
180
+ megam_rest.post_addon(to_hash)
181
+ end
182
+
183
+ # Load a account by email_p
184
+ def self.list(node_name,tmp_email=nil, tmp_api_key=nil)
185
+ addon = self.new(tmp_email, tmp_api_key)
186
+ addon.megam_rest.get_addons(node_name)
187
+ #self
188
+ end
189
+
190
+ def to_s
191
+ Megam::Stuff.styled_hash(to_hash)
192
+ end
193
+
194
+ end
195
+ end
@@ -0,0 +1,148 @@
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 MarketPlaceAddonsCollection
18
+ include Enumerable
19
+
20
+
21
+ attr_reader :iterator
22
+ def initialize
23
+ @addons = Array.new
24
+ @addons_by_name = Hash.new
25
+ @insert_after_idx = nil
26
+ end
27
+
28
+ def all_addons
29
+ @addons
30
+ end
31
+
32
+ def [](index)
33
+ @addons[index]
34
+ end
35
+
36
+ def []=(index, arg)
37
+ is_megam_addon(arg)
38
+ @addons[index] = arg
39
+ @addons_by_name[arg.id] = index
40
+ end
41
+
42
+ def <<(*args)
43
+ args.flatten.each do |a|
44
+ is_megam_addon(a)
45
+ @addons << a
46
+ @addons_by_name[a.id] = @addons.length - 1
47
+ end
48
+ self
49
+ end
50
+
51
+ # 'push' is an alias method to <<
52
+ alias_method :push, :<<
53
+
54
+ def insert(addon)
55
+ is_megam_addon(addon)
56
+ if @insert_after_idx
57
+ # in the middle of executing a run, so any addons inserted now should
58
+ # be placed after the most recent addition done by the currently executing
59
+ # addons
60
+ @addons.insert(@insert_after_idx + 1, addon)
61
+ # update name -> location mappings and register new addons
62
+ @addons_by_name.each_key do |key|
63
+ @addons_by_name[key] += 1 if @addons_by_name[key] > @insert_after_idx
64
+ end
65
+ @addons_by_name[addon.id] = @insert_after_idx + 1
66
+ @insert_after_idx += 1
67
+ else
68
+ @addons << addon
69
+ @addons_by_name[addon.id] = @addons.length - 1
70
+ end
71
+ end
72
+
73
+ def each
74
+ @addons.each do |addon|
75
+ yield addon
76
+ end
77
+ end
78
+
79
+ def each_index
80
+ @addons.each_index do |i|
81
+ yield i
82
+ end
83
+ end
84
+
85
+ def empty?
86
+ @addons.empty?
87
+ end
88
+
89
+ def lookup(addon)
90
+ lookup_by = nil
91
+ if addon.kind_of?(Megam::MarketPlaceAddons)
92
+ lookup_by = addon.id
93
+ elsif addon.kind_of?(String)
94
+ lookup_by = addon
95
+ else
96
+ raise ArgumentError, "Must pass a Megam::MarketPlaceAddons or String to lookup"
97
+ end
98
+ res = @addons_by_name[lookup_by]
99
+ unless res
100
+ raise ArgumentError, "Cannot find a appreq matching #{lookup_by} (did you define it first?)"
101
+ end
102
+ @addons[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 |addon|
109
+ index_hash[addon.id] = addon.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 |addons_list|
124
+ addons_array = addons_list.kind_of?(Array) ? addons_list : [ addons_list ]
125
+ addons_array.each do |addon|
126
+ collection.insert(addon)
127
+ end
128
+ end
129
+ collection
130
+ end
131
+
132
+ private
133
+
134
+
135
+
136
+ def is_megam_addon(arg)
137
+ unless arg.kind_of?(Megam::MarketPlaceAddons)
138
+ raise ArgumentError, "Members must be Megam::MarketPlaceAddons"
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
@@ -0,0 +1,41 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ #=begin
5
+ def test_post_addon
6
+ @com = {
7
+ "disaster"=>{
8
+ "locations"=>"locations",
9
+ "fromhost"=>"appsample1.megam.co",
10
+ "tohosts"=>"appsample2.megam.co;appsample3.megam.co"
11
+ },
12
+ "loadbalancing"=>{
13
+ "haproxyhost"=>"",
14
+ "loadbalancehost"=>""
15
+ },
16
+ "autoscaling"=>{
17
+ "cputhreshold"=>"",
18
+ "memorythreshold"=>"",
19
+ "noofinstances"=>""
20
+ },
21
+ "monitoring"=>{
22
+ "agent"=>"op5"
23
+ }
24
+ }
25
+
26
+ tmp_hash = {
27
+ "node_id" => "NOD450939631320432640",
28
+ "node_name" => "appsample1.megam.co",
29
+ "marketplace_id" => "APP",
30
+ "config" => @com
31
+ }
32
+ response = megams.post_addon(tmp_hash)
33
+ assert_equal(201, response.status)
34
+ end
35
+ #=end
36
+
37
+ # def test_get_nodes
38
+ # response = megams.get_addons("appsample1.megam.co")
39
+ # assert_equal(200, response.status)
40
+ # end
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.11'
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kishorekumar Neelamegam, Thomas Alrin, Subash Sethurajan, Rajthilak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-28 00:00:00.000000000 Z
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -138,6 +138,7 @@ files:
138
138
  - lib/megam/api/errors.rb
139
139
  - lib/megam/api/login.rb
140
140
  - lib/megam/api/logs.rb
141
+ - lib/megam/api/marketplace_addons.rb
141
142
  - lib/megam/api/marketplaces.rb
142
143
  - lib/megam/api/nodes.rb
143
144
  - lib/megam/api/predef_clouds.rb
@@ -171,6 +172,8 @@ files:
171
172
  - lib/megam/core/json_compat.rb
172
173
  - lib/megam/core/log.rb
173
174
  - lib/megam/core/marketplace.rb
175
+ - lib/megam/core/marketplace_addon.rb
176
+ - lib/megam/core/marketplace_addon_collection.rb
174
177
  - lib/megam/core/marketplace_collection.rb
175
178
  - lib/megam/core/monologger.rb
176
179
  - lib/megam/core/node.rb
@@ -199,6 +202,7 @@ files:
199
202
  - test/test_helper.rb
200
203
  - test/test_login.rb
201
204
  - test/test_logs.rb
205
+ - test/test_marketplaceaddons.rb
202
206
  - test/test_marketplaces.rb
203
207
  - test/test_nodes.rb
204
208
  - test/test_predefclouds.rb
@@ -225,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
229
  version: '0'
226
230
  requirements: []
227
231
  rubyforge_project:
228
- rubygems_version: 2.1.11
232
+ rubygems_version: 2.2.2
229
233
  signing_key:
230
234
  specification_version: 4
231
235
  summary: Ruby Client for the Megam Cloud