# class MCollective::PluginPackager::AgentDefinition

MCollective Agent Plugin package

### Attributes

dependencies[RW]
iteration[RW]
mcname[RW]
mcversion[RW]
metadata[RW]
packagedata[RW]
path[RW]
plugintype[RW]
postinstall[RW]
preinstall[RW]
target_path[RW]
vendor[RW]

### Public Class Methods

new(path, name, vendor, preinstall, postinstall, iteration, dependencies, mcdependency, plugintype) click to toggle source

    # File lib/mcollective/pluginpackager/agent_definition.rb, line 8
    def initialize(path, name, vendor, preinstall, postinstall, iteration, dependencies, mcdependency, plugintype)
      @plugintype = plugintype
      @path = path
      @packagedata = {}
      @iteration = iteration || 1
      @preinstall = preinstall
      @postinstall = postinstall
      @vendor = vendor || "Puppet Labs"
      @dependencies = dependencies || []
      @target_path = File.expand_path(@path)
      @metadata, mcversion = PluginPackager.get_metadata(@path, "agent")
      @mcname = mcdependency[:mcname] ||  "mcollective"
      @mcversion = mcdependency[:mcversion] || mcversion
      @dependencies << {:name => "#{@mcname}-common", :version => @mcversion}

      @metadata[:name] = (name || @metadata[:name]).downcase.gsub(/\s+|_/, "-")
      identify_packages
    end

### Public Instance Methods

agent() click to toggle source

Obtain Agent package files and dependencies.

    # File lib/mcollective/pluginpackager/agent_definition.rb, line 38
    def agent
      agent = {:files => [],
               :dependencies => @dependencies.clone,
               :description => "Agent plugin for #{@metadata[:name]}"}

      agentdir = File.join(@path, "agent")

      if PluginPackager.check_dir_present agentdir
        ddls = Dir.glob(File.join(agentdir, "*.ddl"))
        agent[:files] = (Dir.glob(File.join(agentdir, "*")) - ddls)
      else
        return nil
      end
      agent[:plugindependency] = {:name => "#{@mcname}-#{@metadata[:name]}-common", :version => @metadata[:version], :iteration => @iteration}
      agent
    end

client() click to toggle source

Obtain client package files and dependencies.

    # File lib/mcollective/pluginpackager/agent_definition.rb, line 56
    def client
      client = {:files => [],
                :dependencies => @dependencies.clone,
                :description => "Client plugin for #{@metadata[:name]}"}

      clientdir = File.join(@path, "application")
      aggregatedir = File.join(@path, "aggregate")

      client[:files] += Dir.glob(File.join(clientdir, "*")) if PluginPackager.check_dir_present clientdir
      client[:files] += Dir.glob(File.join(aggregatedir, "*")) if PluginPackager.check_dir_present aggregatedir
      client[:plugindependency] = {:name => "#{@mcname}-#{@metadata[:name]}-common", :version => @metadata[:version], :iteration => @iteration}
      client[:files].empty? ? nil : client
    end

common() click to toggle source

Obtain common package files and dependencies.

    # File lib/mcollective/pluginpackager/agent_definition.rb, line 71
    def common
      common = {:files =>[],
                :dependencies => @dependencies.clone,
                :description => "Common libraries for #{@metadata[:name]}"}

      datadir = File.join(@path, "data", "**")
      utildir = File.join(@path, "util", "**", "**")
      ddldir = File.join(@path, "agent", "*.ddl")
      validatordir = File.join(@path, "validator", "**")

      [datadir, utildir, validatordir, ddldir].each do |directory|
        common[:files] += Dir.glob(directory)
      end

      # We fail if there is no ddl file present
      if common[:files].grep(/^.*\.ddl$/).empty?
        raise "cannot create package - No ddl file found in #{File.join(@path, "agent")}"
      end

      common[:files].empty? ? nil : common
    end

identify_packages() click to toggle source

Identify present packages and populate packagedata hash.

    # File lib/mcollective/pluginpackager/agent_definition.rb, line 28
    def identify_packages
      common_package = common
      @packagedata[:common] = common_package if common_package
      agent_package = agent
      @packagedata[:agent] = agent_package if agent_package
      client_package = client
      @packagedata[:client] = client_package if client_package
    end