ona 0.1.26 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/ona +2 -12
- data/lib/ona.rb +2 -1
- data/lib/ona_cli.rb +70 -20
- data/lib/ona_instructions.rb +43 -0
- data/ona.gemspec +3 -2
- metadata +6 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/ona
CHANGED
@@ -13,20 +13,10 @@ eval File.read 'Onafile'
|
|
13
13
|
cli = Ona::Cli.new(stack)
|
14
14
|
|
15
15
|
loop do
|
16
|
-
line = Readline.readline(
|
16
|
+
line = Readline.readline("[0;36;1mOna[0m> ", true)
|
17
17
|
if (line == 'quit') || (line == 'exit')
|
18
18
|
puts 'bye.'
|
19
19
|
break
|
20
20
|
end
|
21
|
-
cli.
|
22
|
-
cli.help if line == 'help'
|
23
|
-
cli.show line if line =~ /show/
|
24
|
-
cli.setup line if line =~ /setup/
|
25
|
-
cli.deploy line if line =~ /deploy/
|
26
|
-
cli.ssh_root line if line =~ /ssh#/
|
27
|
-
cli.ssh_deploy line if line =~ /ssh /
|
28
|
-
cli.http line if line =~ /http/
|
29
|
-
cli.key line if line =~ /key /
|
30
|
-
cli.keys if line =~ /keys/
|
31
|
-
cli.rake line if line =~ /rake /
|
21
|
+
cli.parse(line)
|
32
22
|
end
|
data/lib/ona.rb
CHANGED
data/lib/ona_cli.rb
CHANGED
@@ -2,12 +2,62 @@ module Ona
|
|
2
2
|
|
3
3
|
class Cli
|
4
4
|
|
5
|
+
TRANSLATION = {
|
6
|
+
'show' => { :method => :show, :id_required => true },
|
7
|
+
'setup' => { :method => :setup, :id_required => true },
|
8
|
+
'deploy' => { :method => :deploy, :id_required => true },
|
9
|
+
'ssh#' => { :method => :ssh_root, :id_required => true },
|
10
|
+
'ssh' => { :method => :ssh_deploy,:id_required => true },
|
11
|
+
'http' => { :method => :http, :id_required => true },
|
12
|
+
'key' => { :method => :key, :id_required => true },
|
13
|
+
'keys' => { :method => :keys, :id_required => true },
|
14
|
+
'rake' => { :method => :rake, :id_required => true },
|
15
|
+
'ls' => { :method => :ls, :id_required => false },
|
16
|
+
'help' => { :method => :help, :id_required => false },
|
17
|
+
}
|
18
|
+
|
5
19
|
def initialize(stack)
|
6
|
-
@stack
|
20
|
+
@stack = stack
|
21
|
+
@instructions = Ona::Instructions.new(/[a-z]+[#]*/, /\d+/)
|
7
22
|
end
|
8
23
|
|
9
|
-
def
|
10
|
-
|
24
|
+
def parse command_string
|
25
|
+
# Handle this separately for now.
|
26
|
+
return run_instruction('ls', 0) if command_string == 'ls'
|
27
|
+
return run_instruction('help', 0) if command_string == 'help'
|
28
|
+
|
29
|
+
@instructions.define_command_string(command_string)
|
30
|
+
group = @instructions.group_targets_by_instruction
|
31
|
+
copy = group.dup
|
32
|
+
copy.pop
|
33
|
+
|
34
|
+
# Only last group has ids?
|
35
|
+
if copy.all? { |x| x.values == [[]] }
|
36
|
+
@instructions.instructions.each do |instruction|
|
37
|
+
@instructions.targets.each do |target|
|
38
|
+
run_instruction instruction, target
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
# Run by group.
|
45
|
+
group.each do |hash|
|
46
|
+
instruction, targets = hash.to_a[0][0], hash.to_a[0][1]
|
47
|
+
targets.each do |target|
|
48
|
+
run_instruction instruction, target
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def run_instruction instruction, target
|
54
|
+
return unless TRANSLATION.keys.include?(instruction)
|
55
|
+
hash = TRANSLATION[instruction]
|
56
|
+
cmd = "#{TRANSLATION[instruction][:method]}"
|
57
|
+
if (hash[:id_required])
|
58
|
+
cmd << "(#{target.to_i})"
|
59
|
+
end
|
60
|
+
eval cmd
|
11
61
|
end
|
12
62
|
|
13
63
|
def help
|
@@ -37,21 +87,21 @@ module Ona
|
|
37
87
|
"
|
38
88
|
end
|
39
89
|
|
40
|
-
def http
|
41
|
-
|
90
|
+
def http server_id
|
91
|
+
@stack.find_all(server_id).each do |server|
|
42
92
|
system server.to_http
|
43
93
|
end
|
44
94
|
end
|
45
95
|
|
46
|
-
def key
|
47
|
-
|
96
|
+
def key server_id
|
97
|
+
@stack.find_all(server_id).each do |server|
|
48
98
|
puts 'Setting up key for root'
|
49
99
|
system server.setup_ssh
|
50
100
|
end
|
51
101
|
end
|
52
102
|
|
53
|
-
def show
|
54
|
-
|
103
|
+
def show server_id
|
104
|
+
@stack.find_all(server_id).each do |server|
|
55
105
|
puts server.to_s
|
56
106
|
end
|
57
107
|
end
|
@@ -62,20 +112,20 @@ module Ona
|
|
62
112
|
end
|
63
113
|
end
|
64
114
|
|
65
|
-
def ssh_deploy
|
66
|
-
|
115
|
+
def ssh_deploy server_id
|
116
|
+
@stack.find_all(server_id).each do |server|
|
67
117
|
system server.to_ssh 'deploy'
|
68
118
|
end
|
69
119
|
end
|
70
120
|
|
71
|
-
def ssh_root
|
72
|
-
|
121
|
+
def ssh_root server_id
|
122
|
+
@stack.find_all(server_id).each do |server|
|
73
123
|
system server.to_ssh 'root'
|
74
124
|
end
|
75
125
|
end
|
76
126
|
|
77
|
-
def deploy
|
78
|
-
|
127
|
+
def deploy server_id
|
128
|
+
@stack.find_all(server_id).each do |server|
|
79
129
|
prompt_for_continuation server
|
80
130
|
system server.say_sure_to_deploy
|
81
131
|
line = gets
|
@@ -85,9 +135,9 @@ module Ona
|
|
85
135
|
end
|
86
136
|
end
|
87
137
|
|
88
|
-
def setup
|
89
|
-
key
|
90
|
-
|
138
|
+
def setup server_id
|
139
|
+
key server_id
|
140
|
+
@stack.find_all(server_id).each do |server|
|
91
141
|
prompt_for_continuation server
|
92
142
|
system server.say_sure_to_setup
|
93
143
|
line = gets
|
@@ -97,8 +147,8 @@ module Ona
|
|
97
147
|
end
|
98
148
|
end
|
99
149
|
|
100
|
-
def rake
|
101
|
-
|
150
|
+
def rake server_id
|
151
|
+
@stack.find_all(server_id).each do |server|
|
102
152
|
server.to_s
|
103
153
|
server.rake.each do |task|
|
104
154
|
puts task
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Ona
|
2
|
+
|
3
|
+
class Instructions
|
4
|
+
|
5
|
+
def initialize instruction_matcher, target_matcher
|
6
|
+
define_instruction_matcher instruction_matcher
|
7
|
+
define_target_matcher target_matcher
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_command_string command_string
|
11
|
+
@command_string = command_string
|
12
|
+
end
|
13
|
+
|
14
|
+
def define_instruction_matcher matcher_regex
|
15
|
+
@instruction_matcher = matcher_regex
|
16
|
+
end
|
17
|
+
|
18
|
+
def define_target_matcher matcher_regex
|
19
|
+
@target_matcher = matcher_regex
|
20
|
+
end
|
21
|
+
|
22
|
+
def targets
|
23
|
+
@command_string.scan(@target_matcher)
|
24
|
+
end
|
25
|
+
|
26
|
+
def instructions
|
27
|
+
@command_string.scan(@instruction_matcher)
|
28
|
+
end
|
29
|
+
|
30
|
+
def group_targets_by_instruction
|
31
|
+
group = []
|
32
|
+
chunks = (@command_string.split(@instruction_matcher) - [""])
|
33
|
+
return group if chunks.size != instructions.size
|
34
|
+
chunks.each_with_index do |instruction_targets, index|
|
35
|
+
instruction_targets = (instruction_targets.scan(@target_matcher) - [])
|
36
|
+
group << { instructions[index] => instruction_targets }
|
37
|
+
end
|
38
|
+
group
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/ona.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ona}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kazuyoshi tlacaelel"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-10-27}
|
13
13
|
s.default_executable = %q{ona}
|
14
14
|
s.description = %q{Simple shell for deployment.}
|
15
15
|
s.email = %q{kazu.dev@gmail.com}
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"bin/ona",
|
30
30
|
"lib/ona.rb",
|
31
31
|
"lib/ona_cli.rb",
|
32
|
+
"lib/ona_instructions.rb",
|
32
33
|
"lib/ona_server.rb",
|
33
34
|
"lib/ona_stack.rb",
|
34
35
|
"ona.gemspec",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ona
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- kazuyoshi tlacaelel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-10-27 00:00:00 -05:00
|
19
19
|
default_executable: ona
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- bin/ona
|
53
53
|
- lib/ona.rb
|
54
54
|
- lib/ona_cli.rb
|
55
|
+
- lib/ona_instructions.rb
|
55
56
|
- lib/ona_server.rb
|
56
57
|
- lib/ona_stack.rb
|
57
58
|
- ona.gemspec
|