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")
- MICRO_BOSH_YAML =
"micro_bosh.yml"
Deployer::Helpers::DEPLOYMENTS_FILE
Instance Method Summary
collapse
#cloud_plugin, #dig_hash, #is_tgz?
Constructor Details
#initialize(runner) ⇒ Micro
Returns a new instance of Micro.
14
15
16
17
|
# File 'lib/bosh/cli/commands/micro.rb', line 14
def initialize(runner)
super(runner)
options[:config] ||= DEFAULT_CONFIG_PATH end
|
Instance Method Details
#agent(*args) ⇒ Object
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/bosh/cli/commands/micro.rb', line 243
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
258
259
260
|
# File 'lib/bosh/cli/commands/micro.rb', line 258
def apply(spec)
deployer.apply(load_yaml_file(spec))
end
|
#delete ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/bosh/cli/commands/micro.rb', line 184
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/bosh/cli/commands/micro.rb', line 216
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
|
#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
21
22
23
24
25
26
27
28
|
# File 'lib/bosh/cli/commands/micro.rb', line 21
def micro_help
say("bosh micro sub-commands:")
nl
cmds = Bosh::Cli::Config.commands.values.find_all {|c|
c.usage =~ /^micro/
}
Bosh::Cli::Command::Help.list_commands(cmds)
end
|
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/bosh/cli/commands/micro.rb', line 103
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 = 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 in #{MICRO_BOSH_YAML}".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
40
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
|
# File 'lib/bosh/cli/commands/micro.rb', line 40
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
74
75
76
|
# File 'lib/bosh/cli/commands/micro.rb', line 74
def show_current
say(deployment ? "Current deployment is '#{deployment.green}'" : "Deployment not set")
end
|
#status ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/bosh/cli/commands/micro.rb', line 80
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 = target ? target.green : "not set".red
say("Target".ljust(15) + target_name)
end
|