Class: Bosh::Cli::Command::Misc

Inherits:
Base show all
Defined in:
lib/cli/commands/misc.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_DIRECTOR_PORT

Instance Attribute Summary

Attributes inherited from Base

#args, #exit_code, #info, #options, #out, #runner, #work_dir

Instance Method Summary collapse

Methods inherited from Base

#add_option, #blob_manager, #blobstore, #cache_dir, #config, #confirmed?, #credentials, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #progress_renderer, #redirect, #release, #remove_option, #run_nested_command, #show_current_state, #target, #target_name, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

#desc, #method_added, #option, #register_command, #usage

Methods included from DeploymentHelper

#build_manifest, #cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_unique_in_deployment?, #jobs_and_indexes, #prepare_deployment_manifest, #prompt_for_errand_name, #prompt_for_job_and_index

Constructor Details

This class inherits a constructor from Bosh::Cli::Command::Base

Instance Method Details

#list_aliasesObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# 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_targetsObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# 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) ⇒ Object



146
147
148
149
150
# 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) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# 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

#statusObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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

#versionObject



6
7
8
# File 'lib/cli/commands/misc.rb', line 6

def version
  say("BOSH %s" % [Bosh::Cli::VERSION])
end