teuton 2.7.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fa647498d568e303c8c02ea44277a595f3796a404a523daf6c1b0408110de97
4
- data.tar.gz: b733858b7e97b373aca8477a359649b5e6614cdd60caffbdd052e450aa12dffa
3
+ metadata.gz: ffeca52de938d3464c4c9f4bacf4acb7fd229cc3a02daa9d653d68dfe2d65750
4
+ data.tar.gz: 96a03b03bba6ff9ca381ce1b248f93f341b9aa53c2727258032e6a8d24d42454
5
5
  SHA512:
6
- metadata.gz: 60b94cd2ef2632e1fdbe81515909be71bce35d011f739ecc97806c1cfaa8115a7b743ee4369b54dffe366f1d7b06486fe451827c2fb4ce7fd37448fbf56b549b
7
- data.tar.gz: 312bd19998b3ef68cc61780dda49cf1711033736a2593206501d5f428cd64780974a2adfc4198dd1097b178f6202637dcc10e11131c90495de553fc33547520f
6
+ metadata.gz: 8ef9650f56b556eaa91c81c04a07c0e621f9903416333a8b12ea8febb6a07e91cddeaabe80a17d9d82fdaaac337cba2af9e6aa7bc881c3801fee8f90a5ed636c
7
+ data.tar.gz: a2003337f9a7ae148b0976cdd87cd0ef1fdb255a18bec08a390adec32c94f7c13a71db9bfa83452fed93259e8d5a53db34e5bfec265831a0d3237390be2de6de
@@ -7,11 +7,23 @@
7
7
  ## Example
8
8
 
9
9
  ```ruby
10
- target "Exist user root"
10
+ target "Exist user root (exit code ok)"
11
11
  run "id root"
12
12
  expect_exit 0
13
13
 
14
- target "No user vader"
14
+ target "No user vader (exit code fail)"
15
15
  run "id vader"
16
16
  expect_exit 1
17
17
  ```
18
+
19
+ ## More examples
20
+
21
+ ```ruby
22
+ target "Using a range"
23
+ run "id vader"
24
+ expect_exit 1..3
25
+
26
+ target "Using a list"
27
+ run "id vader"
28
+ expect_exit [1, 3, 7]
29
+ ```
@@ -0,0 +1,70 @@
1
+ require "net/ssh"
2
+ require "net/sftp"
3
+ require "rainbow"
4
+ require_relative "../../utils/project"
5
+ require_relative "../../utils/verbose"
6
+ require_relative "execute_base"
7
+
8
+ class CopySSH < ExecuteBase
9
+ def call(host, localfilename)
10
+ # Check params
11
+ unless config.get("#{host}_route".to_sym) == "NODATA"
12
+ log("'copy script' requires direct host access!", :error)
13
+ return false
14
+ end
15
+
16
+ host = host.to_s
17
+
18
+ begin
19
+ if sessions[host].nil?
20
+ # Open new SSH session
21
+ ip = config.get("#{host}_ip".to_sym).to_s
22
+ username = config.get("#{host}_username".to_sym).to_s
23
+ password = config.get("#{host}_password".to_sym).to_s
24
+ port = config.get("#{host}_port".to_sym).to_i
25
+ port = 22 if port.zero?
26
+
27
+ sessions[host] = Net::SSH.start(
28
+ ip,
29
+ username,
30
+ port: port,
31
+ password: password,
32
+ keepalive: true,
33
+ timeout: 30,
34
+ non_interactive: true
35
+ )
36
+ end
37
+ if sessions[host].instance_of? Net::SSH::Connection::Session
38
+ copy_to(host, localfilename)
39
+ else
40
+ "SSH: NO CONNECTION!"
41
+ end
42
+ rescue => e
43
+ sessions[host] = :nosession
44
+ conn_status[host] = :error
45
+ log("[#{e.class}] SSH on <#{username}@#{ip}>", :error)
46
+ end
47
+ end
48
+
49
+ def copy_to(host, localfilename)
50
+ ip = get((host + "_ip").to_sym)
51
+ username = get((host + "_username").to_sym).to_s
52
+ password = get((host + "_password").to_sym).to_s
53
+ port = get((host + "_port").to_sym).to_i
54
+ port = 22 if port.zero?
55
+
56
+ localfilepath = File.join(Dir.pwd, localfilename)
57
+ remotefilepath = File.join(".", File.basename(localfilename))
58
+
59
+ # Upload a file or directory to the remote host
60
+ begin
61
+ Net::SFTP.start(ip, username, password: password, port: port) do |sftp|
62
+ sftp.upload!(localfilepath, remotefilepath)
63
+ end
64
+ rescue
65
+ log("copy file: #{localfilename} => #{remotefilepath}", :error)
66
+ return false
67
+ end
68
+ true
69
+ end
70
+ end
@@ -26,8 +26,8 @@ class ExecuteManager
26
26
  @parent.config
27
27
  end
28
28
 
29
- def log
30
- @parent.log
29
+ def log(...)
30
+ @parent.log(...)
31
31
  end
32
32
 
33
33
  def run_on(host)
@@ -95,7 +95,7 @@ class ShowReport
95
95
  puts lines[0]
96
96
  else
97
97
  lines.each do |i|
98
- if i.class.to_s == "Hash"
98
+ if i.instance_of?(::Hash)
99
99
  value = 0.0
100
100
  value = i[:weight] if i[:check]
101
101
  print tab + "%03d" % i[:id].to_i
@@ -48,7 +48,7 @@ module Formatter
48
48
  report2 = report.clone
49
49
  report2.groups.each do |group|
50
50
  group.each do |item|
51
- puts item.to_s
51
+ puts item
52
52
  end
53
53
  end
54
54
  end
@@ -1,5 +1,5 @@
1
1
  module Teuton
2
- VERSION = "2.7.0"
2
+ VERSION = "2.7.1"
3
3
  APPNAME = "teuton"
4
4
  GEMNAME = "teuton"
5
5
  DOCKERNAME = "dvarrui/#{GEMNAME}"
data/lib/teuton.rb CHANGED
@@ -41,7 +41,7 @@ module Teuton
41
41
  begin
42
42
  require_relative Project.value[:script_path]
43
43
  rescue => e
44
- warn e.to_s
44
+ warn e
45
45
  warn Rainbow.new("[FAIL ] Reading file #{Project.value[:script_path]}").red
46
46
  warn Rainbow.new("[ERROR] Syntax Error!").red
47
47
  exit 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teuton
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -281,6 +281,7 @@ files:
281
281
  - lib/teuton/case/dsl/send.rb
282
282
  - lib/teuton/case/dsl/target.rb
283
283
  - lib/teuton/case/dsl/unique.rb
284
+ - lib/teuton/case/execute/copy_ssh.rb
284
285
  - lib/teuton/case/execute/execute_base.rb
285
286
  - lib/teuton/case/execute/execute_local.rb
286
287
  - lib/teuton/case/execute/execute_manager.rb