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(configuration, mcdependency, plugintype) ⇒ AgentDefinition

Returns a new instance of AgentDefinition.



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

def initialize(configuration, mcdependency, plugintype)
  @plugintype = plugintype
  @path = PluginPackager.get_plugin_path(configuration[:target])
  @packagedata = {}
  @revision = configuration[:revision] || 1
  @preinstall = configuration[:preinstall]
  @postinstall = configuration[:postinstall]
  @vendor = configuration[:vendor] || "Choria.IO User"
  @dependencies = configuration[:dependency] || []
  @target_path = File.expand_path(@path)
  @metadata, mcversion = PluginPackager.(@path, "agent")
  @mcname = mcdependency[:mcname] || "mcollective"
  @mcversion = mcdependency[:mcversion] || mcversion
  @metadata[:version] = (configuration[:version] || @metadata[:version])
  @dependencies << {:name => "#{@mcname}-common", :version => @mcversion}
  @agent_name = @metadata[:name].downcase
  @metadata[:name] = (configuration[:pluginname] || @metadata[:name]).downcase.gsub(/\s+|_/, "-")

  identify_packages
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



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

def dependencies
  @dependencies
end

#mcnameObject

Returns the value of attribute mcname.



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

def mcname
  @mcname
end

#mcversionObject

Returns the value of attribute mcversion.



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

def mcversion
  @mcversion
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.



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

def plugintype
  @plugintype
end

#postinstallObject

Returns the value of attribute postinstall.



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

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

#revisionObject

Returns the value of attribute revision.



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

def revision
  @revision
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.



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

def agent
  agent = {
    :files => [],
    :executable_files => [],
    :dependencies => @dependencies.clone,
    :description => "Agent plugin for #{@metadata[:name]}"
  }

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

  return nil unless PluginPackager.check_dir_present(agentdir)

  ddls = Dir.glob(File.join(agentdir, "*.{ddl,json}"))
  agent[:files] = (Dir.glob(File.join(agentdir, "**", "**")) - ddls)
  agent[:plugindependency] = {:name => "#{@mcname}-#{@metadata[:name]}-common", :version => @metadata[:version], :revision => @revision}

  agent[:executable_files] << File.join(agentdir, @agent_name) if @metadata[:provider] == "external"

  agent
end

#clientObject

Obtain client package files and dependencies.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 61

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], :revision => @revision}
  client[:files].empty? ? nil : client
end

#commonObject

Obtain common package files and dependencies.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/mcollective/pluginpackager/agent_definition.rb', line 78

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,json}")
  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
  raise "cannot create package - No ddl file found in #{File.join(@path, 'agent')}" if common[:files].grep(/^.*\.ddl$/).empty?

  common[:files].uniq!

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

#identify_packagesObject

Identify present packages and populate packagedata hash.



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

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