megam_api 0.100 → 1.5.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -69
  3. data/lib/megam/api.rb +15 -37
  4. data/lib/megam/api/errors.rb +19 -19
  5. data/lib/megam/api/version.rb +1 -1
  6. data/lib/megam/core/account.rb +1 -1
  7. data/lib/megam/core/assemblies.rb +1 -1
  8. data/lib/megam/core/assemblies_collection.rb +7 -15
  9. data/lib/megam/core/assembly.rb +1 -1
  10. data/lib/megam/core/assembly_collection.rb +7 -15
  11. data/lib/megam/core/balances.rb +1 -1
  12. data/lib/megam/core/balances_collection.rb +8 -16
  13. data/lib/megam/core/billedhistories.rb +1 -1
  14. data/lib/megam/core/billedhistories_collection.rb +7 -15
  15. data/lib/megam/core/components.rb +1 -1
  16. data/lib/megam/core/components_collection.rb +103 -110
  17. data/lib/megam/core/domain_collection.rb +102 -109
  18. data/lib/megam/core/domains.rb +1 -1
  19. data/lib/megam/core/error.rb +1 -15
  20. data/lib/megam/core/json_compat.rb +170 -208
  21. data/lib/megam/core/marketplace.rb +1 -1
  22. data/lib/megam/core/marketplace_collection.rb +7 -16
  23. data/lib/megam/core/organizations.rb +1 -1
  24. data/lib/megam/core/organizations_collection.rb +8 -40
  25. data/lib/megam/core/promos.rb +1 -1
  26. data/lib/megam/core/request.rb +1 -1
  27. data/lib/megam/core/request_collection.rb +7 -16
  28. data/lib/megam/core/rest_adapter.rb +54 -0
  29. data/lib/megam/core/sensors.rb +1 -1
  30. data/lib/megam/core/sensors_collection.rb +7 -14
  31. data/lib/megam/core/sshkey.rb +1 -1
  32. data/lib/megam/core/sshkey_collection.rb +103 -110
  33. data/lib/megam/core/stuff.rb +2 -34
  34. data/lib/megam/core/text.rb +1 -0
  35. data/lib/megam/core/text_formatter.rb +2 -1
  36. data/megam_api.gemspec +2 -2
  37. metadata +10 -56
  38. data/lib/megam/api/availableunits.rb +0 -50
  39. data/lib/megam/api/billings.rb +0 -50
  40. data/lib/megam/api/credithistories.rb +0 -50
  41. data/lib/megam/api/csars.rb +0 -75
  42. data/lib/megam/api/discounts.rb +0 -50
  43. data/lib/megam/api/invoices.rb +0 -50
  44. data/lib/megam/api/login.rb +0 -29
  45. data/lib/megam/api/subscriptions.rb +0 -50
  46. data/lib/megam/core/auth.rb +0 -91
  47. data/lib/megam/core/availableunits.rb +0 -182
  48. data/lib/megam/core/availableunits_collection.rb +0 -144
  49. data/lib/megam/core/billings.rb +0 -242
  50. data/lib/megam/core/billings_collection.rb +0 -144
  51. data/lib/megam/core/config.rb +0 -41
  52. data/lib/megam/core/credithistories.rb +0 -191
  53. data/lib/megam/core/credithistories_collection.rb +0 -144
  54. data/lib/megam/core/csar.rb +0 -179
  55. data/lib/megam/core/csar_collection.rb +0 -148
  56. data/lib/megam/core/discounts.rb +0 -204
  57. data/lib/megam/core/discounts_collection.rb +0 -164
  58. data/lib/megam/core/invoices.rb +0 -231
  59. data/lib/megam/core/invoices_collection.rb +0 -144
  60. data/lib/megam/core/server_api.rb +0 -52
  61. data/lib/megam/core/subscriptions.rb +0 -191
  62. data/lib/megam/core/subscriptions_collection.rb +0 -144
  63. data/test/test_availableunits.rb +0 -28
  64. data/test/test_billings.rb +0 -33
  65. data/test/test_cat_requests.rb +0 -20
  66. data/test/test_credithistories.rb +0 -29
  67. data/test/test_csars.rb +0 -22
  68. data/test/test_discounts.rb +0 -31
  69. data/test/test_invoices.rb +0 -31
  70. data/test/test_login.rb +0 -10
  71. data/test/test_marketplaceaddons.rb +0 -46
  72. data/test/test_predefclouds.rb +0 -80
  73. data/test/test_subscriptions.rb +0 -29
@@ -1,144 +0,0 @@
1
- # Copyright:: Copyright (c) 2013-2016 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 SubscriptionsCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @subscriptions = Array.new
23
- @subscriptions_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
26
-
27
- def all_subscriptions
28
- @subscriptions
29
- end
30
-
31
- def [](index)
32
- @subscriptions[index]
33
- end
34
-
35
- def []=(index, arg)
36
- is_megam_subscriptions(arg)
37
- @subscriptions[index] = arg
38
- @subscriptions_by_name[arg.repo_name] = index
39
- end
40
-
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_subscriptions(a)
44
- @subscriptions << a
45
- @subscriptions_by_name[a.repo_name] =@subscriptions.length - 1
46
- end
47
- self
48
- end
49
-
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(subscriptions)
54
- is_megam_subscriptions(subscriptions)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any subscriptions inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # subscriptions
59
- @subscriptions.insert(@insert_after_idx + 1, subscriptions)
60
- # update name -> location mappings and register new subscriptions
61
- @subscriptions_by_name.each_key do |key|
62
- @subscriptions_by_name[key] += 1 if@subscriptions_by_name[key] > @insert_after_idx
63
- end
64
- @subscriptions_by_name[subscriptions.repo_name] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @subscriptions << subscriptions
68
- @subscriptions_by_name[subscriptions.repo_name] =@subscriptions.length - 1
69
- end
70
- end
71
-
72
- def each
73
- @subscriptions.each do |subscriptions|
74
- yield subscriptions
75
- end
76
- end
77
-
78
- def each_index
79
- @subscriptions.each_index do |i|
80
- yield i
81
- end
82
- end
83
-
84
- def empty?
85
- @subscriptions.empty?
86
- end
87
-
88
- def lookup(subscriptions)
89
- lookup_by = nil
90
- if subscriptions.kind_of?(Megam::Subscriptions)
91
- lookup_by = subscriptions.repo_name
92
- elsif subscriptions.kind_of?(String)
93
- lookup_by = subscriptions
94
- else
95
- raise ArgumentError, "Must pass a Megam::subscriptions or String to lookup"
96
- end
97
- res =@subscriptions_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a subscriptions matching #{lookup_by} (did you define it first?)"
100
- end
101
- @subscriptions[res]
102
- end
103
-
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |subscriptions|
108
- index_hash[subscriptions.repo_name] = subscriptions.to_s
109
- end
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 self.json_create(o)
120
- collection = self.new()
121
- o["results"].each do |subscriptions_list|
122
- subscriptions_array = subscriptions_list.kind_of?(Array) ? subscriptions_list : [ subscriptions_list ]
123
- subscriptions_array.each do |subscriptions|
124
- collection.insert(subscriptions)
125
- end
126
- end
127
- collection
128
- end
129
-
130
- private
131
-
132
- def is_megam_subscriptions(arg)
133
- unless arg.kind_of?(Megam::Subscriptions)
134
- raise ArgumentError, "Members must be Megam::Subscriptions"
135
- end
136
- true
137
- end
138
-
139
- def to_s
140
- Megam::Stuff.styled_hash(to_hash)
141
- end
142
-
143
- end
144
- end
@@ -1,28 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
- =begin
5
- def test_post_availableunits1
6
- tmp_hash = { :name => "name",
7
- :duration => "duration",
8
- :charges_per_duration => "charges_per_duration"
9
- }
10
-
11
- response = megams.post_availableunits(tmp_hash)
12
- assert_equal(201, response.status)
13
- end
14
- =end
15
-
16
- =begin
17
- def test_get_availableunits
18
- response = megams.get_availableunits
19
- assert_equal(200, response.status)
20
- end
21
- =end
22
- =begin
23
- def test_get_availableunits
24
- response = megams.get_availableunit("iaas_default")
25
- assert_equal(200, response.status)
26
- end
27
- =end
28
- end
@@ -1,33 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
- =begin
5
- def test_post_billings
6
- tmp_hash = { :accounts_id => "ACT93476985797",
7
- :line1 => "paypal",
8
- :line2 => "#kjbh76",
9
- :country_code => "",
10
- :postal_code => "",
11
- :state => "",
12
- :phone => "",
13
- :bill_type => ""
14
- }
15
-
16
- response = megams.post_billings(tmp_hash)
17
- assert_equal(201, response.status)
18
- end
19
- =end
20
-
21
- =begin
22
- def test_get_billings
23
- response = megams.get_billings
24
- assert_equal(200, response.status)
25
- end
26
- =end
27
- =begin
28
- def test_get_billings
29
- response = megams.get_billing("iaas_default")
30
- assert_equal(200, response.status)
31
- end
32
- =end
33
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
-
5
- @@tmp_hash = {
6
- "cat_id" => "ASM1136003656177549312",
7
- "name" => "careworn", #APP or Bolt
8
- "cattype" => "app",
9
- "action" => "start",
10
- "category" => "control"
11
- }
12
-
13
- =begin
14
- def test_request_app_start
15
- response = megams.post_catrequest(@@tmp_hash)
16
- assert_equal(201, response.status)
17
- end
18
- =end
19
-
20
- end
@@ -1,29 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
- =begin
5
- def test_post_credithistories
6
- tmp_hash = { :accounts_id => "ACT93476985797",
7
- :bill_type => "paypal",
8
- :credit_amount => "50",
9
- :currency_type => ""
10
- }
11
-
12
- response = megams.post_credithistories(tmp_hash)
13
- assert_equal(201, response.status)
14
- end
15
- =end
16
-
17
- =begin
18
- def test_get_credithistories
19
- response = megams.get_credithistories
20
- assert_equal(200, response.status)
21
- end
22
- =end
23
- =begin
24
- def test_get_credithistories
25
- response = megams.get_credithistories("iaas_default")
26
- assert_equal(200, response.status)
27
- end
28
- =end
29
- end
data/test/test_csars.rb DELETED
@@ -1,22 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
- =begin
5
- def test_get_csars
6
- response = megams.get_csars
7
- assert_equal(200, response.status)
8
- end
9
-
10
- def test_get_csar
11
- response = megams.get_csar("CSI1116385673159507968")
12
- assert_equal(200, response.status)
13
- end
14
-
15
-
16
- def test_get_csar_not_found
17
- assert_raises(Megam::API::Errors::NotFound) do
18
- megams.get_csar("stupid.megam.co")
19
- end
20
- end
21
- =end
22
- end
@@ -1,31 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
- =begin
5
- def test_post_discount
6
- tmp_hash = { :accounts_id => "ACT93476985797",
7
- :bill_type => "paypal",
8
- :code => "#kjbh76",
9
- :status => ""
10
- }
11
-
12
- response = megams.post_discounts(tmp_hash)
13
- assert_equal(201, response.status)
14
- end
15
- =end
16
-
17
- =begin
18
- def test_get_discounts
19
- response = megams.get_discounts
20
- puts response.inspect
21
- assert_equal(200, response.status)
22
-
23
- end
24
- =end
25
- =begin
26
- def test_get_discounts
27
- response = megams.get_discounts("iaas_default")
28
- assert_equal(200, response.status)
29
- end
30
- =end
31
- end
@@ -1,31 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
- =begin
5
- def test_post_invoices
6
- tmp_hash = { :from_date => "2015-10-09",
7
- :to_date => "2015-11-30",
8
- :month => "oct",
9
- :bill_type => "paypal",
10
- :billing_amount => "45",
11
- :currency_type => "USD"
12
- }
13
-
14
- response = megams.post_invoices(tmp_hash)
15
- assert_equal(201, response.status)
16
- end
17
- =end
18
-
19
- =begin
20
- def test_get_invoices
21
- response = megams.get_invoices
22
- assert_equal(200, response.status)
23
- end
24
- =end
25
- =begin
26
- def test_get_invoice
27
- response = megams.get_invoice("INV1264211919892512768")
28
- assert_equal(200, response.status)
29
- end
30
- =end
31
- end
data/test/test_login.rb DELETED
@@ -1,10 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestLogin < MiniTest::Unit::TestCase
4
- =begin
5
- def test_post_login
6
- response =megams.post_auth()
7
- assert_equal(200, response.status)
8
- end
9
- =end
10
- end
@@ -1,46 +0,0 @@
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
- "recipe"=>"role[drbd]"
12
- },
13
- "loadbalancing"=>{
14
- "haproxyhost"=>"",
15
- "loadbalancehost"=>"",
16
- "recipe"=>""
17
- },
18
- "autoscaling"=>{
19
- "cputhreshold"=>"",
20
- "memorythreshold"=>"",
21
- "noofinstances"=>"",
22
- "recipe"=>""
23
- },
24
- "monitoring"=>{
25
- "agent"=>"op5",
26
- "recipe"=>"role[op5]"
27
- }
28
- }
29
-
30
- tmp_hash = {
31
- "node_id" => "NOD450939631320432640",
32
- "node_name" => "appsample1.megam.co",
33
- "marketplace_id" => "APP",
34
- "config" => @com
35
- }
36
- response = megams.post_addon(tmp_hash)
37
- assert_equal(201, response.status)
38
- end
39
- #=end
40
-
41
- # def test_get_nodes
42
- # response = megams.get_addons("appsample1.megam.co")
43
- # assert_equal(200, response.status)
44
- #=end
45
- =end
46
- end
@@ -1,80 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
-
3
- class TestApps < MiniTest::Unit::TestCase
4
- =begin
5
- def test_post_predefcloud1
6
- tmp_hash = { :name => "aws_ec2_predef_medium", :spec => {
7
- :type_name => "aws-ec2",
8
- :groups => "megam",
9
- :image => "ami-d783cd85",
10
- :flavor => "m1.medium",
11
- :tenant_id => ""
12
- },
13
- :access => {
14
- :ssh_key => "megam_ec2",
15
- :identity_file => "~/.ssh/megam_ec2.pem",
16
- :ssh_user => "ubuntu",
17
- :vault_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
18
- :sshpub_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
19
- :zone => "",
20
- :region => "southeast"
21
- },
22
- #:ideal => "ror,redis,riak",
23
- #:performance => "10rpm"
24
- }
25
-
26
- response = megams.post_predefcloud(tmp_hash)
27
- assert_equal(201, response.status)
28
- end
29
- =end
30
- =begin
31
- #=end
32
- def test_post_predefcloud2
33
- tmp_hash = { :name => "rkspce_sundown_play", :spec => {
34
- :type_name => "rackspace",
35
- :groups => "staging_france_boeing",
36
- :image => "RCP000XERAOl",
37
- :flavor => "m1-miniscule",
38
- :tenant_id => ""
39
- },
40
- :access => {
41
- :ssh_key => "boo_flightssh",
42
- :identity_file => "https://boering.dropbox.closedloc/aorc.pem",
43
- :ssh_user => "ubuntu",
44
- :vault_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
45
- :sshpub_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
46
- :zone => "",
47
- :region => ""
48
- },
49
- #:ideal => "play,redis,riak",
50
- #:performance => "10rpm"
51
- }
52
- response = megams.post_predefcloud(tmp_hash)
53
- assert_equal(201, response.status)
54
- end
55
- =end
56
- =begin
57
-
58
- def test_get_predefclouds
59
- response = megams.get_predefclouds
60
- assert_equal(200, response.status)
61
- end
62
- =end
63
- =begin
64
- def test_get_predefcloud2
65
- response = megams.get_predefcloud("rkspce_sundown_play")
66
- assert_equal(200, response.status)
67
- end
68
- #=begin
69
- def test_get_predefcloud1
70
- response = megams.get_predefcloud("iaas_default")
71
- assert_equal(200, response.status)
72
- end
73
-
74
- def test_get_predefcloud_not_found
75
- assert_raises(Megam::API::Errors::NotFound) do
76
- megams.get_predefcloud("stupid.megam.co")
77
- end
78
- end
79
- =end
80
- end