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

Inherits:
Base show all
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, #exit_code, #options, #out, #runner, #work_dir

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from Bosh::Cli::CommandDiscovery

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

Methods included from DeploymentHelper

#cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_must_exist_in_deployment, #job_unique_in_deployment?, #jobs_and_indexes, #latest_release_versions, #prepare_deployment_manifest, #prompt_for_job_and_index, #resolve_release_aliases, #warn_about_stemcell_changes

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

def list(deployment_name = nil)
  auth_required
  no_track_unsupported

  if deployment_name.nil?
    deps = director.list_deployments
    err('No deployments') if deps.empty?
    deps.each { |dep| show_deployment(dep['name'], options) }
  else
    show_deployment deployment_name, options
  end
end

#show_deployment(name, options = {}) ⇒ Object



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
64
65
66
67
68
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
# File 'lib/cli/commands/vms.rb', line 23

def show_deployment(name, options={})
  say("Deployment `#{name.make_green}'")

  vms = director.fetch_vm_state(name)

  if vms.empty?
    nl
    say('No VMs')
    nl
    return
  end

  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']
    if options[:details]
      headings += ['CID', 'Agent ID', 'Resurrection']
    end
    if options[:dns]
      headings += ['DNS A records']
    end
    if options[:vitals]
      headings += [{:value => "Load\n(avg01, avg05, avg15)", :alignment => :center}]
      headings += ["CPU\nUser", "CPU\nSys", "CPU\nWait"]
      headings += ['Memory Usage', 'Swap Usage']
      headings += ["System\nDisk Usage", "Ephemeral\nDisk Usage", "Persistent\nDisk Usage"]
    end
    t.headings = headings

    sorted.each do |vm|
      job = "#{vm['job_name'] || 'unknown'}/#{vm['index'] || 'unknown'}"
      ips = Array(vm['ips']).join("\n")
      dns_records = Array(vm['dns']).join("\n")
      vitals = vm['vitals']

      row = [job, vm['job_state'], vm['resource_pool'], ips]

      if options[:details]
        row += [vm['vm_cid'], vm['agent_id'], vm['resurrection_paused'] ? 'paused' : 'active']
      end

      if options[:dns]
        row += [dns_records.empty? ? 'n/a' : dns_records]
      end

      if options[:vitals]
        if vitals
          cpu =  vitals['cpu']
          mem =  vitals['mem']
          swap = vitals['swap']
          disk = vitals['disk']

          row << vitals['load'].join(', ')
          row << "#{cpu['user']}%"
          row << "#{cpu['sys']}%"
          row << "#{cpu['wait']}%"
          row << "#{mem['percent']}% (#{pretty_size(mem['kb'].to_i * 1024)})"
          row << "#{swap['percent']}% (#{pretty_size(swap['kb'].to_i * 1024)})"
          row << "#{disk['system']['percent']}%"
          if disk['ephemeral'].nil?
            row << 'n/a'
          else
            row << "#{disk['ephemeral']['percent']}%"
          end
          if disk['persistent'].nil?
            row << 'n/a'
          else
            row << "#{disk['persistent']['percent']}%"
          end
        else
          9.times { row << 'n/a' }
        end
      end

      t << row
    end
  end

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