Class: Luban::Deployment::Command
Defined Under Namespace
Modules: Tasks
Constant Summary
Parameters::General::DefaultLubanRootPath
Class Attribute Summary collapse
#config
Class Method Summary
collapse
Instance Method Summary
collapse
included
#parameter
#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?
Class Attribute Details
.default_templates_paths ⇒ Object
Returns the value of attribute default_templates_paths.
277
278
279
|
# File 'lib/luban/deployment/cli/command.rb', line 277
def default_templates_paths
@default_templates_paths
end
|
Class Method Details
.default_worker_class ⇒ Object
279
280
281
|
# File 'lib/luban/deployment/cli/command.rb', line 279
def default_worker_class
Luban::Deployment::Worker::Base
end
|
.dispatch_task(task, to:, as: task, locally: false, &blk) ⇒ Object
292
293
294
295
296
297
298
299
|
# File 'lib/luban/deployment/cli/command.rb', line 292
def dispatch_task(task, to:, as: task, locally: false, &blk)
define_method(task) do |args:, opts:|
run_task(cmd: as, args: args, opts: opts, locally: locally,
worker_class: self.class.worker_class(to), &blk)
end
protected task
end
|
.inherited(subclass) ⇒ Object
269
270
271
272
273
274
275
|
# File 'lib/luban/deployment/cli/command.rb', line 269
def inherited(subclass)
super
paths = instance_variable_get('@default_templates_paths')
subclass.instance_variable_set('@default_templates_paths', paths.nil? ? [] : paths.clone)
end
|
.worker_class(worker) ⇒ Object
283
284
285
286
287
288
289
290
|
# File 'lib/luban/deployment/cli/command.rb', line 283
def worker_class(worker)
class_name = worker.camelcase
if const_defined?(class_name)
const_get(class_name)
else
abort "Aborted! #{name}::#{class_name} is NOT defined."
end
end
|
Instance Method Details
#base_templates_path(base_path) ⇒ Object
330
331
332
333
|
# File 'lib/luban/deployment/cli/command.rb', line 330
def base_templates_path(base_path)
path = Pathname.new(base_path).dirname.join('templates')
path.exist? ? path.realpath : nil
end
|
#controllable? ⇒ Boolean
265
|
# File 'lib/luban/deployment/cli/command.rb', line 265
def controllable?; false; end
|
#default_templates ⇒ Object
335
336
337
338
339
340
|
# File 'lib/luban/deployment/cli/command.rb', line 335
def default_templates
return @default_templates unless @default_templates.nil?
(@default_templates = []).tap do |t|
default_templates_paths.each { |p| t.concat(p.children).uniq! }
end
end
|
#default_templates_paths ⇒ Object
342
|
# File 'lib/luban/deployment/cli/command.rb', line 342
def default_templates_paths; self.class.default_templates_paths; end
|
#deployable? ⇒ Boolean
264
|
# File 'lib/luban/deployment/cli/command.rb', line 264
def deployable?; false; end
|
#display_name ⇒ Object
261
|
# File 'lib/luban/deployment/cli/command.rb', line 261
def display_name; @display_name ||= name.camelcase; end
|
#monitorable? ⇒ Boolean
266
|
# File 'lib/luban/deployment/cli/command.rb', line 266
def monitorable?; false; end
|
#provisionable? ⇒ Boolean
263
|
# File 'lib/luban/deployment/cli/command.rb', line 263
def provisionable?; false; end
|
#run_task(cmd: nil, args:, opts:, locally: false, worker_class: self.class.default_worker_class, &blk) ⇒ Object
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
# File 'lib/luban/deployment/cli/command.rb', line 302
def run_task(cmd: nil, args:, opts:, locally: false,
worker_class: self.class.default_worker_class, &blk)
backtrace = opts[:backtrace]
task_args = compose_task_arguments(args)
task_opts = compose_task_options(opts)
run_opts = (task_opts)
run_opts[:hosts] = :local if locally
task_msg = { cmd: cmd, config: config, local: locally,
args: task_args, opts: task_opts}
result = []
mutex = Mutex.new
run(**run_opts) do |backend|
begin
r = worker_class.new(task_msg.merge(backend: backend), &blk).run
rescue StandardError => e
r = {
hostname: backend.host.hostname,
status: :failed,
message: backtrace ? "#{e.message}\n#{e.backtrace.join("\n")}" : e.message,
error: e
}
end
mutex.synchronize { result << r }
end
print_task_result(result) if opts[:format] == :blackhole
locally ? result.first[:__return__] : result
end
|