bosh_cli 1.3178.0 → 1.3181.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c301e84146873f8d658e9777dfd45bb680f47e5
4
- data.tar.gz: 967d60eab9b45d2f4243b41e3c96179766a7ab51
3
+ metadata.gz: f3752794136b632c019fbc30d74f20d9b2af6dd9
4
+ data.tar.gz: 0c09ce0323b35eedae508812a396f79c6f5da9e6
5
5
  SHA512:
6
- metadata.gz: 96e70e4b956deb8502ee5145ef39cf1eb1a9d8d71391d3c8eb7a79a3d8d5421ca9f0153e6895c58e3dc476f83fb444212f66d3c5161a8c5e002541294f985617
7
- data.tar.gz: 43368c13fe63e26c61124ea4484f9a5db177d2b43c8d51c691bc40966e5e5663a07708a6dbad8b1784ab0d47f6654d35940dd5c0e1c2cf13b64364da8d6b13be
6
+ metadata.gz: 1b2a7a5b96cb7d59a1581e0b4a736729ddedc03bc0e379d7c601cf29478a5fbbae51c6595ba7cc5df918a68c5f210796236439704f534709c885198ea05200da
7
+ data.tar.gz: 452bad4c0109afb3953bce13352ef59f43fcca822a7b71609f7d8d2249f825babcd23fca16fe9cf023c51b5e5921bec0e7cf4a8d19de9fc89c7fcbeacd796d1a
@@ -248,18 +248,29 @@ module Bosh
248
248
 
249
249
  recreate = options.delete(:recreate)
250
250
  skip_drain = options.delete(:skip_drain)
251
+ context = options.delete(:context)
251
252
  options[:content_type] = 'text/yaml'
252
253
  options[:payload] = manifest_yaml
253
254
 
254
255
  url = '/deployments'
255
256
 
256
257
  extras = []
257
- extras << ['recreate', 'true'] if recreate
258
+ extras << ['recreate', 'true'] if recreate
259
+ extras << ['context', JSON.dump(context)] if context
258
260
  extras << ['skip_drain', skip_drain] if skip_drain
259
261
 
260
262
  request_and_track(:post, add_query_string(url, extras), options)
261
263
  end
262
264
 
265
+ def diff_deployment(name, manifest_yaml)
266
+ status, body = post("/deployments/#{name}/diff", 'text/yaml', manifest_yaml)
267
+ if status == 200
268
+ JSON.parse(body)
269
+ else
270
+ err(parse_error_message(status, body))
271
+ end
272
+ end
273
+
263
274
  def setup_ssh(deployment_name, job, id, user,
264
275
  public_key, password, options = {})
265
276
  options = options.dup
@@ -138,11 +138,7 @@ module Bosh::Cli::Command
138
138
 
139
139
  manifest = prepare_deployment_manifest(resolve_properties: true, show_state: true)
140
140
 
141
- inspect_deployment_changes(
142
- manifest.hash,
143
- interactive: interactive?,
144
- redact_diff: redact_diff
145
- )
141
+ context = DeploymentDiff.new(director, manifest).print({redact_diff: redact_diff})
146
142
  say('Please review all changes carefully'.make_yellow) if interactive?
147
143
 
148
144
  header('Deploying')
@@ -151,7 +147,7 @@ module Bosh::Cli::Command
151
147
  cancel_deployment
152
148
  end
153
149
 
154
- deploy_options = { recreate: recreate }
150
+ deploy_options = { recreate: recreate, context: context }
155
151
 
156
152
  if options.has_key?(:skip_drain)
157
153
  # when key is present but no jobs specified OptionParser
@@ -0,0 +1,52 @@
1
+ module Bosh::Cli::Command
2
+ class DeploymentDiff < Base
3
+ def initialize(director, manifest)
4
+ @director = director
5
+ @manifest = manifest
6
+ end
7
+
8
+ def print(options)
9
+ begin
10
+ changes = @director.diff_deployment(@manifest.name, @manifest.yaml)
11
+ diff = changes['diff']
12
+
13
+ header('Detecting deployment changes')
14
+
15
+ diff.each do |line_diff|
16
+ formatted_line_diff, state = line_diff
17
+
18
+ # colorization explicitly disabled
19
+ if Bosh::Cli::Config.use_color?
20
+ case state
21
+ when 'added'
22
+ say(formatted_line_diff.make_green)
23
+ when 'removed'
24
+ say(formatted_line_diff.make_red)
25
+ else
26
+ say(formatted_line_diff)
27
+ end
28
+
29
+ else
30
+ case state
31
+ when 'added'
32
+ say('+ ' + formatted_line_diff)
33
+ when 'removed'
34
+ say('- ' + formatted_line_diff)
35
+ else
36
+ say(' ' + formatted_line_diff)
37
+ end
38
+ end
39
+ end
40
+
41
+ changes['context']
42
+ rescue Bosh::Cli::ResourceNotFound
43
+ inspect_deployment_changes(
44
+ @manifest,
45
+ redact_diff: options[:redact_diff]
46
+ )
47
+
48
+ nil
49
+ end
50
+ end
51
+ end
52
+ end
data/lib/cli/config.rb CHANGED
@@ -39,6 +39,14 @@ module Bosh::Cli
39
39
  @commands[command.usage] = command
40
40
  end
41
41
 
42
+ def self.use_color?
43
+ # colorization explicitly enabled, or output is tty
44
+ return false if Bosh::Cli::Config.colorize == false
45
+
46
+ # colorization explicitly enabled, or output is tty
47
+ Bosh::Cli::Config.colorize || Bosh::Cli::Config.output.tty?
48
+ end
49
+
42
50
  def initialize(filename, work_dir = Dir.pwd)
43
51
  @filename = File.expand_path(filename || Bosh::Cli::DEFAULT_CONFIG_PATH)
44
52
  @work_dir = work_dir
data/lib/cli/core_ext.rb CHANGED
@@ -140,11 +140,7 @@ module BoshStringExtensions
140
140
  # output disabled
141
141
  return self if !Bosh::Cli::Config.output
142
142
 
143
- # colorization explicitly disabled
144
- return self if Bosh::Cli::Config.colorize == false
145
-
146
- # colorization explicitly enabled, or output is tty
147
- if Bosh::Cli::Config.colorize || Bosh::Cli::Config.output.tty?
143
+ if Bosh::Cli::Config.use_color?
148
144
  "#{COLOR_CODES[color_code]}#{self}\e[0m"
149
145
  else
150
146
  self
@@ -46,12 +46,14 @@ module Bosh::Cli
46
46
  # a meaningful return value.
47
47
  # @return Boolean Were there any changes in deployment manifest?
48
48
  def inspect_deployment_changes(manifest, options = {})
49
+ manifest.resolve_release_aliases
50
+ manifest.resolve_stemcell_aliases
51
+
49
52
  show_empty_changeset = options.fetch(:show_empty_changeset, true)
50
- interactive = options.fetch(:interactive, false)
51
53
  redact_diff = options.fetch(:redact_diff, false)
52
54
 
53
- manifest = manifest.dup
54
- current_deployment = director.get_deployment(manifest['name'])
55
+ manifest_hash = manifest.hash.dup
56
+ current_deployment = director.get_deployment(manifest_hash['name'])
55
57
 
56
58
  # We cannot retrieve current manifest until there was at least one
57
59
  # successful deployment. There used to be a warning about that
@@ -65,7 +67,7 @@ module Bosh::Cli
65
67
  end
66
68
 
67
69
  diff = Bosh::Cli::HashChangeset.new
68
- diff.add_hash(normalize_deployment_manifest(manifest), :new)
70
+ diff.add_hash(normalize_deployment_manifest(manifest_hash), :new)
69
71
  diff.add_hash(normalize_deployment_manifest(current_manifest), :old)
70
72
  @_diff_key_visited = { 'name' => 1, 'director_uuid' => 1 }
71
73
 
@@ -9,6 +9,19 @@ module Bosh::Cli
9
9
  def normalize
10
10
  normalized = Bosh::Common::DeepCopy.copy(manifest_hash)
11
11
 
12
+ # for backwards compatibility, new directors always convert stemcell and release versions to string
13
+ if normalized['resource_pools']
14
+ normalized['resource_pools'].each do |rp|
15
+ rp['stemcell']['version'] = rp['stemcell']['version'].to_s
16
+ end
17
+ end
18
+
19
+ if normalized['releases']
20
+ normalized['releases'].each do |release|
21
+ release['version'] = release['version'].to_s
22
+ end
23
+ end
24
+
12
25
  %w(releases networks jobs resource_pools disk_pools).each do |section|
13
26
  normalized[section] ||= []
14
27
 
data/lib/cli/job_state.rb CHANGED
@@ -46,7 +46,7 @@ module Bosh::Cli
46
46
  def change_job_state(new_state, job, index_or_id, operation_desc, force)
47
47
  @command.say("You are about to #{operation_desc.make_green}")
48
48
 
49
- check_if_manifest_changed(@manifest.hash, force)
49
+ check_if_manifest_changed(force)
50
50
  unless @command.confirmed?("#{operation_desc.capitalize}?")
51
51
  @command.cancel_deployment
52
52
  end
@@ -57,8 +57,8 @@ module Bosh::Cli
57
57
  end
58
58
 
59
59
 
60
- def check_if_manifest_changed(manifest_hash, force)
61
- other_changes_present = @command.inspect_deployment_changes(manifest_hash, show_empty_changeset: false)
60
+ def check_if_manifest_changed(force)
61
+ other_changes_present = @command.inspect_deployment_changes(@manifest, show_empty_changeset: false)
62
62
 
63
63
  if other_changes_present && !force
64
64
  @command.err("Cannot perform job management when other deployment changes are present. Please use `--force' to override.")
data/lib/cli/manifest.rb CHANGED
@@ -62,16 +62,13 @@ module Bosh::Cli
62
62
  "please add 'release' or 'releases' section")
63
63
  end
64
64
 
65
- resolve_release_aliases
66
- resolve_stemcell_aliases
67
-
68
65
  report_manifest_warnings
69
66
 
70
67
  @hash
71
68
  end
72
69
 
73
70
  def yaml
74
- @yaml ||= Psych.dump(@hash)
71
+ Psych.dump(@hash)
75
72
  end
76
73
 
77
74
  # @param [Hash] manifest Deployment manifest (will be modified)
@@ -89,12 +86,6 @@ module Bosh::Cli
89
86
  if latest_version.nil?
90
87
  err("Latest version for stemcell `#{stemcell['name']}' is unknown")
91
88
  end
92
- # Avoiding {Float,Fixnum} -> String noise in diff
93
- if latest_version.to_s == latest_version.to_f.to_s
94
- latest_version = latest_version.to_f
95
- elsif latest_version.to_s == latest_version.to_i.to_s
96
- latest_version = latest_version.to_i
97
- end
98
89
  stemcell['version'] = latest_version
99
90
  end
100
91
  end
@@ -132,10 +123,6 @@ module Bosh::Cli
132
123
  end
133
124
  release['version'] = latest_release_version
134
125
  end
135
-
136
- if release['version'].to_i.to_s == release['version']
137
- release['version'] = release['version'].to_i
138
- end
139
126
  end
140
127
  end
141
128
 
@@ -41,23 +41,14 @@ module Bosh::Cli
41
41
  end
42
42
  end
43
43
 
44
- in_build_dir do
45
- `tar -czf #{filepath} . 2>&1`
46
- unless $?.exitstatus == 0
47
- raise InvalidRelease, "Cannot create release tarball"
48
- end
49
- say("Generated #{filepath.make_green}")
50
- say("Release size: #{pretty_size(filepath).make_green}")
51
- end
44
+ SortedReleaseArchiver.new(build_dir).archive(filepath)
45
+
46
+ say("Generated #{filepath.make_green}")
47
+ say("Release size: #{pretty_size(filepath).make_green}")
52
48
  end
53
49
 
54
50
  private
55
51
 
56
52
  attr_reader :manifest, :packages, :jobs, :license, :build_dir
57
-
58
- def in_build_dir(&block)
59
- Dir.chdir(build_dir) { yield }
60
- end
61
-
62
53
  end
63
54
  end
@@ -28,6 +28,9 @@ module Bosh::Cli
28
28
  def unpack_jobs
29
29
  return @unpacked_jobs unless @unpacked_jobs.nil?
30
30
  exit_success = safe_fast_unpack('./jobs/')
31
+ unless all_release_jobs_unpacked?
32
+ exit_success = safe_unpack('./jobs/')
33
+ end
31
34
  @unpacked_jobs = !!exit_success
32
35
  end
33
36
 
@@ -48,6 +51,15 @@ module Bosh::Cli
48
51
  exit_status
49
52
  end
50
53
 
54
+ def safe_unpack(target)
55
+ exit_status = raw_unpack(target)
56
+ if !exit_status
57
+ processed_target = handle_dot_slash_prefix(target)
58
+ exit_status = raw_unpack(processed_target)
59
+ end
60
+ exit_status
61
+ end
62
+
51
63
  # This will [add or remove] the './' when trying to extract a specific file from archive
52
64
  def handle_dot_slash_prefix(target)
53
65
  if target =~ /^\.\/.*/
@@ -64,16 +76,29 @@ module Bosh::Cli
64
76
  when /.*gnu.*/i
65
77
  Kernel.system("tar", "-C", @unpack_dir, "-xzf", @tarball_path, "--occurrence", "#{target}", out: "/dev/null", err: "/dev/null")
66
78
  when /.*bsd.*/i
67
- if target[-1, 1] == "/"
68
- Kernel.system("tar", "-C", @unpack_dir, "-xzf", @tarball_path, "#{target}", out: "/dev/null", err: "/dev/null")
69
- else
70
- Kernel.system("tar", "-C", @unpack_dir, "--fast-read", "-xzf", @tarball_path, "#{target}", out: "/dev/null", err: "/dev/null")
71
- end
79
+ if target[-1, 1] == "/"
80
+ raw_unpack(target)
81
+ else
82
+ Kernel.system("tar", "-C", @unpack_dir, "--fast-read", "-xzf", @tarball_path, "#{target}", out: "/dev/null", err: "/dev/null")
83
+ end
72
84
  else
73
- Kernel.system("tar", "-C", @unpack_dir, "-xzf", @tarball_path, "#{target}", out: "/dev/null", err: "/dev/null")
85
+ raw_unpack(target)
74
86
  end
75
87
  end
76
88
 
89
+ def raw_unpack(target)
90
+ Kernel.system("tar", "-C", @unpack_dir, "-xzf", @tarball_path, "#{target}", out: "/dev/null", err: "/dev/null")
91
+ end
92
+
93
+ # verifies that all jobs in release manifest were unpacked
94
+ def all_release_jobs_unpacked?
95
+ return false if manifest_yaml['jobs'].nil?
96
+
97
+ manifest_job_names = manifest_yaml['jobs'].map { |j| j['name'] }.sort
98
+ unpacked_job_file_names = Dir.glob(File.join(@unpack_dir, 'jobs', '*')).map { |f| File.basename(f, '.*') }.sort
99
+ unpacked_job_file_names == manifest_job_names
100
+ end
101
+
77
102
  # Unpacks tarball to @unpack_dir, returns true if succeeded, false if failed
78
103
  def unpack
79
104
  return @unpacked unless @unpacked.nil?
@@ -84,7 +109,7 @@ module Bosh::Cli
84
109
  # Creates a new tarball from the current contents of @unpack_dir
85
110
  def create_from_unpacked(target_path)
86
111
  raise "Not unpacked yet!" unless @unpacked
87
- !!system("tar", "-C", @unpack_dir, "-pczf", File.expand_path(target_path), ".", out: "/dev/null", err: "/dev/null")
112
+ SortedReleaseArchiver.new(@unpack_dir).archive(File.expand_path(target_path))
88
113
  end
89
114
 
90
115
  def exists?
@@ -0,0 +1,28 @@
1
+ module Bosh::Cli
2
+ class SortedReleaseArchiver
3
+ def initialize(dir)
4
+ @dir = dir
5
+ end
6
+
7
+ def archive(destination_file)
8
+ Dir.chdir(@dir) do
9
+ success = Kernel.system('tar', '-C', @dir, '-pczf', destination_file, *ordered_release_files, out: '/dev/null', err: '/dev/null')
10
+ if !success
11
+ raise InvalidRelease, 'Cannot create release tarball'
12
+ end
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def ordered_release_files
19
+ ordered_release_files = ['./release.MF']
20
+ license_files = (Dir.entries('.') & ['LICENSE', 'NOTICE']).sort
21
+ unless license_files.empty?
22
+ ordered_release_files += license_files.map { |filename| "./#{filename}" }
23
+ end
24
+ ordered_release_files += ['./jobs', './packages']
25
+ ordered_release_files
26
+ end
27
+ end
28
+ end
data/lib/cli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Cli
3
- VERSION = '1.3178.0'
3
+ VERSION = '1.3181.0'
4
4
  end
5
5
  end
data/lib/cli.rb CHANGED
@@ -96,6 +96,7 @@ require 'cli/release_archiver'
96
96
  require 'cli/release_builder'
97
97
  require 'cli/release_compiler'
98
98
  require 'cli/release_tarball'
99
+ require 'cli/sorted_release_archiver'
99
100
 
100
101
  require 'cli/blob_manager'
101
102
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3178.0
4
+ version: 1.3181.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_common
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3178.0
19
+ version: 1.3181.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3178.0
26
+ version: 1.3181.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bosh-template
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3178.0
33
+ version: 1.3181.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3178.0
40
+ version: 1.3181.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cf-uaa-lib
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 1.3178.0
131
+ version: 1.3181.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 1.3178.0
138
+ version: 1.3181.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: net-ssh
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -359,6 +359,7 @@ files:
359
359
  - lib/cli/commands/cloudcheck.rb
360
360
  - lib/cli/commands/complete.rb
361
361
  - lib/cli/commands/deployment.rb
362
+ - lib/cli/commands/deployment_diff.rb
362
363
  - lib/cli/commands/disks.rb
363
364
  - lib/cli/commands/errand.rb
364
365
  - lib/cli/commands/help.rb
@@ -426,6 +427,7 @@ files:
426
427
  - lib/cli/resources/package.rb
427
428
  - lib/cli/resurrection.rb
428
429
  - lib/cli/runner.rb
430
+ - lib/cli/sorted_release_archiver.rb
429
431
  - lib/cli/source_control/git_ignore.rb
430
432
  - lib/cli/ssh_session.rb
431
433
  - lib/cli/stemcell.rb