Sha256: 94968f8bdf05087cc56bc4057e5decf9877e8476d9d8d367a242f5d013f6d8e6

Contents?: true

Size: 1.64 KB

Versions: 13

Compression:

Stored size: 1.64 KB

Contents

require 'base64'

module MCollective
  module Agent
    class Dev_manager < RPC::Agent

      AGENT_MCOLLECTIVE_LOCATION = "#{::MCollective::Config.instance.libdir.join}/mcollective/agent/"
 
      action "inject_agent" do
        begin

          ret ||= Response.new() 

          request[:agent_files].each do |k,v|
            if v == :deleted
              File.delete("#{AGENT_MCOLLECTIVE_LOCATION}#{k}")
              next
            end
            content = Base64.decode64(v)
            File.open("#{AGENT_MCOLLECTIVE_LOCATION}#{k}",'w') do |file|
              file << content
            end
          end
          ret.set_status_succeeded!()

          t1 = Thread.new do
            system("sudo /etc/init.d/mcollective restart")
          end

          return ret

        rescue Exception => e
          Log.instance.error e
          ret.set_status_failed!()
          error_info = { :error => { :message => "Error syncing agents: #{e}" } }
          ret.merge!(error_info)
        end
        return ret
      end
    end
    #TODO: this should be common accross Agents
    class Response < Hash
      def initialize(hash={})
        super()
        self.merge!(hash)
        self[:status] = :unknown unless hash.has_key?(:status)
      end

      def to_hash()
        Hash.new.merge(self)
      end

      def failed?()
        self[:status] == :failed
      end

      def set_status_failed!()
        self[:status] = :failed
      end
      def set_status_succeeded!()
        self[:status] = :succeeded
      end
      def set_dynamic_attributes!(dynamic_attributes)
        self[:dynamic_attributes] = dynamic_attributes
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dtk-node-agent-0.6.7 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.6.6 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.6.4 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.6.3 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.6.2 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.6.1 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.6.0 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.5.17 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.5.16 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.5.15 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.5.14 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.5.13 mcollective_additions/plugins/v2.2/agent/dev_manager.rb
dtk-node-agent-0.5.12 mcollective_additions/plugins/v2.2/agent/dev_manager.rb