3 # MCollective Agent Plugin package
5 attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :revision, :preinstall
6 attr_accessor :plugintype, :dependencies, :postinstall, :mcname, :mcversion
8 def initialize(configuration, mcdependency, plugintype)
9 @plugintype = plugintype
10 @path = configuration[:target]
12 @revision = configuration[:revision] || 1
13 @preinstall = configuration[:preinstall]
14 @postinstall = configuration[:postinstall]
15 @vendor = configuration[:vendor] || "Puppet Labs"
16 @dependencies = configuration[:dependency] || []
17 @target_path = File.expand_path(@path)
18 @metadata, mcversion = PluginPackager.get_metadata(@path, "agent")
19 @mcname = mcdependency[:mcname] || "mcollective"
20 @mcversion = mcdependency[:mcversion] || mcversion
21 @metadata[:version] = (configuration[:version] || @metadata[:version])
22 @dependencies << {:name => "#{@mcname}-common", :version => @mcversion}
23 @metadata[:name] = (configuration[:pluginname] || @metadata[:name]).downcase.gsub(/\s+|_/, "-")
27 # Identify present packages and populate packagedata hash.
29 common_package = common
30 @packagedata[:common] = common_package if common_package
32 @packagedata[:agent] = agent_package if agent_package
33 client_package = client
34 @packagedata[:client] = client_package if client_package
37 # Obtain Agent package files and dependencies.
39 agent = {:files => [],
40 :dependencies => @dependencies.clone,
41 :description => "Agent plugin for #{@metadata[:name]}"}
43 agentdir = File.join(@path, "agent")
45 if PluginPackager.check_dir_present agentdir
46 ddls = Dir.glob(File.join(agentdir, "*.ddl"))
47 agent[:files] = (Dir.glob(File.join(agentdir, "*")) - ddls)
51 agent[:plugindependency] = {:name => "#{@mcname}-#{@metadata[:name]}-common", :version => @metadata[:version], :revision => @revision}
55 # Obtain client package files and dependencies.
57 client = {:files => [],
58 :dependencies => @dependencies.clone,
59 :description => "Client plugin for #{@metadata[:name]}"}
61 clientdir = File.join(@path, "application")
62 aggregatedir = File.join(@path, "aggregate")
64 client[:files] += Dir.glob(File.join(clientdir, "*")) if PluginPackager.check_dir_present clientdir
65 client[:files] += Dir.glob(File.join(aggregatedir, "*")) if PluginPackager.check_dir_present aggregatedir
66 client[:plugindependency] = {:name => "#{@mcname}-#{@metadata[:name]}-common", :version => @metadata[:version], :revision => @revision}
67 client[:files].empty? ? nil : client
70 # Obtain common package files and dependencies.
72 common = {:files =>[],
73 :dependencies => @dependencies.clone,
74 :description => "Common libraries for #{@metadata[:name]}"}
76 datadir = File.join(@path, "data", "**")
77 utildir = File.join(@path, "util", "**", "**")
78 ddldir = File.join(@path, "agent", "*.ddl")
79 validatordir = File.join(@path, "validator", "**")
81 [datadir, utildir, validatordir, ddldir].each do |directory|
82 common[:files] += Dir.glob(directory)
85 # We fail if there is no ddl file present
86 if common[:files].grep(/^.*\.ddl$/).empty?
87 raise "cannot create package - No ddl file found in #{File.join(@path, "agent")}"
90 common[:files].empty? ? nil : common