megam_api 1.8.2 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fe322a12b43de3a7f578b59e1f3cc468945006a
4
- data.tar.gz: 075ccc88dab62d0122caa2b0a2fef03f0ac96e85
3
+ metadata.gz: e946570e46430d98c50ce13295049342e172b7fb
4
+ data.tar.gz: 6058140fe707dc542bfcfa63fe23d677799fc296
5
5
  SHA512:
6
- metadata.gz: a4f91f4b249a4be36fe3d585eecceb0b716786548453cc8487a151c2b71027399cd8fce52e22cfc74c9aac66b674f6a27fd6bf3c7cde669e2c7fc688cd3aa304
7
- data.tar.gz: 2bac046921d8cc0efece334d4596a6c55293f57e41af1cc67efe8e1a995918236b2097cf1de8bd15e21f7a7d0b8e71f99436299010c7c17aa51d378f043fddcc
6
+ metadata.gz: d3caabbdc2a2279965c43f4ca0489eefdb5cd661b58aa7418407250e1d00f3f06f35f32f93a646ea3cafdd7e10f20063232e897d6d7199a6c37f0cb7d09f8697
7
+ data.tar.gz: bb4a08331a0a5dae94a9bf38f6e5f9b8bb5816360528808b6d380bf0fd132c89b58e1ea95f6f2c173c18b611f6f327ef9fbba332629dee42b95146c413954c4b
@@ -49,10 +49,9 @@ require 'megam/core/log'
49
49
  require 'megam/core/json_compat'
50
50
  require 'megam/core/error'
51
51
  require 'megam/core/account'
52
+ require 'megam/core/account_collection'
52
53
  require 'megam/core/request'
53
54
  require 'megam/core/request_collection'
54
- require 'megam/core/license'
55
- require 'megam/core/license_collection'
56
55
  require 'megam/core/sshkey'
57
56
  require 'megam/core/sshkey_collection'
58
57
  require 'megam/core/eventsall'
@@ -1,7 +1,6 @@
1
1
  module Megam
2
2
  class API
3
3
  # GET /accounts
4
- #Yet to be tested
5
4
  def get_accounts(email)
6
5
  @options = {:path => "/accounts/#{email}",
7
6
  :body => ''}.merge(@options)
@@ -24,7 +23,7 @@ module Megam
24
23
  :body => @options[:body]
25
24
  )
26
25
  end
27
-
26
+
28
27
  # The body content needs to be a json.
29
28
  def post_accounts(new_account)
30
29
  @options = {path: '/accounts/content',
@@ -70,5 +69,17 @@ module Megam
70
69
  )
71
70
  end
72
71
 
72
+ # ADMIN: LIST /accounts
73
+ def list_accounts
74
+ @options = {:path => "/accounts",
75
+ :body => ''}.merge(@options)
76
+
77
+ request(
78
+ :expects => 200,
79
+ :method => :get,
80
+ :body => @options[:body]
81
+ )
82
+ end
83
+
73
84
  end
74
- end
85
+ end
@@ -1,7 +1,7 @@
1
1
  module Megam
2
2
  class API
3
3
 
4
- VERSION = "1.8.2"
4
+ VERSION = "1.8.4"
5
5
 
6
6
  end
7
7
  end
@@ -28,7 +28,7 @@ module Megam
28
28
  @suspend = {}
29
29
  @dates = {}
30
30
  @some_msg = {}
31
-
31
+
32
32
  super({ email: o[:email], api_key: o[:api_key],
33
33
  host: o[:host], password_hash: o[:password_hash], org_id: o[:org_id] })
34
34
  end
@@ -154,7 +154,8 @@ module Megam
154
154
  def login
155
155
  megam_rest.login(to_hash)
156
156
  end
157
-
157
+
158
+
158
159
  def self.create(o)
159
160
  acct = from_hash(o)
160
161
  acct.create
@@ -169,6 +170,15 @@ module Megam
169
170
  acct.megam_rest.get_accounts(o[:email])
170
171
  end
171
172
 
173
+ def self.list(o)
174
+ acct = from_hash(o)
175
+ acct.list
176
+ end
177
+
178
+ def list
179
+ megam_rest.list_accounts
180
+ end
181
+
172
182
  def self.update(o)
173
183
  acct = from_hash(o)
174
184
  acct.update
@@ -0,0 +1,122 @@
1
+ module Megam
2
+ class AccountCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @accounts = Array.new
8
+ @accounts_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_accounts
13
+ @accounts
14
+ end
15
+
16
+ def [](index)
17
+ @accounts[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_account_hash(arg)
22
+ @accounts[index] = arg
23
+ @accounts_by_name[arg[:email]] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_account_hash(a)
29
+ @accounts << a
30
+ @accounts_by_name[a[:email]] = @accounts.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(accounts)
39
+ is_account_hash(accounts)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any nodes inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # node
44
+ @accounts.insert(@insert_after_idx + 1, accounts)
45
+ # update name -> location mappings and register new node
46
+ @accounts_by_name.each_key do |key|
47
+ @accounts_by_name[key] += 1 if @accounts_by_name[key] > @insert_after_idx
48
+ end
49
+ @accounts_by_name[accounts[:email]] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @accounts << accounts
53
+ @accounts_by_name[accounts[:email]] = @accounts.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @accounts.each do |accounts|
59
+ yield accounts
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @accounts.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @accounts.empty?
71
+ end
72
+
73
+ def lookup(accounts)
74
+ lookup_by = nil
75
+ if accounts.kind_of?(Hash)
76
+ lookup_by = accounts[:email]
77
+ elsif accounts.kind_of?(String)
78
+ lookup_by = accounts
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Account or String to lookup"
81
+ end
82
+ res = @accounts_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @accounts[res]
87
+ end
88
+
89
+ def to_s
90
+ @accounts.join(", ")
91
+ end
92
+
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
96
+
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
100
+
101
+ def self.json_create(o)
102
+ collection = self.new()
103
+ o["results"].each do |accounts_list|
104
+ accounts_array = accounts_list.kind_of?(Array) ? accounts_list : [ accounts_list ]
105
+ accounts_array.each do |accounts|
106
+ collection.insert(accounts)
107
+
108
+ end
109
+ end
110
+ collection
111
+ end
112
+
113
+ private
114
+
115
+ def is_account_hash(arg)
116
+ unless arg.kind_of?(Hash)
117
+ raise ArgumentError, "Members must be a Hash"
118
+ end
119
+ true
120
+ end
121
+ end
122
+ end
@@ -12,6 +12,7 @@ module Megam
12
12
  JSON_CLAZ = 'json_claz'.freeze
13
13
 
14
14
  MEGAM_ACCOUNT = 'Megam::Account'.freeze
15
+ MEGAM_ACCOUNTCOLLECTION = 'Megam::AccountCollection'.freeze
15
16
  MEGAM_ASSEMBLIES = 'Megam::Assemblies'.freeze
16
17
  MEGAM_ASSEMBLIESCOLLECTION = 'Megam::AssembliesCollection'.freeze
17
18
  MEGAM_ASSEMBLY = 'Megam::Assembly'.freeze
@@ -39,8 +40,6 @@ module Megam
39
40
  MEGAM_SNAPSHOTSCOLLECTION = 'Megam::SnapshotsCollection'.freeze
40
41
  MEGAM_DISKS = 'Megam::Disks'.freeze
41
42
  MEGAM_DISKSCOLLECTION = 'Megam::DisksCollection'.freeze
42
- MEGAM_LICENSE = 'Megam::License'.freeze
43
- MEGAM_LICENSECOLLECTION = 'Megam::LicenseCollection'.freeze
44
43
  MEGAM_SSHKEY = 'Megam::SshKey'.freeze
45
44
  MEGAM_SSHKEYCOLLECTION = 'Megam::SshKeyCollection'.freeze
46
45
  MEGAM_EVENTSALL = 'Megam::EventsAll'.freeze
@@ -65,7 +64,7 @@ module Megam
65
64
  begin
66
65
  FFI_Yajl::Parser.parse(source, opts)
67
66
  rescue FFI_Yajl::ParseError => e
68
- raise JSON::ParseError, e.message
67
+ raise StandardError, e.message
69
68
  end
70
69
  end
71
70
 
@@ -144,6 +143,8 @@ module Megam
144
143
  Megam::Error
145
144
  when MEGAM_ACCOUNT
146
145
  Megam::Account
146
+ when MEGAM_ACCOUNTCOLLECTION
147
+ Megam::AccountCollection
147
148
  when MEGAM_ASSEMBLIES
148
149
  Megam::Assemblies
149
150
  when MEGAM_ASSEMBLIESCOLLECTION
@@ -168,8 +169,6 @@ module Megam
168
169
  Megam::EventsVm
169
170
  when MEGAM_EVENTSVMCOLLECTION
170
171
  Megam::EventsVmCollection
171
- when MEGAM_LICENSECOLLECTION
172
- Megam::LicenseCollection
173
172
  when MEGAM_EVENTSALL
174
173
  Megam::EventsAll
175
174
  when MEGAM_EVENTSALLCOLLECTION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Vinodhini V, Rathish VBR, Rajesh
@@ -153,7 +153,6 @@ files:
153
153
  - lib/megam/api/eventscontainer.rb
154
154
  - lib/megam/api/eventsstorage.rb
155
155
  - lib/megam/api/eventsvm.rb
156
- - lib/megam/api/license.rb
157
156
  - lib/megam/api/marketplaces.rb
158
157
  - lib/megam/api/organizations.rb
159
158
  - lib/megam/api/promos.rb
@@ -164,6 +163,7 @@ files:
164
163
  - lib/megam/api/subscriptions.rb
165
164
  - lib/megam/api/version.rb
166
165
  - lib/megam/core/account.rb
166
+ - lib/megam/core/account_collection.rb
167
167
  - lib/megam/core/addons.rb
168
168
  - lib/megam/core/addons_collection.rb
169
169
  - lib/megam/core/assemblies.rb
@@ -195,8 +195,6 @@ files:
195
195
  - lib/megam/core/eventsvm_collection.rb
196
196
  - lib/megam/core/json_compat.rb
197
197
  - lib/megam/core/konipai.rb
198
- - lib/megam/core/license-collection.rb
199
- - lib/megam/core/license.rb
200
198
  - lib/megam/core/log.rb
201
199
  - lib/megam/core/marketplace.rb
202
200
  - lib/megam/core/marketplace_collection.rb
@@ -277,4 +275,30 @@ rubygems_version: 2.5.1
277
275
  signing_key:
278
276
  specification_version: 4
279
277
  summary: Ruby Client for the Megam Vertice
280
- test_files: []
278
+ test_files:
279
+ - test/mixins/test_assemblies.rb
280
+ - test/mixins/test_assembly.rb
281
+ - test/mixins/test_component.rb
282
+ - test/test_accounts.rb
283
+ - test/test_addons.rb
284
+ - test/test_assemblies.rb
285
+ - test/test_assembly.rb
286
+ - test/test_balances.rb
287
+ - test/test_billedhistories.rb
288
+ - test/test_billingtranscations.rb
289
+ - test/test_components.rb
290
+ - test/test_disks.rb
291
+ - test/test_domains.rb
292
+ - test/test_eventsbilling.rb
293
+ - test/test_eventscontainer.rb
294
+ - test/test_eventsstorage.rb
295
+ - test/test_eventsvm.rb
296
+ - test/test_helper.rb
297
+ - test/test_marketplaces.rb
298
+ - test/test_organizations.rb
299
+ - test/test_promos.rb
300
+ - test/test_requests.rb
301
+ - test/test_sensors.rb
302
+ - test/test_snapshots.rb
303
+ - test/test_sshkeys.rb
304
+ - test/test_subscriptions.rb
@@ -1,35 +0,0 @@
1
- module Megam
2
- class API
3
- def get_licenses
4
- @options = {:path => '/license',:body => ""}.merge(@options)
5
-
6
- request(
7
- :expects => 200,
8
- :method => :get,
9
- :body => @options[:body]
10
- )
11
- end
12
-
13
- def get_license(license_name)
14
- @options = {:path => "/license/#{license_name}",:body => ""}.merge(@options)
15
-
16
- request(
17
- :expects => 200,
18
- :method => :get,
19
- :body => @options[:body]
20
- )
21
- end
22
-
23
- def post_license(new_license)
24
- @options = {:path => '/license/content',
25
- :body => Megam::JSONCompat.to_json(new_license)}.merge(@options)
26
-
27
- request(
28
- :expects => 201,
29
- :method => :post,
30
- :body => @options[:body]
31
- )
32
- end
33
-
34
- end
35
- end
@@ -1,122 +0,0 @@
1
- module Megam
2
- class LicenseCollection
3
- include Enumerable
4
-
5
- attr_reader :iterator
6
-
7
- def initialize
8
- @license = Array.new
9
- @license_by_name = Hash.new
10
- @insert_after_idx = nil
11
- end
12
-
13
- def all_license
14
- @license
15
- end
16
-
17
- def [](index)
18
- @license[index]
19
- end
20
-
21
- def []=(index, arg)
22
- is_megam_license(arg)
23
- @license[index] = arg
24
- @license_by_name[arg.name] = index
25
- end
26
-
27
- def <<(*args)
28
- args.flatten.each do |a|
29
- is_megam_license(a)
30
- @license << a
31
- @license_by_name[a.name] =@license.length - 1
32
- end
33
- self
34
- end
35
-
36
- # 'push' is an alias method to <<
37
- alias_method :push, :<<
38
-
39
- def insert(license)
40
- is_megam_license(license)
41
- if @insert_after_idx
42
- # in the middle of executing a run, so any license inserted now should
43
- # be placed after the most recent addition done by the currently executing
44
- # license
45
- @license.insert(@insert_after_idx + 1, license)
46
- # update name -> location mappings and register new license
47
- @license_by_name.each_key do |key|
48
- @license_by_name[key] += 1 if@license_by_name[key] > @insert_after_idx
49
- end
50
- @license_by_name[license.name] = @insert_after_idx + 1
51
- @insert_after_idx += 1
52
- else
53
- @license << license
54
- @license_by_name[license.name] =@license.length - 1
55
- end
56
- end
57
-
58
- def each
59
- @license.each do |license|
60
- yield license
61
- end
62
- end
63
-
64
- def each_index
65
- @license.each_index do |i|
66
- yield i
67
- end
68
- end
69
-
70
- def empty?
71
- @license.empty?
72
- end
73
-
74
- def lookup(license)
75
- lookup_by = nil
76
- if license.kind_of?(Megam::License)
77
- lookup_by = license.name
78
- elsif license.kind_of?(String)
79
- lookup_by = license
80
- else
81
- raise ArgumentError, "Must pass a Megam::license or String to lookup"
82
- end
83
- res =@license_by_name[lookup_by]
84
- unless res
85
- raise ArgumentError, "Cannot find a license matching #{lookup_by} (did you define it first?)"
86
- end
87
- @license[res]
88
- end
89
-
90
- def to_s
91
- @license.join(", ")
92
- end
93
-
94
- def for_json
95
- to_a.map { |item| item.to_s }
96
- end
97
-
98
- def to_json(*a)
99
- Megam::JSONCompat.to_json(for_json, *a)
100
- end
101
-
102
- def self.json_create(o)
103
- collection = self.new()
104
- o["results"].each do |license_list|
105
- license_array = license_list.kind_of?(Array) ? license_list : [ license_list ]
106
- license_array.each do |license|
107
- collection.insert(license)
108
- end
109
- end
110
- collection
111
- end
112
-
113
- private
114
-
115
- def is_megam_license(arg)
116
- unless arg.kind_of?(Megam::License)
117
- raise ArgumentError, "Members must be Megam::License's"
118
- end
119
- true
120
- end
121
- end
122
- end
@@ -1,173 +0,0 @@
1
- module Megam
2
- class License < Megam::RestAdapter
3
- def initialize(o)
4
- @id = nil
5
- @name = nil
6
- @org_id = nil
7
- @privatekey=nil
8
- @publickey=nil
9
- @created_at = nil
10
- @some_msg = {}
11
- super(o)
12
- end
13
-
14
- def license
15
- self
16
- end
17
-
18
- def id(arg=nil)
19
- if arg != nil
20
- @id = arg
21
- else
22
- @id
23
- end
24
- end
25
-
26
- def name(arg=nil)
27
- if arg != nil
28
- @name = arg
29
- else
30
- @name
31
- end
32
- end
33
-
34
- def org_id(arg=nil)
35
- if arg != nil
36
- @org_id= arg
37
- else
38
- @org_id
39
- end
40
- end
41
-
42
- def privatekey(arg=nil)
43
- if arg != nil
44
- @privatekey = arg
45
- else
46
- @privatekey
47
- end
48
- end
49
-
50
- def publickey(arg=nil)
51
- if arg != nil
52
- @publickey = arg
53
- else
54
- @publickey
55
- end
56
- end
57
-
58
-
59
- def created_at(arg=nil)
60
- if arg != nil
61
- @created_at = arg
62
- else
63
- @created_at
64
- end
65
- end
66
-
67
- def some_msg(arg=nil)
68
- if arg != nil
69
- @some_msg = arg
70
- else
71
- @some_msg
72
- end
73
- end
74
-
75
- def error?
76
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
77
- end
78
-
79
- # Transform the ruby obj -> to a Hash
80
- def to_hash
81
- index_hash = Hash.new
82
- index_hash["json_claz"] = self.class.name
83
- index_hash["id"] = id
84
- index_hash["name"] = name
85
- index_hash["org_id"] = org_id
86
- index_hash["privatekey"] = privatekey
87
- index_hash["publickey"] = publickey
88
- index_hash["created_at"] = created_at
89
- index_hash
90
- end
91
-
92
- # Serialize this object as a hash: called from JsonCompat.
93
- # Verify if this called from JsonCompat during testing.
94
- def to_json(*a)
95
- for_json.to_json(*a)
96
- end
97
-
98
- def for_json
99
- result = {
100
- "id" => id,
101
- "name" => name,
102
- "org_id" => org_id,
103
- "privatekey" => privatekey,
104
- "publickey" => publickey,
105
- "created_at" => created_at
106
- }
107
- result
108
- end
109
-
110
- #
111
- def self.json_create(o)
112
- license = new({})
113
- license.id(o["id"]) if o.has_key?("id")
114
- license.name(o["name"]) if o.has_key?("name")
115
- license.privatekey(o["privatekey"]) if o.has_key?("privatekey")
116
- license.publickey(o["publickey"]) if o.has_key?("publickey")
117
- license.created_at(o["created_at"]) if o.has_key?("created_at")
118
- #success or error
119
- license.some_msg[:code] = o["code"] if o.has_key?("code")
120
- license.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
121
- license.some_msg[:msg]= o["msg"] if o.has_key?("msg")
122
- license.some_msg[:links] = o["links"] if o.has_key?("links")
123
- license
124
- end
125
-
126
- def self.from_hash(o)
127
- license = self.new(o)
128
- license.from_hash(o)
129
- license
130
- end
131
-
132
- def from_hash(o)
133
- @id = o[:id] if o.has_key?(:id)
134
- @name = o[:name] if o.has_key?(:name)
135
- @org_id = o[:org_id] if o.has_key?(:org_id)
136
- @privatekey = o[:privatekey] if o.has_key?(:privatekey)
137
- @publickey = o[:publickey] if o.has_key?(:publickey)
138
- @created_at = o[:created_at] if o.has_key?(:created_at)
139
- self
140
- end
141
-
142
- def self.create(params)
143
- acct = from_hash(params)
144
- acct.create
145
- end
146
-
147
- # Create the predef via the REST API
148
- def create
149
- megam_rest.post_license(to_hash)
150
- end
151
-
152
- # Load all license -
153
- # returns a LicensesCollection
154
- # don't return self. check if the Megam::LicenseCollection is returned.
155
- def self.list(params)
156
- license = self.new(params)
157
- license.megam_rest.get_license
158
- end
159
-
160
- # Show a particular License by name,
161
- # Megam::License
162
- def self.show(params)
163
- pre = self.new(params)
164
- pre.megam_rest.get_license(params["name"])
165
- end
166
-
167
- def to_s
168
- Megam::Stuff.styled_hash(to_hash)
169
- #"---> Megam::Account:[error=#{error?}]\n"+
170
- end
171
-
172
- end
173
- end