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.
- checksums.yaml +4 -4
- data/lib/cli/base_command.rb +1 -1
- data/lib/cli/client/director.rb +38 -14
- data/lib/cli/commands/deployment.rb +57 -57
- data/lib/cli/commands/disks.rb +63 -0
- data/lib/cli/commands/instances.rb +99 -49
- data/lib/cli/commands/job_management.rb +11 -11
- data/lib/cli/commands/log_management.rb +9 -11
- data/lib/cli/commands/maintenance.rb +16 -40
- data/lib/cli/commands/snapshot.rb +14 -5
- data/lib/cli/commands/ssh.rb +12 -12
- data/lib/cli/commands/vm.rb +5 -5
- data/lib/cli/commands/vms.rb +36 -9
- data/lib/cli/core_ext.rb +1 -1
- data/lib/cli/deployment_helper.rb +11 -5
- data/lib/cli/job_command_args.rb +8 -12
- data/lib/cli/job_state.rb +8 -8
- data/lib/cli/logs_downloader.rb +2 -2
- data/lib/cli/resources/job.rb +2 -2
- data/lib/cli/version.rb +1 -1
- metadata +9 -8
data/lib/cli/commands/ssh.rb
CHANGED
@@ -20,19 +20,19 @@ module Bosh::Cli
|
|
20
20
|
|
21
21
|
def shell(*args)
|
22
22
|
if args.size > 0
|
23
|
-
job,
|
23
|
+
job, id, command = JobCommandArgs.new(args).to_a
|
24
24
|
else
|
25
25
|
command = ''
|
26
|
-
job,
|
26
|
+
job, id = prompt_for_job_and_index
|
27
27
|
end
|
28
28
|
|
29
29
|
manifest = prepare_deployment_manifest(show_state: true)
|
30
30
|
|
31
31
|
if command.empty?
|
32
|
-
setup_interactive_shell(manifest.name, job,
|
32
|
+
setup_interactive_shell(manifest.name, job, id)
|
33
33
|
else
|
34
|
-
say("Executing `#{command.join(' ')}' on #{job}/#{
|
35
|
-
perform_operation(:exec, manifest.name, job,
|
34
|
+
say("Executing `#{command.join(' ')}' on #{job}/#{id}")
|
35
|
+
perform_operation(:exec, manifest.name, job, id, command)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -105,7 +105,7 @@ module Bosh::Cli
|
|
105
105
|
# @param [String] job
|
106
106
|
# @param [Integer] index
|
107
107
|
# @param [optional,String] password
|
108
|
-
def setup_ssh(deployment_name, job,
|
108
|
+
def setup_ssh(deployment_name, job, id, password)
|
109
109
|
|
110
110
|
say("Target deployment is `#{deployment_name}'")
|
111
111
|
nl
|
@@ -114,7 +114,7 @@ module Bosh::Cli
|
|
114
114
|
ssh_session = SSHSession.new
|
115
115
|
|
116
116
|
status, task_id = director.setup_ssh(
|
117
|
-
deployment_name, job,
|
117
|
+
deployment_name, job, id, ssh_session.user,
|
118
118
|
ssh_session.public_key, encrypt_password(password))
|
119
119
|
|
120
120
|
unless status == :done
|
@@ -158,7 +158,7 @@ module Bosh::Cli
|
|
158
158
|
nl
|
159
159
|
say('Cleaning up ssh artifacts')
|
160
160
|
ssh_session.cleanup
|
161
|
-
indices = sessions.map { |session| session['index'] }
|
161
|
+
indices = sessions.map { |session| session['id'] || session['index'] }
|
162
162
|
director.cleanup_ssh(deployment_name, job, "^#{ssh_session.user}$", indices)
|
163
163
|
gateway.shutdown! if gateway
|
164
164
|
end
|
@@ -166,17 +166,17 @@ module Bosh::Cli
|
|
166
166
|
|
167
167
|
# @param [String] job Job name
|
168
168
|
# @param [Integer] index Job index
|
169
|
-
def setup_interactive_shell(deployment_name, job,
|
169
|
+
def setup_interactive_shell(deployment_name, job, id)
|
170
170
|
password = options[:default_password] || ''
|
171
171
|
|
172
|
-
setup_ssh(deployment_name, job,
|
172
|
+
setup_ssh(deployment_name, job, id, password) do |sessions, gateway, ssh_session|
|
173
173
|
session = sessions.first
|
174
174
|
|
175
175
|
unless session['status'] == 'success' && session['ip']
|
176
|
-
err("Failed to set up SSH on #{job}/#{
|
176
|
+
err("Failed to set up SSH on #{job}/#{id}: #{session.inspect}")
|
177
177
|
end
|
178
178
|
|
179
|
-
say("Starting interactive shell on job #{job}/#{
|
179
|
+
say("Starting interactive shell on job #{job}/#{id}")
|
180
180
|
|
181
181
|
skip_strict_host_key_checking = options[:strict_host_key_checking] =~ (/(no|false)$/i) ?
|
182
182
|
'-o StrictHostKeyChecking=no' : '-o StrictHostKeyChecking=yes'
|
data/lib/cli/commands/vm.rb
CHANGED
@@ -6,21 +6,21 @@ module Bosh::Cli
|
|
6
6
|
class Vm < Base
|
7
7
|
usage 'vm resurrection'
|
8
8
|
desc 'Enable/Disable resurrection for a given vm'
|
9
|
-
def resurrection_state(job=nil,
|
9
|
+
def resurrection_state(job=nil, index_or_id=nil, new_state)
|
10
10
|
auth_required
|
11
11
|
|
12
|
-
if job.nil? &&
|
12
|
+
if job.nil? && index_or_id.nil?
|
13
13
|
resurrection = Resurrection.new(new_state)
|
14
14
|
show_current_state
|
15
15
|
|
16
16
|
director.change_vm_resurrection_for_all(resurrection.paused?)
|
17
17
|
else
|
18
|
-
job_args = JobCommandArgs.new([job,
|
19
|
-
job,
|
18
|
+
job_args = JobCommandArgs.new([job, index_or_id])
|
19
|
+
job, index_or_id, _ = job_args.to_a
|
20
20
|
resurrection = Resurrection.new(new_state)
|
21
21
|
|
22
22
|
manifest = prepare_deployment_manifest(show_state: true)
|
23
|
-
director.change_vm_resurrection(manifest.name, job,
|
23
|
+
director.change_vm_resurrection(manifest.name, job, index_or_id, resurrection.paused?)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/cli/commands/vms.rb
CHANGED
@@ -34,15 +34,18 @@ module Bosh::Cli::Command
|
|
34
34
|
return
|
35
35
|
end
|
36
36
|
|
37
|
-
sorted = vms
|
38
|
-
|
39
|
-
|
40
|
-
s = a['resource_pool'].to_s <=> b['resource_pool'].to_s if s == 0
|
41
|
-
s
|
42
|
-
end
|
37
|
+
sorted = sort(vms)
|
38
|
+
|
39
|
+
has_az = vms.any? {|vm| vm.has_key? 'az' }
|
43
40
|
|
44
41
|
vms_table = table do |t|
|
45
|
-
headings = ['
|
42
|
+
headings = ['VM', 'State']
|
43
|
+
|
44
|
+
if has_az
|
45
|
+
headings << 'AZ'
|
46
|
+
end
|
47
|
+
headings += ['VM Type', 'IPs']
|
48
|
+
|
46
49
|
if options[:details]
|
47
50
|
headings += ['CID', 'Agent ID', 'Resurrection']
|
48
51
|
end
|
@@ -58,12 +61,26 @@ module Bosh::Cli::Command
|
|
58
61
|
t.headings = headings
|
59
62
|
|
60
63
|
sorted.each do |vm|
|
61
|
-
|
64
|
+
job_name = vm['job_name'] || 'unknown'
|
65
|
+
job_index = vm['index'] || 'unknown'
|
66
|
+
job = vm.has_key?('id') ? "#{job_name}/#{job_index} (#{vm['id']})" : "#{job_name}/#{job_index}"
|
62
67
|
ips = Array(vm['ips']).join("\n")
|
63
68
|
dns_records = Array(vm['dns']).join("\n")
|
64
69
|
vitals = vm['vitals']
|
70
|
+
az = vm['az'].nil? ? 'n/a' : vm['az']
|
71
|
+
|
72
|
+
row = [job, vm['job_state']]
|
73
|
+
if has_az
|
74
|
+
row << az
|
75
|
+
end
|
76
|
+
|
77
|
+
if vm['resource_pool']
|
78
|
+
row << vm['resource_pool']
|
79
|
+
else
|
80
|
+
row << vm['vm_type']
|
81
|
+
end
|
65
82
|
|
66
|
-
row
|
83
|
+
row << ips
|
67
84
|
|
68
85
|
if options[:details]
|
69
86
|
row += [vm['vm_cid'], vm['agent_id'], vm['resurrection_paused'] ? 'paused' : 'active']
|
@@ -112,5 +129,15 @@ module Bosh::Cli::Command
|
|
112
129
|
say('VMs total: %d' % vms.size)
|
113
130
|
end
|
114
131
|
|
132
|
+
def sort(vms)
|
133
|
+
sorted = vms.sort do |a, b|
|
134
|
+
comparison = a['job_name'].to_s <=> b['job_name'].to_s
|
135
|
+
comparison = a['az'].to_s <=> b['az'].to_s if comparison == 0
|
136
|
+
comparison = a['index'].to_i <=> b['index'].to_i if comparison == 0
|
137
|
+
comparison
|
138
|
+
end
|
139
|
+
sorted
|
140
|
+
end
|
141
|
+
|
115
142
|
end
|
116
143
|
end
|
data/lib/cli/core_ext.rb
CHANGED
@@ -5,7 +5,7 @@ module BoshExtensions
|
|
5
5
|
def say(message, sep = "\n")
|
6
6
|
return unless Bosh::Cli::Config.output && message
|
7
7
|
message = message.dup.to_s
|
8
|
-
sep = "" if message[-1
|
8
|
+
sep = "" if message[-1] == sep
|
9
9
|
Bosh::Cli::Config.output.print("#{$indent}#{message}#{sep}")
|
10
10
|
end
|
11
11
|
|
@@ -129,14 +129,20 @@ module Bosh::Cli
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def prompt_for_job_and_index
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
manifest = prepare_deployment_manifest
|
133
|
+
deployment_name = manifest.name
|
134
|
+
instances = director.fetch_vm_state(deployment_name, {}, false)
|
135
|
+
return [instances.first['job'], instances.first['index'] ] if instances.size == 1
|
135
136
|
|
136
137
|
choose do |menu|
|
137
138
|
menu.prompt = 'Choose an instance: '
|
138
|
-
|
139
|
-
|
139
|
+
instances.each do |instance|
|
140
|
+
job_name = instance['job']
|
141
|
+
index = instance['index']
|
142
|
+
id = instance['id']
|
143
|
+
name = "#{job_name}/#{index}"
|
144
|
+
name = "#{name} (#{id})" if id
|
145
|
+
menu.choice(name) { [job_name, index] }
|
140
146
|
end
|
141
147
|
end
|
142
148
|
end
|
data/lib/cli/job_command_args.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
module Bosh::Cli
|
2
|
-
class JobCommandArgs < Struct.new(:job, :
|
2
|
+
class JobCommandArgs < Struct.new(:job, :id, :args)
|
3
3
|
def initialize(args)
|
4
4
|
job = args.shift
|
5
5
|
err('Please provide job name') if job.nil?
|
6
|
-
job,
|
6
|
+
job, id = job.split('/', 2)
|
7
7
|
|
8
|
-
if
|
9
|
-
if index =~ /^\d+$/
|
10
|
-
index = index.to_i
|
11
|
-
else
|
12
|
-
err('Invalid job index, integer number expected')
|
13
|
-
end
|
14
|
-
elsif args[0] =~ /^\d+$/
|
15
|
-
index = args.shift.to_i
|
16
|
-
end
|
8
|
+
id = args.shift if id.nil?
|
17
9
|
|
18
10
|
self.job = job
|
19
|
-
self.
|
11
|
+
self.id = id
|
20
12
|
self.args = args
|
21
13
|
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
id
|
17
|
+
end
|
22
18
|
end
|
23
19
|
end
|
data/lib/cli/job_state.rb
CHANGED
@@ -30,19 +30,20 @@ module Bosh::Cli
|
|
30
30
|
@options = options
|
31
31
|
end
|
32
32
|
|
33
|
-
def change(state, job,
|
34
|
-
|
33
|
+
def change(state, job, index_or_id, force)
|
34
|
+
job, index_or_id = job.split('/') if index_or_id.nil?
|
35
|
+
description = job_description(job, index_or_id)
|
35
36
|
op_desc = OPERATION_DESCRIPTIONS.fetch(state) % description
|
36
37
|
new_state = NEW_STATES.fetch(state)
|
37
38
|
completion_desc = COMPLETION_DESCRIPTIONS.fetch(state) % description.make_green
|
38
|
-
status, task_id = change_job_state(new_state, job,
|
39
|
+
status, task_id = change_job_state(new_state, job, index_or_id, op_desc, force)
|
39
40
|
|
40
41
|
[status, task_id, completion_desc]
|
41
42
|
end
|
42
43
|
|
43
44
|
private
|
44
45
|
|
45
|
-
def change_job_state(new_state, job,
|
46
|
+
def change_job_state(new_state, job, index_or_id, operation_desc, force)
|
46
47
|
@command.say("You are about to #{operation_desc.make_green}")
|
47
48
|
|
48
49
|
check_if_manifest_changed(@manifest.hash, force)
|
@@ -52,7 +53,7 @@ module Bosh::Cli
|
|
52
53
|
|
53
54
|
@command.nl
|
54
55
|
@command.say("Performing `#{operation_desc}'...")
|
55
|
-
@command.director.change_job_state(@manifest.name, @manifest.yaml, job,
|
56
|
+
@command.director.change_job_state(@manifest.name, @manifest.yaml, job, index_or_id, new_state, @options)
|
56
57
|
end
|
57
58
|
|
58
59
|
|
@@ -64,10 +65,9 @@ module Bosh::Cli
|
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
|
-
def job_description(job,
|
68
|
+
def job_description(job, index_or_id)
|
68
69
|
return 'all jobs' if job == '*'
|
69
|
-
|
70
|
+
index_or_id ? "#{job}/#{index_or_id}" : "#{job}/*"
|
70
71
|
end
|
71
|
-
|
72
72
|
end
|
73
73
|
end
|
data/lib/cli/logs_downloader.rb
CHANGED
@@ -5,9 +5,9 @@ module Bosh::Cli
|
|
5
5
|
@ui = ui
|
6
6
|
end
|
7
7
|
|
8
|
-
def build_destination_path(job_name,
|
8
|
+
def build_destination_path(job_name, job_index_or_id, directory)
|
9
9
|
time = Time.now.strftime('%Y-%m-%d-%H-%M-%S')
|
10
|
-
File.join(directory, "#{job_name}.#{
|
10
|
+
File.join(directory, "#{job_name}.#{job_index_or_id}.#{time}.tgz")
|
11
11
|
end
|
12
12
|
|
13
13
|
def download(resource_id, logs_destination_path)
|
data/lib/cli/resources/job.rb
CHANGED
@@ -59,7 +59,7 @@ module Bosh::Cli::Resources
|
|
59
59
|
raise Bosh::Cli::InvalidJob, "'#{name}' is not a valid BOSH identifier"
|
60
60
|
end
|
61
61
|
|
62
|
-
unless spec['templates'].is_a?(Hash)
|
62
|
+
unless spec['templates'].nil? or spec['templates'].is_a?(Hash)
|
63
63
|
raise Bosh::Cli::InvalidJob, "Incorrect templates section in '#{name}' job spec (Hash expected, #{spec['templates'].class} given)"
|
64
64
|
end
|
65
65
|
|
@@ -138,7 +138,7 @@ module Bosh::Cli::Resources
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def templates
|
141
|
-
spec['templates'].keys
|
141
|
+
spec['templates'] ? spec['templates'].keys : []
|
142
142
|
end
|
143
143
|
|
144
144
|
def templates_dir
|
data/lib/cli/version.rb
CHANGED
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.
|
4
|
+
version: 1.3163.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VMware
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-23 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.
|
19
|
+
version: 1.3163.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.
|
26
|
+
version: 1.3163.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.
|
33
|
+
version: 1.3163.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.
|
40
|
+
version: 1.3163.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.
|
131
|
+
version: 1.3163.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.
|
138
|
+
version: 1.3163.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/disks.rb
|
362
363
|
- lib/cli/commands/errand.rb
|
363
364
|
- lib/cli/commands/help.rb
|
364
365
|
- lib/cli/commands/instances.rb
|