awt 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/awt.gemspec +1 -0
- data/bin/awt +2 -34
- data/lib/awt.rb +1 -0
- data/lib/awt/cli.rb +60 -0
- data/lib/awt/server.rb +22 -1
- data/lib/awt/version.rb +1 -1
- data/spec/awt/cli_spec.rb +111 -0
- data/spec/awt/server_spec.rb +64 -7
- data/spec/spec_helper.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e3158b8b1980b0db7939acfe0af10e5c4f6940b
|
4
|
+
data.tar.gz: c17259140354d4debd4ede725e46c8f4281bb2ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7abeaab52b73ce75ff0884a8d83139f86e862b98f2ed593cfa25fe17dcf98b3a1f963b4914440b8d6d19348a4cc3981d933a4be0d8f09fe82730dc0130dc60c4
|
7
|
+
data.tar.gz: 100d3833184ce553f7378ab6a63ae4bf1bbdee267fe78a47176738f996afb3633ddee07a1708391dede024816d319a2582ae4e8f367934232265a4730949c66a
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Awt
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/awt)
|
3
4
|
[](https://travis-ci.org/i2bskn/awt)
|
4
5
|
[](https://coveralls.io/r/i2bskn/awt)
|
5
6
|
[](https://codeclimate.com/github/i2bskn/awt)
|
@@ -43,6 +44,8 @@ server "hostname", user: "awt", port: 22, key: "/path/to/id_rsa"
|
|
43
44
|
|
44
45
|
task :task_name do
|
45
46
|
run "do something"
|
47
|
+
put "/path/to/local/file", "/path/to/remote/file"
|
48
|
+
get "/path/to/remote/file", "/path/to/local/file"
|
46
49
|
end
|
47
50
|
```
|
48
51
|
|
data/awt.gemspec
CHANGED
data/bin/awt
CHANGED
@@ -3,38 +3,6 @@
|
|
3
3
|
path = File.expand_path("../../lib", __FILE__)
|
4
4
|
$:.unshift(path) unless $:.include?(path)
|
5
5
|
|
6
|
-
require "
|
6
|
+
require "awt/cli"
|
7
7
|
|
8
|
-
|
9
|
-
require "awt/dsl"
|
10
|
-
|
11
|
-
include Awt::DSL
|
12
|
-
|
13
|
-
options = {}
|
14
|
-
OptionParser.new do |opt|
|
15
|
-
opt.on("-H VAL") {|v| options[:hosts] = v.split(",")}
|
16
|
-
opt.on("-u VAL") {|v| options[:user] = v}
|
17
|
-
opt.on("-p VAL") {|v| options[:port] = v.to_i}
|
18
|
-
opt.on("-i VAL") {|v| options[:key] = v}
|
19
|
-
opt.on("-f VAL") {|v| options[:task_file] = v}
|
20
|
-
|
21
|
-
begin
|
22
|
-
opt.parse!(ARGV)
|
23
|
-
rescue => e
|
24
|
-
puts e
|
25
|
-
exit 1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
task_name = ARGV.first.to_sym
|
30
|
-
hosts = options.delete(:hosts) || []
|
31
|
-
task_file = options.delete(:task_file) || task_find
|
32
|
-
|
33
|
-
hosts.each do |host|
|
34
|
-
server host, options
|
35
|
-
end
|
36
|
-
|
37
|
-
unless task_file.nil?
|
38
|
-
load task_file
|
39
|
-
$AWT_TASKS[task_name].exec($AWT_TARGETS)
|
40
|
-
end
|
8
|
+
Awt::CLI.start
|
data/lib/awt.rb
CHANGED
data/lib/awt/cli.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
require "awt"
|
4
|
+
require "awt/dsl"
|
5
|
+
|
6
|
+
include Awt::DSL
|
7
|
+
|
8
|
+
module Awt
|
9
|
+
class CLI
|
10
|
+
attr_reader :executable
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
parse_opt
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
register_targets(@hosts)
|
18
|
+
raise "Awtfile not found." if @task_file.nil?
|
19
|
+
load @task_file
|
20
|
+
$AWT_TASKS[@task_name].exec($AWT_TARGETS)
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def start
|
25
|
+
begin
|
26
|
+
cli = self.new
|
27
|
+
cli.execute
|
28
|
+
rescue => e
|
29
|
+
puts e
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def parse_opt
|
36
|
+
@options = {}
|
37
|
+
@hosts = []
|
38
|
+
@task_file = task_find
|
39
|
+
OptionParser.new do |opt|
|
40
|
+
opt.version = VERSION
|
41
|
+
opt.banner = "Usage: awt [options] TASK_NAME"
|
42
|
+
opt.on("-H HOSTNAME", "target host names.") {|v| @hosts = v.split(",")}
|
43
|
+
opt.on("-u USER", "login user.") {|v| @options[:user] = v}
|
44
|
+
opt.on("-p PORT", "ssh port number.") {|v| @options[:port] = v.to_i}
|
45
|
+
opt.on("-i IDENTITY_FILE", "SSH private key file.") {|v| @options[:key] = v}
|
46
|
+
opt.on("-f Awtfile", "Task file.") {|v| @task_file = v}
|
47
|
+
opt.parse!(ARGV)
|
48
|
+
end
|
49
|
+
|
50
|
+
raise "Task name is not specified." if ARGV.empty?
|
51
|
+
@task_name = ARGV.first.to_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
def register_targets(hosts)
|
55
|
+
hosts.each do |host|
|
56
|
+
server host, @options
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/awt/server.rb
CHANGED
@@ -10,12 +10,33 @@ module Awt
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def run(cmd)
|
13
|
-
|
13
|
+
reset_printer_host
|
14
14
|
Net::SSH.start(@host, @user, @options) do |ssh|
|
15
15
|
@printer.print_run cmd
|
16
16
|
out = ssh.exec!(cmd)
|
17
17
|
@printer.print_out out
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def put(local, remote)
|
22
|
+
reset_printer_host
|
23
|
+
Net::SSH.start(@host, @user, @options) do |ssh|
|
24
|
+
@printer.print_upload local
|
25
|
+
ssh.scp.upload! local, remote
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def get(remote, local)
|
30
|
+
reset_printer_host
|
31
|
+
Net::SSH.start(@host, @user, @options) do |ssh|
|
32
|
+
@printer.print_download remote
|
33
|
+
ssh.scp.download! remote, local
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def reset_printer_host
|
39
|
+
@printer.host = @host if @printer.host != @host
|
40
|
+
end
|
20
41
|
end
|
21
42
|
end
|
data/lib/awt/version.rb
CHANGED
@@ -0,0 +1,111 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Awt::CLI do
|
4
|
+
let(:cli) {Awt::CLI.new}
|
5
|
+
|
6
|
+
before do
|
7
|
+
ARGV.clear
|
8
|
+
["-H", "host1,host2", "-u", "awt", "-p", "30022", "-i", "/path/to/id_rsa", "-f", "Awtfile", "example"].each do |opt|
|
9
|
+
ARGV << opt
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#initialize" do
|
14
|
+
it "should call CLI#parse_opt" do
|
15
|
+
Awt::CLI.any_instance.should_receive(:parse_opt)
|
16
|
+
Awt::CLI.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#execute" do
|
21
|
+
before do
|
22
|
+
Awt::Server.any_instance.stub(:run)
|
23
|
+
Awt::CLI.any_instance.stub(:load)
|
24
|
+
cli.instance_eval do
|
25
|
+
task :example do
|
26
|
+
run "something"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
after do
|
32
|
+
$AWT_TASKS.clear
|
33
|
+
$AWT_TARGETS.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should call #register_targets" do
|
37
|
+
Awt::CLI.any_instance.should_receive(:register_targets).with(["host1", "host2"])
|
38
|
+
cli.execute
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should throw exception if @task_file is nil" do
|
42
|
+
cli.instance_eval {@task_file = nil}
|
43
|
+
expect {
|
44
|
+
cli.execute
|
45
|
+
}.to raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should load task file" do
|
49
|
+
Awt::CLI.any_instance.should_receive(:load)
|
50
|
+
cli.execute
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should call Awt::Task#exec" do
|
54
|
+
mock = double("Awt::Task mock").as_null_object
|
55
|
+
mock.should_receive(:exec)
|
56
|
+
$AWT_TASKS.store(:example, mock)
|
57
|
+
cli.execute
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#parse_opt" do
|
62
|
+
it "should set task_name" do
|
63
|
+
expect(cli.instance_eval{@task_name}).to eq(:example)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should set hosts" do
|
67
|
+
expect(cli.instance_eval{@hosts}).to eq(["host1", "host2"])
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set user" do
|
71
|
+
expect(cli.instance_eval{@options[:user]}).to eq("awt")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should set port" do
|
75
|
+
expect(cli.instance_eval{@options[:port]}).to eq(30022)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should set port" do
|
79
|
+
expect(cli.instance_eval{@options[:key]}).to eq("/path/to/id_rsa")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should set task file" do
|
83
|
+
expect(cli.instance_eval{@task_file}).to eq("Awtfile")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#register_targets" do
|
88
|
+
before {$AWT_TARGETS.clear}
|
89
|
+
|
90
|
+
it "should add targets" do
|
91
|
+
cli.send(:register_targets, cli.instance_eval{@hosts})
|
92
|
+
expect($AWT_TARGETS.size).to eq(2)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe ".#start" do
|
97
|
+
it "should call Awt::CLI#execute" do
|
98
|
+
Awt::CLI.any_instance.should_receive(:execute)
|
99
|
+
Awt::CLI.start
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should print error message if raise error" do
|
103
|
+
Awt::CLI.any_instance.should_receive(:execute).and_raise("error")
|
104
|
+
expect(
|
105
|
+
capture(:stdout){
|
106
|
+
Awt::CLI.start
|
107
|
+
}.chomp
|
108
|
+
).to eq("error")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/spec/awt/server_spec.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Awt::Server do
|
4
|
+
let(:server) {Awt::Server.new}
|
5
|
+
let(:ssh) {double("Net::SSH mock").as_null_object}
|
6
|
+
let(:scp) {double("Net::SCP mock").as_null_object}
|
7
|
+
let(:local) {"/local/file"}
|
8
|
+
let(:remote) {"/remote/file"}
|
9
|
+
|
4
10
|
describe "#initialize" do
|
5
11
|
context "with default params" do
|
6
|
-
let(:server) {Awt::Server.new}
|
7
|
-
|
8
12
|
it "should set default host" do
|
9
13
|
expect(server.host).to eq("localhost")
|
10
14
|
end
|
@@ -50,9 +54,6 @@ describe Awt::Server do
|
|
50
54
|
end
|
51
55
|
|
52
56
|
describe "#run" do
|
53
|
-
let(:server) {Awt::Server.new}
|
54
|
-
let(:ssh) {double("Net::SSH mock").as_null_object}
|
55
|
-
|
56
57
|
before do
|
57
58
|
Net::SSH.stub(:start).and_yield(ssh)
|
58
59
|
Awt::Printer.any_instance.stub(:print_run)
|
@@ -66,13 +67,69 @@ describe Awt::Server do
|
|
66
67
|
Awt::Printer.any_instance.should_receive(:print_out)
|
67
68
|
end
|
68
69
|
|
69
|
-
it "should call Net::SSH
|
70
|
+
it "should call #exec! of Net::SSH" do
|
70
71
|
ssh.should_receive(:exec!)
|
71
72
|
end
|
72
73
|
|
73
|
-
it "should
|
74
|
+
it "should call #reset_printer_host" do
|
75
|
+
Awt::Server.any_instance.should_receive(:reset_printer_host)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#put" do
|
80
|
+
before do
|
81
|
+
ssh.stub(:scp).and_return(scp)
|
82
|
+
Net::SSH.stub(:start).and_yield(ssh)
|
83
|
+
Awt::Printer.any_instance.stub(:print_upload)
|
84
|
+
end
|
85
|
+
|
86
|
+
after {server.put(local, remote)}
|
87
|
+
|
88
|
+
it "should call Awt::Printer#print_*" do
|
89
|
+
Awt::Printer.any_instance.should_receive(:print_upload)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should call #upload! of Net::SCP" do
|
93
|
+
scp.should_receive(:upload!)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should call #reset_printer_host" do
|
97
|
+
Awt::Server.any_instance.should_receive(:reset_printer_host)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#get" do
|
102
|
+
before do
|
103
|
+
ssh.stub(:scp).and_return(scp)
|
104
|
+
Net::SSH.stub(:start).and_yield(ssh)
|
105
|
+
Awt::Printer.any_instance.stub(:print_download)
|
106
|
+
end
|
107
|
+
|
108
|
+
after {server.get(remote, local)}
|
109
|
+
|
110
|
+
it "should call Awt::Printer#print_*" do
|
111
|
+
Awt::Printer.any_instance.should_receive(:print_download)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should call #download! of Net::SCP" do
|
115
|
+
scp.should_receive(:download!)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should call #reset_printer_host" do
|
119
|
+
Awt::Server.any_instance.should_receive(:reset_printer_host)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#reset_printer_host" do
|
124
|
+
after {server.send(:reset_printer_host)}
|
125
|
+
|
126
|
+
it "should re-set host of Printer if changed host" do
|
74
127
|
Awt::Printer.any_instance.should_receive(:host=)
|
75
128
|
server.host = "example.com"
|
76
129
|
end
|
130
|
+
|
131
|
+
it "should not re-set host of Printer" do
|
132
|
+
Awt::Printer.any_instance.should_not_receive(:host=)
|
133
|
+
end
|
77
134
|
end
|
78
135
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awt
|
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
|
- i2bskn
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-scp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,11 +98,13 @@ files:
|
|
84
98
|
- awt.gemspec
|
85
99
|
- bin/awt
|
86
100
|
- lib/awt.rb
|
101
|
+
- lib/awt/cli.rb
|
87
102
|
- lib/awt/dsl.rb
|
88
103
|
- lib/awt/printer.rb
|
89
104
|
- lib/awt/server.rb
|
90
105
|
- lib/awt/task.rb
|
91
106
|
- lib/awt/version.rb
|
107
|
+
- spec/awt/cli_spec.rb
|
92
108
|
- spec/awt/dsl_spec.rb
|
93
109
|
- spec/awt/printer_spec.rb
|
94
110
|
- spec/awt/server_spec.rb
|
@@ -115,11 +131,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
131
|
version: '0'
|
116
132
|
requirements: []
|
117
133
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.1.
|
134
|
+
rubygems_version: 2.1.6
|
119
135
|
signing_key:
|
120
136
|
specification_version: 4
|
121
137
|
summary: Awt is cli tool for system administration.
|
122
138
|
test_files:
|
139
|
+
- spec/awt/cli_spec.rb
|
123
140
|
- spec/awt/dsl_spec.rb
|
124
141
|
- spec/awt/printer_spec.rb
|
125
142
|
- spec/awt/server_spec.rb
|