blackstack-nodes 1.2.15 → 1.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/blackstack-nodes.rb +38 -15
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baa210daeea5b1e58fb15147e50003cef8e154085926c2b85cc80701965d3c92
4
- data.tar.gz: d68c0e01dcd790b4bc3032f25bc7b8159cb1287260ce7c41b00eed02ee176553
3
+ metadata.gz: 45a726611b5bad35e0d76252b517c2ddc39628bb140e7f497292b0a65992ad54
4
+ data.tar.gz: f1d1662260d1d18251069b5ca5ef67253d837086f299fc688c3d90e1c68483eb
5
5
  SHA512:
6
- metadata.gz: 74e04021b9f39eb587a0a2471e2bf1406dca2be895e65af0316c0dc89a94652148ac1a16c6ab5b16cc073f5b4cfa0bbf0414e13961357e5695e7a834e98eeec8
7
- data.tar.gz: ab8d5169af5376d2c6e52251a4b1e4b76c9e45187ec1db42dd18741a8eaf1a2865293bfda6f68bdb279f42ed9ea75b617240dfe70eab04ff09992ef3182c6dea
6
+ metadata.gz: df3fd698e785fdad3139a7fbfcdf5a45569e13a98bbd07ca3a296b051a6fe195fb6909d548c8425761e0b6632aa56f176aa1bffe740349a6a8b9a9ae85a552e0
7
+ data.tar.gz: b48d4d6cef656baa41cbeb79c39c357d25df02cbb8e9c00118107682e4033b89f8cf0efd720248bac8d4af4258a5ed3c55aec5827ea1d547c251f4465c9cc31a
@@ -8,7 +8,7 @@ module BlackStack
8
8
  # this module has attributes an methods used by both classes Node and Node.
9
9
  module NodeModule
10
10
  # :name is this is just a descriptive name for the node. It is not the host name, nor the domain, nor any ip.
11
- attr_accessor :name, :net_remote_ip, :ssh_username, :ssh_password, :ssh_port, :ssh_private_key_file, :tags
11
+ attr_accessor :name, :ip, :ssh_username, :ssh_password, :ssh_port, :ssh_private_key_file, :tags
12
12
  # non-database attributes, used for ssh connection and logging
13
13
  attr_accessor :ssh, :logger
14
14
 
@@ -24,8 +24,8 @@ module BlackStack
24
24
  # validate: the parameter h[:name] is a string
25
25
  errors << "The parameter h[:name] is not a string" unless h[:name].is_a?(String)
26
26
 
27
- # validate: the paramerer h has a key :net_remote_ip
28
- errors << "The parameter h does not have a key :net_remote_ip" unless h.has_key?(:net_remote_ip)
27
+ # validate: the paramerer h has a key :ip
28
+ errors << "The parameter h does not have a key :ip" unless h.has_key?(:ip)
29
29
 
30
30
  # validate: the paramerer h has a key :ssh_username
31
31
  errors << "The parameter h does not have a key :ssh_username" unless h.has_key?(:ssh_username)
@@ -64,7 +64,7 @@ module BlackStack
64
64
  raise "The node descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0
65
65
  # map attributes
66
66
  self.name = h[:name]
67
- self.net_remote_ip = h[:net_remote_ip]
67
+ self.ip = h[:ip]
68
68
  self.ssh_username = h[:ssh_username]
69
69
  self.ssh_password = h[:ssh_password]
70
70
  self.ssh_port = h[:ssh_port]
@@ -82,7 +82,7 @@ module BlackStack
82
82
  def to_hash
83
83
  {
84
84
  :name => self.name,
85
- :net_remote_ip => self.net_remote_ip,
85
+ :ip => self.ip,
86
86
  :ssh_username => self.ssh_username,
87
87
  :ssh_password => self.ssh_password,
88
88
  :ssh_port => self.ssh_port,
@@ -93,20 +93,40 @@ module BlackStack
93
93
 
94
94
  # return true if the node is all set to connect using ssh user and password.
95
95
  def using_password?
96
- !self.net_remote_ip.nil? && !self.ssh_username.nil? && !self.ssh_password.nil?
96
+ !self.ip.nil? && !self.ssh_username.nil? && !self.ssh_password.nil?
97
97
  end
98
98
 
99
99
  # return true if the node is all set to connect using a private key file.
100
100
  def using_private_key_file?
101
- !self.net_remote_ip.nil? && !self.ssh_username.nil? && !self.ssh_private_key_file.nil?
101
+ !self.ip.nil? && !self.ssh_username.nil? && !self.ssh_private_key_file.nil?
102
102
  end
103
103
 
104
+ # Returns true if the SSH connection is not established or inactive
105
+ def disconnected?
106
+ self.ssh.nil? || self.ssh.closed?
107
+ end
108
+
109
+ # Returns true if the SSH connection is established
110
+ def connected?
111
+ !disconnected?
112
+ end
113
+
114
+ #
104
115
  def connect
105
116
  # connect
106
117
  if self.using_password?
107
- self.ssh = Net::SSH.start(self.net_remote_ip, self.ssh_username, :password => self.ssh_password, :port => self.ssh_port)
118
+ self.ssh = Net::SSH.start(
119
+ self.ip,
120
+ self.ssh_username,
121
+ :password => self.ssh_password,
122
+ :port => self.ssh_port,
123
+ :verify_host_key => :never, # Disable host key verification
124
+ :non_interactive => true, # Ensure non-interactive mode
125
+ :timeout => 10, # Set a connection timeout (in seconds)
126
+ #:verbose => :debug # Enable verbose logging
127
+ )
108
128
  elsif self.using_private_key_file?
109
- self.ssh = Net::SSH.start(self.net_remote_ip, self.ssh_username, :keys => self.ssh_private_key_file, :port => self.ssh_port)
129
+ self.ssh = Net::SSH.start(self.ip, self.ssh_username, :keys => self.ssh_private_key_file, :port => self.ssh_port)
110
130
  else
111
131
  raise "No ssh credentials available"
112
132
  end
@@ -128,16 +148,19 @@ module BlackStack
128
148
  #
129
149
  def exec(
130
150
  command,
131
- output_file: "~/.bash-command-stdout-buffer",
132
- error_file: "~/.bash-command-stderr-buffer",
133
- exit_code_file: "~/.bash-command-exit-code"
151
+ output_file: "$HOME/.bash-command-stdout-buffer",
152
+ error_file: "$HOME/.bash-command-stderr-buffer",
153
+ exit_code_file: "$HOME/.bash-command-exit-code"
134
154
  )
135
155
  # Construct the remote command with redirection for stdout, stderr, and capturing exit code
136
156
  remote_command = "#{command} > #{output_file} 2> #{error_file}; echo $? > #{exit_code_file}"
137
-
157
+
138
158
  # Execute the command on the remote server, truncating output, error, and exit code files
139
- self.ssh.exec!("truncate -s 0 #{output_file} #{error_file} #{exit_code_file} && #{remote_command}")
140
-
159
+ self.ssh.exec!("truncate -s 0 #{output_file} #{error_file} #{exit_code_file}")
160
+
161
+ # Execute the command on the remote server, truncating output, error, and exit code files
162
+ self.ssh.exec!(remote_command)
163
+
141
164
  # Retrieve the exit code
142
165
  exit_code = self.ssh.exec!("cat #{exit_code_file}").to_s.chomp.to_i
143
166
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackstack-nodes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.15
4
+ version: 1.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-20 00:00:00.000000000 Z
11
+ date: 2024-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh