class ManicBaker::Cli
Public Instance Methods
bootstrap()
click to toggle source
# File lib/manic_baker/cli.rb, line 50 def bootstrap check_dataset check_servers remote.upload("#{script_path}/", "script/") remote.system!("script/bootstrap.sh") say_message_for(:bootstrap, :success, dataset_servers.first.name) end
chef()
click to toggle source
# File lib/manic_baker/cli.rb, line 60 def chef check_dataset check_servers install_cookbooks if cheffile_exists? remote_config.run_chef say_message_for(:chef, :success, dataset_servers.first.name) end
launch(dataset = nil)
click to toggle source
# File lib/manic_baker/cli.rb, line 15 def launch(dataset = nil) unless dataset.nil? config.dataset = dataset config.save end check_dataset check_no_servers say_message_for(:start, :success, config.dataset) joyent.servers.create(config.to_hash) say_waiting_until { dataset_servers.first.state == "running" } say_message_for(:start, :success, dataset_servers.first.name) end
panic()
click to toggle source
# File lib/manic_baker/cli.rb, line 31 def panic check_dataset check_servers dataset_servers.each { |s| say_message_for(:stop, :success, s.name) } dataset_servers.each(&:destroy) say_waiting_until { !any_running? } say_message_for(:terminate, :success) end
snapshot(name)
click to toggle source
# File lib/manic_baker/cli.rb, line 70 def snapshot(name) check_dataset check_servers check_no_snapshot_named(name) joyent.snapshots.create(dataset_servers.first.id, name) say_message_for(:snapshot, :success, dataset_servers.first.name, name) end
ssh()
click to toggle source
# File lib/manic_baker/cli.rb, line 42 def ssh check_dataset check_servers exec("ssh -i #{config.private_key_path} root@#{dataset_servers.first.public_ip_address}") end
Private Instance Methods
any_running?()
click to toggle source
# File lib/manic_baker/cli.rb, line 93 def any_running? dataset_servers.any? do |server| begin server.reload server.state == "running" rescue Excon::Errors::Gone false end end end
check_dataset()
click to toggle source
# File lib/manic_baker/cli.rb, line 104 def check_dataset if config.dataset.nil? raise Thor::Error.new("requires a dataset the first time out") end end
check_no_servers()
click to toggle source
# File lib/manic_baker/cli.rb, line 116 def check_no_servers unless dataset_servers.empty? raise Thor::Error.new("cannot clobber an existing instance") end end
check_no_snapshot_named(name)
click to toggle source
# File lib/manic_baker/cli.rb, line 122 def check_no_snapshot_named(name) if dataset_servers.first.snapshots.any? { |s| s.name == name } raise Thor::Error.new("there is already a snapshot called #{name}") end end
check_servers()
click to toggle source
# File lib/manic_baker/cli.rb, line 110 def check_servers if dataset_servers.empty? raise Thor::Error.new("found zero servers with dataset #{config.dataset}") end end
cheffile_exists?()
click to toggle source
# File lib/manic_baker/cli.rb, line 81 def cheffile_exists? File.exists?(File.expand_path("../Cheffile", config_path)) end
dataset_servers()
click to toggle source
# File lib/manic_baker/cli.rb, line 132 def dataset_servers joyent.servers.reload.select do |server| server.dataset == config.dataset end end
install_cookbooks()
click to toggle source
# File lib/manic_baker/cli.rb, line 85 def install_cookbooks Dir.chdir(File.dirname(config_path)) do Librarian::Chef::Cli.with_environment do Librarian::Chef::Cli.new.install end end end
say_waiting_until() { || ... }
click to toggle source
# File lib/manic_baker/cli.rb, line 138 def say_waiting_until say_waiting say_until(".", nil, false) do yield.tap do |all_done| unless all_done say_boring if rand < 0.1 sleep 1 end end
script_path()
click to toggle source
# File lib/manic_baker/cli.rb, line 128 def script_path File.expand_path("../../../script", __FILE__) end