blackstack-nodes 1.2.12 → 1.2.14

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 +26 -33
  3. metadata +2 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc21a5ad0c4b17836d8f63f5adf7b376ae8e274135b6371e40ee263cc7181aa7
4
- data.tar.gz: 4bfe763d33a8bded730860508dc66ce97177d8718f13a80a998f90f09929e7e1
3
+ metadata.gz: 4ed42ce28e323788e17215ca87fc900d25493a140adce92d38c5eac9d0469ce8
4
+ data.tar.gz: 4de3f22c58fb77ea176e6697594be8f44beb4079d1acb6b2a5e722f46be3ddd3
5
5
  SHA512:
6
- metadata.gz: bc436cf1f7378481b0064cd8fb1b464e4c3a833b682cbcc1bfe72cd6dce85b839f7b09318325ec4bc1da26e64e947873755a05d161b8cca9083f2cc68f21e690
7
- data.tar.gz: 4886dbf65cdbed4e5a7eb31eccf4f216b83163f5dd18c25ad6f069e672b4c4af8f3d0953d3a9ff174ad10a28b3dff5938e5544c501d2421b5e7a16dab74c9cfd
6
+ metadata.gz: a0ca565b5076a4c50f1a7ac8ceacc81821ffa6147795c3ee24427e115910fe57f7ca6794a153358498fa6f96020619fafa22d48c34b137d2280c94a2b6489114
7
+ data.tar.gz: '080428a73ccbb5b9cb189b32ea114ec9f7e1c93ec3a266ba42f5e21aed39566cf00616eb3d97bde1460dc1f9dd8ebaebd641894840c3836949492d15d75c1390'
@@ -76,7 +76,7 @@ module BlackStack
76
76
  self.tags = []
77
77
  end
78
78
  # create a logger
79
- self.logger = !i_logger.nil? ? i_logger : BlackStack::BaseLogger.new(nil)
79
+ self.logger = !i_logger.nil? ? i_logger : BlackStack::DummyLogger.new(nil)
80
80
  end # def self.create(h)
81
81
 
82
82
  def to_hash
@@ -117,26 +117,30 @@ module BlackStack
117
117
  self.ssh.close
118
118
  end
119
119
 
120
- def code(command, sudo=true)
121
- s = nil
122
- if sudo
123
- command.gsub!(/'/, "\\\\'")
124
- if self.using_password?
125
- s = "echo '#{self.ssh_password.gsub(/'/, "\\\\'")}' | sudo -S su root -c '#{command}'"
126
- elsif self.using_private_key_file?
127
- s = "sudo -S su root -c '#{command}'"
128
- end
129
- else
130
- s = command
120
+ def exec(
121
+ command,
122
+ output_file: "~/bash-command-stdout-buffer",
123
+ error_file: "~/bash-command-stderr-buffer"
124
+ )
125
+ # Construct the remote command with redirection for stdout and stderr
126
+ remote_command = "#{command} > #{output_file} 2> #{error_file}"
127
+
128
+ # Execute the command on the remote server
129
+ self.ssh.exec!("truncate -s 0 #{output_file} #{error_file} && #{remote_command}")
130
+
131
+ # Retrieve the content of the error file from the remote server
132
+ error_content = self.ssh.exec!("cat #{error_file}").to_s.chomp
133
+
134
+ # Check if the error file has any content
135
+ unless error_content.empty?
136
+ # Raise an exception with the error message
137
+ raise "Command failed with the following error:\n#{error_content}"
131
138
  end
132
- s
133
- end
134
139
 
135
- def exec(command, sudo=true)
136
- code = self.code(command, sudo)
137
- s = self.ssh.exec!(code)
138
- s
139
- end # def exec
140
+ # Retrieve and return the content of the output file from the remote server
141
+ # truncate any last newline character
142
+ self.ssh.exec!("cat #{output_file}").to_s.chomp
143
+ end
140
144
 
141
145
  def reboot()
142
146
  tries = 0
@@ -178,7 +182,7 @@ module BlackStack
178
182
  def usage()
179
183
  ret = {}
180
184
 
181
- self.connect
185
+ #self.connect
182
186
 
183
187
  ret[:b_total_memory] = self.ssh.exec!('cat /proc/meminfo | grep MemTotal').delete('^0-9').to_i*1024
184
188
  ret[:kb_total_memory] = ret[:b_total_memory] / 1024
@@ -221,17 +225,14 @@ module BlackStack
221
225
  # mapping lan attributes
222
226
  ret[:net_mac_address] = self.ssh.exec!('ifconfig | grep ether').split[1].upcase.strip.gsub(':', '-')
223
227
 
224
- self.disconnect
228
+ #self.disconnect
225
229
 
226
230
  ret
227
231
  end # def usage
228
232
 
229
233
  # return the latest `n`` lines of the file specified by the `filename` parameter
230
234
  def tail(filename, n=10)
231
- self.connect
232
- s = self.ssh.exec!("tail -n #{n.to_s} #{filename}")
233
- self.disconnect
234
- s
235
+ self.ssh.exec!("tail -n #{n.to_s} #{filename}")
235
236
  end
236
237
 
237
238
  end # module NodeModule
@@ -244,13 +245,5 @@ module BlackStack
244
245
  class Node
245
246
  include NodeModule
246
247
  end # class Node
247
- =begin
248
- # Node Skeleton
249
- # This class represents a node, with connection to the database.
250
- # Use this class at the server side.
251
- class Node < Sequel::Model(:node)
252
- include NodeModule
253
- end
254
- =end
255
248
  end # module Infrastructure
256
249
  end # module BlackStack
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.12
4
+ version: 1.2.14
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: 2022-12-11 00:00:00.000000000 Z
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 6.1.0
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 6.1.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: 6.1.0
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 6.1.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: simple_cloud_logging
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -37,9 +31,6 @@ dependencies:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
33
  version: 1.2.2
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.2.2
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +38,6 @@ dependencies:
47
38
  - - "~>"
48
39
  - !ruby/object:Gem::Version
49
40
  version: 1.2.2
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 1.2.2
53
41
  description: "BlackStack Nodes is a simple library to managing a computer remotely
54
42
  via SSH, and perform some common operations.\nThis library is used and extended
55
43
  by many others like: \n- [BlackStack Deployer](https://github.com/leandrosardi/blackstack-deployer)\n-