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.
270
271
272
|
# File 'lib/luban/deployment/cli/command.rb', line 270
def default_templates_paths
@default_templates_paths
end
|
Class Method Details
.default_worker_class ⇒ Object
272
273
274
|
# File 'lib/luban/deployment/cli/command.rb', line 272
def default_worker_class
Luban::Deployment::Worker::Base
end
|
.dispatch_task(task, to:, as: task, locally: false, &blk) ⇒ Object
285
286
287
288
289
290
291
292
|
# File 'lib/luban/deployment/cli/command.rb', line 285
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
262
263
264
265
266
267
268
|
# File 'lib/luban/deployment/cli/command.rb', line 262
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
276
277
278
279
280
281
282
283
|
# File 'lib/luban/deployment/cli/command.rb', line 276
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
323
324
325
326
|
# File 'lib/luban/deployment/cli/command.rb', line 323
def base_templates_path(base_path)
path = Pathname.new(base_path).dirname.join('templates')
path.exist? ? path.realpath : nil
end
|
#controllable? ⇒ Boolean
258
|
# File 'lib/luban/deployment/cli/command.rb', line 258
def controllable?; false; end
|
#default_templates ⇒ Object
328
329
330
331
332
333
|
# File 'lib/luban/deployment/cli/command.rb', line 328
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
335
|
# File 'lib/luban/deployment/cli/command.rb', line 335
def default_templates_paths; self.class.default_templates_paths; end
|
#deployable? ⇒ Boolean
257
|
# File 'lib/luban/deployment/cli/command.rb', line 257
def deployable?; false; end
|
#display_name ⇒ Object
254
|
# File 'lib/luban/deployment/cli/command.rb', line 254
def display_name; @display_name ||= name.camelcase; end
|
#monitorable? ⇒ Boolean
259
|
# File 'lib/luban/deployment/cli/command.rb', line 259
def monitorable?; false; end
|
#provisionable? ⇒ Boolean
256
|
# File 'lib/luban/deployment/cli/command.rb', line 256
def provisionable?; false; end
|
#run_task(cmd: nil, args:, opts:, locally: false, worker_class: self.class.default_worker_class, &blk) ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/luban/deployment/cli/command.rb', line 295
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
|