class Pennyworth::CliHostController
Public Class Methods
new(config_dir, output)
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 20 def initialize(config_dir, output) @config_dir = config_dir @out = output end
Public Instance Methods
info(host_name)
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 70 def info(host_name) check_host(host_name) locker = LockService.new(host_config.lock_server_address) @out.puts(locker.info(host_name)) end
list()
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 38 def list host_config.hosts.each do |host_name| host = host_config.host(host_name) out = "#{host_name}" attributes = [] if host['address'] attributes.push("address: #{host['address']}") end if host['base_snapshot_id'] attributes.push("base snapshot id: #{host['base_snapshot_id']}") end if !attributes.empty? out += " (" + attributes.join(", ") + ")" end @out.puts(out) end end
lock(host_name)
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 56 def lock(host_name) check_host(host_name) locker = LockService.new(host_config.lock_server_address) if locker.request_lock(host_name) @out.puts "Lock acquired for host '#{host_name}'" locker.keep_lock else @out.puts "Failed to acquire lock for host '#{host_name}': " + "#{locker.info(host_name)}" end end
reset(host_name)
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 77 def reset(host_name) check_host(host_name) runner = HostRunner.new(host_name, host_config) runner.start runner.cleanup end
setup(url)
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 25 def setup(url) if !url raise GLI::BadCommandLine.new("Please provide a URL argument") end @out.puts "Setup from '#{url}'" begin HostConfig.for_directory(@config_dir).setup(url) rescue HostFileError => e @out.puts "Error: #{e}" end end
Private Instance Methods
check_host(host_name)
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 87 def check_host(host_name) if !host_name raise GLI::BadCommandLine.new("Please provide a host name argument") end if !host_config.host(host_name) raise LockError.new("Host name #{host_name} doesn't exist in " + "configuration file '#{host_config.config_file}'") end end
host_config()
click to toggle source
# File lib/pennyworth/cli_host_controller.rb, line 98 def host_config return @host_config if @host_config @host_config = HostConfig.for_directory(@config_dir) @host_config.read @host_config end