Class: Bosh::Cli::Command::Micro
- Inherits:
-
Base
- Object
- Base
- Bosh::Cli::Command::Micro
show all
- Includes:
- DeploymentHelper, Deployer::Helpers
- Defined in:
- lib/bosh/cli/commands/micro.rb
Defined Under Namespace
Classes: DeployerRenderer
Constant Summary
collapse
- MICRO_DIRECTOR_PORT =
25555
- DEFAULT_CONFIG_PATH =
File.expand_path("~/.bosh_deployer_config")
Deployer::Helpers::DEPLOYMENTS_FILE
Instance Method Summary
collapse
#cloud_plugin, #dig_hash, #is_tgz?
Constructor Details
#initialize(options = {}) ⇒ Micro
Returns a new instance of Micro.
56
57
58
59
|
# File 'lib/bosh/cli/commands/micro.rb', line 56
def initialize(options = {})
options[:config] ||= DEFAULT_CONFIG_PATH super(options)
end
|
Instance Method Details
#agent(*args) ⇒ Object
252
253
254
255
256
257
258
259
260
261
262
263
|
# File 'lib/bosh/cli/commands/micro.rb', line 252
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
265
266
267
|
# File 'lib/bosh/cli/commands/micro.rb', line 265
def apply(spec)
deployer.apply(load_yaml_file(spec))
end
|
#delete ⇒ Object
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
|
# File 'lib/bosh/cli/commands/micro.rb', line 159
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".red
unless confirmed?
say "Canceled deleting deployment".green
return
end
renderer = 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).green} to complete")
end
|
#list ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/bosh/cli/commands/micro.rb', line 227
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: %d" % deployments.size)
end
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
|
# File 'lib/bosh/cli/commands/micro.rb', line 81
def perform(*options)
update = options.delete("--update")
stemcell = options.shift
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, "cloud", "properties", "stemcell", "image_id")
if stemcell.nil?
err "No stemcell provided"
end
end
rel_path = deployment[/#{Regexp.escape File.join(work_dir, '')}(.*)/, 1]
desc = "`#{rel_path.green}' to `#{target_name.green}'"
if update
unless deployer.exists?
err "No existing instance to update"
end
confirmation = "Updating"
method = :update_deployment
else
if deployer.exists?
err "Instance exists. Did you mean to --update?"
end
unless dig_hash(manifest, "resources", "persistent_disk")
quit("No persistent disk configured!".red)
end
confirmation = "Deploying new"
method = :create_deployment
end
confirm_deployment("#{confirmation} micro BOSH instance #{desc}")
if is_tgz?(stemcell)
stemcell_file = Bosh::Cli::Stemcell.new(stemcell, cache)
say("\nVerifying stemcell...")
stemcell_file.validate
say("\n")
unless stemcell_file.valid?
err("Stemcell is invalid, please fix, verify and upload again")
end
end
renderer = DeployerRenderer.new
renderer.start
deployer.renderer = renderer
start_time = Time.now
deployer.send(method, stemcell)
renderer.finish("done")
duration = renderer.duration || (Time.now - start_time)
update_target
say("Deployed #{desc}, took #{format_time(duration).green} to complete")
end
|
#set_current(name) ⇒ Object
189
190
191
192
193
194
195
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
|
# File 'lib/bosh/cli/commands/micro.rb', line 189
def set_current(name)
manifest_filename = find_deployment(name)
if !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!".red} Your target has been changed to `#{target.red}'!"
end
say "Deployment set to '#{manifest_filename.green}'"
config.set_deployment(manifest_filename)
config.save
end
|
#show_current ⇒ Object
223
224
225
|
# File 'lib/bosh/cli/commands/micro.rb', line 223
def show_current
say(deployment ? "Current deployment is '#{deployment.green}'" : "Deployment not set")
end
|
#status ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/bosh/cli/commands/micro.rb', line 61
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.green : "not set".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 = full_target_name ? full_target_name.green : "not set".red
say("Target".ljust(15) + target_name)
end
|