Class: Bcome::Orchestrator::CommandGroup::Direct

Inherits:
Base
  • Object
show all
Defined in:
lib/orchestrator/command_group/direct.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#machines

Instance Method Summary collapse

Methods inherited from Base

klass_for_type, new_of_type_from, #set_machines

Methods included from ValidateAndSet

#validate_and_set

Constructor Details

#initialize(*params) ⇒ Direct

Returns a new instance of Direct.



6
7
8
# File 'lib/orchestrator/command_group/direct.rb', line 6

def initialize(*params)
  super
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



4
5
6
# File 'lib/orchestrator/command_group/direct.rb', line 4

def commands
  @commands
end

#direct_command_groupsObject

Returns the value of attribute direct_command_groups.



4
5
6
# File 'lib/orchestrator/command_group/direct.rb', line 4

def direct_command_groups
  @direct_command_groups
end

Instance Method Details

#execute!(current_context_machines, bootstrap) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/orchestrator/command_group/direct.rb', line 22

def execute!(current_context_machines, bootstrap)
  # Per command group
  @direct_command_groups.each do |direct_command_group| 
    # Per unique machine instance
    machines.each do |machine|
      kommands = []
      direct_command_group.command_instances.flatten.each do |command_instance|
        kommands << ::Bcome::Command.new(:command => command_instance.cmd, :instance => machine, :bootstrap => bootstrap, :success_exit_codes => command_instance.success_exit_codes) 
      end

      begin 
        execute_commands(kommands)
      rescue Net::SSH::AuthenticationFailed => e
        if machine.bootstrap_settings
          ## Fallback to execute commands without bootstrap set
          kommands.each {|kommand| kommand.bootstrap = true }
          execute_commands(kommands)
        else
          raise e
        end
      end
    end
  end
end

#execute_commands(commands) ⇒ Object



47
48
49
50
# File 'lib/orchestrator/command_group/direct.rb', line 47

def execute_commands(commands)
  ssh = ::Bcome::Ssh.new(commands)
  ssh.execute!
end

#json_attributesObject



10
11
12
# File 'lib/orchestrator/command_group/direct.rb', line 10

def json_attributes
  super + [:direct_command_set_key]
end