asteroid 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile +1 -0
- data/README.md +45 -4
- data/Rakefile +1 -0
- data/asteroid.gemspec +0 -1
- data/bin/asteroid +4 -2
- data/lib/asteroid.rb +11 -10
- data/lib/asteroid/application.rb +60 -7
- data/lib/asteroid/config.rb +28 -14
- data/lib/asteroid/file_reference.rb +102 -0
- data/lib/asteroid/generator.rb +0 -4
- data/lib/asteroid/instance.rb +29 -9
- data/lib/asteroid/instance/command.rb +71 -36
- data/lib/asteroid/instance/scp.rb +26 -0
- data/lib/asteroid/instance/ssh.rb +2 -1
- data/lib/asteroid/instance/vars.rb +5 -2
- data/lib/asteroid/key_reference.rb +45 -0
- data/lib/asteroid/provider/abstract.rb +16 -1
- data/lib/asteroid/provider/digital_ocean.rb +35 -6
- data/lib/asteroid/provider/mock.rb +36 -14
- data/lib/asteroid/script.rb +3 -57
- data/lib/asteroid/server.rb +44 -25
- data/lib/asteroid/template.rb +19 -7
- data/lib/asteroid/template/liquid.rb +0 -0
- data/lib/asteroid/version.rb +1 -1
- data/sample/.gitignore +2 -0
- data/sample/README.md +1 -0
- data/sample/Rakefile +0 -0
- data/sample/TODO +9 -0
- data/sample/asteroid/files/nginx/available_site.conf.erb +0 -0
- data/sample/asteroid/files/nginx/nginx.conf +1 -0
- data/sample/asteroid/scripts/ubuntu.aster +4 -0
- data/sample/asteroid/servers/default.yml +3 -0
- data/sample/asteroid/servers/web.yml +5 -0
- data/sample/config/asteroid.rb +9 -0
- data/test/helper.rb +18 -2
- data/test/unit/test_application.rb +17 -0
- data/test/unit/test_file_reference.rb +18 -0
- data/test/unit/test_instance.rb +20 -4
- data/test/unit/test_script_reference.rb +9 -0
- data/test/unit/test_server.rb +46 -2
- data/test/unit/test_template.rb +16 -0
- metadata +24 -17
- data/lib/asteroid/config_file.rb +0 -46
data/lib/asteroid/server.rb
CHANGED
@@ -5,25 +5,51 @@ require "active_support/core_ext/hash"
|
|
5
5
|
module Asteroid
|
6
6
|
class Server
|
7
7
|
|
8
|
-
attr_accessor :
|
9
|
-
:
|
8
|
+
attr_accessor :name,
|
9
|
+
:scripts,
|
10
|
+
:configure_steps,
|
11
|
+
:instance_options,
|
12
|
+
:ssh_key
|
13
|
+
|
14
|
+
def self.all
|
15
|
+
Dir[Asteroid::Config.server_dir + '/**/*.yml'].delete_if do |g|
|
16
|
+
File.basename(g) == "default.yml"
|
17
|
+
end.map do |g|
|
18
|
+
load g
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.default_config
|
23
|
+
data = YAML.load_file File.join(Asteroid::Config.server_dir, '/default.yml') || {}
|
24
|
+
ActiveSupport::HashWithIndifferentAccess.new data
|
25
|
+
end
|
10
26
|
|
11
27
|
def self.named(name)
|
12
|
-
|
28
|
+
load Asteroid::Config.server_dir + "/#{name}.yml"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.load(filename)
|
32
|
+
data = YAML.load_file filename
|
13
33
|
new data
|
14
34
|
end
|
15
35
|
|
16
|
-
def initialize(
|
17
|
-
data =
|
18
|
-
|
36
|
+
def initialize(options = {})
|
37
|
+
data = self.class.default_config
|
38
|
+
data.deep_merge! options
|
39
|
+
|
40
|
+
@name = data.delete(:name)
|
41
|
+
|
19
42
|
@provider = if data[:provider]
|
20
43
|
Provider.named data[:provider]
|
21
44
|
else
|
22
45
|
Config.providers.first
|
23
46
|
end
|
24
|
-
|
25
47
|
|
26
|
-
@
|
48
|
+
@instance_options = data.delete :instance_options || {}
|
49
|
+
|
50
|
+
@commands = data.delete(:commands) || {}
|
51
|
+
|
52
|
+
@ssh_key = KeyReference.new data.delete(:ssh_key)
|
27
53
|
|
28
54
|
@config = data["config"] || {
|
29
55
|
"admin_username" => "ubuntu",
|
@@ -34,15 +60,11 @@ module Asteroid
|
|
34
60
|
"login.username" => "root",
|
35
61
|
"ssh.port" => "22"
|
36
62
|
}
|
37
|
-
end
|
38
63
|
|
39
|
-
|
40
|
-
def name
|
41
|
-
@attributes[:name]
|
42
64
|
end
|
43
65
|
|
44
|
-
def
|
45
|
-
@
|
66
|
+
def name
|
67
|
+
@name && @name.to_sym
|
46
68
|
end
|
47
69
|
|
48
70
|
def commands
|
@@ -70,25 +92,22 @@ module Asteroid
|
|
70
92
|
end
|
71
93
|
|
72
94
|
def ssh_key_filename
|
73
|
-
|
95
|
+
if @ssh_key
|
96
|
+
File.join Asteroid::Config.secret_key_dir, @ssh_key
|
97
|
+
else
|
98
|
+
nil
|
99
|
+
end
|
74
100
|
end
|
75
101
|
|
76
102
|
def provider
|
77
103
|
@provider
|
78
104
|
end
|
79
105
|
|
80
|
-
def generate_instance_name
|
81
|
-
"#{self.name}-#{
|
106
|
+
def generate_instance_name
|
107
|
+
"#{self.name}-#{SecureRandom.hex(4)}"
|
82
108
|
end
|
83
109
|
|
84
|
-
def create_instance!
|
85
|
-
|
86
|
-
#key_ids = SSHKey.all.select do |k|
|
87
|
-
# @ssh_keys.include?(k.name)
|
88
|
-
#end.map do |k|
|
89
|
-
# k.id
|
90
|
-
#end
|
91
|
-
|
110
|
+
def create_instance!
|
92
111
|
provider.create_instance(self)
|
93
112
|
end
|
94
113
|
|
data/lib/asteroid/template.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
1
3
|
module Asteroid
|
2
4
|
class Template
|
3
5
|
|
4
|
-
|
6
|
+
attr_accessor :text
|
7
|
+
|
8
|
+
def initialize(type = :erb, text = nil)
|
5
9
|
@type = type
|
10
|
+
@text = text
|
11
|
+
end
|
12
|
+
|
13
|
+
def render(locals = {})
|
14
|
+
render_text(@text, locals)
|
6
15
|
end
|
7
16
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
17
|
+
def render_text(text = nil, locals = {})
|
18
|
+
m = "render_#{@type}"
|
19
|
+
if Asteroid::Config.template_engines[@type]
|
20
|
+
self.send m, text, locals
|
11
21
|
else
|
12
|
-
raise "
|
22
|
+
raise "No template engine for type #{@type}"
|
13
23
|
end
|
14
24
|
end
|
15
25
|
|
@@ -20,6 +30,8 @@ module Asteroid
|
|
20
30
|
data = OpenStruct.new(locals).instance_eval{ binding }
|
21
31
|
)
|
22
32
|
end
|
23
|
-
|
33
|
+
|
24
34
|
end
|
25
|
-
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Asteroid::Config.template_engines[:erb] = Asteroid::Template
|
File without changes
|
data/lib/asteroid/version.rb
CHANGED
data/sample/.gitignore
ADDED
data/sample/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Change me
|
data/sample/Rakefile
ADDED
File without changes
|
data/sample/TODO
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/test/helper.rb
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w(.. lib asteroid))
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
|
+
Asteroid.root = File.join(File.dirname(__FILE__), '../sample')
|
6
|
+
Asteroid::Config.configure Asteroid.root
|
5
7
|
|
6
|
-
Asteroid::Config.providers << Asteroid::Provider::Mock.new
|
7
8
|
|
9
|
+
#Asteroid::Config.providers << Asteroid::Provider::Mock.new
|
8
10
|
|
11
|
+
|
12
|
+
class TestCase < Minitest::Test
|
13
|
+
include Asteroid
|
14
|
+
|
15
|
+
def setup
|
16
|
+
Asteroid::Provider::Mock.clear!
|
17
|
+
Asteroid::Config.providers = [Asteroid::Provider::Mock.new]
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_not_nil o
|
21
|
+
assert_equal false, o.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
require 'asteroid/application'
|
4
|
+
|
5
|
+
class TestApplication < TestCase
|
6
|
+
|
7
|
+
def test_server_list
|
8
|
+
s = Application::Server.start %w(list)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_server_create
|
12
|
+
count = Asteroid::Instance.all.count
|
13
|
+
s = Application::Server.start %w(create web)
|
14
|
+
assert_equal(count + 1, Asteroid::Instance.all.count)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class TestFileReference < TestCase
|
4
|
+
|
5
|
+
def test_init
|
6
|
+
s = FileReference.new "nginx/nginx.conf"
|
7
|
+
assert_equal(true, s.exists?)
|
8
|
+
assert_equal(false, s.template?)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_template
|
12
|
+
s = FileReference.new "nginx/available_site.conf"
|
13
|
+
assert_equal(true, s.exists?)
|
14
|
+
assert_equal(true, s.template?)
|
15
|
+
assert_equal(:erb, s.type)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/test/unit/test_instance.rb
CHANGED
@@ -1,18 +1,34 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
|
3
|
-
class TestInstance <
|
4
|
-
include Asteroid
|
3
|
+
class TestInstance < TestCase
|
5
4
|
|
6
5
|
def test_get_all_instances
|
7
6
|
instances = Instance.all
|
8
7
|
assert_kind_of(Array, instances)
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
|
10
|
+
def test_infer_type_from_name
|
11
|
+
i = Instance.new name: "web-thing"
|
12
|
+
assert_equal :web, i.type
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_aster_environment
|
16
|
+
instance = Instance.new type: :web
|
17
|
+
e = instance.aster_environment
|
18
|
+
assert_equal("2", e.eval("add 1 1"))
|
19
|
+
e.eval "upload nginx/nginx.conf ~/nginx.test"
|
20
|
+
assert_equal ["~/nginx.test"], instance.mock_file_system.keys
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_default_config
|
24
|
+
hex = SecureRandom.hex
|
25
|
+
i = Instance.new type: :web, id: hex
|
26
|
+
assert_equal "22", i["ssh.port"]
|
27
|
+
i["ssh.port"] = "1234"
|
15
28
|
|
29
|
+
i = Instance.new type: :web, id: hex
|
30
|
+
assert_equal "1234", i["ssh.port"]
|
31
|
+
end
|
16
32
|
|
17
33
|
|
18
34
|
end
|
data/test/unit/test_server.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
|
3
|
-
class TestServer <
|
4
|
-
include Asteroid
|
3
|
+
class TestServer < TestCase
|
5
4
|
|
6
5
|
def test_create_instance_server
|
7
6
|
s = Server.new name: "web"
|
@@ -10,10 +9,55 @@ class TestServer < Minitest::Test
|
|
10
9
|
assert_equal(instance.server, s)
|
11
10
|
end
|
12
11
|
|
12
|
+
def test_find_all
|
13
|
+
servers = Server.all
|
14
|
+
assert_equal 1, servers.count
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_ssh_key
|
18
|
+
server = Server.new ssh_key: "web"
|
19
|
+
assert_not_nil(server.ssh_key)
|
20
|
+
assert_kind_of(KeyReference, server.ssh_key)
|
21
|
+
assert_respond_to(server.ssh_key, :private)
|
22
|
+
assert_respond_to(server.ssh_key, :public)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_instance_options
|
26
|
+
config = {
|
27
|
+
"whatever" => 123,
|
28
|
+
"something" => "else"
|
29
|
+
}
|
30
|
+
s = Server.new name: "web", instance_options: config
|
31
|
+
assert_equal config, s.instance_options
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_commands
|
35
|
+
commands = {
|
36
|
+
"two" => ['add 1 1'],
|
37
|
+
"add-two" => {"args" => ['a'], "steps" => ['add $a 2']},
|
38
|
+
"something" => ['run something', 'do thing']
|
39
|
+
}
|
40
|
+
@s = Server.new name: "web", commands: commands
|
41
|
+
assert_equal commands, @s.commands
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_command_instance
|
45
|
+
test_commands
|
46
|
+
instance = @s.create_instance!
|
47
|
+
assert_equal "2", instance.eval_command("two")
|
48
|
+
assert_equal "4", instance.eval_command("add-two 2")
|
49
|
+
end
|
50
|
+
|
13
51
|
def test_server_type
|
14
52
|
s = Server.new name: "web"
|
15
53
|
assert_equal :web, s.type
|
16
54
|
end
|
17
55
|
|
56
|
+
def test_create_server
|
57
|
+
cobol = Server.new name: "cobol"
|
58
|
+
instance = cobol.create_instance!
|
59
|
+
assert_equal(instance.server, cobol)
|
60
|
+
assert_equal(:cobol, instance.type)
|
61
|
+
end
|
18
62
|
|
19
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asteroid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Murphy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -150,20 +150,6 @@ dependencies:
|
|
150
150
|
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: autotest
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - '>='
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - '>='
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
153
|
description:
|
168
154
|
email:
|
169
155
|
- sam.murphy@gmail.com
|
@@ -173,6 +159,7 @@ extensions: []
|
|
173
159
|
extra_rdoc_files: []
|
174
160
|
files:
|
175
161
|
- .gitignore
|
162
|
+
- .travis.yml
|
176
163
|
- Gemfile
|
177
164
|
- LICENSE.txt
|
178
165
|
- README.md
|
@@ -190,7 +177,7 @@ files:
|
|
190
177
|
- lib/asteroid.rb
|
191
178
|
- lib/asteroid/application.rb
|
192
179
|
- lib/asteroid/config.rb
|
193
|
-
- lib/asteroid/
|
180
|
+
- lib/asteroid/file_reference.rb
|
194
181
|
- lib/asteroid/generator.rb
|
195
182
|
- lib/asteroid/instance.rb
|
196
183
|
- lib/asteroid/instance/aster.rb
|
@@ -198,6 +185,7 @@ files:
|
|
198
185
|
- lib/asteroid/instance/scp.rb
|
199
186
|
- lib/asteroid/instance/ssh.rb
|
200
187
|
- lib/asteroid/instance/vars.rb
|
188
|
+
- lib/asteroid/key_reference.rb
|
201
189
|
- lib/asteroid/provider.rb
|
202
190
|
- lib/asteroid/provider/abstract.rb
|
203
191
|
- lib/asteroid/provider/digital_ocean.rb
|
@@ -207,10 +195,25 @@ files:
|
|
207
195
|
- lib/asteroid/server.rb
|
208
196
|
- lib/asteroid/ssh_key.rb
|
209
197
|
- lib/asteroid/template.rb
|
198
|
+
- lib/asteroid/template/liquid.rb
|
210
199
|
- lib/asteroid/version.rb
|
200
|
+
- sample/.gitignore
|
201
|
+
- sample/README.md
|
202
|
+
- sample/Rakefile
|
203
|
+
- sample/TODO
|
204
|
+
- sample/asteroid/files/nginx/available_site.conf.erb
|
205
|
+
- sample/asteroid/files/nginx/nginx.conf
|
206
|
+
- sample/asteroid/scripts/ubuntu.aster
|
207
|
+
- sample/asteroid/servers/default.yml
|
208
|
+
- sample/asteroid/servers/web.yml
|
209
|
+
- sample/config/asteroid.rb
|
211
210
|
- test/helper.rb
|
211
|
+
- test/unit/test_application.rb
|
212
|
+
- test/unit/test_file_reference.rb
|
212
213
|
- test/unit/test_instance.rb
|
214
|
+
- test/unit/test_script_reference.rb
|
213
215
|
- test/unit/test_server.rb
|
216
|
+
- test/unit/test_template.rb
|
214
217
|
homepage: ''
|
215
218
|
licenses:
|
216
219
|
- MIT
|
@@ -237,5 +240,9 @@ specification_version: 4
|
|
237
240
|
summary: A server configuration framework
|
238
241
|
test_files:
|
239
242
|
- test/helper.rb
|
243
|
+
- test/unit/test_application.rb
|
244
|
+
- test/unit/test_file_reference.rb
|
240
245
|
- test/unit/test_instance.rb
|
246
|
+
- test/unit/test_script_reference.rb
|
241
247
|
- test/unit/test_server.rb
|
248
|
+
- test/unit/test_template.rb
|