megam_api 0.1.0

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.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.project +17 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +5 -0
  6. data/README.md +83 -0
  7. data/Rakefile +10 -0
  8. data/lib/certs/cacert.pem +3554 -0
  9. data/lib/megam/api.rb +244 -0
  10. data/lib/megam/api/accounts.rb +29 -0
  11. data/lib/megam/api/appdefns.rb +26 -0
  12. data/lib/megam/api/appreqs.rb +27 -0
  13. data/lib/megam/api/boltdefns.rb +27 -0
  14. data/lib/megam/api/boltreqs.rb +27 -0
  15. data/lib/megam/api/cloud_tools.rb +35 -0
  16. data/lib/megam/api/errors.rb +27 -0
  17. data/lib/megam/api/login.rb +14 -0
  18. data/lib/megam/api/logs.rb +18 -0
  19. data/lib/megam/api/nodes.rb +50 -0
  20. data/lib/megam/api/predef_clouds.rb +35 -0
  21. data/lib/megam/api/predefs.rb +35 -0
  22. data/lib/megam/api/requests.rb +37 -0
  23. data/lib/megam/api/version.rb +5 -0
  24. data/lib/megam/core/account.rb +170 -0
  25. data/lib/megam/core/appdefns.rb +192 -0
  26. data/lib/megam/core/appdefns_collection.rb +148 -0
  27. data/lib/megam/core/appreqs.rb +224 -0
  28. data/lib/megam/core/appreqs_collection.rb +148 -0
  29. data/lib/megam/core/auth.rb +91 -0
  30. data/lib/megam/core/boltdefns.rb +198 -0
  31. data/lib/megam/core/boltdefns_collection.rb +148 -0
  32. data/lib/megam/core/boltreqs.rb +224 -0
  33. data/lib/megam/core/boltreqs_collection.rb +148 -0
  34. data/lib/megam/core/cloudinstruction.rb +110 -0
  35. data/lib/megam/core/cloudinstruction_collection.rb +145 -0
  36. data/lib/megam/core/cloudinstruction_group.rb +99 -0
  37. data/lib/megam/core/cloudtemplate.rb +127 -0
  38. data/lib/megam/core/cloudtemplate_collection.rb +145 -0
  39. data/lib/megam/core/cloudtool.rb +153 -0
  40. data/lib/megam/core/cloudtool_collection.rb +145 -0
  41. data/lib/megam/core/config.rb +44 -0
  42. data/lib/megam/core/error.rb +99 -0
  43. data/lib/megam/core/json_compat.rb +183 -0
  44. data/lib/megam/core/log.rb +33 -0
  45. data/lib/megam/core/node.rb +347 -0
  46. data/lib/megam/core/node_collection.rb +166 -0
  47. data/lib/megam/core/predef.rb +208 -0
  48. data/lib/megam/core/predef_collection.rb +164 -0
  49. data/lib/megam/core/predefcloud.rb +229 -0
  50. data/lib/megam/core/predefcloud_collection.rb +168 -0
  51. data/lib/megam/core/request.rb +187 -0
  52. data/lib/megam/core/request_collection.rb +145 -0
  53. data/lib/megam/core/stuff.rb +69 -0
  54. data/lib/megam/core/text.rb +88 -0
  55. data/lib/megam_api.rb +1 -0
  56. data/megam_api.gemspec +26 -0
  57. data/test/test_accounts.rb +46 -0
  58. data/test/test_appdefns.rb +23 -0
  59. data/test/test_appreqs.rb +28 -0
  60. data/test/test_boltdefns.rb +23 -0
  61. data/test/test_boltreqs.rb +28 -0
  62. data/test/test_cloudtools.rb +22 -0
  63. data/test/test_helper.rb +67 -0
  64. data/test/test_login.rb +12 -0
  65. data/test/test_logs.rb +15 -0
  66. data/test/test_nodes.rb +141 -0
  67. data/test/test_predefclouds.rb +67 -0
  68. data/test/test_predefs.rb +72 -0
  69. data/test/test_requests.rb +85 -0
  70. metadata +213 -0
@@ -0,0 +1,28 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ def test_post_boltreqs
6
+
7
+ tmp_hash = {
8
+ "req_type" => "NStart",
9
+ "node_name" => "black1.megam.co",
10
+ "boltdefns_id" => "12455454",
11
+ "lc_apply" => "APPly",
12
+ "lc_additional" => "ADDition",
13
+ "lc_when" => "When"
14
+ }
15
+
16
+ puts "======================> POST BOLTREQS TEMP HASH <============================================= "
17
+ puts tmp_hash
18
+ response = megams.post_boltreq(tmp_hash)
19
+ assert_equal(201, response.status)
20
+ end
21
+
22
+ def test_get_boltreqs
23
+ response = megams.get_boltreq("black1.megam.co")
24
+ assert_equal(200, response.status)
25
+ end
26
+
27
+
28
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ def test_get_cloudtools
6
+ response = megams.get_cloudtools
7
+ assert_equal(200, response.status)
8
+ end
9
+ =begin
10
+ def test_get_cloudtools1
11
+ response = megams.get_cloudtool("chef")
12
+ assert_equal(200, response.status)
13
+ end
14
+
15
+
16
+ def test_get_cloudtool_not_found
17
+ assert_raises(Megam::API::Errors::NotFound) do
18
+ megams.get_cloudtool("stupid.megam.co")
19
+ end
20
+ end
21
+ =end
22
+ end
@@ -0,0 +1,67 @@
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 => 'https',
10
+ :host => 'api.megam.co',
11
+ :nonblock => false,
12
+ #:port => 9000
13
+ :port => 443
14
+ }
15
+
16
+
17
+ def megam(options)
18
+ options = SANDBOX_HOST_OPTIONS.merge(options)
19
+ mg=Megam::API.new(options)
20
+ end
21
+
22
+ def megams_new(options={})
23
+ s_options = SANDBOX_HOST_OPTIONS.merge({
24
+ :email => "a@b.com",
25
+ :api_key => "CSefq53pY3Sv6iBERSjyRQ=="
26
+ })
27
+ options = s_options.merge(options)
28
+ mg=Megam::API.new(options)
29
+ end
30
+
31
+ def megams(options={})
32
+ s_options = SANDBOX_HOST_OPTIONS.merge({
33
+ :email => sandbox_email,
34
+ :api_key => sandbox_apikey
35
+ })
36
+ options = s_options.merge(options)
37
+ mg=Megam::API.new(options)
38
+ end
39
+
40
+ def random_domain
41
+ "megam.co"
42
+ end
43
+
44
+ def random_id
45
+ SecureRandom.random_number(1000)
46
+ end
47
+
48
+ def random_name
49
+ SecureRandom.hex(15)
50
+ end
51
+
52
+ def random_apikey
53
+ SecureRandom.hex(10)
54
+ end
55
+
56
+ def random_email
57
+ "email@#{random_apikey}.com"
58
+ end
59
+
60
+
61
+ def sandbox_apikey
62
+ "IamAtlas{74}NobodyCanSeeME#07"
63
+ end
64
+
65
+ def sandbox_email
66
+ "sandy@megamsandbox.com"
67
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestLogin < MiniTest::Unit::TestCase
4
+
5
+ def test_post_login
6
+ response =megams.post_auth()
7
+ assert_equal(200, response.status)
8
+ end
9
+
10
+ end
11
+
12
+
@@ -0,0 +1,15 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestLogs < MiniTest::Unit::TestCase
4
+
5
+ #Testing with the logstash key(syslog).
6
+ #This testing gives 303(See Other)
7
+ #The result will be redirected to somewhere, from where we can get the logs.
8
+ def test_get_logs
9
+ response = megams.get_logs("syslog")
10
+
11
+ assert_equal(200, response.status)
12
+ assert_match(%r{^https://localhost\.megam\.co/streams/[-a-zA-Z0-9]*\?srv=[0-9]*$}, response.body)
13
+ end
14
+
15
+ end
@@ -0,0 +1,141 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ #=begin
5
+ def test_post_node1
6
+
7
+ @com = {
8
+ "systemprovider" => {
9
+ "provider" => {
10
+ "prov" => "chef"
11
+ }
12
+ },
13
+ "compute" => {
14
+ "cctype" => "ec2",
15
+ "cc" => {
16
+ "groups" => "megam",
17
+ "image" => "ami-d783cd85",
18
+ "flavor" => "t1.micro"
19
+ },
20
+ "access" => {
21
+ "ssh_key" => "megam_ec2",
22
+ "identity_file" => "~/.ssh/megam_ec2.pem",
23
+ "ssh_user" => "ubuntu"
24
+ }
25
+ },
26
+ "cloudtool" => {
27
+ "chef" => {
28
+ "command" => "knife",
29
+ "plugin" => "ec2 server create", #ec2 server delete or create
30
+ "run_list" => "role[opendj]",
31
+ "name" => "-N TestOverAll"
32
+ }
33
+ }
34
+ }
35
+
36
+ tmp_hash = {
37
+ "node_name" => "black.megam.co",
38
+ "node_type" => "APP", #APP or Bolt
39
+ "req_type" => "create", #CREATE OR DELETE
40
+ "noofinstances" => 2, # integer
41
+ "command" => @com,
42
+ "predefs" => {"name" => "rails", "scm" => "https://github.com/temp.git",
43
+ "db" => "postgres@postgresql1.megam.com/night.megam.co", "war" => "http://s3pub.com/0.1/granny.war", "queue" => "queue@queue1", "runtime_exec" => "sudo start rails"},
44
+ "appdefns" => {"timetokill" => "0", "metered" => "megam", "logging" => "megam", "runtime_exec" => "runtime_execTOM"},
45
+ "boltdefns" => {"username" => "tom", "apikey" => "123456", "store_name" => "tom_db", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
46
+ "appreq" => {},
47
+ "boltreq" => {}
48
+ }
49
+
50
+ puts "======================> TEMP HASH <============================================= "
51
+ puts tmp_hash.class
52
+ puts tmp_hash
53
+ response = megams.post_node(tmp_hash)
54
+ assert_equal(201, response.status)
55
+ end
56
+
57
+ #=end
58
+ =begin
59
+ def test_post_node2
60
+ tmp_hash = {
61
+ "node_name" => "sundown.megam.co",
62
+ "command" => "commands2",
63
+ "predefs" => {"name" => "rails", "scm" => "https://github.com/awesome.git",
64
+ "db" => "postgres@postgresql2.megam.com/morning.megam.co", "war" => "http://s3pub.com/0.1/orion.war", "queue" => "rabbit@queue1"}
65
+ }
66
+ response = megams.post_node(tmp_hash)
67
+ assert_equal(201, response.status)
68
+ end
69
+
70
+ def test_get_nodes
71
+ response = megams.get_nodes
72
+ assert_equal(200, response.status)
73
+ end
74
+ =end
75
+ def test_get_node0
76
+ response = megams.get_node("black1.megam.co")
77
+ puts "=================> Response ========>"
78
+ puts response.inspect
79
+ assert_equal(200, response.status)
80
+ end
81
+
82
+ #=end
83
+ =begin
84
+ def test_get_node1
85
+ response = megams.get_node("night.megam.co")
86
+ assert_equal(200, response.status)
87
+ end
88
+
89
+ def test_get_node_not_found
90
+ assert_raises(Megam::API::Errors::NotFound) do
91
+ megams.get_node("stupid.megam.co")
92
+ end
93
+ end
94
+ =end
95
+
96
+ def test_delete_node1
97
+
98
+ @com = {
99
+ "systemprovider" => {
100
+ "provider" => {
101
+ "prov" => "chef"
102
+ }
103
+ },
104
+ "compute" => {
105
+ "cctype" => "ec2",
106
+ "cc" => {
107
+ "groups" => "",
108
+ "image" => "",
109
+ "flavor" => ""
110
+ },
111
+ "access" => {
112
+ "ssh_key" => "megam_ec2",
113
+ "identity_file" => "~/.ssh/megam_ec2.pem",
114
+ "ssh_user" => ""
115
+ }
116
+ },
117
+ "cloudtool" => {
118
+ "chef" => {
119
+ "command" => "knife",
120
+ "plugin" => "ec2 server delete", #ec2 server delete or create
121
+ "run_list" => "",
122
+ "name" => ""
123
+ }
124
+ }
125
+ }
126
+
127
+ tmp_hash = {
128
+ "node_name" => "black1.megam.co",
129
+ "req_type" => "delete", #CREATE OR DELETE
130
+ "command" => @com
131
+ }
132
+
133
+ puts "======================> TEMP HASH <============================================= "
134
+ puts tmp_hash.class
135
+ puts tmp_hash
136
+ response = megams.post_request(tmp_hash)
137
+ assert_equal(201, response.status)
138
+ end
139
+
140
+ end
141
+
@@ -0,0 +1,67 @@
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
+ },
12
+ :access => {
13
+ :ssh_key => "megam_ec2",
14
+ :identity_file => "~/.ssh/megam_ec2.pem",
15
+ :ssh_user => "ubuntu"
16
+ },
17
+ :ideal => "ror,redis,riak",
18
+ :performance => "10rpm"
19
+ }
20
+
21
+ response = megams.post_predefcloud(tmp_hash)
22
+ assert_equal(201, response.status)
23
+ end
24
+
25
+ def test_post_predefcloud2
26
+ tmp_hash = { :name => "rkspce_sundown_play", :spec => {
27
+ :type_name => "rackspace",
28
+ :groups => "staging_france_boeing",
29
+ :image => "RCP000XERAOl",
30
+ :flavor => "m1-miniscule"
31
+ },
32
+ :access => {
33
+ :ssh_key => "boo_flightssh",
34
+ :identity_file => "https://boering.dropbox.closedloc/aorc.pem",
35
+ :ssh_user => "ubuntu"
36
+ },
37
+ :ideal => "play,redis,riak",
38
+ :performance => "10rpm"
39
+ }
40
+ response = megams.post_predefcloud(tmp_hash)
41
+ assert_equal(201, response.status)
42
+ end
43
+
44
+ #=end
45
+ def test_get_predefclouds
46
+ response = megams.get_predefclouds
47
+ assert_equal(200, response.status)
48
+ end
49
+
50
+ def test_get_predefcloud2
51
+ response = megams.get_predefcloud("iaas_default")
52
+ assert_equal(200, response.status)
53
+ end
54
+
55
+ def test_get_predefcloud1
56
+ response = megams.get_predefcloud("iaas_default")
57
+ assert_equal(200, response.status)
58
+ end
59
+ =begin
60
+ def test_get_predefcloud_not_found
61
+ assert_raises(Megam::API::Errors::NotFound) do
62
+ megams.get_predefcloud("stupid.megam.co")
63
+ end
64
+ end
65
+ =end
66
+ end
67
+
@@ -0,0 +1,72 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ =begin
5
+ def test_post_predef
6
+ tmp_hash = {
7
+ "node_name" => "black1.megam.co",
8
+ "command" => "commands2",
9
+ "predefs" => {"name" => "rails", "scm" => "https://github.com/awesome.git",
10
+ "db" => "postgres@postgresql2.megam.com/morning.megam.co", "war" => "http://s3pub.com/0.1/orion.war", "queue" => "rabbit@queue1", "runtime_exec" => "sudo start rails"}
11
+ }
12
+ response = megams.post_node(tmp_hash)
13
+ assert_equal(201, response.status)
14
+ end
15
+ =end
16
+ def test_get_predefs
17
+ response = megams.get_predefs
18
+ assert_equal(200, response.status)
19
+ end
20
+
21
+ def test_get_predef_faulty
22
+ assert_raises(Megam::API::Errors::NotFound) do
23
+ response = megams.get_predef("faulty")
24
+ end
25
+ end
26
+
27
+ def test_get_predef_rails
28
+ response = megams.get_predef("rails")
29
+ assert_equal(200, response.status)
30
+ end
31
+
32
+ def test_get_predef_java
33
+ response = megams.get_predef("java")
34
+ assert_equal(200, response.status)
35
+ end
36
+
37
+ def test_get_predef_play
38
+ response = megams.get_predef("play")
39
+ assert_equal(200, response.status)
40
+ end
41
+
42
+ def test_get_predef_nodejs
43
+ response = megams.get_predef("nodejs")
44
+ assert_equal(200, response.status)
45
+ end
46
+
47
+ def test_get_predef_akka
48
+ response = megams.get_predef("akka")
49
+ assert_equal(200, response.status)
50
+ end
51
+
52
+ def test_get_predef_postgresql
53
+ response = megams.get_predef("riak")
54
+ assert_equal(200, response.status)
55
+ end
56
+
57
+ def test_get_predef_postgresql
58
+ response = megams.get_predef("postgresql")
59
+ assert_equal(200, response.status)
60
+ end
61
+
62
+ def test_get_predef_rabbitmq
63
+ response = megams.get_predef("rabbitmq")
64
+ assert_equal(200, response.status)
65
+ end
66
+
67
+ def test_get_predef_rabbitmq
68
+ response = megams.get_predef("redis")
69
+ assert_equal(200, response.status)
70
+ end
71
+
72
+ end
@@ -0,0 +1,85 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ =begin
6
+ def test_get_requests
7
+ response = megams.get_requests
8
+ assert_equal(200, response.status)
9
+ end
10
+
11
+ def test_get_request_faulty
12
+ assert_raises(Megam::API::Errors::NotFound) do
13
+ response = megams.get_request("faulty")
14
+ end
15
+ end
16
+
17
+ def test_get_request_good
18
+ response = megams.get_request("morning.megam.co")
19
+ assert_equal(200, response.status)
20
+ end
21
+ =end
22
+
23
+
24
+ @com = {
25
+ "systemprovider" => {
26
+ "provider" => {
27
+ "prov" => "chef"
28
+ }
29
+ },
30
+ "compute" => {
31
+ "cctype" => "ec2",
32
+ "cc" => {
33
+ "groups" => "",
34
+ "image" => "",
35
+ "flavor" => ""
36
+ },
37
+ "access" => {
38
+ "ssh_key" => "megam_ec2",
39
+ "identity_file" => "~/.ssh/megam_ec2.pem",
40
+ "ssh_user" => ""
41
+ }
42
+ },
43
+ "cloudtool" => {
44
+ "chef" => {
45
+ "command" => "knife",
46
+ "plugin" => "ec2 server delete",
47
+ "run_list" => "",
48
+ "name" => ""
49
+ }
50
+ }
51
+ }
52
+
53
+ @@tmp_hash = {
54
+ "node_name" => "black1.megam.co",
55
+ "node_type" => "APP", #APP or Bolt
56
+ "req_type" => "delete",
57
+ "noofinstances" => 0,
58
+ "command" => @com,
59
+ "predefs" => {"name" => "", "scm" => "", "db" => "", "war" => "", "queue" => ""},
60
+ "appdefns" => {"timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
61
+ "boltdefns" => {"username" => "", "apikey" => "", "store_name" => "", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
62
+ "appreq" => {},
63
+ "boltreq" => {}
64
+ }
65
+
66
+ def test_request_node_delete
67
+
68
+ puts "======================> DELETE NODE Request TEMP HASH <============================================= "
69
+ puts @@tmp_hash
70
+ response = megams.post_request(@@tmp_hash)
71
+ assert_equal(201, response.status)
72
+ end
73
+
74
+ def test_request_node_stop
75
+ @@tmp_hash["req_type"] = "stop"
76
+ @@tmp_hash["command"]["cloudtool"]["chef"]["plugin"] = "ec2 server stop"
77
+ puts "======================> STOP NODE Request TEMP HASH <============================================= "
78
+ puts @@tmp_hash
79
+
80
+ response = megams.post_request(@@tmp_hash)
81
+ assert_equal(201, response.status)
82
+ end
83
+
84
+
85
+ end