Class: MotherBrain::Command

Inherits:
Object
  • Object
show all
Includes:
MB::Mixin::Locks, VariaModel
Defined in:
lib/mb/command.rb

Defined Under Namespace

Classes: CleanRoom

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, scope, &block) ⇒ Command

Returns a new instance of Command.

Parameters:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mb/command.rb', line 27

def initialize(name, scope, &block)
  set_attribute(:name, name.to_s)
  @scope = scope

  case @scope
  when MB::Plugin
    @plugin = @scope
    @type   = :plugin
  when MB::Component
    @plugin = @scope.plugin
    @type   = :component
  else
    raise RuntimeError, "no matching command type for the given scope: #{scope}."
  end

  if block_given?
    dsl_eval(&block)
  end
end

Instance Attribute Details

#pluginMB::Plugin (readonly)

Returns:



21
22
23
# File 'lib/mb/command.rb', line 21

def plugin
  @plugin
end

#scopeMB::Plugin, MB::Component (readonly)



19
20
21
# File 'lib/mb/command.rb', line 19

def scope
  @scope
end

#typeSymbol (readonly)

Returns:

  • (Symbol)


23
24
25
# File 'lib/mb/command.rb', line 23

def type
  @type
end

Instance Method Details

#descriptionString

Returns:

  • (String)


48
49
50
# File 'lib/mb/command.rb', line 48

def description
  _attributes_.description || "run #{name} command on #{scope.name}"
end

#idSymbol

Returns:

  • (Symbol)


53
54
55
# File 'lib/mb/command.rb', line 53

def id
  self.name.to_sym
end

#invoke(job, environment, node_filter, *args) ⇒ Object

Run the command on the given environment

Parameters:

  • job (MB::Job)

    a job to update with progress

  • environment (String)

    the environment to invoke the command on

  • node_filter (Array)

    list of nodes to limit the command to

  • args (Array)

    additional arguments to pass to the command

Raises:



69
70
71
# File 'lib/mb/command.rb', line 69

def invoke(job, environment, node_filter, *args)
  CommandRunner.new(job, environment, scope, execute, node_filter, *args)
end