class Bosh::Cli::Command::Misc

Public Instance Methods

list_aliases() click to toggle source
# File lib/cli/commands/misc.rb, line 155
def list_aliases
  aliases = config.aliases(:cli) || {}
  err("No aliases found") if aliases.empty?

  sorted = aliases.sort_by { |name, _| name }
  aliases_table = table do |t|
    t.headings = %w(Alias Command)
    sorted.each { |row| t << [row[0], row[1]] }
  end

  nl
  say(aliases_table)
  nl
  say("Aliases total: %d" % aliases.size)
end
list_targets() click to toggle source
# File lib/cli/commands/misc.rb, line 127
def list_targets
  targets = config.aliases(:target) || {}

  err("No targets found") if targets.empty?

  targets_table = table do |t|
    t.headings = [ "Name", "Director URL" ]
    targets.each { |row| t << [row[0], row[1]] }
  end

  nl
  say(targets_table)
  nl
  say("Targets total: %d" % targets.size)
end
set_alias(name, command) click to toggle source
# File lib/cli/commands/misc.rb, line 146
def set_alias(name, command)
  config.set_alias(:cli, name, command.to_s.strip)
  config.save
  say("Alias '#{name.make_green}' created for command '#{command.make_green}'")
end
set_target(director_url = nil, name = nil) click to toggle source
# File lib/cli/commands/misc.rb, line 69
def set_target(director_url = nil, name = nil)
  if director_url.nil?
    show_target
    return
  end

  if name.nil?
    director_url =
      config.resolve_alias(:target, director_url) || director_url
  end

  if director_url.blank?
    err("Target name cannot be blank")
  end

  director_url = normalize_url(director_url)
  director = Bosh::Cli::Client::Director.new(director_url, nil, ca_cert: options[:ca_cert])

  begin
    status = director.get_status
  rescue Bosh::Cli::AuthError
    status = {}
  rescue Bosh::Cli::DirectorError
    err("Cannot talk to director at '#{director_url}', " +
        "please set correct target")
  end

  config.target = director_url
  config.target_name = status["name"]
  config.target_version = status["version"]
  config.target_uuid = status["uuid"]

  old_ca_cert_path = config.ca_cert
  expanded_ca_cert_path = config.save_ca_cert_path(options[:ca_cert])
  if old_ca_cert_path != expanded_ca_cert_path
    say("Updating certificate file path to '#{expanded_ca_cert_path.to_s.make_green}'")
    nl
  end

  unless name.blank?
    config.set_alias(:target, name, director_url)
  end

  unless status["uuid"].blank?
    config.set_alias(:target, status["uuid"], director_url)
  end

  config.save
  say("Target set to '#{target_name.make_green}'")

  if interactive? && !logged_in?
    redirect("login")
  end
end
status() click to toggle source
# File lib/cli/commands/misc.rb, line 14
def status
  if options[:uuid]
    begin
      say(get_director_status["uuid"])
    rescue => e
      err("Error fetching director status: #{e.message}")
    end
  else
    say("Config".make_green)
    print_value("", config.filename)

    nl
    say("Director".make_green)
    if target.nil?
      say("  not set".make_yellow)
    else
      begin
        status = get_director_status

        print_value("Name", status["name"])
        print_value("URL", target_url)
        print_value("Version", status["version"])
        print_value("User", status["user"], "not logged in")
        print_value("UUID", status["uuid"])
        print_value("CPI", status["cpi"], "n/a")
        print_feature_list(status["features"]) if status["features"]

        unless options[:target]
          config.target_name = status["name"]
          config.target_version = status["version"]
          config.target_uuid = status["uuid"]
          config.save
        end
      rescue TimeoutError
        say("  timed out fetching director status".make_red)
      rescue => e
        say("  error fetching director status: #{e.message}".make_red)
      end
    end

    nl
    say("Deployment".make_green)

    if deployment
      print_value("Manifest", deployment)
    else
      say("  not set".make_yellow)
    end
  end
end
version() click to toggle source
# File lib/cli/commands/misc.rb, line 6
def version
  say("BOSH %s" % [Bosh::Cli::VERSION])
end

Private Instance Methods

format_feature_extras(extras) click to toggle source
# File lib/cli/commands/misc.rb, line 227
def format_feature_extras(extras)
  return "" if extras.nil? || extras.empty?

  result = []
  extras.each do |name, value|
    result << "#{name}: #{value}"
  end

  "(#{result.join(", ")})"
end
format_feature_status(status, extras) click to toggle source
# File lib/cli/commands/misc.rb, line 217
def format_feature_status(status, extras)
  if status.nil?
    "n/a"
  elsif status
    "enabled #{format_feature_extras(extras)}"
  else
    "disabled"
  end
end
get_director_status() click to toggle source
# File lib/cli/commands/misc.rb, line 238
def get_director_status
  Bosh::Cli::Client::Director.new(target, credentials, ca_cert: config.ca_cert).get_status
end
print_feature_list(features) click to toggle source
print_value(label, value, if_none = nil) click to toggle source
show_target() click to toggle source
# File lib/cli/commands/misc.rb, line 182
def show_target
  if config.target
    if interactive?
      if config.target_name
        name = "#{config.target} (#{config.target_name})"
      else
        name = config.target
      end
      say("Current target is #{name.make_green}")
    else
      say(config.target)
    end
  else
    err("Target not set")
  end
end