Class: AvstCloud::SshCommandTask

Inherits:
SshTask show all
Defined in:
lib/avst-cloud/task.rb

Direct Known Subclasses

PostProvisionCleanup

Instance Method Summary collapse

Methods inherited from SshTask

#execute

Methods inherited from Task

#execute

Methods included from Logging

included, logger, #logger, logger=, mask_message, show_passwords=

Constructor Details

#initialize(cmds, debug = false, structured_log = false) ⇒ SshCommandTask

Returns a new instance of SshCommandTask.



73
74
75
76
77
# File 'lib/avst-cloud/task.rb', line 73

def initialize(cmds, debug = false, structured_log = false)
    @cmds = cmds
    @debug = debug
    @structured_log = structured_log
end

Instance Method Details

#ssh_command(session) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/avst-cloud/task.rb', line 79

def ssh_command(session)
    Array(@cmds).each do |cmd|
        next unless cmd
        cmd.strip!
        next if cmd == ""
        logger.debug("Running command on server as root: sudo su -c \"#{cmd}\"")
        start_time = Time.now

        session.exec!("sudo su -c \"#{cmd}\"") do |ch, stream, data|
            if @debug
                logger.debug "Got this on the #{stream} stream: "
                if @structured_log && logger.methods.include?(:log_structured_code)
                    logger.log_structured_code(data)
                else
                    logger.debug(data)
                end
            end
        end
        total_time = Time.now - start_time
        logger.debug("Completed in #{total_time} seconds")
    end
end