class Ec2ssh::Command::Init
Public Class Methods
new(cli)
click to toggle source
Calls superclass method
Ec2ssh::Command::Base::new
# File lib/ec2ssh/command/init.rb, line 8 def initialize(cli) super end
Public Instance Methods
init_dotfile()
click to toggle source
# File lib/ec2ssh/command/init.rb, line 21 def init_dotfile if File.exist?(dotfile_path) cli.yellow "Warning: #{dotfile_path} already exists." return end write_dotfile_example cli.green "Generated #{dotfile_path}" cli.yellow "Please check and edit #{dotfile_path} before run `ec2ssh update`" end
init_ssh_config()
click to toggle source
# File lib/ec2ssh/command/init.rb, line 52 def init_ssh_config if ssh_config.mark_exist? raise MarkAlreadyExists else ssh_config.append_mark! cli.green "Added mark to #{ssh_config_path}" end end
run()
click to toggle source
# File lib/ec2ssh/command/init.rb, line 12 def run begin init_ssh_config rescue DotfileNotFound init_dotfile retry end end
ssh_config()
click to toggle source
# File lib/ec2ssh/command/init.rb, line 61 def ssh_config @ssh_config ||= SshConfig.new(ssh_config_path) end
write_dotfile_example()
click to toggle source
# File lib/ec2ssh/command/init.rb, line 33 def write_dotfile_example example = <<-DOTFILE path '#{ENV['HOME']}/.ssh/config' profiles 'default', 'myprofile' regions ENV['AWS_REGION'] || ENV['AMAZON_REGION'] || ENV['AWS_DEFAULT_REGION'] || 'us-east-1' # Enable regions as you like # regions *%w(ap-northeast-1 ap-southeast-1 ap-southeast-2 eu-west-1 sa-east-1 us-east-1 us-west-1 us-west-2) # You can use methods of AWS::EC2::Instance. # See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html host_line <<END Host <%= tag('Name') %>.<%= placement.availability_zone %> HostName <%= public_dns_name || private_ip_address %> END DOTFILE File.open(dotfile_path, 'w') {|f| f.write example } end