Class: Rudy::CLI::Machines
Instance Attribute Summary
Attributes inherited from CommandBase
#config
Instance Method Summary
collapse
Methods included from Huxtable
change_environment, change_position, change_region, change_role, change_zone, #check_keys, #config_dirname, create_domain, #current_group_name, #current_machine_address, #current_machine_count, #current_machine_group, #current_machine_hostname, #current_machine_image, #current_machine_name, #current_machine_size, #current_user, #current_user_keypairpath, debug?, #debug?, domain, domain_exists?, #group_metadata, #has_keypair?, #has_keys?, #has_pem_keys?, #has_root_keypair?, keypair_path_to_name, #known_machine_group?, #root_keypairname, #root_keypairpath, #switch_user, update_config, update_global, update_logger, #user_keypairname, #user_keypairpath
Instance Method Details
#machines ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rudy/cli/machines.rb', line 8
def machines
more, less = nil, nil
less = [:environment, :role] if @option.all
rmach = Rudy::Machines.new
mlist = rmach.list(more, less) || []
if mlist.empty?
if @option.all
puts "No machines running"
else
puts "No machines running in #{current_machine_group}"
puts "Try: rudy machines --all"
end
end
mlist.each do |m|
puts @@global.verbose > 0 ? m.inspect : m.dump(@@global.format)
end
end
|
#machines_wash ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/rudy/cli/machines.rb', line 32
def machines_wash
rmach = Rudy::Machines.new
dirt = (rmach.list || []).select { |m| !m.running? }
if dirt.empty?
puts "Nothing to wash in #{rmach.current_machine_group}"
return
end
puts "The following machine metadata will be deleted:".bright
puts dirt.collect {|m| m.name.bright }
execute_check(:medium)
dirt.each do |m|
m.destroy
end
end
|
#ssh ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/rudy/cli/machines.rb', line 51
def ssh
pkey = user_keypairpath(@@global.user)
unless pkey
puts "No private key configured for #{@@global.user} in #{current_machine_group}"
end
ssh_opts = { :user => @@global.user || Rudy.sysinfo.user, :debug => nil }
if pkey
raise "Cannot find file #{pkey}" unless File.exists?(pkey)
raise InsecureKeyPermissions, @pkey unless File.stat(pkey).mode == 33152
ssh_opts[:keys] = pkey
end
if @argv.first
command, command_args = @argv.shift, @argv || []
puts "#{command} #{command_args.join(' ')}" if @@global.verbose > 1
else
command, command_args = :interactive_ssh, @option.print.nil?
end
checked = false
rudy = Rudy::Machines.new
lt = rudy.list
unless lt
puts "No machines running in #{rudy.current_machine_group}"
exit
end
lt.each do |machine|
machine.update
if @@global.quiet
print "You are #{ssh_opts[:user].to_s.bright}. " if !checked else
puts machine_separator(machine.name, machine.awsid)
puts "Connecting #{ssh_opts[:user].to_s.bright}@#{machine.dns_public} "
puts
end
if !checked && command != :interactive_ssh
execute_check(:low) if ssh_opts[:user] == "root"
checked = true
end
rbox = Rye::Box.new(machine.dns_public, ssh_opts)
ret = rbox.send(command, command_args)
puts ret unless command == :interactive_ssh
end
end
|