Class: Bosh::Cli::Command::Micro
- Inherits:
-
Base
- Object
- Base
- Bosh::Cli::Command::Micro
show all
- Includes:
- Deployer::Helpers
- Defined in:
- lib/bosh/cli/commands/micro.rb
Constant Summary
collapse
- MICRO_DIRECTOR_PORT =
25555
- DEFAULT_CONFIG_PATH =
File.expand_path('~/.bosh_deployer_config')
- MICRO_BOSH_YAML =
'micro_bosh.yml'
Deployer::Helpers::DEPLOYMENTS_FILE
Instance Method Summary
collapse
#close_ssh_sessions, #cloud_plugin, #dig_hash, #is_tgz?, #process_exists?, #remote_tunnel, #socket_readable?, #strip_relative_path
Constructor Details
#initialize(runner) ⇒ Micro
Returns a new instance of Micro.
15
16
17
18
|
# File 'lib/bosh/cli/commands/micro.rb', line 15
def initialize(runner)
super(runner)
options[:config] ||= DEFAULT_CONFIG_PATH
end
|
Instance Method Details
#agent(*args) ⇒ Object
287
288
289
290
291
292
293
294
295
296
297
298
|
# File 'lib/bosh/cli/commands/micro.rb', line 287
def agent(*args)
message = args.shift
args = args.map do |arg|
if File.exists?(arg)
load_yaml_file(arg)
else
arg
end
end
say(deployer.agent.send(message.to_sym, *args).pretty_inspect)
end
|
#apply(spec) ⇒ Object
302
303
304
|
# File 'lib/bosh/cli/commands/micro.rb', line 302
def apply(spec)
deployer.apply(Bosh::Deployer::Specification.new(load_yaml_file(spec)))
end
|
#delete ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# File 'lib/bosh/cli/commands/micro.rb', line 196
def delete
unless deployer.exists?
err 'No existing instance to delete'
end
name = deployer.state.name
say(
"\nYou are going to delete micro BOSH deployment `#{name}'.\n\n" +
"THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red
)
unless confirmed?
say 'Canceled deleting deployment'.make_green
return
end
renderer = Bosh::Deployer::DeployerRenderer.new
renderer.start
deployer.renderer = renderer
start_time = Time.now
deployer.delete_deployment
renderer.finish('done')
duration = renderer.duration || (Time.now - start_time)
say("Deleted deployment '#{name}', took #{format_time(duration).make_green} to complete")
end
|
#list ⇒ Object
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/bosh/cli/commands/micro.rb', line 230
def list
file = File.join(work_dir, DEPLOYMENTS_FILE)
if File.exists?(file)
deployments = load_yaml_file(file)['instances']
else
deployments = []
end
err('No deployments') if deployments.size == 0
na = 'n/a'
deployments_table = table do |t|
t.headings = ['Name', 'VM name', 'Stemcell name']
deployments.each do |r|
t << [r[:name], r[:vm_cid] || na, r[:stemcell_cid] || na]
end
end
say("\n")
say(deployments_table)
say("\n")
say("Deployments total: #{deployments.size}")
end
|
#micro_deployment(name = nil) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/bosh/cli/commands/micro.rb', line 32
def micro_deployment(name = nil)
if name
set_current(name)
else
show_current
end
end
|
#micro_help ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/bosh/cli/commands/micro.rb', line 22
def micro_help
say('bosh micro sub-commands:')
nl
cmds = Bosh::Cli::Config.commands
cmds = cmds.values.find_all { |c| c.usage =~ /^micro/ }
Bosh::Cli::Command::Help.list_commands(cmds)
end
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/bosh/cli/commands/micro.rb', line 107
def perform(stemcell = nil)
update = !!options[:update]
err 'No deployment set' unless deployment
manifest = load_yaml_file(deployment)
if stemcell.nil?
unless manifest.is_a?(Hash)
err('Invalid manifest format')
end
stemcell = dig_hash(manifest, 'resources', 'cloud_properties', 'image_id')
if stemcell.nil?
err 'No stemcell provided'
end
end
deployer.check_dependencies
rel_path = strip_relative_path(deployment)
desc = "`#{rel_path.make_green}' to `#{target_name.make_green}'"
if deployer.exists?
if !options[:update_if_exists] && !update
err 'Instance exists. Did you mean to --update?'
end
confirmation = 'Updating'
method = :update_deployment
else
prefered_dir = File.dirname(File.dirname(deployment))
unless prefered_dir == Dir.pwd
confirm_deployment(
"\n#{'No `bosh-deployments.yml` file found in current directory.'.make_red}\n\n" +
'Conventionally, `bosh-deployments.yml` should be saved in ' +
"#{prefered_dir.make_green}.\n" +
"Is #{Dir.pwd.make_yellow} a directory where you can save state?"
)
end
err 'No existing instance to update' if update
confirmation = 'Deploying new micro BOSH instance'
method = :create_deployment
unless dig_hash(manifest, 'resources', 'persistent_disk')
quit("No persistent disk configured in #{MICRO_BOSH_YAML}".make_red)
end
end
confirm_deployment("#{confirmation} #{desc}")
if is_tgz?(stemcell)
stemcell_file = Bosh::Cli::Stemcell.new(stemcell)
say("\nVerifying stemcell...")
stemcell_file.validate
say("\n")
unless stemcell_file.valid?
err('Stemcell is invalid, please fix, verify and upload again')
end
stemcell_archive = Bosh::Stemcell::Archive.new(stemcell)
end
renderer = Bosh::Deployer::DeployerRenderer.new
renderer.start
deployer.renderer = renderer
start_time = Time.now
deployer.send(method, stemcell, stemcell_archive)
renderer.finish('done')
duration = renderer.duration || (Time.now - start_time)
update_target
say("Deployed #{desc}, took #{format_time(duration).make_green} to complete")
end
|
#set_current(name) ⇒ Object
rubocop:disable MethodLength
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/bosh/cli/commands/micro.rb', line 41
def set_current(name)
manifest_filename = find_deployment(name)
unless File.exists?(manifest_filename)
err "Missing manifest for #{name} (tried '#{manifest_filename}')"
end
manifest = load_yaml_file(manifest_filename)
unless manifest.is_a?(Hash)
err 'Invalid manifest format'
end
if manifest['network'].blank?
err 'network is not defined in deployment manifest'
end
ip = deployer(manifest_filename).discover_bosh_ip || name
if target
old_director_ip = URI.parse(target).host
else
old_director_ip = nil
end
if old_director_ip != ip
set_target(ip)
say "#{'WARNING!'.make_red} Your target has been changed to `#{target.make_red}'!"
end
say "Deployment set to '#{manifest_filename.make_green}'"
config.set_deployment(manifest_filename)
config.save
end
|
#show_current ⇒ Object
rubocop:enable MethodLength
76
77
78
|
# File 'lib/bosh/cli/commands/micro.rb', line 76
def show_current
say(deployment ? "Current deployment is '#{deployment.make_green}'" : 'Deployment not set')
end
|
#status ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/bosh/cli/commands/micro.rb', line 82
def status
stemcell_cid = deployer_state(:stemcell_cid)
stemcell_name = deployer_state(:stemcell_name)
vm_cid = deployer_state(:vm_cid)
disk_cid = deployer_state(:disk_cid)
deployment = config.deployment ? config.deployment.make_green : 'not set'.make_red
say('Stemcell CID'.ljust(15) + stemcell_cid)
say('Stemcell name'.ljust(15) + stemcell_name)
say('VM CID'.ljust(15) + vm_cid)
say('Disk CID'.ljust(15) + disk_cid)
say('Micro BOSH CID'.ljust(15) + Bosh::Deployer::Config.uuid)
say('Deployment'.ljust(15) + deployment)
update_target
target_name = target ? target.make_green : 'not set'.make_red
say('Target'.ljust(15) + target_name)
end
|