bosh_cli 1.2513.0 → 1.2524.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cli.rb CHANGED
@@ -70,6 +70,8 @@ require 'cli/release_tarball'
70
70
 
71
71
  require 'cli/blob_manager'
72
72
 
73
+ require 'cli/logs_downloader'
74
+
73
75
  require 'common/properties'
74
76
  require 'cli/job_property_collection'
75
77
  require 'cli/job_property_validator'
@@ -1,19 +1,23 @@
1
1
  module Bosh::Cli::Client
2
2
  class ErrandsClient
3
3
  class ErrandResult
4
- attr_reader :exit_code, :stdout, :stderr
4
+ attr_reader :exit_code, :stdout, :stderr, :logs_blobstore_id
5
5
 
6
- def initialize(exit_code, stdout, stderr)
6
+ def initialize(exit_code, stdout, stderr, logs_blobstore_id)
7
7
  @exit_code = exit_code
8
8
  @stdout = stdout
9
9
  @stderr = stderr
10
+ @logs_blobstore_id = logs_blobstore_id
10
11
  end
11
12
 
12
13
  def ==(other)
13
14
  unless other.is_a?(self.class)
14
15
  raise ArgumentError, "Must be #{self.class} to compare"
15
16
  end
16
- [exit_code, stdout, stderr] == [other.exit_code, other.stdout, other.stderr]
17
+
18
+ local = [exit_code, stdout, stderr, logs_blobstore_id]
19
+ other = [other.exit_code, other.stdout, other.stderr, other.logs_blobstore_id]
20
+ local == other
17
21
  end
18
22
  end
19
23
 
@@ -36,7 +40,10 @@ module Bosh::Cli::Client
36
40
 
37
41
  if errand_result_output
38
42
  task_result = JSON.parse(errand_result_output)
39
- errand_result = ErrandResult.new(*task_result.values_at('exit_code', 'stdout', 'stderr'))
43
+ errand_result = ErrandResult.new(
44
+ *task_result.values_at('exit_code', 'stdout', 'stderr'),
45
+ task_result.fetch('logs', {})['blobstore_id'],
46
+ )
40
47
  end
41
48
 
42
49
  [status, task_id, errand_result]
@@ -4,6 +4,8 @@ module Bosh::Cli::Command
4
4
  class Errand < Base
5
5
  usage 'run errand'
6
6
  desc 'Run specified errand'
7
+ option '--download-logs', 'download logs'
8
+ option '--logs-dir destination_directory', String, 'logs download directory'
7
9
  def run_errand(errand_name)
8
10
  auth_required
9
11
  deployment_required
@@ -28,6 +30,17 @@ module Bosh::Cli::Command
28
30
  say(errand_result.stderr.empty?? 'None' : errand_result.stderr)
29
31
  nl
30
32
 
33
+ if options[:download_logs] && errand_result.logs_blobstore_id
34
+ logs_downloader = Bosh::Cli::LogsDownloader.new(director, self)
35
+ logs_path = logs_downloader.build_destination_path(errand_name, 0, options[:logs_dir] || Dir.pwd)
36
+
37
+ begin
38
+ logs_downloader.download(errand_result.logs_blobstore_id, logs_path)
39
+ rescue Bosh::Cli::CliError => e
40
+ @download_logs_error = e
41
+ end
42
+ end
43
+
31
44
  title_prefix = "Errand `#{errand_name}'"
32
45
  exit_code_suffix = "(exit code #{errand_result.exit_code})"
33
46
 
@@ -38,6 +51,8 @@ module Bosh::Cli::Command
38
51
  else
39
52
  err("#{title_prefix} completed with error #{exit_code_suffix}")
40
53
  end
54
+
55
+ raise @download_logs_error if @download_logs_error
41
56
  end
42
57
  end
43
58
  end
@@ -1,5 +1,3 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh::Cli::Command
4
2
  class LogManagement < Base
5
3
  # bosh logs
@@ -16,9 +14,11 @@ module Bosh::Cli::Command
16
14
  index = valid_index_for(job, index)
17
15
  check_arguments(index)
18
16
 
17
+ logs_downloader = Bosh::Cli::LogsDownloader.new(director, self)
18
+
19
19
  resource_id = fetch_log_resource_id(index, job)
20
- log_file_path = log_file_destination(index, job)
21
- download_logs(log_file_path, resource_id)
20
+ logs_path = logs_downloader.build_destination_path(job, index, options[:dir] || Dir.pwd)
21
+ logs_downloader.download(resource_id, logs_path)
22
22
  end
23
23
 
24
24
  def fetch_log_resource_id(index, job)
@@ -38,20 +38,6 @@ module Bosh::Cli::Command
38
38
  options[:job]
39
39
  end
40
40
 
41
- def download_logs(log_file_path, resource_id)
42
- say("Downloading log bundle (#{resource_id.to_s.make_green})...")
43
-
44
- begin
45
- tmp_file = director.download_resource(resource_id)
46
- FileUtils.mv(tmp_file, log_file_path)
47
- say("Logs saved in `#{log_file_path.make_green}'")
48
- rescue Bosh::Cli::DirectorError => e
49
- err("Unable to download logs from director: #{e}")
50
- ensure
51
- FileUtils.rm_rf(tmp_file) if tmp_file && File.exists?(tmp_file)
52
- end
53
- end
54
-
55
41
  def check_arguments(index)
56
42
  auth_required
57
43
  no_track_unsupported
@@ -85,15 +71,6 @@ module Bosh::Cli::Command
85
71
  filter
86
72
  end
87
73
 
88
- def log_file_destination(index, job)
89
- time = Time.now.strftime('%Y-%m-%d@%H-%M-%S')
90
- File.join(log_directory, "#{job}.#{index}.#{time}.tgz")
91
- end
92
-
93
- def log_directory
94
- options[:dir] || Dir.pwd
95
- end
96
-
97
74
  def deployment_name
98
75
  prepare_deployment_manifest['name']
99
76
  end
@@ -0,0 +1,33 @@
1
+ module Bosh::Cli
2
+ class LogsDownloader
3
+ def initialize(director, ui)
4
+ @director = director
5
+ @ui = ui
6
+ end
7
+
8
+ def build_destination_path(job_name, job_index, directory)
9
+ time = Time.now.strftime('%Y-%m-%d-%H-%M-%S')
10
+ File.join(directory, "#{job_name}.#{job_index}.#{time}.tgz")
11
+ end
12
+
13
+ def download(resource_id, logs_destination_path)
14
+ @ui.say("Downloading log bundle (#{resource_id.to_s.make_green})...")
15
+ @ui.nl
16
+
17
+ begin
18
+ tmp_file = @director.download_resource(resource_id)
19
+
20
+ FileUtils.mv(tmp_file, logs_destination_path)
21
+
22
+ @ui.say("Logs saved in `#{logs_destination_path.make_green}'")
23
+ @ui.nl
24
+
25
+ rescue Bosh::Cli::DirectorError => e
26
+ @ui.err("Unable to download logs from director: #{e}")
27
+
28
+ ensure
29
+ FileUtils.rm_rf(tmp_file) if tmp_file
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Cli
3
- VERSION = '1.2513.0'
3
+ VERSION = '1.2524.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2513.0
4
+ version: 1.2524.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-30 00:00:00.000000000 Z
12
+ date: 2014-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bosh_common
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.2513.0
21
+ version: 1.2524.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.2513.0
29
+ version: 1.2524.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: json_pure
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 1.2513.0
117
+ version: 1.2524.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 1.2513.0
125
+ version: 1.2524.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: net-ssh
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -269,7 +269,7 @@ dependencies:
269
269
  version: '0'
270
270
  description: ! 'BOSH CLI
271
271
 
272
- f90a96'
272
+ 0501e4'
273
273
  email: support@cloudfoundry.com
274
274
  executables:
275
275
  - bosh
@@ -330,6 +330,7 @@ files:
330
330
  - lib/cli/job_property_validator.rb
331
331
  - lib/cli/job_state.rb
332
332
  - lib/cli/line_wrap.rb
333
+ - lib/cli/logs_downloader.rb
333
334
  - lib/cli/manifest_warnings.rb
334
335
  - lib/cli/name_version_pair.rb
335
336
  - lib/cli/package_builder.rb
@@ -381,7 +382,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
381
382
  version: '0'
382
383
  segments:
383
384
  - 0
384
- hash: 1822677666364164043
385
+ hash: -281260894014773282
385
386
  requirements: []
386
387
  rubyforge_project:
387
388
  rubygems_version: 1.8.23