megam_api 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +202 -0
- data/lib/megam/api.rb +24 -38
- data/lib/megam/api/cloud_tool_settings.rb +36 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/builder/delete_node.rb +2 -1
- data/lib/megam/builder/make_node.rb +52 -52
- data/lib/megam/core/account.rb +3 -3
- data/lib/megam/core/cloudtoolsetting.rb +197 -0
- data/lib/megam/core/cloudtoolsetting_collection.rb +168 -0
- data/lib/megam/core/json_compat.rb +6 -0
- data/lib/megam/core/log.rb +2 -1
- data/lib/megam/core/monologger.rb +89 -0
- data/lib/megam/core/predefcloud.rb +4 -2
- data/lib/megam/core/text.rb +13 -0
- data/lib/megam/core/text_formatter.rb +63 -0
- data/megam_api.gemspec +4 -4
- data/test/test_accounts.rb +4 -3
- data/test/test_cloudtoolsettings.rb +49 -0
- data/test/test_helper.rb +1 -0
- data/test/test_nodes.rb +5 -2
- data/test/test_predefclouds.rb +8 -6
- data/test/test_requests.rb +3 -1
- metadata +9 -2
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# Copyright:: Copyright (c) 2012, 2013 Megam Systems
|
2
3
|
# License:: Apache License, Version 2.0
|
3
4
|
#
|
@@ -167,6 +168,7 @@ module Megam
|
|
167
168
|
predefcd.access[:ssh_user]= op["ssh_user"] if op && op.has_key?("ssh_user")
|
168
169
|
predefcd.access[:vault_location]= op["vault_location"] if op && op.has_key?("vault_location")
|
169
170
|
predefcd.access[:sshpub_location]= op["sshpub_location"] if op && op.has_key?("sshpub_location")
|
171
|
+
predefcd.access[:zone]= op["zone"] if op && op.has_key?("zone")
|
170
172
|
#access
|
171
173
|
# predefcd.ideal(o["ideal"]) if o.has_key?("ideal")
|
172
174
|
# predefcd.performance(o["performance"]) if o.has_key?("performance")
|
@@ -210,14 +212,14 @@ module Megam
|
|
210
212
|
# returns a PredefsCollection
|
211
213
|
# don't return self. check if the Megam::PredefCollection is returned.
|
212
214
|
def self.list
|
213
|
-
|
215
|
+
predef = self.new()
|
214
216
|
predef.megam_rest.get_predefclouds
|
215
217
|
end
|
216
218
|
|
217
219
|
# Show a particular predef by name,
|
218
220
|
# Megam::Predef
|
219
221
|
def self.show(p_name)
|
220
|
-
|
222
|
+
pre = self.new()
|
221
223
|
pre.megam_rest.get_predefcloud(p_name)
|
222
224
|
end
|
223
225
|
|
data/lib/megam/core/text.rb
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
+
require "megam/core/text_formatter"
|
16
17
|
module Megam
|
17
18
|
class Text
|
18
19
|
|
@@ -31,6 +32,18 @@ module Megam
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
# Summarize the data. Defaults to text format output,
|
36
|
+
# which may not be very summary-like
|
37
|
+
def summarize(data)
|
38
|
+
text_format(data)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Converts the +data+ to a String in the text format. Uses
|
42
|
+
# Chef::Knife::Core::TextFormatter
|
43
|
+
def text_format(data)
|
44
|
+
Megam::TextFormatter.new(data, self).formatted_data
|
45
|
+
end
|
46
|
+
|
34
47
|
def msg(message)
|
35
48
|
stdout.puts message
|
36
49
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Megam
|
2
|
+
class TextFormatter
|
3
|
+
|
4
|
+
attr_reader :data
|
5
|
+
attr_reader :ui
|
6
|
+
def initialize(data, ui)
|
7
|
+
@ui = ui
|
8
|
+
@data = if data.respond_to?(:display_hash)
|
9
|
+
data.display_hash
|
10
|
+
elsif data.kind_of?(Array)
|
11
|
+
data
|
12
|
+
elsif data.respond_to?(:to_hash)
|
13
|
+
data.to_hash
|
14
|
+
else
|
15
|
+
data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def formatted_data
|
20
|
+
@formatted_data ||= text_format(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def text_format(data)
|
24
|
+
buffer = ''
|
25
|
+
|
26
|
+
if data.respond_to?(:keys)
|
27
|
+
justify_width = data.keys.map {|k| k.to_s.size }.max.to_i + 1
|
28
|
+
data.sort.each do |key, value|
|
29
|
+
# key: ['value'] should be printed as key: value
|
30
|
+
if value.kind_of?(Array) && value.size == 1 && is_singleton(value[0])
|
31
|
+
value = value[0]
|
32
|
+
end
|
33
|
+
if is_singleton(value)
|
34
|
+
# Strings are printed as key: value.
|
35
|
+
justified_key = ui.color("#{key}:".ljust(justify_width), :cyan)
|
36
|
+
buffer << "#{justified_key} #{value}\n"
|
37
|
+
else
|
38
|
+
# Arrays and hashes get indented on their own lines.
|
39
|
+
buffer << ui.color("#{key}:\n", :cyan)
|
40
|
+
lines = text_format(value).split("\n")
|
41
|
+
lines.each { |line| buffer << " #{line}\n" }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
elsif data.kind_of?(Array)
|
45
|
+
data.each_index do |index|
|
46
|
+
item = data[index]
|
47
|
+
buffer << text_format(data[index])
|
48
|
+
# Separate items with newlines if it's an array of hashes or an
|
49
|
+
# array of arrays
|
50
|
+
buffer << "\n" if !is_singleton(data[index]) && index != data.size-1
|
51
|
+
end
|
52
|
+
else
|
53
|
+
buffer << "#{data}\n"
|
54
|
+
end
|
55
|
+
buffer
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_singleton(value)
|
59
|
+
!(value.kind_of?(Array) || value.respond_to?(:keys))
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
data/megam_api.gemspec
CHANGED
@@ -10,11 +10,11 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://github.com/indykish/megam_api"
|
11
11
|
s.license = "Apache V2"
|
12
12
|
sextra_rdoc_files = ["README.md", "LICENSE" ]
|
13
|
-
s.summary
|
13
|
+
s.summary = %q{Ruby Client for the Megam Cloud}
|
14
14
|
s.description = %q{Ruby Client for the Megam Cloud. Performs REST based HTTP calls to api.megam.co http://github.com/indykish/megam_play.git}
|
15
|
-
s.files
|
16
|
-
s.test_files
|
17
|
-
s.executables
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
s.add_runtime_dependency 'excon'
|
20
20
|
s.add_runtime_dependency 'highline'
|
data/test/test_accounts.rb
CHANGED
@@ -6,12 +6,13 @@ class TestAccounts < MiniTest::Unit::TestCase
|
|
6
6
|
$normal = "normal-tom"
|
7
7
|
|
8
8
|
def test_get_accounts_good
|
9
|
-
response =megams.get_accounts(sandbox_email)
|
9
|
+
#response =megams.get_accounts(sandbox_email)
|
10
|
+
response =megams.get_accounts('a@b.com')
|
10
11
|
response.body.to_s
|
11
12
|
assert_equal(200, response.status)
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
+
=begin
|
15
16
|
def test_get_accounts_bad
|
16
17
|
assert_raises(Megam::API::Errors::NotFound) do
|
17
18
|
response =megams.get_accounts(sandbox_email+"_bad")
|
@@ -41,6 +42,6 @@ class TestAccounts < MiniTest::Unit::TestCase
|
|
41
42
|
response.body.to_s
|
42
43
|
end
|
43
44
|
end
|
44
|
-
|
45
|
+
=end
|
45
46
|
end
|
46
47
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class TestApps < MiniTest::Unit::TestCase
|
4
|
+
=begin
|
5
|
+
def test_post_cloudtoolsetting1
|
6
|
+
tmp_hash = { :cloud_type => "chef",
|
7
|
+
:repo => "https://github.com"
|
8
|
+
:vault_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default"
|
9
|
+
}
|
10
|
+
|
11
|
+
response = megams.post_cloudtoolsetting(tmp_hash)
|
12
|
+
assert_equal(201, response.status)
|
13
|
+
end
|
14
|
+
=end
|
15
|
+
=begin
|
16
|
+
def test_post_cloudtoolsetting2
|
17
|
+
tmp_hash = { :cloud_type => "chef",
|
18
|
+
:repo => "https://github.com",
|
19
|
+
:vault_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default"
|
20
|
+
}
|
21
|
+
response = megams.post_cloudtoolsetting(tmp_hash)
|
22
|
+
assert_equal(201, response.status)
|
23
|
+
end
|
24
|
+
=end
|
25
|
+
#=begin
|
26
|
+
def test_get_cloudtoolsettings
|
27
|
+
response = megams.get_cloudtoolsettings
|
28
|
+
assert_equal(200, response.status)
|
29
|
+
end
|
30
|
+
#=end
|
31
|
+
=begin
|
32
|
+
def test_get_cloudtoolsetting2
|
33
|
+
response = megams.get_cloudtoolsetting("rkspce_sundown_play")
|
34
|
+
assert_equal(200, response.status)
|
35
|
+
end
|
36
|
+
#=begin
|
37
|
+
def test_get_cloudtoolsetting1
|
38
|
+
response = megams.get_cloudtoolsetting("iaas_default")
|
39
|
+
assert_equal(200, response.status)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_cloudtoolsetting_not_found
|
43
|
+
assert_raises(Megam::API::Errors::NotFound) do
|
44
|
+
megams.get_cloudtoolsetting("stupid.megam.co")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
=end
|
48
|
+
end
|
49
|
+
|
data/test/test_helper.rb
CHANGED
data/test/test_nodes.rb
CHANGED
@@ -22,7 +22,8 @@ class TestApps < MiniTest::Unit::TestCase
|
|
22
22
|
"identity_file" => "~/.ssh/megam_ec2.pem",
|
23
23
|
"ssh_user" => "ubuntu",
|
24
24
|
"vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
25
|
-
"sshpub_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default"
|
25
|
+
"sshpub_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
26
|
+
"zone" => ""
|
26
27
|
}
|
27
28
|
},
|
28
29
|
"cloudtool" => {
|
@@ -118,7 +119,9 @@ end
|
|
118
119
|
"ssh_key" => "megam_ec2",
|
119
120
|
"identity_file" => "~/.ssh/megam_ec2.pem",
|
120
121
|
"ssh_user" => "",
|
121
|
-
"vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default"
|
122
|
+
"vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
123
|
+
"sshpub_location" => "",
|
124
|
+
"zone" => ""
|
122
125
|
}
|
123
126
|
},
|
124
127
|
"cloudtool" => {
|
data/test/test_predefclouds.rb
CHANGED
@@ -14,10 +14,11 @@ class TestApps < MiniTest::Unit::TestCase
|
|
14
14
|
:identity_file => "~/.ssh/megam_ec2.pem",
|
15
15
|
:ssh_user => "ubuntu",
|
16
16
|
:vault_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
17
|
-
:sshpub_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default"
|
17
|
+
:sshpub_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
18
|
+
:zone => ""
|
18
19
|
},
|
19
|
-
|
20
|
-
|
20
|
+
#:ideal => "ror,redis,riak",
|
21
|
+
#:performance => "10rpm"
|
21
22
|
}
|
22
23
|
|
23
24
|
response = megams.post_predefcloud(tmp_hash)
|
@@ -36,10 +37,11 @@ class TestApps < MiniTest::Unit::TestCase
|
|
36
37
|
:identity_file => "https://boering.dropbox.closedloc/aorc.pem",
|
37
38
|
:ssh_user => "ubuntu",
|
38
39
|
:vault_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
39
|
-
:sshpub_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default"
|
40
|
+
:sshpub_location => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
41
|
+
:zone => ""
|
40
42
|
},
|
41
|
-
|
42
|
-
|
43
|
+
#:ideal => "play,redis,riak",
|
44
|
+
#:performance => "10rpm"
|
43
45
|
}
|
44
46
|
response = megams.post_predefcloud(tmp_hash)
|
45
47
|
assert_equal(201, response.status)
|
data/test/test_requests.rb
CHANGED
@@ -38,7 +38,9 @@ class TestApps < MiniTest::Unit::TestCase
|
|
38
38
|
"ssh_key" => "megam_ec2",
|
39
39
|
"identity_file" => "~/.ssh/megam_ec2.pem",
|
40
40
|
"ssh_user" => "",
|
41
|
-
"vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default"
|
41
|
+
"vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default",
|
42
|
+
"sshpub_location" => "",
|
43
|
+
"zone" => ""
|
42
44
|
}
|
43
45
|
},
|
44
46
|
"cloudtool" => {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megam_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kishorekumar Neelamegam, Thomas Alrin, Subash Sethurajan, Rajthilak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- .project
|
124
124
|
- .travis.yml
|
125
125
|
- Gemfile
|
126
|
+
- LICENSE
|
126
127
|
- README.md
|
127
128
|
- Rakefile
|
128
129
|
- lib/certs/cacert.pem
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- lib/megam/api/appdefns.rb
|
133
134
|
- lib/megam/api/bolt_request.rb
|
134
135
|
- lib/megam/api/boltdefns.rb
|
136
|
+
- lib/megam/api/cloud_tool_settings.rb
|
135
137
|
- lib/megam/api/cloud_tools.rb
|
136
138
|
- lib/megam/api/errors.rb
|
137
139
|
- lib/megam/api/login.rb
|
@@ -160,10 +162,13 @@ files:
|
|
160
162
|
- lib/megam/core/cloudtemplate_collection.rb
|
161
163
|
- lib/megam/core/cloudtool.rb
|
162
164
|
- lib/megam/core/cloudtool_collection.rb
|
165
|
+
- lib/megam/core/cloudtoolsetting.rb
|
166
|
+
- lib/megam/core/cloudtoolsetting_collection.rb
|
163
167
|
- lib/megam/core/config.rb
|
164
168
|
- lib/megam/core/error.rb
|
165
169
|
- lib/megam/core/json_compat.rb
|
166
170
|
- lib/megam/core/log.rb
|
171
|
+
- lib/megam/core/monologger.rb
|
167
172
|
- lib/megam/core/node.rb
|
168
173
|
- lib/megam/core/node_collection.rb
|
169
174
|
- lib/megam/core/predef.rb
|
@@ -174,6 +179,7 @@ files:
|
|
174
179
|
- lib/megam/core/request_collection.rb
|
175
180
|
- lib/megam/core/stuff.rb
|
176
181
|
- lib/megam/core/text.rb
|
182
|
+
- lib/megam/core/text_formatter.rb
|
177
183
|
- lib/megam_api.rb
|
178
184
|
- megam_api.gemspec
|
179
185
|
- test/test_accounts.rb
|
@@ -182,6 +188,7 @@ files:
|
|
182
188
|
- test/test_boltdefns.rb
|
183
189
|
- test/test_boltreqs.rb
|
184
190
|
- test/test_cloudtools.rb
|
191
|
+
- test/test_cloudtoolsettings.rb
|
185
192
|
- test/test_helper.rb
|
186
193
|
- test/test_login.rb
|
187
194
|
- test/test_logs.rb
|