bosh_cli 1.3160.0 → 1.3163.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Cli::Command
4
2
  class Instances < Base
5
3
  usage 'instances'
@@ -9,7 +7,7 @@ module Bosh::Cli::Command
9
7
  option '--vitals', 'Return instance vitals information'
10
8
  option '--ps', "Return instance process information"
11
9
  option '--failing', "Only show failing ones"
12
- def list()
10
+ def list
13
11
  auth_required
14
12
  deployment_required
15
13
  manifest = Bosh::Cli::Manifest.new(deployment, director)
@@ -30,7 +28,6 @@ module Bosh::Cli::Command
30
28
 
31
29
  def show_deployment(name, options={})
32
30
  instances = director.fetch_vm_state(name)
33
- instance_count = instances.size
34
31
 
35
32
  if instances.empty?
36
33
  nl
@@ -39,43 +36,58 @@ module Bosh::Cli::Command
39
36
  return
40
37
  end
41
38
 
42
- sorted = instances.sort do |a, b|
43
- s = a['job_name'].to_s <=> b['job_name'].to_s
44
- s = a['index'].to_i <=> b['index'].to_i if s == 0
45
- s = a['resource_pool'].to_s <=> b['resource_pool'].to_s if s == 0
46
- s
39
+ sorted = sort(instances)
40
+
41
+ instances_table, row_count = construct_table_to_display(options, sorted)
42
+
43
+ if options[:failing] && row_count == 0
44
+ nl
45
+ say('No failing instances')
46
+ nl
47
+ return
47
48
  end
48
49
 
50
+ legend = '(*) Bootstrap node'
51
+
52
+ nl
53
+ say(instances_table)
54
+ nl
55
+ say(legend)
56
+ nl
57
+ say('Instances total: %d' % row_count)
58
+ end
59
+
60
+ private
61
+
62
+ def construct_table_to_display(options, instances)
49
63
  row_count = 0
50
- has_disk_cid = instances[0].has_key?('disk_cid')
64
+ has_disk_cid = instances.any? {|instance| instance.has_key?('disk_cid') }
65
+ has_az = instances.any? {|instance| instance.has_key?('az') }
51
66
  has_uptime = instances[0]['processes'] && instances[0]['processes'].size > 0 && instances[0]['processes'][0].has_key?('uptime')
52
67
  has_cpu = instances[0]['processes'] && instances[0]['processes'].size > 0 && instances[0]['processes'][0].has_key?('cpu')
68
+ instance_count = instances.size
69
+
70
+ result = table do |display_table|
53
71
 
54
- instances_table = table do |t|
55
- headings = ['Instance', 'State', 'Resource Pool', 'IPs']
72
+ headings = ['Instance', 'State']
73
+ if has_az
74
+ headings << 'AZ'
75
+ end
76
+ headings += ['VM Type', 'IPs']
56
77
  if options[:details]
78
+ headings << 'VM CID'
57
79
  if has_disk_cid
58
- headings += ['VM CID', 'Disk CID', 'Agent ID', 'Resurrection']
59
- else
60
- headings += ['VM CID', 'Agent ID', 'Resurrection']
80
+ headings += ['Disk CID']
61
81
  end
82
+ headings += ['Agent ID', 'Resurrection']
62
83
  end
63
84
 
64
85
  if options[:dns]
65
86
  headings += ['DNS A records']
66
87
  end
67
88
 
68
- if options[:vitals]
69
- headings += [{:value => "Uptime", :alignment => :center}] if options[:ps] && has_uptime
70
- headings += [{:value => "Load\n(avg01, avg05, avg15)", :alignment => :center}]
71
- headings += [{:value => "CPU %\n(User, Sys, Wait)", :alignment => :center}]
72
- headings += ["CPU %"] if options[:ps] && has_cpu
73
- headings += ['Memory Usage', 'Swap Usage']
74
- headings += ["System\nDisk Usage", "Ephemeral\nDisk Usage", "Persistent\nDisk Usage"]
75
- end
76
-
77
- last_job = ''
78
- sorted.each do |instance|
89
+ instances_to_show = []
90
+ instances.each do |instance|
79
91
  if options[:failing]
80
92
  if options[:ps]
81
93
  instance['processes'].keep_if { |p| p['state'] != 'running' }
@@ -91,15 +103,56 @@ module Bosh::Cli::Command
91
103
  end
92
104
  end
93
105
 
106
+ instances_to_show << instance
107
+ end
108
+
109
+ if options[:vitals]
110
+ show_total = instance_count > 1 || instances_to_show[0]['processes'].size > 0
111
+
112
+ headings += [{:value => 'Uptime', :alignment => :center}] if options[:ps] && has_uptime && show_total
113
+ headings += [{:value => "Load\n(avg01, avg05, avg15)", :alignment => :center}]
114
+ headings += [{:value => "CPU %\n(User, Sys, Wait)", :alignment => :center}]
115
+ headings += ['CPU %'] if options[:ps] && has_cpu && show_total
116
+ headings += ['Memory Usage', 'Swap Usage']
117
+ headings += ["System\nDisk Usage", "Ephemeral\nDisk Usage", "Persistent\nDisk Usage"]
118
+ end
119
+ display_table.headings = headings
120
+
121
+ last_job = ''
122
+ instances_to_show.each do |instance|
94
123
  row_count += 1
95
124
 
96
- job = "#{instance['job_name'] || 'unknown'}/#{instance['index'] || 'unknown'}"
125
+ job_name = instance['job_name'] || 'unknown'
126
+ index = instance['index'] || 'unknown'
127
+ job = if instance.has_key?('id')
128
+ bootstrap = instance.fetch('bootstrap', false)
129
+ if bootstrap
130
+ "#{job_name}/#{index} (#{instance['id']})*"
131
+ else
132
+ "#{job_name}/#{index} (#{instance['id']})"
133
+ end
134
+ else
135
+ "#{job_name}/#{index}"
136
+ end
97
137
  ips = Array(instance['ips']).join("\n")
98
138
  dns_records = Array(instance['dns']).join("\n")
99
139
  vitals = instance['vitals']
140
+ az = instance['az'].nil? ? 'n/a' : instance['az']
141
+
142
+ row = [job, instance['job_state']]
143
+ if has_az
144
+ row << az
145
+ end
100
146
 
101
- row = [job, instance['job_state'], instance['resource_pool'], ips]
102
- t << :separator if row_count.between?(2, instance_count) && (options[:ps] || last_job != '' && instance['job_name'] != last_job)
147
+ if instance['resource_pool']
148
+ row << instance['resource_pool']
149
+ else
150
+ row << instance['vm_type']
151
+ end
152
+
153
+ row << ips
154
+
155
+ display_table << :separator if row_count.between?(2, instance_count) && (options[:ps] || last_job != '' && instance['job_name'] != last_job)
103
156
 
104
157
  if options[:details]
105
158
  if has_disk_cid
@@ -115,8 +168,8 @@ module Bosh::Cli::Command
115
168
 
116
169
  if options[:vitals]
117
170
  if vitals
118
- cpu = vitals['cpu']
119
- mem = vitals['mem']
171
+ cpu = vitals['cpu']
172
+ mem = vitals['mem']
120
173
  swap = vitals['swap']
121
174
  disk = vitals['disk']
122
175
 
@@ -140,7 +193,7 @@ module Bosh::Cli::Command
140
193
  else
141
194
  9.times { row << 'n/a' }
142
195
  end
143
- t << row
196
+ display_table << row
144
197
 
145
198
  if options[:ps] && instance['processes']
146
199
  instance['processes'].each do |process|
@@ -149,6 +202,7 @@ module Bosh::Cli::Command
149
202
  prow += ['','','']
150
203
  prow << '' if has_disk_cid
151
204
  end
205
+ prow << '' if has_az
152
206
  if has_uptime
153
207
  if process['uptime'] && process['uptime']['secs']
154
208
  uptime = Integer(process['uptime']['secs'])
@@ -165,41 +219,37 @@ module Bosh::Cli::Command
165
219
  prow << (process['cpu'] ? "#{process['cpu']['total']}%":'') if has_cpu
166
220
  prow << (process['mem'] ? "#{process['mem']['percent']}% (#{pretty_size(process['mem']['kb'].to_i * 1024)})":'')
167
221
  4.times { prow << '' }
168
- t << prow
222
+ display_table << prow
169
223
  end
170
224
  end
171
225
  else
172
- t << row
226
+ display_table << row
173
227
  if options[:ps] && instance['processes']
174
228
  instance['processes'].each do |process|
175
229
  name = process['name']
176
230
  state = process['state']
177
231
  process_row = [" #{name}", "#{state}"]
178
232
  (headings.size - 2).times { process_row << '' }
179
- t << process_row
233
+ display_table << process_row
180
234
  end
181
235
  end
182
236
  end
183
237
 
184
238
  last_job = instance['job_name'] || 'unknown'
185
- if instance['processes'].size == 0 && instance_count == 1
186
- headings.delete_at(4)
187
- headings.delete_at(6)
188
- end
189
239
  end
190
- t.headings = headings
240
+ display_table.headings = headings
191
241
  end
192
242
 
193
- if options[:failing] && row_count == 0
194
- nl
195
- say('No failing instances')
196
- nl
197
- return
243
+ return result, row_count
244
+ end
245
+
246
+ def sort(instances)
247
+ instances.sort do |instance1, instance2|
248
+ comparison = instance1['job_name'].to_s <=> instance2['job_name'].to_s
249
+ comparison = instance1['az'].to_s <=> instance2['az'].to_s if comparison == 0
250
+ comparison = instance1['index'].to_i <=> instance2['index'].to_i if comparison == 0
251
+ comparison
198
252
  end
199
- nl
200
- say(instances_table)
201
- nl
202
- say('Instances total: %d' % row_count )
203
253
  end
204
254
  end
205
255
  end
@@ -11,8 +11,8 @@ module Bosh::Cli
11
11
  usage 'start'
12
12
  desc 'Start all jobs/job/instance'
13
13
  option '--force', FORCE
14
- def start_job(job = '*', index = nil)
15
- change_job_state(:start, job, index)
14
+ def start_job(job = '*', index_or_id = nil)
15
+ change_job_state(:start, job, index_or_id)
16
16
  end
17
17
 
18
18
  # bosh stop
@@ -22,11 +22,11 @@ module Bosh::Cli
22
22
  option '--hard', 'Power off VM'
23
23
  option '--force', FORCE
24
24
  option '--skip-drain', SKIP_DRAIN
25
- def stop_job(job = '*', index = nil)
25
+ def stop_job(job = '*', index_or_id = nil)
26
26
  if hard?
27
- change_job_state(:detach, job, index)
27
+ change_job_state(:detach, job, index_or_id)
28
28
  else
29
- change_job_state(:stop, job, index)
29
+ change_job_state(:stop, job, index_or_id)
30
30
  end
31
31
  end
32
32
 
@@ -35,8 +35,8 @@ module Bosh::Cli
35
35
  desc 'Restart all jobs/job/instance (soft stop + start)'
36
36
  option '--force', FORCE
37
37
  option '--skip-drain', SKIP_DRAIN
38
- def restart_job(job = '*', index = nil)
39
- change_job_state(:restart, job, index)
38
+ def restart_job(job = '*', index_or_id = nil)
39
+ change_job_state(:restart, job, index_or_id)
40
40
  end
41
41
 
42
42
  # bosh recreate
@@ -44,17 +44,17 @@ module Bosh::Cli
44
44
  desc 'Recreate all jobs/job/instance (hard stop + start)'
45
45
  option '--force', FORCE
46
46
  option '--skip-drain', SKIP_DRAIN
47
- def recreate_job(job = '*', index = nil)
48
- change_job_state(:recreate, job, index)
47
+ def recreate_job(job = '*', index_or_id = nil)
48
+ change_job_state(:recreate, job, index_or_id)
49
49
  end
50
50
 
51
51
  private
52
52
 
53
- def change_job_state(state, job, index = nil)
53
+ def change_job_state(state, job, index_or_id = nil)
54
54
  auth_required
55
55
  manifest = parse_manifest(state)
56
56
  job_state = JobState.new(self, manifest, skip_drain: skip_drain?)
57
- status, task_id, completion_desc = job_state.change(state, job, index, force?)
57
+ status, task_id, completion_desc = job_state.change(state, job, index_or_id, force?)
58
58
  task_report(status, task_id, completion_desc)
59
59
  end
60
60
 
@@ -11,28 +11,28 @@ module Bosh::Cli::Command
11
11
  option '--dir destination_directory', String, 'download directory'
12
12
  option '--all', 'deprecated'
13
13
 
14
- def fetch_logs(job, index)
14
+ def fetch_logs(job, index_or_id)
15
15
  auth_required
16
16
 
17
17
  manifest = prepare_deployment_manifest(show_state: true)
18
- check_arguments(index)
18
+ check_arguments
19
19
 
20
20
  logs_downloader = Bosh::Cli::LogsDownloader.new(director, self)
21
21
 
22
- resource_id = fetch_log_resource_id(manifest.name, index, job)
23
- logs_path = logs_downloader.build_destination_path(job, index, options[:dir] || Dir.pwd)
22
+ resource_id = fetch_log_resource_id(manifest.name, index_or_id, job)
23
+ logs_path = logs_downloader.build_destination_path(job, index_or_id, options[:dir] || Dir.pwd)
24
24
  logs_downloader.download(resource_id, logs_path)
25
25
  end
26
26
 
27
- def fetch_log_resource_id(deployment_name, index, job)
28
- resource_id = director.fetch_logs(deployment_name, job, index, log_type, filters)
27
+ private
28
+
29
+ def fetch_log_resource_id(deployment_name, index_or_id, job)
30
+ resource_id = director.fetch_logs(deployment_name, job, index_or_id, log_type, filters)
29
31
  err('Error retrieving logs') if resource_id.nil?
30
32
 
31
33
  resource_id
32
34
  end
33
35
 
34
- private
35
-
36
36
  def agent_logs_wanted?
37
37
  options[:agent]
38
38
  end
@@ -41,11 +41,9 @@ module Bosh::Cli::Command
41
41
  options[:job]
42
42
  end
43
43
 
44
- def check_arguments(index)
44
+ def check_arguments
45
45
  no_track_unsupported
46
46
 
47
- err('Job index is expected to be a positive integer') if index !~ /^\d+$/
48
-
49
47
  if agent_logs_wanted? && options[:only]
50
48
  err('Custom filtering is not supported for agent logs')
51
49
  end
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Cli::Command
4
2
  class Maintenance < Base
5
3
 
@@ -17,34 +15,18 @@ module Bosh::Cli::Command
17
15
 
18
16
  remove_all = !!options[:all]
19
17
 
20
- releases_to_keep = remove_all ? 0 : RELEASES_TO_KEEP
21
- stemcells_to_keep = remove_all ? 0 : STEMCELLS_TO_KEEP
22
-
23
- release_wording = pluralize(releases_to_keep, 'latest version')
24
- stemcell_wording = pluralize(stemcells_to_keep, 'latest version')
25
-
26
- desc = <<-EOS.gsub(/^ */, "")
27
- Cleanup command will attempt to delete old unused
28
- release versions and stemcells from your currently
29
- targeted director at #{target_name.make_green}.
30
-
31
- Only #{release_wording.make_green} of each release
32
- and #{stemcell_wording.make_green} of each stemcell will be kept.
33
-
34
- Releases and stemcells that are in use will not be affected.
35
- EOS
36
-
37
- nl
38
- say(desc)
39
- nl
40
-
41
- err('Cleanup canceled') unless confirmed?
42
-
43
- nl
44
- cleanup_stemcells(stemcells_to_keep)
45
- nl
46
- cleanup_releases(releases_to_keep)
47
-
18
+ num_releases_to_keep = remove_all ? 0 : RELEASES_TO_KEEP
19
+ num_stemcells_to_keep = remove_all ? 0 : STEMCELLS_TO_KEEP
20
+
21
+ begin
22
+ director.cleanup({'remove_all' => remove_all})
23
+ rescue Bosh::Cli::ResourceNotFound
24
+ # old directors won't have `cleanup` endpoint, therefore use legacy endpoints
25
+ nl
26
+ cleanup_stemcells(num_stemcells_to_keep)
27
+ nl
28
+ cleanup_releases(num_releases_to_keep)
29
+ end
48
30
  nl
49
31
  say('Cleanup complete'.make_green)
50
32
  end
@@ -86,16 +68,10 @@ module Bosh::Cli::Command
86
68
 
87
69
  director.list_releases.each do |release|
88
70
  name = release['name']
89
- if release['release_versions']
90
- # reverse compatibility with old director response format
91
- versions = release['release_versions'].map { |release_version| release_version['version'] }
92
- currently_deployed = release['release_versions'].
93
- select { |release_version| release_version['currently_deployed'] }.
94
- map{ |release_version| release_version['version'] }
95
- else
96
- versions = release['versions']
97
- currently_deployed = release['in_use']
98
- end
71
+ versions = release['release_versions'].map { |release_version| release_version['version'] }
72
+ currently_deployed = release['release_versions']
73
+ .select { |release_version| release_version['currently_deployed'] }
74
+ .map { |release_version| release_version['version'] }
99
75
 
100
76
  version_tuples = versions.map do |v|
101
77
  {
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2013 VMware, Inc.
2
-
3
1
  module Bosh::Cli::Command
4
2
  class Snapshot < Base
5
3
  usage 'snapshots'
@@ -11,18 +9,29 @@ module Bosh::Cli::Command
11
9
 
12
10
  snapshots = director.list_snapshots(deployment_name, job, index)
13
11
 
12
+ if snapshots.empty?
13
+ nl
14
+ say('No snapshots')
15
+ nl
16
+ return
17
+ end
18
+
14
19
  sorted = snapshots.sort do |a, b|
15
20
  s = a['job'].to_s <=> b['job'].to_s
16
- s = a['index'].to_i <=> b['index'].to_i if s == 0
21
+ if a['uuid']
22
+ s = a['uuid'].to_i <=> b['uuid'].to_i if s == 0
23
+ else
24
+ s = a['index'].to_i <=> b['index'].to_i if s == 0
25
+ end
17
26
  s = a['created_at'].to_s <=> b['created_at'].to_s if s == 0
18
27
  s
19
28
  end
20
29
 
21
30
  snapshots_table = table do |t|
22
- t.headings = ['Job/index', 'Snapshot CID', 'Created at', 'Clean']
31
+ t.headings = ['Job/ID', 'Snapshot CID', 'Created at', 'Clean']
23
32
 
24
33
  sorted.each do |snapshot|
25
- job = "#{snapshot['job'] || 'unknown'}/#{snapshot['index'] || 'unknown'}"
34
+ job = "#{snapshot['job'] || 'unknown'}/#{snapshot['uuid'] || 'unknown'} (#{snapshot['index'] || 'unknown'})"
26
35
  t << [job, snapshot['snapshot_cid'], snapshot['created_at'], snapshot['clean']]
27
36
  end
28
37
  end