class Inception::Cli

Public Instance Methods

configure_provider() click to toggle source
# File lib/inception/cli.rb, line 96
def configure_provider
  save_settings!
  provider_cli = Cyoi::Cli::Provider.new([settings_dir])
  provider_cli.execute!
  reload_settings!
end
converge_cookbooks() click to toggle source

Perform converge chef cookbooks upon inception server Does not update settings

# File lib/inception/cli.rb, line 133
def converge_cookbooks
  if @next_deploy_actions.skip_chef_converge?
    header "Prepare inception server", skip: "Requested to be skipped on this deploy."
  else
    header "Prepare inception server"
    server = InceptionServer.new(provider_client, settings.inception, settings_ssh_dir)
    cookbook = InceptionServerCookbook.new(server, settings, settings_dir)
    cookbook.prepare
    settings.set("cookbook.prepared", true)
    save_settings!
    cookbook.converge
  end
end
delete() click to toggle source

method_option :“non-interactive”, aliases: [“-n”], type: :boolean, desc: “Don't ask questions, just get crankin'”

# File lib/inception/cli.rb, line 40
def delete
  migrate_old_settings
  perform_delete(options[:"non-interactive"])
end
deploy() click to toggle source
# File lib/inception/cli.rb, line 30
def deploy
  migrate_old_settings
  configure_provider
  prepare_deploy_settings
  perform_deploy
  converge_cookbooks
end
perform_delete(non_interactive) click to toggle source
# File lib/inception/cli.rb, line 147
def perform_delete(non_interactive)
  server = InceptionServer.new(provider_client, settings.inception, settings_ssh_dir)
  header "Deleting inception server, volumes and releasing IP address"
  server.delete_all
ensure
  # after any error handling, still save the current InceptionServer state back into settings.inception
  settings["inception"] = server.export_attributes
  settings.delete("cookbook")
  save_settings!
end
perform_deploy() click to toggle source
# File lib/inception/cli.rb, line 116
def perform_deploy
  header "Provision inception server"
  server = InceptionServer.new(provider_client, settings.inception, settings_ssh_dir)
  server.create
ensure
  # after any error handling, still save the current InceptionServer state back into settings.inception
  settings["inception"] = server.export_attributes
  save_settings!
end
prepare_deploy_settings() click to toggle source

update settings.git.name/git.email from local ~/.gitconfig if available provision public IP address for inception server if not allocated one Note: helper methods are in inception/cli_helpers/prepare_deploy_settings.rb

# File lib/inception/cli.rb, line 106
def prepare_deploy_settings
  header "Preparing deployment settings"
  update_git_config
  provision_or_reuse_public_ip_address_for_inception unless settings.exists?("inception.provisioned.ip_address")
  recreate_key_pair_for_inception unless settings.exists?("inception.key_pair.private_key")
  recreate_private_key_file_for_inception
  validate_deploy_settings
  setup_next_deploy_actions
end
run_ssh_command_or_open_tunnel(cmd) click to toggle source
# File lib/inception/cli.rb, line 158
def run_ssh_command_or_open_tunnel(cmd)
  recreate_private_key_file_for_inception
  unless settings.exists?("inception.provisioned.host")
    exit "inception server has not finished launching; run to complete: inception deploy"
  end

  server = InceptionServer.new(provider_client, settings.inception, settings_ssh_dir)
  username = settings.inception.provisioned.username
  host = settings.inception.provisioned.host
  result = system Escape.shell_command(["ssh", "-i", server.private_key_path, "#{username}@#{host}", cmd].flatten.compact)
  exit result
end
setup_next_deploy_actions() click to toggle source
# File lib/inception/cli.rb, line 126
def setup_next_deploy_actions
  settings["next_deploy_actions"] ||= {}
  @next_deploy_actions = NextDeployActions.new(settings.next_deploy_actions, options)
end
share_ssh(name=settings.inception.name) click to toggle source
# File lib/inception/cli.rb, line 65
    def share_ssh(name=settings.inception.name)
      user = settings.inception.provisioned.username
      host = settings.inception.provisioned.host
      private_key_path = "~/.ssh/#{name}"
      private_key = settings.inception.key_pair.private_key
      say <<-EOS
To access the inception server, add the following to your ~/.ssh/config

  Host #{name}
    User #{user}
    Hostname #{host}
    IdentityFile #{private_key_path}

Create a file #{private_key_path} with all the lines below:

#{private_key}

Change the private key to be read-only to you:

  $ chmod 700 ~/.ssh
  $ chmod 600 #{private_key_path}

You can now access the inception server running either:

  $ ssh #{name}
  $ ssh #{name} -t "tmux attach || tmux new-session"

EOS
    end
ssh(cmd=nil) click to toggle source
# File lib/inception/cli.rb, line 49
def ssh(cmd=nil)
  migrate_old_settings
  run_ssh_command_or_open_tunnel(cmd)
end
tmux() click to toggle source
# File lib/inception/cli.rb, line 59
def tmux
  migrate_old_settings
  run_ssh_command_or_open_tunnel(["-t", "tmux attach || tmux new-session"])
end