lib/gogetit/util.rb in gogetit-0.12.3 vs lib/gogetit/util.rb in gogetit-0.12.4
- old
+ new
@@ -7,14 +7,27 @@
require 'timeout'
module Gogetit
module Util
def run_command(cmd)
- logger.info("Calling <#{__method__.to_s}> to run #{cmd}")
+ logger.info("Calling <#{__method__.to_s}> to run '#{cmd}'")
system(cmd)
end
+ def get_provider_of(name, providers)
+ if providers[:lxd].container_exists?(name)
+ logger.info("Calling <#{__method__.to_s}>, It is a LXD container.")
+ return 'lxd'
+ elsif providers[:libvirt].domain_exists?(name)
+ logger.info("Calling <#{__method__.to_s}>, It is a KVM domain.")
+ return 'libvirt'
+ else
+ puts "#{name} is not found"
+ return nil
+ end
+ end
+
def is_port_open?(ip, port)
logger.info("Calling <#{__method__.to_s}> to check #{ip}:#{port}")
begin
Timeout::timeout(1) do
begin
@@ -40,15 +53,15 @@
http = Net::HTTP.new(uri.host, uri.port)
res = http.request_post(uri.path, nil)
if res.code == "200"
res.body
else
- logger.info("Unable to reach the content of #{url}.")
+ logger.error("Unable to reach the content of #{url}.")
false
end
else
- logger.info("Unable to reach the server: #{uri.host} or port: #{uri.port}.")
+ logger.error("Unable to reach the server: #{uri.host} or port: #{uri.port}.")
false
end
end
def knife_bootstrap(name, provider, config)
@@ -138,22 +151,9 @@
if system('knife ssl check')
puts "Deleting node #{name}.."
system("knife node delete -y #{name}")
puts "Deleting client #{name}.."
system("knife client delete -y #{name}")
- end
- end
- end
-
- def recognize_env
- thedir = 'lib/env'
- gateway = get_gateway(4)
- Dir.foreach(thedir) do |item|
- if item.match(/\.json$/)
- env_data = JSON.parse(File.read(thedir+'/'+item))
- if gateway =~ Regexp.new(env_data['regexp_pattern'])
- return env_data['name']
- end
end
end
end
def get_gateway(version)