Module: HttpdConfigmapGenerator::Base::Network
- Included in:
- HttpdConfigmapGenerator::Base
- Defined in:
- lib/httpd_configmap_generator/base/network.rb
Constant Summary collapse
- HOSTNAME_COMMAND =
"/usr/bin/hostname".freeze
Instance Method Summary collapse
- #domain ⇒ Object
- #domain_from_host(host) ⇒ Object
- #fetch_network_file(source_file, target_file) ⇒ Object
- #host_reachable?(host) ⇒ Boolean
- #realm ⇒ Object
- #update_hostname(host) ⇒ Object
Instance Method Details
#domain ⇒ Object
10 11 12 |
# File 'lib/httpd_configmap_generator/base/network.rb', line 10 def domain domain_from_host(opts[:host]) end |
#domain_from_host(host) ⇒ Object
14 15 16 |
# File 'lib/httpd_configmap_generator/base/network.rb', line 14 def domain_from_host(host) host.gsub(/^([^.]+\.)/, '') if host.present? && host.include?('.') end |
#fetch_network_file(source_file, target_file) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/httpd_configmap_generator/base/network.rb', line 27 def fetch_network_file(source_file, target_file) require "net/http" delete_target_file(target_file) create_target_directory(target_file) info_msg("Downloading #{source_file} ...") result = Net::HTTP.get_response(URI(source_file)) raise "Failed to fetch URL file source #{source_file}" unless result.kind_of?(Net::HTTPSuccess) File.write(target_file, result.body) end |
#host_reachable?(host) ⇒ Boolean
18 19 20 21 |
# File 'lib/httpd_configmap_generator/base/network.rb', line 18 def host_reachable?(host) require "net/ping" Net::Ping::External.new(host).ping end |
#realm ⇒ Object
6 7 8 |
# File 'lib/httpd_configmap_generator/base/network.rb', line 6 def realm domain.upcase end |
#update_hostname(host) ⇒ Object
23 24 25 |
# File 'lib/httpd_configmap_generator/base/network.rb', line 23 def update_hostname(host) command_run!(HOSTNAME_COMMAND, :params => [host]) if command_run(HOSTNAME_COMMAND).output.strip != host end |