blackstack-nodes 1.2.4 → 1.2.8

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 +25 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b715095e772fb75530a3e4340f703a8581b6784f3596cfa412a7528fbd2a865
4
- data.tar.gz: ce11f94afead91279cd7e5e1a793c8030c42bfc17f35dee3a5806d4e56460b29
3
+ metadata.gz: 7dfff9ef5d2e94244befce50fd7dff63ff570be36b54da12e550ef100841c2de
4
+ data.tar.gz: fa9f19672395322af75efafc19d09add8ddc86e510125f4f37433ef7c9c1bd29
5
5
  SHA512:
6
- metadata.gz: 277fd5c174de605aca61735767fcdfbd3643b48663cef5132a4d08c94d5a654374fac6c86c003f98632e55f2eefeab19a23c801e7b7cf3df9b67f0b7b17701da
7
- data.tar.gz: 9f068a0b5852259d7e5c79a1f1e1c3647b53bcbdea66d8f1b0c05361629cbe88872cdace540bf14dec94685c268823bccea6f2561895fe04ee5c6060ea82222c
6
+ metadata.gz: 18abefb039af30eddfca6d081b563b053205e35ee209adb26b1c5e85c3bad8b9ba44198f62552bcc15a76aa5e53d571096881571451d04c4861df60bfbaf1f92
7
+ data.tar.gz: '08df674fc7bcc63bbf792a53d57473bffdd12cc5b72a716ca9b2782e58317e940070b05df16400588d5ab2199827038a0aaa63aa3b3902a15be86abbbfae7257'
@@ -1,4 +1,5 @@
1
1
  require 'net/ssh'
2
+ require 'shellwords'
2
3
  require 'simple_cloud_logging'
3
4
  #
4
5
  module BlackStack
@@ -33,7 +34,7 @@ module BlackStack
33
34
  errors << "The parameter h[:ssh_username] is not a string" unless h[:ssh_username].is_a?(String)
34
35
 
35
36
  # if the parameter h has a key :ssh_private_key_file
36
- if h.has_key?(:ssh_private_key_file)
37
+ if h.has_key?(:ssh_private_key_file) && !h[:ssh_private_key_file].nil?
37
38
  # validate: the parameter h[:ssh_private_key_file] is a string
38
39
  errors << "The parameter h[:ssh_private_key_file] is not a string" unless h[:ssh_private_key_file].is_a?(String)
39
40
 
@@ -104,13 +105,28 @@ module BlackStack
104
105
  self.ssh.close
105
106
  end
106
107
 
107
- def exec(command)
108
- s = nil
109
- if self.using_password?
110
- s = self.ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c '#{command.gsub("'", "\\'")}'")
111
- elsif self.using_private_key_file?
112
- s = self.ssh.exec!("sudo -S su root -c '#{command.gsub("'", "\\'")}'")
108
+ def exec(command, sudo=true)
109
+ code = nil
110
+ if sudo
111
+ if self.using_password?
112
+ code = "echo '#{self.ssh_password}' | sudo -S su root -c '#{command}'"
113
+ elsif self.using_private_key_file?
114
+ code = "sudo -S su root -c '#{command}'"
115
+ end
116
+ else
117
+ code = command
113
118
  end
119
+ #puts
120
+ #puts
121
+ #puts code
122
+ #puts
123
+ #puts
124
+ s = self.ssh.exec!(code)
125
+ #puts
126
+ #puts
127
+ #puts s
128
+ #puts
129
+ #puts
114
130
  s
115
131
  end # def exec
116
132
 
@@ -124,7 +140,7 @@ module BlackStack
124
140
  logger.logs 'reboot... '
125
141
  #stdout = host.reboot
126
142
  begin
127
- stdout = host.ssh.exec!("echo '#{host.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'reboot'")
143
+ stdout = self.exec("reboot")
128
144
  rescue
129
145
  end
130
146
  logger.done #logf("done (#{stdout})")
@@ -150,6 +166,7 @@ module BlackStack
150
166
  raise 'reboot failed' if !success
151
167
  end # def reboot
152
168
 
169
+
153
170
  end # module NodeModule
154
171
 
155
172
  # TODO: declare these classes (stub and skeleton) using blackstack-rpc
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.4
4
+ version: 1.2.8
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-05-31 00:00:00.000000000 Z
11
+ date: 2022-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh