bosh_cli 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/cli.rb CHANGED
@@ -29,9 +29,6 @@ require "tmpdir"
29
29
  require "uri"
30
30
  require "yaml"
31
31
  require "netaddr"
32
- require "net/ssh"
33
- require "net/scp"
34
- require "net/ssh/gateway"
35
32
 
36
33
  unless defined?(Bosh::Cli::VERSION)
37
34
  require "cli/version"
@@ -48,7 +48,8 @@ module Bosh::Cli
48
48
  end
49
49
 
50
50
  def director
51
- @director ||= Bosh::Cli::Director.new(target, username, password)
51
+ @director ||= Bosh::Cli::Director.new(
52
+ target, username, password, @options.select {|k,v| k == :no_track})
52
53
  end
53
54
 
54
55
  def release
@@ -132,12 +133,15 @@ module Bosh::Cli
132
133
  # contains pretty detailed error report and other UI niceties, so most
133
134
  # of the time this could just do nothing
134
135
  # @param [Symbol] status Task status
135
- def task_report(status, success_msg = nil, error_msg = nil)
136
+ # @param [#to_s] task_id Task ID
137
+ def task_report(status, task_id, success_msg = nil, error_msg = nil)
136
138
  case status
137
139
  when :non_trackable
138
140
  report = "Can't track director task".red
139
141
  when :track_timeout
140
142
  report = "Task tracking timeout".red
143
+ when :running
144
+ report = "Director task #{task_id.yellow} is running"
141
145
  when :error
142
146
  report = error_msg
143
147
  when :done
@@ -168,6 +172,12 @@ module Bosh::Cli
168
172
  err("Please choose deployment first") if deployment.nil?
169
173
  end
170
174
 
175
+ def no_track_unsupported
176
+ if @options.delete(:no_track)
177
+ say("Ignoring `" + "--no-track".yellow + "' option")
178
+ end
179
+ end
180
+
171
181
  def check_if_release_dir
172
182
  unless in_release_dir?
173
183
  err("Sorry, your current directory doesn't look " +
@@ -179,7 +189,8 @@ module Bosh::Cli
179
189
  if dirty_state?
180
190
  say("\n%s\n" % [`git status`])
181
191
  err("Your current directory has some local modifications, " +
182
- "please discard or commit them first")
192
+ "please discard or commit them first.\n\n" +
193
+ "Use the --force option to skip this check.")
183
194
  end
184
195
  end
185
196
 
@@ -15,6 +15,7 @@ module Bosh::Cli::Command
15
15
  "don't attempt to resolve problems"
16
16
  def perform(deployment_name = nil)
17
17
  auth_required
18
+ no_track_unsupported
18
19
  @auto_mode = options[:auto]
19
20
  @report_mode = options[:report]
20
21
 
@@ -30,10 +31,10 @@ module Bosh::Cli::Command
30
31
  say("Performing cloud check...")
31
32
  deployment_name ||= prepare_deployment_manifest["name"]
32
33
 
33
- status, _ = director.perform_cloud_scan(deployment_name)
34
+ status, task_id = director.perform_cloud_scan(deployment_name)
34
35
 
35
36
  if status != :done
36
- task_report(status)
37
+ task_report(status, task_id)
37
38
  exit(1)
38
39
  end
39
40
 
@@ -75,10 +76,10 @@ module Bosh::Cli::Command
75
76
  hash
76
77
  end
77
78
 
78
- status, _ = director.apply_resolutions(deployment_name, action_map)
79
+ status, task_id = director.apply_resolutions(deployment_name, action_map)
79
80
 
80
81
  if status != :done
81
- task_report(status)
82
+ task_report(status, task_id)
82
83
  exit(1)
83
84
  end
84
85
 
@@ -101,9 +101,9 @@ module Bosh::Cli::Command
101
101
  cancel_deployment
102
102
  end
103
103
 
104
- status, _ = director.deploy(manifest_yaml, :recreate => recreate)
104
+ status, task_id = director.deploy(manifest_yaml, :recreate => recreate)
105
105
 
106
- task_report(status, "Deployed #{desc}")
106
+ task_report(status, task_id, "Deployed #{desc}")
107
107
  end
108
108
 
109
109
  # bosh delete deployment
@@ -123,9 +123,9 @@ module Bosh::Cli::Command
123
123
  return
124
124
  end
125
125
 
126
- status, _ = director.delete_deployment(name, :force => force)
126
+ status, task_id = director.delete_deployment(name, :force => force)
127
127
 
128
- task_report(status, "Deleted deployment `#{name}'")
128
+ task_report(status, task_id, "Deleted deployment `#{name}'")
129
129
  end
130
130
 
131
131
  # bosh validate jobs
@@ -136,8 +136,19 @@ module Bosh::Cli::Command
136
136
  check_if_release_dir
137
137
  manifest = prepare_deployment_manifest(:resolve_properties => true)
138
138
 
139
- nl
140
- say("Analyzing release directory...".yellow)
139
+ if manifest["release"]
140
+ release_name = manifest["release"]["name"]
141
+ elsif manifest["releases"].count > 1
142
+ err("Cannot validate a deployment manifest with more than 1 release")
143
+ else
144
+ release_name = manifest["releases"].first["name"]
145
+ end
146
+ if release_name == release.dev_name || release_name == release.final_name
147
+ nl
148
+ say("Analyzing release directory...".yellow)
149
+ else
150
+ err("This release was not found in deployment manifest")
151
+ end
141
152
 
142
153
  say(" - discovering packages")
143
154
  packages = Bosh::Cli::PackageBuilder.discover(
@@ -78,10 +78,14 @@ module Bosh::Cli::Command
78
78
  end
79
79
  end
80
80
 
81
+ self.class.list_commands(good_matches)
82
+ end
83
+
84
+ def self.list_commands(commands)
81
85
  help_column_width = terminal_width - 5
82
86
  help_indent = 4
83
87
 
84
- good_matches.each_with_index do |command, i|
88
+ commands.each_with_index do |command, i|
85
89
  nl if i > 0
86
90
  margin = command.usage.size + 1
87
91
  say("#{command.usage_with_params.columnize(70, margin).green}")
@@ -93,4 +97,4 @@ module Bosh::Cli::Command
93
97
  end
94
98
 
95
99
  end
96
- end
100
+ end
@@ -115,10 +115,10 @@ module Bosh::Cli::Command
115
115
  nl
116
116
  say("Performing `#{op_desc}'...")
117
117
 
118
- status, _ = director.change_job_state(
118
+ status, task_id = director.change_job_state(
119
119
  manifest["name"], manifest_yaml, job, index, new_state)
120
120
 
121
- task_report(status, completion_desc)
121
+ task_report(status, task_id, completion_desc)
122
122
  end
123
123
 
124
124
  end
@@ -25,10 +25,10 @@ module Bosh::Cli::Command
25
25
 
26
26
  sanity_check_job_rename(manifest_yaml, old_name, new_name)
27
27
 
28
- status, _ = director.rename_job(
28
+ status, task_id = director.rename_job(
29
29
  manifest["name"], manifest_yaml, old_name, new_name, force)
30
30
 
31
- task_report(status, "Rename successful")
31
+ task_report(status, task_id, "Rename successful")
32
32
  end
33
33
 
34
34
  def sanity_check_job_rename(manifest_yaml, old_name, new_name)
@@ -16,6 +16,7 @@ module Bosh::Cli::Command
16
16
  def fetch_logs(job, index)
17
17
  auth_required
18
18
  target_required
19
+ no_track_unsupported
19
20
 
20
21
  if index !~ /^\d+$/
21
22
  err("Job index is expected to be a positive integer")
@@ -15,6 +15,9 @@ module Bosh::Cli::Command
15
15
  usage "status"
16
16
  desc "Show current status (current target, user, deployment info etc)"
17
17
  def status
18
+ cpi = nil
19
+ features = nil
20
+
18
21
  if config.target
19
22
  say("Updating director data...", " ")
20
23
 
@@ -26,6 +29,8 @@ module Bosh::Cli::Command
26
29
  config.target_name = status["name"]
27
30
  config.target_version = status["version"]
28
31
  config.target_uuid = status["uuid"]
32
+ cpi = status["cpi"]
33
+ features = status["features"]
29
34
  config.save
30
35
  say("done".green)
31
36
  end
@@ -46,6 +51,8 @@ module Bosh::Cli::Command
46
51
  print_value("Version", config.target_version)
47
52
  print_value("User", username, "not logged in")
48
53
  print_value("UUID", config.target_uuid)
54
+ print_value("CPI", cpi, "n/a (update director)")
55
+ print_feature_list(features) if features
49
56
  end
50
57
 
51
58
  nl
@@ -313,5 +320,24 @@ module Bosh::Cli::Command
313
320
  say(t) unless t.rows.empty?
314
321
  end
315
322
 
323
+ def print_feature_list(features)
324
+ if features.respond_to?(:each)
325
+ features.each do |feature, status|
326
+ print_value(feature, format_feature_status(status))
327
+ end
328
+ else
329
+ say("Unknown feature list: #{features.inspect}".red)
330
+ end
331
+ end
332
+
333
+ def format_feature_status(status)
334
+ if status.nil?
335
+ "n/a"
336
+ elsif status
337
+ "enabled"
338
+ else
339
+ "disabled"
340
+ end
341
+ end
316
342
  end
317
343
  end
@@ -184,9 +184,9 @@ module Bosh::Cli::Command
184
184
  end
185
185
 
186
186
  if confirmed?
187
- status, _ = director.delete_release(
187
+ status, task_id = director.delete_release(
188
188
  name, :force => force, :version => version)
189
- task_report(status, "Deleted `#{desc}'")
189
+ task_report(status, task_id, "Deleted `#{desc}'")
190
190
  else
191
191
  say("Canceled deleting release".green)
192
192
  end
@@ -258,12 +258,12 @@ module Bosh::Cli::Command
258
258
 
259
259
  if rebase
260
260
  say("Uploading release (#{"will be rebased".yellow})")
261
- status, _ = director.rebase_release(tarball_path)
262
- task_report(status, "Release rebased")
261
+ status, task_id = director.rebase_release(tarball_path)
262
+ task_report(status, task_id, "Release rebased")
263
263
  else
264
264
  say("\nUploading release\n")
265
- status, _ = director.upload_release(tarball_path)
266
- task_report(status, "Release uploaded")
265
+ status, task_id = director.upload_release(tarball_path)
266
+ task_report(status, task_id, "Release uploaded")
267
267
  end
268
268
  end
269
269
 
@@ -121,6 +121,7 @@ module Bosh::Cli::Command
121
121
  end
122
122
 
123
123
  if options[:gateway_host]
124
+ require "net/ssh/gateway"
124
125
  gw_host = options[:gateway_host]
125
126
  gw_user = options[:gateway_user] || ENV["USER"]
126
127
  gateway = Net::SSH::Gateway.new(gw_host, gw_user)
@@ -255,6 +256,8 @@ module Bosh::Cli::Command
255
256
  if gateway
256
257
  gateway.ssh(ip, user) { |ssh| yield ssh }
257
258
  else
259
+ require "net/ssh"
260
+ require "net/scp"
258
261
  Net::SSH.start(ip, user) { |ssh| yield ssh }
259
262
  end
260
263
  end
@@ -69,9 +69,9 @@ module Bosh::Cli::Command
69
69
  say("Uploading stemcell...")
70
70
  nl
71
71
 
72
- status, _ = director.upload_stemcell(stemcell.stemcell_file)
72
+ status, task_id = director.upload_stemcell(stemcell.stemcell_file)
73
73
 
74
- task_report(status, "Stemcell uploaded and created")
74
+ task_report(status, task_id, "Stemcell uploaded and created")
75
75
  end
76
76
 
77
77
  # bosh stemcells
@@ -105,9 +105,11 @@ module Bosh::Cli::Command
105
105
  desc "Show the list of publicly available stemcells for download."
106
106
  option "--full", "show the full download url"
107
107
  option "--tags tag1,tag2...", Array, "filter by tag"
108
+ option "--all", "show all stemcells"
108
109
  def list_public
109
110
  full = !!options[:full]
110
111
  tags = options[:tags] || [DEFAULT_PUB_STEMCELL_TAG]
112
+ tags = [ALL_STEMCELLS_TAG] if options[:all]
111
113
 
112
114
  yaml = get_public_stemcell_list
113
115
  stemcells_table = table do |t|
@@ -191,9 +193,9 @@ module Bosh::Cli::Command
191
193
  return
192
194
  end
193
195
 
194
- status, _ = director.delete_stemcell(name, version)
196
+ status, task_id = director.delete_stemcell(name, version)
195
197
 
196
- task_report(status, "Deleted stemcell `#{name}/#{version}'")
198
+ task_report(status, task_id, "Deleted stemcell `#{name}/#{version}'")
197
199
  end
198
200
 
199
201
  private
@@ -9,6 +9,7 @@ module Bosh::Cli::Command
9
9
  option "--full", "Return detailed VM information"
10
10
  def list(deployment_name = nil)
11
11
  auth_required
12
+ no_track_unsupported
12
13
  show_full_stats = options[:full]
13
14
 
14
15
  if deployment_name.nil?
@@ -88,7 +88,7 @@ module BoshExtensions
88
88
 
89
89
  # @return [Fixnum]
90
90
  def terminal_width
91
- [HighLine::SystemExtensions.terminal_size[0], 120].min
91
+ STDIN.tty? ? [HighLine::SystemExtensions.terminal_size[0], 120].min : 80
92
92
  end
93
93
  end
94
94
 
@@ -146,11 +146,12 @@ module Bosh::Cli
146
146
  elsif blobstore_id
147
147
  say("FOUND REMOTE".yellow)
148
148
  say("Downloading #{blobstore_id.to_s.green}...")
149
+ tmp_file = Tempfile.new("")
150
+ @blobstore.get(blobstore_id, tmp_file)
151
+ tmp_file.close
149
152
 
150
- payload = @blobstore.get(blobstore_id)
151
-
152
- if Digest::SHA1.hexdigest(payload) == sha1
153
- File.open(filename, "w") { |f| f.write(payload) }
153
+ if Digest::SHA1.file(tmp_file.path).hexdigest == sha1
154
+ FileUtils.mv(tmp_file.path, filename)
154
155
  else
155
156
  err("#{desc} is corrupted in blobstore (id=#{blobstore_id})")
156
157
  end
@@ -126,6 +126,9 @@ module Bosh::Cli
126
126
  @options[:non_interactive] = true
127
127
  Config.colorize = false
128
128
  end
129
+ opts.on("-N", "--no-track", "Return Task ID and don't track") do
130
+ @options[:no_track] = true
131
+ end
129
132
  opts.on("-t", "--target URL", "Override target") do |target|
130
133
  @options[:target] = target
131
134
  end
@@ -147,19 +150,17 @@ module Bosh::Cli
147
150
  def load_plugins
148
151
  plugins_glob = "bosh/cli/commands/*.rb"
149
152
 
150
- unless Gem.respond_to?(:find_files)
153
+ unless Gem::Specification.respond_to?(:latest_specs) &&
154
+ Gem::Specification.instance_methods.include?(:matches_for_glob)
151
155
  say("Cannot load plugins, ".yellow +
152
156
  "please run `gem update --system' to ".yellow +
153
157
  "update your RubyGems".yellow)
154
158
  return
155
159
  end
156
160
 
157
- plugins = begin
158
- Gem.find_files(plugins_glob, true)
159
- rescue ArgumentError
160
- # Handling rubygems compatibility issue
161
- Gem.find_files(plugins_glob)
162
- end
161
+ plugins = Gem::Specification.latest_specs(true).map { |spec|
162
+ spec.matches_for_glob(plugins_glob)
163
+ }.flatten
163
164
 
164
165
  plugins.each do |plugin|
165
166
  n_commands = Config.commands.size
@@ -252,4 +253,4 @@ module Bosh::Cli
252
253
  search_parse_tree(@parse_tree)
253
254
  end
254
255
  end
255
- end
256
+ end
@@ -10,6 +10,8 @@ module Bosh
10
10
 
11
11
  attr_reader :output
12
12
 
13
+ attr_reader :renderer
14
+
13
15
  # @param [Bosh::Cli::Director] director
14
16
  # @param [Integer] task_id
15
17
  # @param [Hash] options
@@ -28,7 +30,9 @@ module Bosh
28
30
  @cache = Config.cache
29
31
  @task = Bosh::Cli::DirectorTask.new(@director, @task_id, @log_type)
30
32
 
31
- if options[:raw_output]
33
+ if options[:renderer]
34
+ @renderer = options[:renderer]
35
+ elsif options[:raw_output]
32
36
  @renderer = Bosh::Cli::TaskLogRenderer.new
33
37
  else
34
38
  @renderer = Bosh::Cli::TaskLogRenderer.create_for_log_type(@log_type)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bosh
4
4
  module Cli
5
- VERSION = "1.0.1"
5
+ VERSION = "1.0.2"
6
6
  end
7
7
  end
@@ -3,5 +3,5 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe Bosh::Cli::JobPropertyValidator do
6
-
6
+ pending "needs tests"
7
7
  end
@@ -124,4 +124,8 @@ describe Bosh::Cli::TaskTracker do
124
124
  tracker.track.should == :cancelled
125
125
  end
126
126
 
127
+ it "accepts alternate :renderer option" do
128
+ tracker = make_tracker("42", {:renderer => "I'm a renderer"})
129
+ tracker.renderer.should == "I'm a renderer"
130
+ end
127
131
  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.0.1
4
+ version: 1.0.2
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: 2012-11-01 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bosh_common
@@ -355,7 +355,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
355
355
  version: '0'
356
356
  segments:
357
357
  - 0
358
- hash: 3824294478508982037
358
+ hash: 1768623608399422134
359
359
  required_rubygems_version: !ruby/object:Gem::Requirement
360
360
  none: false
361
361
  requirements:
@@ -364,7 +364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
364
364
  version: '0'
365
365
  segments:
366
366
  - 0
367
- hash: 3824294478508982037
367
+ hash: 1768623608399422134
368
368
  requirements: []
369
369
  rubyforge_project:
370
370
  rubygems_version: 1.8.24