Class: Bosh::Cli::Command::Vms

Inherits:
Base show all
Includes:
DeploymentHelper
Defined in:
lib/cli/commands/vms.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_DIRECTOR_PORT

Instance Attribute Summary

Attributes inherited from Base

#args, #options, #out, #runner, #work_dir

Instance Method Summary collapse

Methods included from DeploymentHelper

#deployment_changed?, #inspect_deployment_changes, #prepare_deployment_manifest

Methods included from VersionCalc

#major_version, #minor_version, #version_cmp, #version_greater, #version_less, #version_same

Methods inherited from Base

#add_option, #blob_manager, #blobstore, #cache, #config, #confirmed?, #deployment, #director, #exit_code, #initialize, #interactive?, #logged_in?, #non_interactive?, #password, #redirect, #release, #remove_option, #target, #target_name, #task_report, #username, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

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

Constructor Details

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

Instance Method Details

#list(deployment_name = nil) ⇒ Object



10
11
12
13
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
# File 'lib/cli/commands/vms.rb', line 10

def list(deployment_name = nil)
  auth_required
  no_track_unsupported
  show_full_stats = options[:full]

  if deployment_name.nil?
    deployment_required
    manifest = prepare_deployment_manifest
    deployment_name = manifest["name"]
  end

  say("Deployment `#{deployment_name.green}'")
  vms = director.fetch_vm_state(deployment_name)
  err("No VMs") if vms.empty?

  sorted = vms.sort do |a, b|
    s = a["job_name"].to_s <=> b["job_name"].to_s
    s = a["index"].to_i <=> b["index"].to_i if s == 0
    s = a["resource_pool"].to_s <=> b["resource_pool"].to_s if s == 0
    s
  end

  vms_table = table do |t|
    headings = ["Job/index", "State", "Resource Pool", "IPs"]
    headings += ["CID", "Agent ID"] if show_full_stats

    t.headings = headings

    sorted.each do |vm|
      job = "#{vm["job_name"] || "unknown"}/#{vm["index"] || "unknown"}"
      ips = Array(vm["ips"]).join(", ")

      row = [job, vm["job_state"], vm["resource_pool"], ips]
      row += [vm["vm_cid"], vm["agent_id"]] if show_full_stats

      t << row
    end
  end

  nl
  say(vms_table)
  nl
  say("VMs total: %d" % vms.size)
end