choria-mcorpc-support 2.20.5 → 2.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mcollective.rb +1 -1
  3. data/lib/mcollective/application/facts.rb +8 -0
  4. data/lib/mcollective/application/plugin.rb +19 -7
  5. data/lib/mcollective/applications.rb +2 -1
  6. data/lib/mcollective/ddl/agentddl.rb +17 -11
  7. data/lib/mcollective/ddl/base.rb +34 -20
  8. data/lib/mcollective/ddl/dataddl.rb +5 -5
  9. data/lib/mcollective/ddl/discoveryddl.rb +2 -2
  10. data/lib/mcollective/ddl/validatorddl.rb +1 -1
  11. data/lib/mcollective/pluginpackager/agent_definition.rb +33 -19
  12. data/lib/mcollective/pluginpackager/{puppet_module_packager.rb → forge_packager.rb} +57 -50
  13. data/lib/mcollective/pluginpackager/standard_definition.rb +23 -12
  14. data/lib/mcollective/pluginpackager/templates/{puppet_module → forge}/README.md.erb +1 -1
  15. data/lib/mcollective/pluginpackager/templates/{puppet_module → forge}/data/defaults.yaml.erb +0 -0
  16. data/lib/mcollective/pluginpackager/templates/{puppet_module → forge}/data/plugin.yaml.erb +0 -0
  17. data/lib/mcollective/pluginpackager/templates/{puppet_module → forge}/hiera.yaml.erb +0 -0
  18. data/lib/mcollective/pluginpackager/templates/{puppet_module → forge}/manifests/init.pp.erb +2 -0
  19. data/lib/mcollective/pluginpackager/templates/{puppet_module → forge}/metadata.json.erb +2 -2
  20. data/lib/mcollective/validator.rb +2 -2
  21. data/lib/mcollective/validator/array_validator.rb +1 -1
  22. data/lib/mcollective/validator/ipv4address_validator.rb +5 -7
  23. data/lib/mcollective/validator/ipv6address_validator.rb +5 -7
  24. data/lib/mcollective/validator/shellsafe_validator.rb +1 -1
  25. data/lib/mcollective/validator/typecheck_validator.rb +19 -15
  26. metadata +11 -25
  27. data/lib/mcollective/pluginpackager/debpackage_packager.rb +0 -237
  28. data/lib/mcollective/pluginpackager/modulepackage_packager.rb +0 -127
  29. data/lib/mcollective/pluginpackager/ospackage_packager.rb +0 -59
  30. data/lib/mcollective/pluginpackager/rpmpackage_packager.rb +0 -180
  31. data/lib/mcollective/pluginpackager/templates/debian/Makefile.erb +0 -7
  32. data/lib/mcollective/pluginpackager/templates/debian/changelog.erb +0 -5
  33. data/lib/mcollective/pluginpackager/templates/debian/compat.erb +0 -1
  34. data/lib/mcollective/pluginpackager/templates/debian/control.erb +0 -15
  35. data/lib/mcollective/pluginpackager/templates/debian/copyright.erb +0 -8
  36. data/lib/mcollective/pluginpackager/templates/debian/rules.erb +0 -6
  37. data/lib/mcollective/pluginpackager/templates/module/Modulefile.erb +0 -5
  38. data/lib/mcollective/pluginpackager/templates/module/README.md.erb +0 -37
  39. data/lib/mcollective/pluginpackager/templates/module/_manifest.pp.erb +0 -9
  40. data/lib/mcollective/pluginpackager/templates/redhat/rpm_spec.erb +0 -63
@@ -2,12 +2,12 @@ require "yaml"
2
2
 
3
3
  module MCollective
4
4
  module PluginPackager
5
- class PuppetmodulePackager
6
- def initialize(plugin, pluginpath = nil, signature = nil, verbose = false, keep_artifacts = nil, module_template = nil)
5
+ class ForgePackager
6
+ def initialize(plugin, pluginpath=nil, signature=nil, verbose=false, keep_artifacts=nil, module_template=nil)
7
7
  @plugin = plugin
8
8
  @verbose = verbose
9
9
  @keep_artifacts = keep_artifacts
10
- @module_template = module_template || File.join(File.dirname(__FILE__), 'templates', 'puppet_module')
10
+ @module_template = module_template || File.join(File.dirname(__FILE__), "templates", "forge")
11
11
  end
12
12
 
13
13
  def which(cmd)
@@ -18,11 +18,11 @@ module MCollective
18
18
  return exe if File.executable?(exe) && !File.directory?(exe)
19
19
  end
20
20
  end
21
- return nil
21
+ nil
22
22
  end
23
23
 
24
24
  def create_packages
25
- assert_new_enough_puppet
25
+ assert_new_enough_pdk
26
26
  validate_environment
27
27
 
28
28
  begin
@@ -44,7 +44,7 @@ module MCollective
44
44
  ensure
45
45
  if @keep_artifacts
46
46
  puts("Keeping build artifacts")
47
- puts("Build artifacts saved in %s" % @tmpdir)
47
+ puts("Build artifacts saved in %s" % @tmpdir)
48
48
  else
49
49
  cleanup_tmpdirs
50
50
  end
@@ -81,7 +81,15 @@ module MCollective
81
81
  def filelist(type)
82
82
  @plugin.packagedata[type][:files].map do |file|
83
83
  file.gsub(/^\.\//, "") unless File.directory?(file)
84
- end.compact
84
+ end.compact.uniq
85
+ rescue
86
+ []
87
+ end
88
+
89
+ def executablelist(type)
90
+ @plugin.packagedata[type][:executable_files].map do |file|
91
+ file.gsub(/^\.\//, "") unless File.directory?(file)
92
+ end.compact.uniq
85
93
  rescue
86
94
  []
87
95
  end
@@ -100,11 +108,12 @@ module MCollective
100
108
  {
101
109
  hierakey(:config_name) => @plugin.metadata[:name].downcase,
102
110
  hierakey(:common_files) => filelist(:common),
111
+ hierakey(:executable_files) => executablelist(:agent),
103
112
  hierakey(:common_directories) => dirlist(:common),
104
113
  hierakey(:server_files) => filelist(:agent),
105
114
  hierakey(:server_directories) => dirlist(:agent),
106
115
  hierakey(:client_files) => filelist(:client),
107
- hierakey(:client_directories) => dirlist(:client),
116
+ hierakey(:client_directories) => dirlist(:client)
108
117
  }.merge(module_override_data)
109
118
  end
110
119
 
@@ -123,7 +132,7 @@ module MCollective
123
132
  end
124
133
 
125
134
  def copy_module_files
126
- @plugin.packagedata.each do |klass, data|
135
+ @plugin.packagedata.each_value do |data|
127
136
  data[:files].each do |file|
128
137
  clean_dest_file = file.gsub("./lib/mcollective", "")
129
138
  dest_dir = File.expand_path(File.join(@tmpdir, "files", "mcollective", File.dirname(clean_dest_file)))
@@ -142,13 +151,18 @@ module MCollective
142
151
  agent_name = File.basename(file, ".ddl")
143
152
  json_file = File.join(agent_dir, "%s.json" % agent_name)
144
153
 
154
+ if File.exist?(json_file)
155
+ Log.warn("JSON DDL %s already exist, not regenerating from the %s" % [json_file, agent_name])
156
+ next
157
+ end
158
+
145
159
  ddl = DDL.new(agent_name, :agent, false)
146
160
  ddl.instance_eval(File.read(file))
147
161
 
148
162
  data = {
149
163
  "$schema" => "https://choria.io/schemas/mcorpc/ddl/v1/agent.json",
150
164
  "metadata" => ddl.meta,
151
- "actions" => [],
165
+ "actions" => []
152
166
  }
153
167
 
154
168
  ddl.actions.sort.each do |action|
@@ -165,7 +179,7 @@ module MCollective
165
179
  end
166
180
 
167
181
  def render_templates
168
- templates = Dir.chdir(@module_template) do |path|
182
+ templates = Dir.chdir(@module_template) do |_path|
169
183
  Dir.glob("**/*.erb")
170
184
  end
171
185
 
@@ -177,69 +191,62 @@ module MCollective
177
191
  end
178
192
 
179
193
  def render_template(infile, outfile)
180
- begin
181
- erb = ERB.new(File.read(infile), nil, "-")
182
- File.open(outfile, "w") do |f|
183
- f.puts erb.result(binding)
184
- end
185
- rescue
186
- STDERR.puts("Could not render template %s to %s" % [infile, outfile])
187
- raise
194
+ erb = ERB.new(File.read(infile), nil, "-")
195
+ File.open(outfile, "w") do |f|
196
+ f.puts erb.result(binding)
188
197
  end
198
+ rescue
199
+ STDERR.puts("Could not render template %s to %s" % [infile, outfile])
200
+ raise
189
201
  end
190
202
 
191
203
  def validate_environment
192
204
  raise("Supplying a vendor is required, please use --vendor") if @plugin.vendor == "Puppet Labs"
193
- raise("Vendor names may not have a space in them, please specify a valid vendor using --vendor") if @plugin.vendor.match(" ")
205
+ raise("Vendor names may not have a space in them, please specify a valid vendor using --vendor") if @plugin.vendor.include?(" ")
194
206
  end
195
207
 
196
- def assert_new_enough_puppet
197
- puppet_bin = which("puppet")
198
- puppet_bin = "/opt/puppetlabs/bin/puppet" if !puppet_bin
199
- if !puppet_bin
200
- raise("Cannot build package. 'puppet' not found on path, and '/opt/puppetlabs/bin/puppet' is not present on the system.")
201
- end
208
+ def pdk_path
209
+ pdk_bin = which("pdk")
210
+ pdk_bin ||= "/opt/puppetlabs/pdk/bin/pdk"
202
211
 
203
- s = Shell.new("#{puppet_bin} --version")
212
+ pdk_bin
213
+ end
214
+
215
+ def assert_new_enough_pdk
216
+ s = Shell.new("#{pdk_path} --version")
204
217
  s.runcommand
205
218
  actual_version = s.stdout.chomp
206
- required_version = '4.5.1'
219
+ required_version = "1.12.0"
207
220
 
208
221
  if Util.versioncmp(actual_version, required_version) < 0
209
- raise("Cannot build package. puppet #{required_version} or greater required. We have #{actual_version}.")
222
+ raise("Cannot build package. pdk #{required_version} or greater required. We have #{actual_version}.")
210
223
  end
211
224
  end
212
225
 
213
226
  def run_build
214
- begin
215
- PluginPackager.execute_verbosely(@verbose) do
216
- Dir.chdir(@tmpdir) do
217
- PluginPackager.safe_system('puppet module build')
218
- end
227
+ PluginPackager.execute_verbosely(@verbose) do
228
+ Dir.chdir(@tmpdir) do
229
+ PluginPackager.safe_system("#{pdk_path} build --force")
219
230
  end
220
- rescue
221
- STDERR.puts("Build process has failed")
222
- raise
223
231
  end
232
+ rescue
233
+ STDERR.puts("Build process has failed")
234
+ raise
224
235
  end
225
236
 
226
237
  def move_package
227
- begin
228
- package_file = File.join(@tmpdir, "pkg", module_file_name)
229
- FileUtils.cp(package_file, ".")
230
- rescue
231
- STDERR.puts("Could not copy package to working directory")
232
- raise
233
- end
238
+ package_file = File.join(@tmpdir, "pkg", module_file_name)
239
+ FileUtils.cp(package_file, ".")
240
+ rescue
241
+ STDERR.puts("Could not copy package to working directory")
242
+ raise
234
243
  end
235
244
 
236
245
  def cleanup_tmpdirs
237
- begin
238
- FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
239
- rescue
240
- STDERR.puts("Could not remove temporary build directory %s" % [@tmpdir])
241
- raise
242
- end
246
+ FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
247
+ rescue
248
+ STDERR.puts("Could not remove temporary build directory %s" % [@tmpdir])
249
+ raise
243
250
  end
244
251
  end
245
252
  end
@@ -11,7 +11,7 @@ module MCollective
11
11
  @revision = configuration[:revision] || 1
12
12
  @preinstall = configuration[:preinstall]
13
13
  @postinstall = configuration[:postinstall]
14
- @vendor = configuration[:vendor] || "Puppet Labs"
14
+ @vendor = configuration[:vendor] || "Choria.IO User"
15
15
  @dependencies = configuration[:dependency] || []
16
16
  @target_path = File.expand_path(@path)
17
17
  @metadata, mcversion = PluginPackager.get_metadata(@path, @plugintype)
@@ -20,6 +20,7 @@ module MCollective
20
20
  @dependencies << {:name => "#{mcname}-common", :version => @mcversion}
21
21
  @metadata[:name] = (configuration[:pluginname] || @metadata[:name]).downcase.gsub(/\s+|_/, "-")
22
22
  @metadata[:version] = (configuration[:version] || @metadata[:version])
23
+
23
24
  identify_packages
24
25
  end
25
26
 
@@ -33,9 +34,11 @@ module MCollective
33
34
 
34
35
  # Obtain standard plugin files and dependencies
35
36
  def plugin
36
- plugindata = {:files => [],
37
- :dependencies => @dependencies.clone,
38
- :description => "#{@name} #{@plugintype} plugin for the Marionette Collective."}
37
+ plugindata = {
38
+ :files => [],
39
+ :dependencies => @dependencies.clone,
40
+ :description => "#{@name} #{@plugintype} plugin for the Choria Orchestrator."
41
+ }
39
42
 
40
43
  plugindir = File.join(@path, @plugintype.to_s)
41
44
  if PluginPackager.check_dir_present plugindir
@@ -44,25 +47,33 @@ module MCollective
44
47
  return nil
45
48
  end
46
49
 
47
- plugindata[:plugindependency] = {:name => "#{@mcname}-#{@metadata[:name]}-common",
48
- :version => @metadata[:version],
49
- :revision => @revision} if @packagedata[:common]
50
+ if @packagedata[:common]
51
+ plugindata[:plugindependency] = {
52
+ :name => "#{@mcname}-#{@metadata[:name]}-common",
53
+ :version => @metadata[:version],
54
+ :revision => @revision
55
+ }
56
+ end
57
+
50
58
  plugindata
51
59
  end
52
60
 
53
61
  # Obtain list of common files
54
62
  def common
55
- common = {:files => [],
56
- :dependencies => @dependencies.clone,
57
- :description => "Common libraries for #{@name} connector plugin"}
63
+ common = {
64
+ :files => [],
65
+ :dependencies => @dependencies.clone,
66
+ :description => "Common libraries for #{@name} connector plugin"
67
+ }
58
68
 
59
69
  commondir = File.join(@path, "util")
60
70
  if PluginPackager.check_dir_present commondir
61
71
  common[:files] = Dir.glob(File.join(commondir, "*"))
72
+
62
73
  return common
63
- else
64
- return nil
65
74
  end
75
+
76
+ nil
66
77
  end
67
78
  end
68
79
  end
@@ -67,6 +67,6 @@ For a full list of possible configuration settings see the module [source reposi
67
67
 
68
68
  ## Development:
69
69
 
70
- To contribute to this MCollective plugin please visit <%= @plugin.metadata[:url] %>.
70
+ To contribute to this [Choria.IO](https://choria.io) plugin please visit <%= @plugin.metadata[:url] %>.
71
71
 
72
72
  This module was generated using the Choria Plugin Packager based on templates found at the [GitHub Project](https://github.com/choria-io/).
@@ -6,6 +6,7 @@ class <%= module_name %> (
6
6
  Array[String] $server_directories = [],
7
7
  Array[String] $common_files = [],
8
8
  Array[String] $common_directories = [],
9
+ Array[String] $executable_files = [],
9
10
  Boolean $manage_gem_dependencies = true,
10
11
  Hash $gem_dependencies = {},
11
12
  Boolean $manage_package_dependencies = true,
@@ -26,6 +27,7 @@ class <%= module_name %> (
26
27
  client_files => $client_files,
27
28
  server_files => $server_files,
28
29
  common_files => $common_files,
30
+ executable_files => $executable_files,
29
31
  client_directories => $client_directories,
30
32
  server_directories => $server_directories,
31
33
  common_directories => $common_directories,
@@ -7,12 +7,12 @@
7
7
  "source": "<%= @plugin.metadata[:url] %>",
8
8
  "project_page": "<%= @plugin.metadata[:url] %>",
9
9
  "dependencies": [
10
- {"name": "choria/mcollective", "version_requirement": ">= 0.4.0 < 2.0.0"}
10
+ {"name": "choria/mcollective", "version_requirement": ">= 0.9.3 < 2.0.0"}
11
11
  ],
12
12
  "requirements": [
13
13
  {
14
14
  "name": "puppet",
15
- "version_requirement": ">= 4.9.0"
15
+ "version_requirement": ">= 6.0.0"
16
16
  }
17
17
  ]
18
18
  }
@@ -57,7 +57,7 @@ module MCollective
57
57
  Validator.load_validators
58
58
 
59
59
  begin
60
- if [:integer, :boolean, :float, :number, :string].include?(validation)
60
+ if [:integer, :boolean, :float, :number, :string, :array, :hash].include?(validation)
61
61
  Validator.typecheck(validator, validation)
62
62
 
63
63
  else
@@ -76,7 +76,7 @@ module MCollective
76
76
  end
77
77
  end
78
78
  rescue => e
79
- raise ValidatorError, e.to_s
79
+ raise ValidatorError, e.to_s, e.backtrace
80
80
  end
81
81
  end
82
82
  end
@@ -2,7 +2,7 @@ module MCollective
2
2
  module Validator
3
3
  class ArrayValidator
4
4
  def self.validate(validator, array)
5
- raise ValidatorError, "value should be one of %s" % [ array.join(", ") ] unless array.include?(validator)
5
+ raise ValidatorError, "value should be one of %s" % [array.join(", ")] unless array.include?(validator)
6
6
  end
7
7
  end
8
8
  end
@@ -1,15 +1,13 @@
1
1
  module MCollective
2
2
  module Validator
3
3
  class Ipv4addressValidator
4
- require 'ipaddr'
4
+ require "ipaddr"
5
5
 
6
6
  def self.validate(validator)
7
- begin
8
- ip = IPAddr.new(validator)
9
- raise ValidatorError, "value should be an ipv4 adddress" unless ip.ipv4?
10
- rescue
11
- raise ValidatorError, "value should be an ipv4 address"
12
- end
7
+ ip = IPAddr.new(validator)
8
+ raise ValidatorError, "value should be an ipv4 adddress" unless ip.ipv4?
9
+ rescue
10
+ raise ValidatorError, "value should be an ipv4 address"
13
11
  end
14
12
  end
15
13
  end
@@ -1,15 +1,13 @@
1
1
  module MCollective
2
2
  module Validator
3
3
  class Ipv6addressValidator
4
- require 'ipaddr'
4
+ require "ipaddr"
5
5
 
6
6
  def self.validate(validator)
7
- begin
8
- ip = IPAddr.new(validator)
9
- raise ValidatorError, "value should be an ipv6 adddress" unless ip.ipv6?
10
- rescue
11
- raise ValidatorError, "value should be an ipv6 address"
12
- end
7
+ ip = IPAddr.new(validator)
8
+ raise ValidatorError, "value should be an ipv6 adddress" unless ip.ipv6?
9
+ rescue
10
+ raise ValidatorError, "value should be an ipv6 address"
13
11
  end
14
12
  end
15
13
  end
@@ -4,7 +4,7 @@ module MCollective
4
4
  def self.validate(validator)
5
5
  raise ValidatorError, "value should be a String" unless validator.is_a?(String)
6
6
 
7
- ['`', '$', ';', '|', '&&', '>', '<'].each do |chr|
7
+ ["`", "$", ";", "|", "&&", ">", "<"].each do |chr|
8
8
  raise ValidatorError, "value should not have #{chr} in it" if validator.match(Regexp.escape(chr))
9
9
  end
10
10
  end
@@ -2,25 +2,29 @@ module MCollective
2
2
  module Validator
3
3
  class TypecheckValidator
4
4
  def self.validate(validator, validation_type)
5
- raise ValidatorError, "value should be a #{validation_type.to_s}" unless check_type(validator, validation_type)
5
+ raise ValidatorError, "value should be a #{validation_type}" unless check_type(validator, validation_type)
6
6
  end
7
7
 
8
8
  def self.check_type(validator, validation_type)
9
9
  case validation_type
10
- when Class
11
- validator.is_a?(validation_type)
12
- when :integer
13
- validator.is_a?(Integer)
14
- when :float
15
- validator.is_a?(Float)
16
- when :number
17
- validator.is_a?(Numeric)
18
- when :string
19
- validator.is_a?(String)
20
- when :boolean
21
- [TrueClass, FalseClass].include?(validator.class)
22
- else
23
- false
10
+ when Class
11
+ validator.is_a?(validation_type)
12
+ when :integer
13
+ validator.is_a?(Integer)
14
+ when :float
15
+ validator.is_a?(Float)
16
+ when :number
17
+ validator.is_a?(Numeric)
18
+ when :string
19
+ validator.is_a?(String)
20
+ when :boolean
21
+ [TrueClass, FalseClass].include?(validator.class)
22
+ when :array
23
+ validator.is_a?(Array)
24
+ when :hash
25
+ validator.is_a?(Hash)
26
+ else
27
+ false
24
28
  end
25
29
  end
26
30
  end