module NexClient::Commands::Racks
Constants
- COMPUTE_RACKS_TITLE
- GATEWAY_RACKS_TITLE
- RACKS_HEADERS
- ROUTING_RACKS_TITLE
- STORAGE_RACKS_TITLE
Public Class Methods
display_compute_racks(list)
click to toggle source
# File lib/nex_client/commands/racks.rb, line 172 def self.display_compute_racks(list) table = Terminal::Table.new title: COMPUTE_RACKS_TITLE, headings: RACKS_HEADERS do |t| [list].flatten.compact.each do |e| t.add_row([ 'compute', e.id, e.vpc_region, e.stack, e.status, e.private_ip_address, '-', "#{e.used_pu}/#{e.total_pu}", e.machine_type, e.machine_id ]) end end puts table puts "\n" end
display_gateway_racks(list)
click to toggle source
# File lib/nex_client/commands/racks.rb, line 235 def self.display_gateway_racks(list) table = Terminal::Table.new title: GATEWAY_RACKS_TITLE, headings: RACKS_HEADERS do |t| [list].flatten.compact.each do |e| t.add_row([ 'gateway', e.id, e.vpc_region, '-', e.status, e.private_ip_address, e.ip_address, '-', e.machine_type, e.machine_id ]) end end puts table puts "\n" end
display_routing_racks(list)
click to toggle source
# File lib/nex_client/commands/racks.rb, line 214 def self.display_routing_racks(list) table = Terminal::Table.new title: ROUTING_RACKS_TITLE, headings: RACKS_HEADERS do |t| [list].flatten.compact.each do |e| t.add_row([ 'routing', e.id, e.vpc_region, '-', e.status, e.private_ip_address, '-', '-', e.machine_type, e.machine_id ]) end end puts table puts "\n" end
display_storage_racks(list)
click to toggle source
# File lib/nex_client/commands/racks.rb, line 193 def self.display_storage_racks(list) table = Terminal::Table.new title: STORAGE_RACKS_TITLE, headings: RACKS_HEADERS do |t| [list].flatten.compact.each do |e| t.add_row([ 'storage', e.id, e.vpc_region, '-', e.status, e.private_ip_address, '-', "#{e.used_su}/#{e.total_su}", e.machine_type, e.machine_id ]) end end puts table puts "\n" end
download(args,opts)
click to toggle source
Download a file from a container
# File lib/nex_client/commands/racks.rb, line 99 def self.download(args,opts) id = args.first remote_path = args[1] local_path = args[2] || './' rack = find_rack_by_ip(id) # Display error unless rack error("Error! Could not find rack: #{id}") return false end # Download file with_cert_identity do |username,pv_key_path| # Format server copy command cmd = format_cmd(rack.scp_cmd_template, username: username, certfile: pv_key_path, remote_path: remote_path, dst_local_file: local_path ) # Execute commands system(cmd) end end
find_rack_by_ip(ip_address)
click to toggle source
# File lib/nex_client/commands/racks.rb, line 156 def self.find_rack_by_ip(ip_address) rack = nil [ NexClient::ComputeRack, NexClient::GatewayRack, NexClient::RoutingRack, NexClient::StorageRack ].each do |server_type| rack ||= server_type.where(private_ip_address: ip_address).first || server_type.where(ip_address: ip_address).first end return rack end
list(args,opts)
click to toggle source
# File lib/nex_client/commands/racks.rb, line 15 def self.list(args,opts) filters = {} # Type filter only_type = opts.type only_type = 'compute' if opts.stack.present? # Status filter filters[:status] = opts.status || 'running' # Stack filter if opts.stack.present? filters[:stack] = opts.stack end # All option filters = {} if opts.all # Create table if !only_type || only_type == 'compute' list = NexClient::ComputeRack.where(filters).order('vpc_region,status') self.display_compute_racks(list) # Loop through results while (list.pages.links||{})['next'] return true if ask("Press enter for next page ('q' to quit)") =~ /q/ list = list.pages.next self.display_compute_racks(list) end end if !only_type || only_type == 'storage' list = NexClient::StorageRack.where(filters).order('vpc_region,status') self.display_storage_racks(list) # Loop through results while (list.pages.links||{})['next'] return true if ask("Press enter for next page ('q' to quit)") =~ /q/ list = list.pages.next self.display_storage_racks(list) end end if !only_type || only_type == 'routing' list = NexClient::RoutingRack.where(filters).order('vpc_region,status') self.display_routing_racks(list) # Loop through results while (list.pages.links||{})['next'] return true if ask("Press enter for next page ('q' to quit)") =~ /q/ list = list.pages.next self.display_routing_racks(list) end end if !only_type || only_type == 'gateway' list = NexClient::GatewayRack.where(filters).order('vpc_region,status') self.display_gateway_racks(list) # Loop through results while (list.pages.links||{})['next'] return true if ask("Press enter for next page ('q' to quit)") =~ /q/ list = list.pages.next self.display_gateway_racks(list) end end end
ssh(args,opts)
click to toggle source
# File lib/nex_client/commands/racks.rb, line 83 def self.ssh(args,opts) # Find server id = args.first rack = find_rack_by_ip(id) # Display error unless rack error("Error! Could not find rack: #{id}") return false end # Perform command perform_ssh_cmd(rack.ssh_cmd_template) end
upload(args,opts)
click to toggle source
Upload a file to the container
# File lib/nex_client/commands/racks.rb, line 127 def self.upload(args,opts) id = args.first local_path = args[1] remote_path = args[2] || "/tmp/" # Find server rack = find_rack_by_ip(id) # Display error unless rack error("Error! Could not find rack: #{id}") return false end # Upload file with_cert_identity do |username,pv_key_path| # Format server copy command cmd = format_cmd(rack.scp_cmd_template, username: username, certfile: pv_key_path, src_local_file: local_path, remote_path: remote_path ) # Execute command system(cmd) end end