class Sfp::Module::Shell

Attributes

home[R]
main[R]

Public Class Methods

new(metadata) click to toggle source
# File lib/sfpagent/module.rb, line 173
def initialize(metadata)
        ### set module's home directory
        @home = metadata[:home]

        ### set main shell command
        @main = @home + '/main'
end

Public Instance Methods

execute(name, parameters={}) click to toggle source
# File lib/sfpagent/module.rb, line 189
def execute(name, parameters={})
        result = invoke({
                :command => :execute,
                :procedure => name.split('.').last,
                :parameters => parameters,
                :model => @model,
                :path => @path
        })
        if result['status'] != 'ok'
                log.error "Error in executing #{name} - description: #{result['description']}"
                false
        else
                true
        end
end
update_state() click to toggle source
# File lib/sfpagent/module.rb, line 181
def update_state
        @state = invoke({
                :command => :state,
                :model => @model,
                :path => @path
        })
end

Private Instance Methods

invoke(parameters) click to toggle source
# File lib/sfpagent/module.rb, line 207
def invoke(parameters)
        log.info Shellwords.shellescape(JSON.generate(parameters))
        begin
                output = `#{@main} #{Shellwords.shellescape(JSON.generate(parameters))}`
                log.info output
                JSON.parse(output)
        rescue Exception => exp
                log.info "Invalid module output: #{output}"
                raise exp
        end
end