Class: MCollective::PluginPackager::AgentDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/pluginpackager/agent_definition.rb

Overview

MCollective Agent Plugin package

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, name, vendor, preinstall, postinstall, iteration, dependencies, mcodependency, plugintype) ⇒ AgentDefinition

Returns a new instance of AgentDefinition.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 8

def initialize(path, name, vendor, preinstall, postinstall, iteration, dependencies, mcodependency, plugintype)
  @plugintype = plugintype
  @path = path
  @packagedata = {}
  @iteration = iteration || 1
  @preinstall = preinstall
  @postinstall = postinstall
  @vendor = vendor || "Puppet Labs"
  @mcserver = mcodependency[:server] || "mcollective"
  @mcclient = mcodependency[:client] || "mcollective-client"
  @mccommon = mcodependency[:common] || "mcollective-common"
  @dependencies = dependencies || []
  @target_path = File.expand_path(@path)
  @metadata = PluginPackager.(@path, "agent")
  @metadata[:name] = (name || @metadata[:name]).downcase.gsub(" ", "-")
  identify_packages
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



6
7
8
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 6

def dependencies
  @dependencies
end

#iterationObject

Returns the value of attribute iteration.



5
6
7
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 5

def iteration
  @iteration
end

#mcclientObject

Returns the value of attribute mcclient.



6
7
8
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 6

def mcclient
  @mcclient
end

#mccommonObject

Returns the value of attribute mccommon.



6
7
8
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 6

def mccommon
  @mccommon
end

#mcserverObject

Returns the value of attribute mcserver.



6
7
8
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 6

def mcserver
  @mcserver
end

#metadataObject

Returns the value of attribute metadata.



5
6
7
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 5

def 
  @metadata
end

#packagedataObject

Returns the value of attribute packagedata.



5
6
7
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 5

def packagedata
  @packagedata
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 5

def path
  @path
end

#plugintypeObject

Returns the value of attribute plugintype.



6
7
8
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 6

def plugintype
  @plugintype
end

#postinstallObject

Returns the value of attribute postinstall.



6
7
8
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 6

def postinstall
  @postinstall
end

#preinstallObject

Returns the value of attribute preinstall.



5
6
7
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 5

def preinstall
  @preinstall
end

#target_pathObject

Returns the value of attribute target_path.



5
6
7
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 5

def target_path
  @target_path
end

#vendorObject

Returns the value of attribute vendor.



5
6
7
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 5

def vendor
  @vendor
end

Instance Method Details

#agentObject

Obtain Agent package files and dependencies.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 37

def agent
  agent = {:files => [],
           :dependencies => @dependencies.clone << @mcserver,
           :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)
    implementations = Dir.glob(File.join(@metadata[:name], "**"))
    agent[:files] += implementations unless implementations.empty?
  else
    return nil
  end
  agent[:dependencies] << "mcollective-#{@metadata[:name]}-common" if @packagedata[:common]
  agent
end

#clientObject

Obtain client package files and dependencies.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 57

def client
  client = {:files => [],
            :dependencies => @dependencies.clone << @mcclient,
            :description => "Client plugin for #{@metadata[:name]}"}

  clientdir = File.join(@path, "application")
  bindir = File.join(@path, "bin")
  ddldir = File.join(@path, "agent")

  client[:files] += Dir.glob(File.join(clientdir, "*")) if PluginPackager.check_dir_present clientdir
  client[:files] += Dir.glob(File.join(bindir,"*")) if PluginPackager.check_dir_present bindir
  client[:files] += Dir.glob(File.join(ddldir, "*.ddl")) if PluginPackager.check_dir_present ddldir
  client[:dependencies] << "mcollective-#{@metadata[:name]}-common" if @packagedata[:common]
  client[:files].empty? ? nil : client
end

#commonObject

Obtain common package files and dependencies.



74
75
76
77
78
79
80
81
82
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 74

def common
  common = {:files =>[],
            :dependencies => @dependencies.clone << @mccommon,
            :description => "Common libraries for #{@metadata[:name]}"}

  commondir = File.join(@path, "util")
  common[:files] += Dir.glob(File.join(commondir,"*")) if PluginPackager.check_dir_present commondir
  common[:files].empty? ? nil : common
end

#identify_packagesObject

Identify present packages and populate packagedata hash.



27
28
29
30
31
32
33
34
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 27

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