lib/gogetit/util.rb in gogetit-0.12.2 vs lib/gogetit/util.rb in gogetit-0.12.3
- old
+ new
@@ -6,16 +6,17 @@
require 'socket'
require 'timeout'
module Gogetit
module Util
- def run_command(cmd, logger)
+ def run_command(cmd)
logger.info("Calling <#{__method__.to_s}> to run #{cmd}")
system(cmd)
end
def is_port_open?(ip, port)
+ logger.info("Calling <#{__method__.to_s}> to check #{ip}:#{port}")
begin
Timeout::timeout(1) do
begin
s = TCPSocket.new(ip, port)
s.close
@@ -48,11 +49,11 @@
logger.info("Unable to reach the server: #{uri.host} or port: #{uri.port}.")
false
end
end
- def knife_bootstrap(name, provider, config, logger)
+ def knife_bootstrap(name, provider, config)
logger.info("Calling <#{__method__.to_s}>")
config[:chef][:target_environment] ||= '_default'
if find_executable 'knife'
if system('knife ssl check')
install_cmd = "curl \
@@ -69,11 +70,11 @@
system(knife_cmd)
end
end
end
- def update_databags(config, logger)
+ def update_databags(config)
logger.info("Calling <#{__method__.to_s}>")
data_bags_dir = "#{config[:chef][:chef_repo_root]}/data_bags"
puts 'Listing databags..'
databags_as_is = `knife data bag list`.split
@@ -87,20 +88,20 @@
:echo => true,
:limited_to => ['y', 'n']
)
case answer
when 'y'
- run_command("knife data bag delete -y #{bag}", logger)
+ run_command("knife data bag delete -y #{bag}")
when 'n'
puts 'Keeping..'
end
end
puts 'Checking databags to create..'
(databags_to_be - databags_as_is).each do |bag|
puts "Creating databag '#{bag}'.."
- run_command("knife data bag create #{bag}", logger)
+ run_command("knife data bag create #{bag}")
end
puts 'Checking items..'
databags_to_be.each do |bag|
items_as_is = `knife data bag show #{bag}`.split
@@ -111,32 +112,29 @@
item = item.gsub('.json', '')
if JSON.parse(File.read(item_file))['vault']
if items_as_is.include? item
run_command(
"knife vault update #{bag} #{item} --json #{item_file}"\
- " --search '*:*' -M client",
- logger
+ " --search '*:*' -M client"
)
else
run_command(
"knife vault create #{bag} #{item} --json #{item_file}"\
- " --search '*:*' -M client",
- logger
+ " --search '*:*' -M client"
)
end
run_command(
- "knife vault refresh #{bag} #{item} --clean-unknown-clients -M client",
- logger
+ "knife vault refresh #{bag} #{item} --clean-unknown-clients -M client"
)
else
- run_command("knife data bag from file #{bag} #{item_file}", logger)
+ run_command("knife data bag from file #{bag} #{item_file}")
end
end
end
end
- def knife_remove(name, logger)
+ def knife_remove(name)
logger.info("Calling <#{__method__.to_s}>")
if find_executable 'knife'
if system('knife ssl check')
puts "Deleting node #{name}.."
system("knife node delete -y #{name}")
@@ -168,54 +166,54 @@
nil
end
end
end
- def wait_until_available(ip_or_fqdn, distro_name, logger)
+ def wait_until_available(ip_or_fqdn, distro_name)
logger.info("Calling <#{__method__.to_s}>")
- until ping_available?(ip_or_fqdn, logger)
+ until ping_available?(ip_or_fqdn)
logger.info("Calling <#{__method__.to_s}> for ping to be ready..")
sleep 3
end
logger.info("#{ip_or_fqdn} is now available to ping..")
- until ssh_available?(ip_or_fqdn, distro_name, logger)
+ until ssh_available?(ip_or_fqdn, distro_name)
logger.info("Calling <#{__method__.to_s}> for ssh to be ready..")
sleep 3
end
logger.info("#{ip_or_fqdn} is now available to ssh..")
end
- def ping_available?(host, logger)
+ def ping_available?(host)
# host can be both IP and ip_or_fqdn.
logger.info("Calling <#{__method__.to_s}> for #{host}")
`ping -c 1 -W 1 #{host}`
$?.exitstatus == 0
end
- def ssh_available?(ip_or_fqdn, user, logger)
+ def ssh_available?(ip_or_fqdn, user)
logger.info("Calling <#{__method__.to_s}>")
begin
Net::SSH.start(ip_or_fqdn, user).class
rescue Exception => e
puts e
end
end
- def check_ip_available(addresses, maas, logger)
+ def check_ip_available(addresses, maas)
logger.info("Calling <#{__method__.to_s}>")
# to do a ping test
addresses.each do |ip|
- abort("#{ip} is already being used.") if ping_available?(ip, logger)
+ abort("#{ip} is already being used.") if ping_available?(ip)
end
# to check with MAAS
ifaces = maas.ip_reserved?(addresses)
abort("one of #{addresses.join(', ')} is already being used.") \
unless ifaces
return ifaces
end
- def run_through_ssh(host, distro_name, commands, logger)
+ def run_through_ssh(host, distro_name, commands)
logger.info("Calling <#{__method__.to_s}>")
Net::SSH.start(host, distro_name) do |ssh|
commands.each do |cmd|
logger.info("'#{cmd}' is being executed..")
output = ssh.exec!(cmd)