megam_api 1.6.7 → 1.6.8

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: 776f06fd527678942056d9b9fefee5d3876d28c0
4
- data.tar.gz: 4a56fb364e4d4748f7032da252a405909e03eb12
3
+ metadata.gz: acf9806f47fab932ce69e0db128474d8c9f0f182
4
+ data.tar.gz: dbfc46c378ac00c0170b56e11e7aef94e079a422
5
5
  SHA512:
6
- metadata.gz: c347483a08676ee3b306742abcfa1e70759575e4359ce45d2c6ee972f3ede97e368ba2d7007c4e9de0b49f3350fdbdc949936e77a41f1d69d558d78c120eb217
7
- data.tar.gz: d2ffdd3759f0c2b6e15cf44c8dfc5d1ac133c3b96f586b7e028148a133b56e0511229fd5371688d4fe26a4550ae27a4b11630b733221f0c42dbedbba4ba72e6d
6
+ metadata.gz: 955ae148705c0df26622687a41681c7874eed2cb4a10b0c4e8e471c136f513513e9a04a635dee6ee1d7a21a75769f44f06bd05bf7ba125759a476f936161ab70
7
+ data.tar.gz: 03965dbfff7f7d7dd4fdb3e3f680f92b5a14b1fe4a0eb983fbda81bc014ff2908072740073d73badadde7150c7374d52fcdd5c0e882c35527289a734053248b3
data/lib/megam/api.rb CHANGED
@@ -28,6 +28,7 @@ require 'megam/api/eventscontainer'
28
28
  require 'megam/api/eventsbilling'
29
29
  require 'megam/api/eventsstorage'
30
30
  require 'megam/api/snapshots'
31
+ require 'megam/api/disks'
31
32
  require 'megam/api/subscriptions'
32
33
  require 'megam/api/addons'
33
34
  require 'megam/api/version'
@@ -76,6 +77,8 @@ require 'megam/core/sensors'
76
77
  require 'megam/core/sensors_collection'
77
78
  require 'megam/core/snapshots'
78
79
  require 'megam/core/snapshots_collection'
80
+ require 'megam/core/disks'
81
+ require 'megam/core/disks_collection'
79
82
  require 'megam/core/balances_collection'
80
83
  require 'megam/core/balances'
81
84
  require 'megam/core/billedhistories_collection'
@@ -256,11 +259,11 @@ module Megam
256
259
  current_date = Time.now.strftime('%Y-%m-%d %H:%M')
257
260
 
258
261
  data = "#{current_date}" + "\n" + "#{cmd_parms[:path]}" + "\n" + "#{body_base64}"
259
-
262
+
260
263
  digest = OpenSSL::Digest.new('sha1')
261
-
264
+
262
265
  movingFactor = data
263
-
266
+
264
267
  if !(@password_hash.nil?) && @api_key.nil?
265
268
  hash = OpenSSL::HMAC.hexdigest(digest, Base64.strict_decode64(@password_hash), movingFactor)
266
269
  elsif !(@api_key.nil?)
@@ -273,4 +276,3 @@ module Megam
273
276
  end
274
277
  end
275
278
  end
276
-
@@ -0,0 +1,34 @@
1
+ module Megam
2
+ class API
3
+ # GET /nodes
4
+ def list_disks
5
+ @options = {:path => "/disks",:body => ""}.merge(@options)
6
+
7
+ request(
8
+ :expects => 200,
9
+ :method => :get,
10
+ :body => @options[:body]
11
+ )
12
+ end
13
+
14
+ def get_disks(asm_id)
15
+ @options = {:path => "/disks/#{asm_id}",:body => ""}.merge(@options)
16
+
17
+ request(
18
+ :expects => 200,
19
+ :method => :get,
20
+ :body => @options[:body]
21
+ )
22
+ end
23
+ def post_disks(new_dsk)
24
+ @options = {:path => '/disks/content',
25
+ :body => Megam::JSONCompat.to_json(new_dsk)}.merge(@options)
26
+ request(
27
+ :expects => 201,
28
+ :method => :post,
29
+ :body => @options[:body]
30
+ )
31
+ end
32
+
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "1.6.7"
3
+ VERSION = "1.6.8"
4
4
  end
5
5
  end
@@ -123,8 +123,8 @@ module Megam
123
123
  adn
124
124
  end
125
125
 
126
- def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
127
- adn = self.new(tmp_email, tmp_api_key, tmp_host)
126
+ def self.from_hash(o)
127
+ adn = self.new(o)
128
128
  adn.from_hash(o)
129
129
  adn
130
130
  end
@@ -0,0 +1,194 @@
1
+ module Megam
2
+ class Disks < Megam::RestAdapter
3
+ def initialize(o)
4
+ @id = nil
5
+ @account_id = nil
6
+ @asm_id = nil
7
+ @org_id = nil
8
+ @disk_id= nil
9
+ @size= nil
10
+ @status= nil
11
+ @created_at = nil
12
+ @some_msg = {}
13
+ super(o)
14
+ end
15
+
16
+ def disks
17
+ self
18
+ end
19
+ def id(arg=nil)
20
+ if arg != nil
21
+ @id = arg
22
+ else
23
+ @id
24
+ end
25
+ end
26
+
27
+ def account_id(arg=nil)
28
+ if arg != nil
29
+ @account_id = arg
30
+ else
31
+ @account_id
32
+ end
33
+ end
34
+
35
+ def asm_id(arg=nil)
36
+ if arg != nil
37
+ @asm_id = arg
38
+ else
39
+ @asm_id
40
+ end
41
+ end
42
+
43
+ def org_id(arg=nil)
44
+ if arg != nil
45
+ @org_id = arg
46
+ else
47
+ @org_id
48
+ end
49
+ end
50
+
51
+ def disk_id(arg=nil)
52
+ if arg != nil
53
+ @disk_id = arg
54
+ else
55
+ @disk_id
56
+ end
57
+ end
58
+
59
+ def status(arg=nil)
60
+ if arg != nil
61
+ @status = arg
62
+ else
63
+ @status
64
+ end
65
+ end
66
+
67
+ def size(arg=nil)
68
+ if arg != nil
69
+ @size = arg
70
+ else
71
+ @size
72
+ end
73
+ end
74
+
75
+ def created_at(arg=nil)
76
+ if arg != nil
77
+ @created_at = arg
78
+ else
79
+ @created_at
80
+ end
81
+ end
82
+
83
+ def error?
84
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
85
+ end
86
+
87
+
88
+ def some_msg(arg=nil)
89
+ if arg != nil
90
+ @some_msg = arg
91
+ else
92
+ @some_msg
93
+ end
94
+ end
95
+
96
+
97
+ # Transform the ruby obj -> to a Hash
98
+ def to_hash
99
+ index_hash = Hash.new
100
+ index_hash["json_claz"] = self.class.name
101
+ index_hash["id"] = id
102
+ index_hash["account_id"] = account_id
103
+ index_hash["asm_id"] = asm_id
104
+ index_hash["org_id"] = org_id
105
+ index_hash["disk_id"] = disk_id
106
+ index_hash["size"] = size
107
+ index_hash["status"] = status
108
+ index_hash["created_at"] = created_at
109
+ index_hash["some_msg"] = some_msg
110
+ index_hash
111
+ end
112
+
113
+ # Serialize this object as a hash: called from JsonCompat.
114
+ # Verify if this called from JsonCompat during testing.
115
+ def to_json(*a)
116
+ for_json.to_json(*a)
117
+ end
118
+
119
+ def for_json
120
+ result = {
121
+ "id" => id,
122
+ "account_id" => account_id,
123
+ "asm_id" => asm_id,
124
+ "org_id" => org_id,
125
+ "disk_id" => disk_id,
126
+ "size" => size,
127
+ "status" => status,
128
+ "created_at" => created_at
129
+ }
130
+ result
131
+ end
132
+
133
+ def self.json_create(o)
134
+ sps = new({})
135
+ sps.id(o["id"]) if o.has_key?("id")
136
+ sps.account_id(o["account_id"]) if o.has_key?("account_id")
137
+ sps.asm_id(o["asm_id"]) if o.has_key?("asm_id")
138
+ sps.org_id(o["org_id"]) if o.has_key?("org_id") #this will be an array? can hash store array?
139
+ sps.disk_id(o["disk_id"]) if o.has_key?("disk_id")
140
+ sps.size(o["size"]) if o.has_key?("size")
141
+ sps.status(o["status"]) if o.has_key?("status")
142
+ sps.created_at(o["created_at"]) if o.has_key?("created_at")
143
+ sps.some_msg[:code] = o["code"] if o.has_key?("code")
144
+ sps.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
145
+ sps.some_msg[:msg]= o["msg"] if o.has_key?("msg")
146
+ sps.some_msg[:links] = o["links"] if o.has_key?("links")
147
+ sps
148
+ end
149
+
150
+ def self.from_hash(o)
151
+ dks = self.new(o)
152
+ dks.from_hash(o)
153
+ dks
154
+ end
155
+
156
+ def from_hash(o)
157
+ @id = o[:id] if o.has_key?(:id)
158
+ @account_id = o[:account_id] if o.has_key?(:account_id)
159
+ @asm_id = o[:asm_id] if o.has_key?(:asm_id)
160
+ @org_id = o[:org_id] if o.has_key?(:org_id)
161
+ @disk_id = o[:disk_id] if o.has_key?(:disk_id)
162
+ @size = o[:size] if o.has_key?(:size)
163
+ @status = o[:status] if o.has_key?(:status)
164
+ @created_at = o[:created_at] if o.has_key?(:created_at)
165
+ self
166
+ end
167
+
168
+ def self.create(params)
169
+ dks = from_hash(params)
170
+ dks.create
171
+ end
172
+
173
+ # Create the node via the REST API
174
+ def create
175
+ megam_rest.post_disks(to_hash)
176
+ end
177
+
178
+ # Load a account by email_p
179
+ def self.show(o)
180
+ dks = self.new(o)
181
+ dks.megam_rest.get_disks(o[:id])
182
+ end
183
+
184
+ def self.list(params)
185
+ dks = self.new(params)
186
+ dks.megam_rest.list_disks
187
+ end
188
+
189
+ def to_s
190
+ Megam::Stuff.styled_hash(to_hash)
191
+ end
192
+
193
+ end
194
+ end
@@ -0,0 +1,122 @@
1
+ module Megam
2
+ class DisksCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @disks = Array.new
8
+ @disks_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_disks
13
+ @disks
14
+ end
15
+
16
+ def [](index)
17
+ @disks[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_disks(arg)
22
+ @disks[index] = arg
23
+ @disks_by_name[arg.account_id] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_events(a)
29
+ @disks << a
30
+ @disks_by_name[a.account_id] = @disks.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(disks)
39
+ is_megam_disks(disks)
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
+ @disks.insert(@insert_after_idx + 1, disks)
45
+ # update name -> location mappings and register new node
46
+ @disks_by_name.each_key do |key|
47
+ @disks_by_name[key] += 1 if @disks_by_name[key] > @insert_after_idx
48
+ end
49
+ @disks_by_name[disks.account_id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @disks << disks
53
+ @disks_by_name[disks.account_id] = @disks.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @disks.each do |disks|
59
+ yield disks
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @disks.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @disks.empty?
71
+ end
72
+
73
+ def lookup(disks)
74
+ lookup_by = nil
75
+ if events.kind_of?(Megam::Disks)
76
+ lookup_by = disks.account_id
77
+ elsif disks.kind_of?(String)
78
+ lookup_by = disks
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Disks or String to lookup"
81
+ end
82
+ res = @disks_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
+ @disks[res]
87
+ end
88
+
89
+ def to_s
90
+ @disks.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 |disks_list|
104
+ disks_array = disks_list.kind_of?(Array) ? disks_list : [ disks_list ]
105
+ disks_array.each do |disks|
106
+ collection.insert(disks)
107
+
108
+ end
109
+ end
110
+ collection
111
+ end
112
+
113
+ private
114
+
115
+ def is_megam_disks(arg)
116
+ unless arg.kind_of?(Megam::Disks)
117
+ raise ArgumentError, "Members must be Megam::Disks's"
118
+ end
119
+ true
120
+ end
121
+ end
122
+ end
@@ -38,6 +38,8 @@ module Megam
38
38
  MEGAM_SENSORSCOLLECTION = 'Megam::SensorsCollection'.freeze
39
39
  MEGAM_SNAPSHOTS = 'Megam::Snapshots'.freeze
40
40
  MEGAM_SNAPSHOTSCOLLECTION = 'Megam::SnapshotsCollection'.freeze
41
+ MEGAM_DISKS = 'Megam::Disks'.freeze
42
+ MEGAM_DISKSCOLLECTION = 'Megam::DisksCollection'.freeze
41
43
  MEGAM_SSHKEY = 'Megam::SshKey'.freeze
42
44
  MEGAM_SSHKEYCOLLECTION = 'Megam::SshKeyCollection'.freeze
43
45
  MEGAM_EVENTSVM = 'Megam::EventsVm'.freeze
@@ -211,6 +213,10 @@ module Megam
211
213
  Megam::Subscriptions
212
214
  when MEGAM_SUBSCRIPTIONSCOLLECTION
213
215
  Megam::SubscriptionsCollection
216
+ when MEGAM_DISKS
217
+ Megam::Disks
218
+ when MEGAM_DISKSCOLLECTION
219
+ Megam::DisksCollection
214
220
  when MEGAM_ADDONS
215
221
  Megam::Addons
216
222
  when MEGAM_ADDONSCOLLECTION
@@ -6,6 +6,7 @@ module Megam
6
6
  @asm_id = nil
7
7
  @org_id = nil
8
8
  @name= nil
9
+ @status=nil
9
10
  @created_at = nil
10
11
  @some_msg = {}
11
12
  super(o)
@@ -54,6 +55,14 @@ module Megam
54
55
  end
55
56
  end
56
57
 
58
+ def status(arg=nil)
59
+ if arg != nil
60
+ @status = arg
61
+ else
62
+ @status
63
+ end
64
+ end
65
+
57
66
  def created_at(arg=nil)
58
67
  if arg != nil
59
68
  @created_at = arg
@@ -85,6 +94,7 @@ module Megam
85
94
  index_hash["asm_id"] = asm_id
86
95
  index_hash["org_id"] = org_id
87
96
  index_hash["name"] = name
97
+ index_hash["status"] = status
88
98
  index_hash["created_at"] = created_at
89
99
  index_hash["some_msg"] = some_msg
90
100
  index_hash
@@ -103,6 +113,7 @@ module Megam
103
113
  "asm_id" => asm_id,
104
114
  "org_id" => org_id,
105
115
  "name" => name,
116
+ "status" => status,
106
117
  "created_at" => created_at
107
118
  }
108
119
  result
@@ -115,6 +126,7 @@ module Megam
115
126
  sps.asm_id(o["asm_id"]) if o.has_key?("asm_id")
116
127
  sps.org_id(o["org_id"]) if o.has_key?("org_id") #this will be an array? can hash store array?
117
128
  sps.name(o["name"]) if o.has_key?("name")
129
+ sps.name(o["status"]) if o.has_key?("status")
118
130
  sps.created_at(o["created_at"]) if o.has_key?("created_at")
119
131
  sps.some_msg[:code] = o["code"] if o.has_key?("code")
120
132
  sps.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
@@ -135,6 +147,7 @@ module Megam
135
147
  @asm_id = o[:asm_id] if o.has_key?(:asm_id)
136
148
  @org_id = o[:org_id] if o.has_key?(:org_id)
137
149
  @name = o[:name] if o.has_key?(:name)
150
+ @status = o[:status] if o.has_key?(:status)
138
151
  @created_at = o[:created_at] if o.has_key?(:created_at)
139
152
  self
140
153
  end
@@ -0,0 +1,25 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ def test_post_disks
5
+ tmp_hash = {
6
+ :account_id => "",
7
+ :asm_id => "ASM53557642376448625",
8
+ :org_id => "ORG7879663326321337888",
9
+ :size => "2GB",
10
+ :status => "progress",
11
+
12
+ }
13
+
14
+ response = megams.post_disks(tmp_hash)
15
+ assert_equal(201, response.status)
16
+ end
17
+ def test_get_disks
18
+ response = megams.get_disks("ASM53557642376448625")
19
+ assert_equal(200, response.status)
20
+ end
21
+ def test_list_disks
22
+ response = megams.list_disks
23
+ assert_equal(200, response.status)
24
+ end
25
+ end
data/test/test_helper.rb CHANGED
@@ -7,8 +7,8 @@ require 'time'
7
7
 
8
8
  SANDBOX_HOST_OPTIONS = {
9
9
  :scheme => 'http',
10
- #:host => 'localhost',
11
- :host => 'cloud.det.io',
10
+ :host => 'localhost',
11
+ #:host => 'cloud.det.io',
12
12
  :nonblock => false,
13
13
  :port => 9000
14
14
  }
@@ -30,8 +30,8 @@ end
30
30
 
31
31
  def megams(options={})
32
32
  s_options = SANDBOX_HOST_OPTIONS.merge({
33
- :email => "test@megam.io",
34
- :api_key => "IamAtlas{74}NobdyCanSedfefdeME#07",
33
+ :email => "rajeshr@megam.io",
34
+ :api_key => "a0cf83e360845f2639db63e515c94ad35a94cd50",
35
35
  :org_id => "ORG123",
36
36
  #:password => "bWVnYW0="
37
37
  })
@@ -8,19 +8,21 @@ class TestApps < MiniTest::Unit::TestCase
8
8
  :asm_id => "ASM5355764237644862300",
9
9
  :org_id => "ORG7879663326321337888",
10
10
  :name => "pop.megambox.com",
11
+ :status => "progress",
11
12
 
12
13
  }
13
14
 
14
15
  response = megams.post_snapshots(tmp_hash)
15
16
  assert_equal(201, response.status)
16
17
  end
17
-
18
+ #=begin
18
19
  def test_get_snapshots
19
- response = megams.get_snapshots("ASM5355764237644862351")
20
+ response = megams.get_snapshots("ASM5355764237644862300")
20
21
  assert_equal(200, response.status)
21
22
  end
22
23
  def test_list_snapshots
23
24
  response = megams.list_snapshots
24
25
  assert_equal(200, response.status)
25
26
  end
27
+ #=end
26
28
  end
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.6.7
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Rajesh Rajagopalan, Thomas Alrin,
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-13 00:00:00.000000000 Z
12
+ date: 2016-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -143,6 +143,7 @@ files:
143
143
  - lib/megam/api/billedhistories.rb
144
144
  - lib/megam/api/billingtransactions.rb
145
145
  - lib/megam/api/components.rb
146
+ - lib/megam/api/disks.rb
146
147
  - lib/megam/api/domains.rb
147
148
  - lib/megam/api/errors.rb
148
149
  - lib/megam/api/eventsbilling.rb
@@ -173,6 +174,8 @@ files:
173
174
  - lib/megam/core/billingtransactions_collection.rb
174
175
  - lib/megam/core/components.rb
175
176
  - lib/megam/core/components_collection.rb
177
+ - lib/megam/core/disks.rb
178
+ - lib/megam/core/disks_collection.rb
176
179
  - lib/megam/core/domain_collection.rb
177
180
  - lib/megam/core/domains.rb
178
181
  - lib/megam/core/error.rb
@@ -227,6 +230,7 @@ files:
227
230
  - test/test_billedhistories.rb
228
231
  - test/test_billingtranscations.rb
229
232
  - test/test_components.rb
233
+ - test/test_disks.rb
230
234
  - test/test_domains.rb
231
235
  - test/test_eventsbilling.rb
232
236
  - test/test_eventscontainer.rb
@@ -265,29 +269,4 @@ rubygems_version: 2.5.1
265
269
  signing_key:
266
270
  specification_version: 4
267
271
  summary: Ruby Client for the Megam
268
- test_files:
269
- - test/mixins/test_assemblies.rb
270
- - test/mixins/test_assembly.rb
271
- - test/mixins/test_component.rb
272
- - test/test_accounts.rb
273
- - test/test_addons.rb
274
- - test/test_assemblies.rb
275
- - test/test_assembly.rb
276
- - test/test_balances.rb
277
- - test/test_billedhistories.rb
278
- - test/test_billingtranscations.rb
279
- - test/test_components.rb
280
- - test/test_domains.rb
281
- - test/test_eventsbilling.rb
282
- - test/test_eventscontainer.rb
283
- - test/test_eventsstorage.rb
284
- - test/test_eventsvm.rb
285
- - test/test_helper.rb
286
- - test/test_marketplaces.rb
287
- - test/test_organizations.rb
288
- - test/test_promos.rb
289
- - test/test_requests.rb
290
- - test/test_sensors.rb
291
- - test/test_snapshots.rb
292
- - test/test_sshkeys.rb
293
- - test/test_subscriptions.rb
272
+ test_files: []