Class: Rundock::Operation::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rundock/operation/base.rb

Direct Known Subclasses

Command, Deploy, HostInventory, SampleOperation, Task

Constant Summary collapse

OperationNotImplementedError =
Class.new(NotImplementedError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instruction, attributes) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
# File 'lib/rundock/operation/base.rb', line 9

def initialize(instruction, attributes)
  @instruction = instruction
  @attributes = attributes
  @attributes = {} unless attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/rundock/operation/base.rb', line 7

def attributes
  @attributes
end

#instructionObject (readonly)

Returns the value of attribute instruction.



6
7
8
# File 'lib/rundock/operation/base.rb', line 6

def instruction
  @instruction
end

Instance Method Details

#assign_args(src, args) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rundock/operation/base.rb', line 25

def assign_args(src, args)
  return src unless args
  src.gsub(/\$#/, args.length.to_s)
     .gsub(/\$@/, args.join(' '))
     .gsub(/\$[1-9]/) { |arg_n| args[arg_n.chars[1..-1].join.to_i - 1] }
     .gsub(/(\$\{)(\w+)(\})/) { ENV[Regexp.last_match(2)] }
end

#logging(message, severity) ⇒ Object



19
20
21
22
23
# File 'lib/rundock/operation/base.rb', line 19

def logging(message, severity)
  h_host = @attributes[:nodename].just(' ', 15)
  h_ope = "start #{self.class.to_s.split('::').last.downcase}:"
  Logger.send(severity.to_sym, "#{h_host} #{h_ope} #{message}")
end

#run(backend, attributes = {}) ⇒ Object



15
16
17
# File 'lib/rundock/operation/base.rb', line 15

def run(backend, attributes = {})
  raise OperationNotImplementedError
end