class Anjou::UserHome
Constants
- ANJOU_LOGIN
- SSH_READY_SLEEP_INCREMENT
- SSH_READY_TIMEOUT
Public Class Methods
new(username, hostname)
click to toggle source
# File lib/anjou/user_home.rb, line 9 def initialize(username, hostname) @username = username @hostname = hostname end
Public Instance Methods
create_linux_user()
click to toggle source
# File lib/anjou/user_home.rb, line 14 def create_linux_user ssh_do "sudo adduser --disabled-password --gecos '#{@username}' #{@username}" ssh_do "echo '#{@username} ALL=(ALL) NOPASSWD:ALL' > /tmp/sudoize-#{@username}" ssh_do "sudo chown root:root /tmp/sudoize-#{@username}" ssh_do "sudo chmod 440 /tmp/sudoize-#{@username}" ssh_do "sudo mv /tmp/sudoize-#{@username} /etc/sudoers.d/" end
mount_home_dir()
click to toggle source
# File lib/anjou/user_home.rb, line 22 def mount_home_dir volume = api.user_volume_for @username device = volume.attachments.to_a.first.device.gsub(/sda/, "xvda") ssh_do "sudo mount #{device} /home/#{@username}" end
Private Instance Methods
api()
click to toggle source
# File lib/anjou/user_home.rb, line 47 def api @api ||= Anjou::EC2.new end
ensure_ssh_ready()
click to toggle source
# File lib/anjou/user_home.rb, line 56 def ensure_ssh_ready timeout = 0 until ssh_ready? do raise "SSH connection not ready after #{timeout} attempts." if timeout >= (SSH_READY_TIMEOUT / SSH_READY_SLEEP_INCREMENT) puts " ...connection not ready, waiting a bit..." sleep SSH_READY_SLEEP_INCREMENT timeout += 1 end end
ssh_cmd()
click to toggle source
# File lib/anjou/user_home.rb, line 70 def ssh_cmd @ssh_cmd ||= "ssh -o 'StrictHostKeyChecking no' #{ANJOU_LOGIN}@#{@hostname}" end
ssh_do(cmd)
click to toggle source
# File lib/anjou/user_home.rb, line 51 def ssh_do(cmd) ensure_ssh_ready `#{ssh_cmd} "#{cmd}"` end
ssh_ready?()
click to toggle source
# File lib/anjou/user_home.rb, line 66 def ssh_ready? @ssh_ready ||= `#{ssh_cmd} ls /var/lib/cloud/instance/* 2>&1`.include? 'boot-finished' end