virtengine_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +21 -0
  6. data/README.md +27 -0
  7. data/Rakefile +10 -0
  8. data/lib/megam/api.rb +329 -0
  9. data/lib/megam/api/accounts.rb +96 -0
  10. data/lib/megam/api/addons.rb +27 -0
  11. data/lib/megam/api/assemblies.rb +49 -0
  12. data/lib/megam/api/assembly.rb +56 -0
  13. data/lib/megam/api/backups.rb +57 -0
  14. data/lib/megam/api/balances.rb +45 -0
  15. data/lib/megam/api/billedhistories.rb +35 -0
  16. data/lib/megam/api/billingtransactions.rb +25 -0
  17. data/lib/megam/api/components.rb +24 -0
  18. data/lib/megam/api/credits.rb +34 -0
  19. data/lib/megam/api/disks.rb +44 -0
  20. data/lib/megam/api/domains.rb +25 -0
  21. data/lib/megam/api/errors.rb +29 -0
  22. data/lib/megam/api/eventsall.rb +36 -0
  23. data/lib/megam/api/eventsbilling.rb +35 -0
  24. data/lib/megam/api/eventscontainer.rb +35 -0
  25. data/lib/megam/api/eventsmarketplace.rb +35 -0
  26. data/lib/megam/api/eventsstorage.rb +24 -0
  27. data/lib/megam/api/eventsvm.rb +35 -0
  28. data/lib/megam/api/flavors.rb +56 -0
  29. data/lib/megam/api/license.rb +26 -0
  30. data/lib/megam/api/marketplaces.rb +68 -0
  31. data/lib/megam/api/organizations.rb +50 -0
  32. data/lib/megam/api/promos.rb +18 -0
  33. data/lib/megam/api/quotas.rb +47 -0
  34. data/lib/megam/api/rawimages.rb +36 -0
  35. data/lib/megam/api/reports.rb +24 -0
  36. data/lib/megam/api/requests.rb +36 -0
  37. data/lib/megam/api/sensors.rb +35 -0
  38. data/lib/megam/api/snapshots.rb +46 -0
  39. data/lib/megam/api/sshkeys.rb +35 -0
  40. data/lib/megam/api/subscriptions.rb +26 -0
  41. data/lib/megam/api/version.rb +6 -0
  42. data/lib/megam/core/account.rb +245 -0
  43. data/lib/megam/core/account_collection.rb +122 -0
  44. data/lib/megam/core/addons.rb +169 -0
  45. data/lib/megam/core/addons_collection.rb +121 -0
  46. data/lib/megam/core/assemblies.rb +191 -0
  47. data/lib/megam/core/assemblies_collection.rb +122 -0
  48. data/lib/megam/core/assembly.rb +226 -0
  49. data/lib/megam/core/assembly_collection.rb +122 -0
  50. data/lib/megam/core/backups.rb +259 -0
  51. data/lib/megam/core/backups_collection.rb +122 -0
  52. data/lib/megam/core/balances.rb +187 -0
  53. data/lib/megam/core/balances_collection.rb +121 -0
  54. data/lib/megam/core/billedhistories.rb +190 -0
  55. data/lib/megam/core/billedhistories_collection.rb +121 -0
  56. data/lib/megam/core/billingtransactions.rb +214 -0
  57. data/lib/megam/core/billingtransactions_collection.rb +122 -0
  58. data/lib/megam/core/components.rb +326 -0
  59. data/lib/megam/core/components_collection.rb +123 -0
  60. data/lib/megam/core/credits.rb +146 -0
  61. data/lib/megam/core/credits_collection.rb +121 -0
  62. data/lib/megam/core/disks.rb +199 -0
  63. data/lib/megam/core/disks_collection.rb +122 -0
  64. data/lib/megam/core/domain_collection.rb +122 -0
  65. data/lib/megam/core/domains.rb +118 -0
  66. data/lib/megam/core/error.rb +70 -0
  67. data/lib/megam/core/eventsall.rb +186 -0
  68. data/lib/megam/core/eventsall_collection.rb +122 -0
  69. data/lib/megam/core/eventsbilling.rb +174 -0
  70. data/lib/megam/core/eventsbilling_collection.rb +122 -0
  71. data/lib/megam/core/eventscontainer.rb +187 -0
  72. data/lib/megam/core/eventscontainer_collection.rb +122 -0
  73. data/lib/megam/core/eventsmarketplace.rb +187 -0
  74. data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
  75. data/lib/megam/core/eventsstorage.rb +156 -0
  76. data/lib/megam/core/eventsstorage_collection.rb +122 -0
  77. data/lib/megam/core/eventsvm.rb +187 -0
  78. data/lib/megam/core/eventsvm_collection.rb +122 -0
  79. data/lib/megam/core/flavors.rb +294 -0
  80. data/lib/megam/core/flavors_collection.rb +121 -0
  81. data/lib/megam/core/json_compat.rb +289 -0
  82. data/lib/megam/core/konipai.rb +42 -0
  83. data/lib/megam/core/license.rb +101 -0
  84. data/lib/megam/core/license_collection.rb +122 -0
  85. data/lib/megam/core/log.rb +19 -0
  86. data/lib/megam/core/marketplace.rb +308 -0
  87. data/lib/megam/core/marketplace_collection.rb +123 -0
  88. data/lib/megam/core/monologger.rb +89 -0
  89. data/lib/megam/core/organizations.rb +142 -0
  90. data/lib/megam/core/organizations_collection.rb +121 -0
  91. data/lib/megam/core/promos.rb +145 -0
  92. data/lib/megam/core/quotas.rb +215 -0
  93. data/lib/megam/core/quotas_collection.rb +121 -0
  94. data/lib/megam/core/rawimages.rb +194 -0
  95. data/lib/megam/core/rawimages_collection.rb +121 -0
  96. data/lib/megam/core/reports.rb +176 -0
  97. data/lib/megam/core/reports_collection.rb +121 -0
  98. data/lib/megam/core/request.rb +197 -0
  99. data/lib/megam/core/request_collection.rb +121 -0
  100. data/lib/megam/core/rest_adapter.rb +44 -0
  101. data/lib/megam/core/sensors.rb +141 -0
  102. data/lib/megam/core/sensors_collection.rb +121 -0
  103. data/lib/megam/core/snapshots.rb +268 -0
  104. data/lib/megam/core/snapshots_collection.rb +122 -0
  105. data/lib/megam/core/sshkey.rb +173 -0
  106. data/lib/megam/core/sshkey_collection.rb +122 -0
  107. data/lib/megam/core/stuff.rb +22 -0
  108. data/lib/megam/core/subscriptions.rb +167 -0
  109. data/lib/megam/core/subscriptions_collection.rb +121 -0
  110. data/lib/megam/core/text.rb +87 -0
  111. data/lib/megam/core/text_formatter.rb +64 -0
  112. data/lib/megam/mixins/assemblies.rb +16 -0
  113. data/lib/megam/mixins/assembly.rb +59 -0
  114. data/lib/megam/mixins/common_deployable.rb +78 -0
  115. data/lib/megam/mixins/components.rb +182 -0
  116. data/lib/megam/mixins/megam_attributes.rb +30 -0
  117. data/lib/megam/mixins/outputs.rb +23 -0
  118. data/lib/megam/mixins/policies.rb +27 -0
  119. data/lib/megam_api.rb +1 -0
  120. data/megam_api.gemspec +26 -0
  121. data/test/mixins/test_assemblies.rb +113 -0
  122. data/test/mixins/test_assembly.rb +74 -0
  123. data/test/mixins/test_component.rb +19 -0
  124. data/test/test_accounts.rb +127 -0
  125. data/test/test_addons.rb +26 -0
  126. data/test/test_assemblies.rb +88 -0
  127. data/test/test_assembly.rb +37 -0
  128. data/test/test_backups.rb +29 -0
  129. data/test/test_balances.rb +38 -0
  130. data/test/test_billedhistories.rb +30 -0
  131. data/test/test_billingtranscations.rb +35 -0
  132. data/test/test_components.rb +42 -0
  133. data/test/test_credits.rb +28 -0
  134. data/test/test_disks.rb +25 -0
  135. data/test/test_domains.rb +29 -0
  136. data/test/test_eventsbilling.rb +30 -0
  137. data/test/test_eventscontainer.rb +26 -0
  138. data/test/test_eventsstorage.rb +12 -0
  139. data/test/test_eventsvm.rb +26 -0
  140. data/test/test_helper.rb +77 -0
  141. data/test/test_marketplaces.rb +38 -0
  142. data/test/test_organizations.rb +45 -0
  143. data/test/test_promos.rb +11 -0
  144. data/test/test_quotas.rb +33 -0
  145. data/test/test_reports.rb +32 -0
  146. data/test/test_requests.rb +95 -0
  147. data/test/test_sensors.rb +50 -0
  148. data/test/test_snapshots.rb +30 -0
  149. data/test/test_sshkeys.rb +50 -0
  150. data/test/test_subscriptions.rb +22 -0
  151. metadata +325 -0
@@ -0,0 +1,26 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ def test_get_eventscontainer
6
+ tmp_hash = {
7
+ "account_id" => "",
8
+ "created_at" => "2016-05-05 10:57:30 +0000",
9
+ "assembly_id" => "ASM9038606864211614815",
10
+ "event_type" => "",
11
+ "data" => []
12
+ }
13
+ response = megams.get_eventscontainer("0", tmp_hash)
14
+
15
+ assert_equal(200, response.status)
16
+ end
17
+
18
+ def test_list_eventscontainer
19
+ response = megams.list_eventscontainer("0")
20
+ assert_equal(200, response.status)
21
+ end
22
+ def test_index_eventscontainer
23
+ response = megams.index_eventscontainer
24
+ assert_equal(200, response.status)
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ def test_list_eventsstorage
5
+ response = megams.list_eventsstorage("0")
6
+ assert_equal(200, response.status)
7
+ end
8
+ def test_index_eventsstorage
9
+ response = megams.index_eventsstorage
10
+ assert_equal(200, response.status)
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ def test_get_eventsvm
6
+ tmp_hash = {
7
+ "account_id" => "",
8
+ "created_at" => "2016-05-05 10:57:30 +0000",
9
+ "assembly_id" => "ASM9038606864211614815",
10
+ "event_type" => "",
11
+ "data" => []
12
+ }
13
+ response = megams.get_eventsvm("0", tmp_hash)
14
+
15
+ assert_equal(200, response.status)
16
+ end
17
+
18
+ def test_list_eventsvm
19
+ response = megams.list_eventsvm("0")
20
+ assert_equal(200, response.status)
21
+ end
22
+ def test_index_eventsvm
23
+ response = megams.index_eventsvm
24
+ assert_equal(200, response.status)
25
+ end
26
+ end
@@ -0,0 +1,77 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../lib/megam/api")
2
+
3
+ require 'rubygems'
4
+ gem 'minitest' # ensure we are using the gem version
5
+ require 'minitest/autorun'
6
+ require 'time'
7
+
8
+ SANDBOX_HOST_OPTIONS = {
9
+ :scheme => 'http',
10
+ :host => 'http://localhost:9000/v2',
11
+ :nonblock => false,
12
+ :port => 9000
13
+ }
14
+
15
+
16
+ def megam(options)
17
+ options = SANDBOX_HOST_OPTIONS.merge(options)
18
+ mg=Megam::API.new(options)
19
+ end
20
+
21
+ def megams_new(options={})
22
+ s_options = SANDBOX_HOST_OPTIONS.merge({
23
+ :email => "cd@ss.co",
24
+ :api_key => "1189a21d8965ee670536cbb61fd9f5afed8489c0",
25
+ })
26
+ options = s_options.merge(options)
27
+ mg=Megam::API.new(options)
28
+ end
29
+
30
+ def megams(options={})
31
+ s_options = SANDBOX_HOST_OPTIONS.merge({
32
+ :email => "cd@ss.co",
33
+ :api_key => "1189a21d8965ee670536cbb61fd9f5afed8489c0",
34
+ :org_id => "ORG8385278424580953898",
35
+ #:password => "bWVnYW0="
36
+ })
37
+
38
+ Megam::Log.level(:debug)
39
+ options = s_options.merge(options)
40
+ mg=Megam::API.new(options)
41
+ end
42
+
43
+ def random_domain
44
+ "megam.co"
45
+ end
46
+
47
+ def random_id
48
+ SecureRandom.random_number(1000)
49
+ end
50
+
51
+ def random_name
52
+ SecureRandom.hex(15)
53
+ end
54
+
55
+ def random_apikey
56
+ SecureRandom.hex(10)
57
+ end
58
+
59
+ def random_email
60
+ "email@#{random_apikey}.com"
61
+ end
62
+
63
+ def domain_name
64
+ "megambox.com"
65
+ end
66
+
67
+ def sandbox_name
68
+ "org.megam"
69
+ end
70
+
71
+ def sandbox_apikey
72
+ "IamAtlas{74}NobdyCanSedfefdeME#07"
73
+ end
74
+
75
+ def sandbox_email
76
+ "tour@megam.io"
77
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestMarketplaces < MiniTest::Unit::TestCase
4
+
5
+
6
+ =begin
7
+ def test_post_marketplace
8
+ tmp_hash = {
9
+ "name" => "34-Trac",
10
+ "catalog" => {"logo" => "logo", "category"=> "catagroy", "description"=> "description"},
11
+ "plans" => [{"price"=> "30", "description"=> "description", "plantype"=> "paid", "version"=> "0.1", "source"=> "source"}],
12
+ "cattype" => "DEW",
13
+ "predefnode" => "java",
14
+ "status" => "ACTIVE",
15
+ "order" => "",
16
+ "image" => "",
17
+ "url" => "",
18
+ "envs" => []
19
+ }
20
+
21
+ response = megams.post_marketplaceapp(tmp_hash)
22
+ assert_equal(201, response.status)
23
+ end
24
+ =end
25
+
26
+ #=begin
27
+ def test_get_marketplaces
28
+ response = megams.get_marketplaceapps
29
+ assert_equal(200, response.status)
30
+ end
31
+ #=end
32
+ #=begin
33
+ def test_show_marketplace_item
34
+ response = megams.get_marketplaceapp("Ubuntu")
35
+ assert_equal(200, response.status)
36
+ end
37
+ #=end
38
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestOrganizations < MiniTest::Unit::TestCase
4
+
5
+ $admin = "admin-tom"
6
+ $normal = "normal-tom"
7
+ $tom_email = "tom@gomegam.com"
8
+ $bob_email = "bob@gomegam.com"
9
+
10
+
11
+ #=begin
12
+ def test_post_organizations_good
13
+ tmp_hash = {
14
+ "name" => "org.megam1"}
15
+ response =megams.post_organization(tmp_hash)
16
+ assert_equal(201, response.status)
17
+ end
18
+ #=end
19
+ #=begin
20
+ def test_get_organizations_good1
21
+ response =megams.get_organizations
22
+ assert_equal(200, response.status)
23
+ end
24
+ #=end
25
+ =begin
26
+ def test_update_organizations
27
+ tmp_hash = {
28
+ "id" => "ORG123",
29
+ "accounts_id" => "ACT123123",
30
+ "name" => "org1",
31
+ "related_orgs" => ["etst"],
32
+ "created_at" => ""
33
+ }
34
+ response = megams.update_organization(tmp_hash)
35
+ response.body.to_s
36
+ assert_equal(201, response.status)
37
+ end
38
+ =end
39
+ =begin
40
+ def test_get_organization
41
+ response = megams.get_organization("ORG8032139491299205131")
42
+ assert_equal(200, response.status)
43
+ end
44
+ =end
45
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ =begin
5
+ def test_get_promos()
6
+ response = megams.get_promos("megamfree5")
7
+ assert_equal(200, response.status)
8
+
9
+ end
10
+ =end
11
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ def test_post_quotas
6
+ tmp_hash = {
7
+ "name"=>"cloud-s01",
8
+ "account_id"=>"test@megam.io",
9
+ "allowed"=>[
10
+ {
11
+ "key" => "ram",
12
+ "value" => "4GB"
13
+ },
14
+ {
15
+ "key" => "cpu",
16
+ "value" => "2cores"
17
+ },
18
+ {
19
+ "key" => "disk",
20
+ "value" => "10GB"
21
+ },
22
+ ],
23
+ "allocated_to" => "",
24
+ "quota_type"=> "vm",
25
+ "status" => "active",
26
+ "inputs" => [],
27
+
28
+ }
29
+
30
+ response = megams.post_quotas(tmp_hash)
31
+ assert_equal(201, response.status)
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ def test_post_snapshots
6
+ tmp_hash = {
7
+ :account_id => "test@megam.io",
8
+ :asm_id => "ASM535576423764486230",
9
+ :org_id => "ORG7879663326321337888",
10
+ :name => "pop.megambox.com",
11
+ :status => "progress",
12
+ :start_date => "progress",
13
+ :end_date => "progress",
14
+ :type => "progress",
15
+
16
+ }
17
+
18
+ response = megams.post_reports(tmp_hash)
19
+ assert_equal(201, response.status)
20
+ end
21
+
22
+ # def test_get_snapshots
23
+ # response = megams.post_reports("ASM535576423764486230")
24
+ # assert_equal(200, response.status)
25
+ # end
26
+ =begin
27
+ def test_list_snapshots
28
+ response = megams.list_snapshots
29
+ assert_equal(200, response.status)
30
+ end
31
+ =end
32
+ end
@@ -0,0 +1,95 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ =begin
5
+ def test_get_requests
6
+ response = megams.get_requests
7
+ assert_equal(200, response.status)
8
+ end
9
+
10
+ def test_get_request_faulty
11
+ assert_raises(Megam::API::Errors::NotFound) do
12
+ response = megams.get_request("faulty")
13
+ end
14
+ end
15
+
16
+ #=end
17
+ def test_get_request_good
18
+ response = megams.get_request("black1.megam.co")
19
+ assert_equal(200, response.status)
20
+ end
21
+
22
+ #=begin
23
+ @com = {
24
+ "systemprovider" => {
25
+ "provider" => {
26
+ "prov" => "chef"
27
+ }
28
+ },
29
+ "compute" => {
30
+ "cctype" => "ec2",
31
+ "cc" => {
32
+ "groups" => "",
33
+ "image" => "",
34
+ "flavor" => "",
35
+ "tenant_id" => ""
36
+ },
37
+ "access" => {
38
+ "ssh_key" => "megam_ec2",
39
+ "identity_file" => "~/.ssh/megam_ec2.pem",
40
+ "ssh_user" => "",
41
+ "vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
42
+ "sshpub_location" => "",
43
+ "zone" => "",
44
+ "region" => ""
45
+ }
46
+ },
47
+ "cloudtool" => {
48
+ "chef" => {
49
+ "command" => "knife",
50
+ "plugin" => "ec2 server delete",
51
+ "run_list" => "",
52
+ "name" => ""
53
+ }
54
+ }
55
+ }
56
+
57
+ @@tmp_hash = {
58
+ "node_name" => "black1.megam.co",
59
+ "node_type" => "APP", #APP or Bolt
60
+ "req_type" => "delete",
61
+ "noofinstances" => 0,
62
+ "command" => @com,
63
+ "predefs" => {"name" => "", "scm" => "", "db" => "", "war" => "", "queue" => ""},
64
+ "appdefns" => {"timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
65
+ "boltdefns" => {"username" => "", "apikey" => "", "store_name" => "", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
66
+ "appreq" => {},
67
+ "boltreq" => {}
68
+ }
69
+ =end
70
+
71
+ @@tmp_hash = {
72
+
73
+ "cat_id" => "ASM",
74
+ "cattype" => "app",
75
+ "name" => "yeshapp",
76
+ "action" => "delete",
77
+ "category" => "normal" #normal(create, delete), state, control, policy
78
+ }
79
+
80
+ =begin
81
+ def test_request_node_delete
82
+
83
+ response = megams.post_request(@@tmp_hash)
84
+ assert_equal(201, response.status)
85
+ end
86
+ =begin
87
+ def test_request_node_stop
88
+ @@tmp_hash["req_type"] = "stop"
89
+ @@tmp_hash["command"]["cloudtool"]["chef"]["plugin"] = "ec2 server stop"
90
+ response = megams.post_request(@@tmp_hash)
91
+ assert_equal(201, response.status)
92
+ end
93
+ =end
94
+
95
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ =begin
6
+ def test_get_sensors
7
+ response = megams.get_sensors
8
+ assert_equal(200, response.status)
9
+ end
10
+ =end
11
+ =begin
12
+ def test_get_sensor
13
+ response = megams.get_sensor("SNR1270695834413039616")
14
+ assert_equal(200, response.status)
15
+ end
16
+ =end
17
+
18
+ =begin
19
+ def test_post_sensors
20
+ tmp_hash = {
21
+
22
+ "sensor_type" => "compute.instance.launch",
23
+
24
+ "payload" => {
25
+ "accounts_id" => "ACT000000111",
26
+ "assemblies_id" => "ASM000001",
27
+ "assembly_id" => "AMS0000001",
28
+ "component_id" => "CMP0000001",
29
+ "state" => "active",
30
+ "source" => "one",
31
+ "node" => "192.168.1.100",
32
+ "message" => "Periodic billing event",
33
+ "audit_period_begining" => "2015-10-09:01:01:01",
34
+ "audit_period_ending" => "2015-10-09:01:10:01",
35
+ "metrics" => [ {
36
+ "metric_type" => "delta",
37
+ "metric_value" => 42,
38
+ "metric_units" => "hits",
39
+ "metric_name" => "queries"
40
+
41
+ }
42
+ ]
43
+ }
44
+
45
+ }
46
+ response = megams.post_sensors(tmp_hash)
47
+ assert_equal(200, response.status)
48
+ end
49
+ =end
50
+ end