blackstack-nodes 1.2.16 → 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 +29 -9
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7030c06d185e9257db6bcf42deadcbcc1ac609f79140b8ce63f73f5368232144
4
- data.tar.gz: adc175dd676a9b3940454342016ec82b96d771f885f6ca92d26f317d5f722331
3
+ metadata.gz: 45a726611b5bad35e0d76252b517c2ddc39628bb140e7f497292b0a65992ad54
4
+ data.tar.gz: f1d1662260d1d18251069b5ca5ef67253d837086f299fc688c3d90e1c68483eb
5
5
  SHA512:
6
- metadata.gz: 2d3807f8df44577cff9d4b57329ad28e2a6216bce5566a178893ed390c2b6f943b45ddbd561b2fa793506010a586108468eb0e05c53e55ce81f36c74089bb2eb
7
- data.tar.gz: 3cf124a33af4fcffaa3fd2b642fe561774d296cc629cc67d0e9bb865425eb5688fa13bf0e68b89a0272c1c7337b1fb06490b4669c86165bd421bbc88ef68d37a
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
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.16
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-28 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