diff --git a/internal/gentypes/eval.go b/internal/gentypes/eval.go index 6f10d27..9ef7726 100644 --- a/internal/gentypes/eval.go +++ b/internal/gentypes/eval.go @@ -644,7 +644,9 @@ func (p *parser) defineMethod(c *classCtx) error { if !p.is(tIdent, "do") && (!p.op("{") || !paren) { return fmt.Errorf("define_method without a block") } - c.methods[v.s], c.hidden[v.s] = true, c.priv + if err := c.addMethod(v.s, c.priv); err != nil { + return err + } return p.skipBlock() } diff --git a/internal/gentypes/fidelity_test.go b/internal/gentypes/fidelity_test.go index 2741198..da72a35 100644 --- a/internal/gentypes/fidelity_test.go +++ b/internal/gentypes/fidelity_test.go @@ -71,6 +71,10 @@ func TestFidelityPuppetWritesNothing(t *testing.T) { "rsapi Float overflow": {"m/lib/puppet/type/t.rb": rsapi("", " a: { type: 'Float[1e400]', desc: 'x' },\n")}, "rsapi Float 0e0": {"m/lib/puppet/type/t.rb": rsapi("", " a: { type: 'Float[0e0]', desc: 'x' },\n")}, "rsapi Float zero mantissa exponent": {"m/lib/puppet/type/t.rb": rsapi("", " a: { type: 'Float[0.0e5]', desc: 'x' },\n")}, + "safe_insync? in a Property subclass": {"m/lib/puppet/type/t.rb": "class QS < Puppet::Property\n def safe_insync?(is); end\nend\n" + classic}, + "newvalues in a parent class body": {"m/lib/puppet/type/t.rb": "class QD < Puppet::Property\n newvalues(:x)\nend\nPuppet::Type.newtype(:t) do\n newparam(:name)\n newproperty(:a, parent: QD)\nend\n"}, + "parent defined after use": {"m/lib/puppet/type/t.rb": "Puppet::Type.newtype(:t) do\n newparam(:name)\n newproperty(:a, parent: QL)\nend\nclass QL < Puppet::Property\nend\n"}, + "parent not a Property": {"m/lib/puppet/type/t.rb": "class QP\nend\nPuppet::Type.newtype(:t) do\n newparam(:name)\n newproperty(:a, parent: QP)\nend\n"}, "require resolves to puppet core first": { "m/lib/puppet/util/execution.rb": "module PuppetX\n module Sh\n end\nend\n", "m/lib/puppet_x/sh.rb": "module PuppetX\n module Sh\n end\nend\n", @@ -103,6 +107,19 @@ func TestFidelityNoWrongOutput(t *testing.T) { "b/lib/puppet_x/a/mix.rb": empty, "a/lib/puppet/type/t.rb": "require 'puppet_x/a/mix'\nPuppet::Type.newtype(:t) do\n include PuppetX::A::Mix\n newparam(:name)\nend\n", }, "'ensure'"}, + "parent defines a class method": {map[string]string{ + "m/lib/puppet/type/t.rb": "class QN < Puppet::Property\n def self.isnamevar?\n true\n end\nend\nPuppet::Type.newtype(:t) do\n newparam(:name)\n newproperty(:a, parent: QN)\nend\n", + }, "Param(Any, 'a')"}, + "parent reopened with a class method": {map[string]string{ + "m/lib/puppet/type/t.rb": "class QN < Puppet::Property\nend\nPuppet::Type.newtype(:t) do\n newparam(:name)\n newproperty(:a, parent: QN)\nend\nclass QN\n def self.isnamevar?\n true\n end\nend\n", + }, "Param(Any, 'a')"}, + "type class reopened": {map[string]string{ + "m/lib/puppet/type/t.rb": classic + "class Puppet::Type::T\n def self.title_patterns\n [[/(x)/, [[:name]]]]\n end\nend\n", + }, "'name'"}, + "provider class reopened": {map[string]string{ + "m/lib/puppet/type/t.rb": classic + "class Puppet::Type::T::ProviderX\n @doc = 'patched'\nend\n", + "m/lib/puppet/provider/t/x.rb": "Puppet::Type.type(:t).provide(:x) do\n desc 'x'\nend\n", + }, "# : x\n"}, "constant lexical scope": {map[string]string{ "m/lib/puppet/type/t.rb": "VALS = 'a'\nmodule Puppet\n VALS = 'b'\nend\nPuppet::Type.newtype(:t) do\n newparam(:name)\n newproperty(:p) do\n newvalues(VALS)\n end\nend\n", }, "Enum['b']"}, @@ -146,6 +163,24 @@ func TestFidelityProvidersThatLoad(t *testing.T) { } } +// Each type file defines classes at its top level and loads in openvox 9.3.0, which writes want into t.pp. +func TestFidelityUserClasses(t *testing.T) { + for name, c := range map[string]struct{ src, want string }{ + "nested in reopened Puppet::Property": {"module Puppet\n class Property\n class QV < Property\n def insync?(is)\n true\n end\n end\n" + + " class QM < QV\n end\n end\n Type.newtype(:t) do\n newparam(:name)\n newproperty(:a, array_matching: :all, parent: Puppet::Property::QM) do\n" + + " desc 'a'\n end\n end\nend\n", " # a\n Puppet::Resource::Param(Any, 'a')\n"}, + "user subclass of Parameter::Boolean": {"require 'puppet/parameter/boolean'\nclass QB < Puppet::Parameter::Boolean\n def x; end\nend\n" + + "Puppet::Type.newtype(:t) do\n newparam(:name)\n newparam(:b, parent: QB)\nend\n", "Puppet::Resource::Param(Variant[Boolean, Enum['true', 'false', 'yes', 'no']], 'b')"}, + } { + t.Run(name, func(t *testing.T) { + b, err := os.ReadFile(filepath.Join(fidelityEnv(t, map[string]string{"m/lib/puppet/type/t.rb": c.src}), OutDir, "t.pp")) + if err != nil || !strings.Contains(string(b), c.want) { + t.Fatalf("t.pp lacks %q: %v\n%s", c.want, err, b) + } + }) + } +} + // With toml declared, each env either loads in openvox 9.3.0 with toml 0.3.0 installed or skips because what loads // depends on whether another type activated the gem first. func TestGemToml(t *testing.T) { diff --git a/internal/gentypes/generate.go b/internal/gentypes/generate.go index 2663f4e..011f1f8 100644 --- a/internal/gentypes/generate.go +++ b/internal/gentypes/generate.go @@ -18,7 +18,7 @@ import ( const OutDir = ".resource_types" // Version changes whenever generated output can change, so deploys rebuild typed environments. -const Version = "8" +const Version = "9" var moduleName = regexp.MustCompile(`^[a-z][a-z0-9_]*$`) diff --git a/internal/gentypes/generate_test.go b/internal/gentypes/generate_test.go index 0e08532..e6f5363 100644 --- a/internal/gentypes/generate_test.go +++ b/internal/gentypes/generate_test.go @@ -90,7 +90,7 @@ func TestReviewSkips(t *testing.T) { "r_prov_parent_missing": "parent provider nope is not defined", "r_send": "line 4: unsupported top-level Puppet::Type.type", "r_inline_provide": "line 4: unsupported top-level Puppet::Type.type", - "r_helper": "line 1: unsupported top-level module RHelper", + "r_helper": "line 9: unsupported top-level RHelper.add", "r_require_missing": `require "puppet_x/review/nope": no module provides it`, "r_rs_str_key": "register_type: unsupported string key", "r_rs_bad_lower": `type "string": unsupported type`, @@ -103,8 +103,8 @@ func TestReviewSkips(t *testing.T) { "r_dup_param": "duplicate parameter a", "r_dup_ensure": "duplicate property ensure", "r_bare": "unsupported top-level Type.newtype", - "r_mod_foo": "unsupported top-level module RFoo", - "r_mod_compact": "unsupported top-level module Puppet::RCompact", + "r_mod_foo": "unsupported Type.newtype in RFoo", + "r_mod_compact": "unsupported Type.newtype in Puppet::RCompact", "r_include_noreq": "include PuppetX::Review::Mix: no require defines it", "r_feature_const": "uninitialized constant RNope", "grafana_ldap_config": `require "toml": no module provides it`, diff --git a/internal/gentypes/load.go b/internal/gentypes/load.go index de44e80..0a114d9 100644 --- a/internal/gentypes/load.go +++ b/internal/gentypes/load.go @@ -27,6 +27,8 @@ type world struct { loaded map[string]bool gems map[string]bool classes map[string]*classCtx + // tclasses are the classes newtype defined, which already hold their providers when later code reopens them + tclasses map[string]bool // typ is the type whose providers are loading; sdefs are user classes' singleton methods by class typ *rtype sdefs map[string]map[string]*sdef @@ -57,7 +59,7 @@ var startup = func() map[string]byte { }() func newWorld(resolve Resolver) *world { - w := &world{resolve: resolve, defined: map[string]bool{}, kind: map[string]byte{}, sup: map[string]string{}, user: map[string]bool{}, mods: map[string][]string{}, loaded: map[string]bool{}, classes: map[string]*classCtx{}} + w := &world{resolve: resolve, defined: map[string]bool{}, kind: map[string]byte{}, sup: map[string]string{}, user: map[string]bool{}, mods: map[string][]string{}, loaded: map[string]bool{}, classes: map[string]*classCtx{}, tclasses: map[string]bool{}} for c, k := range startup { w.define(c, k) } @@ -263,6 +265,11 @@ func (p *parser) namespace() error { if top, _, _ := strings.Cut(name, "::"); p.w.gemTop(top) != "" { return fmt.Errorf("%s opens a namespace of gem %s", name, p.w.gemTop(top)) } + for t := range p.w.tclasses { + if strings.HasPrefix(name, t+"::") { + return fmt.Errorf("%s opens a namespace of type class %s", name, t) + } + } k, had := p.w.kind[name] switch { case !isClass: @@ -313,7 +320,40 @@ func (p *parser) namespace() error { p.w.classes[name] = c } c.priv = false - return p.body("end", p.classStmt(name, c)) + stmt := p.classStmt(name, c) + return p.body("end", func() (bool, error) { + t := p.cur() + inert := t.kind == tIdent && (t.text == "def" && p.at(1).text != "self" || t.text == "private" || t.text == "protected" || t.text == "public" || + (t.text == "module" || t.text == "class") && p.at(1).kind == tConst) + if !inert && c.parented { + return true, fmt.Errorf("%s runs class-level code after an attribute inherits from it", name) + } + c.active = c.active || !inert + return stmt() + }) +} + +// userParent resolves attribute parent c, a chain of user classes whose bodies define only instance methods, to the +// puppet class it inherits from: their genclass'd subclass then has that class's values, doc and class methods. +func (w *world) userParent(c string) (string, error) { + for w != nil && w.user[c] { + cc := w.classes[c] + if cc == nil || cc.kind != kClass || cc.active { + return "", fmt.Errorf("parent %s runs class-level code", c) + } + cc.parented = true + c = w.sup[c] + } + return c, nil +} + +// addMethod records instance method n; Puppet::Property.method_added raises on safe_insync? in its subclasses. +func (c *classCtx) addMethod(n string, hidden bool) error { + if n == "safe_insync?" && c.kind == kClass && c.parent != "" { + return fmt.Errorf("Puppet::Property.method_added raises on safe_insync?") + } + c.methods[n], c.hidden[n] = true, hidden + return nil } func (p *parser) constPath() (string, error) { @@ -350,8 +390,10 @@ type classCtx struct { sdefs map[string]*sdef parent string parentUnknown bool - typ *rtype - block bool + // active marks class-level code in a user class body; parented marks a class an attribute inherits from + active, parented bool + typ *rtype + block bool // a module's instance method bodies and included hook; extended methods that stand in for the ones they shadow idefs map[string]*sdef included *sdef @@ -449,7 +491,9 @@ func (p *parser) defMethod(c *classCtx, single bool) error { single, n, off = true, p.at(3).text, 3 } if !single { - c.methods[n], c.hidden[n] = true, c.priv + if err := c.addMethod(n, c.priv); err != nil { + return err + } if c.kind != kMod { return p.skipStatement() } @@ -516,7 +560,9 @@ func (p *parser) accessors(c *classCtx) error { names, err := p.symArgs() for _, n := range names { if kind != "attr_writer" { - c.methods[n], c.hidden[n] = true, c.priv + if err := c.addMethod(n, c.priv); err != nil { + return err + } } if kind != "attr_reader" { c.methods[n+"="], c.hidden[n+"="] = true, c.priv @@ -563,8 +609,7 @@ func (p *parser) alias(c *classCtx) error { if !c.methods[from] { return fmt.Errorf("alias of undefined method %s", from) } - c.methods[to], c.hidden[to] = true, c.hidden[from] - return nil + return c.addMethod(to, c.hidden[from]) } // mixin returns the public instance methods of module m, which one loaded file must define without include hooks. diff --git a/internal/gentypes/parse.go b/internal/gentypes/parse.go index d974647..7dade9c 100644 --- a/internal/gentypes/parse.go +++ b/internal/gentypes/parse.go @@ -504,6 +504,8 @@ func (p *parser) topStmt(inPuppet bool) func() (bool, error) { return true, p.require() case t.kind == tIdent && t.text == "begin": return true, p.beginRequire() + case t.kind == tIdent && (t.text == "module" || t.text == "class") && p.at(1).kind == tConst: + return true, p.namespace() case t.kind == tConst && p.methodCall("newtype", inPuppet): return true, p.newtype() case t.kind == tConst && p.methodCall("register_type", inPuppet): @@ -711,6 +713,14 @@ func (p *parser) newtype() error { } t := &rtype{name: name, methods: map[string]bool{}} p.types = append(p.types, t) + if p.w != nil && name != "" { + c := "Puppet::Type::" + strings.ToUpper(name[:1]) + strings.ToLower(name[1:]) + if p.w.user[c] { + return fmt.Errorf("newtype replaces class %s", c) + } + p.w.define(c, kClass) + p.w.tclasses[c] = true + } closeTok, err := p.blockOpen() if err != nil { return err @@ -1177,11 +1187,19 @@ func (p *parser) newattr(t *rtype, property bool) error { return fmt.Errorf("attribute %s: %w", name, err) } if v, ok := opts.get("parent"); ok { - vals, known := parents[v.s] - if v.k != vConst || !known { + if v.k != vConst { return fmt.Errorf("attribute %s: unsupported parent %s", name, v.s) } - a.ensure = v.s == "Puppet::Property::Ensure" + root, err := p.w.userParent(v.s) + if err != nil { + return fmt.Errorf("attribute %s: %w", name, err) + } + base := map[bool]string{true: "Puppet::Property", false: "Puppet::Parameter"}[property] + vals, known := parents[root] + if !known && (root != base || root == v.s) { + return fmt.Errorf("attribute %s: unsupported parent %s", name, v.s) + } + a.ensure = root == "Puppet::Property::Ensure" for _, s := range vals { a.addValue(s, nil) } diff --git a/internal/gentypes/testdata/env/external_modules/zfs_core/lib/puppet/provider/zpool/zpool.rb b/internal/gentypes/testdata/env/external_modules/zfs_core/lib/puppet/provider/zpool/zpool.rb new file mode 100644 index 0000000..799ebdc --- /dev/null +++ b/internal/gentypes/testdata/env/external_modules/zfs_core/lib/puppet/provider/zpool/zpool.rb @@ -0,0 +1,189 @@ +Puppet::Type.type(:zpool).provide(:zpool) do + desc 'Provider for zpool.' + + commands zpool: 'zpool' + + # NAME SIZE ALLOC FREE CAP HEALTH ALTROOT + def self.instances + zpool(:list, '-H').split("\n").map do |line| + name, _size, _alloc, _free, _cap, _health, _altroot = line.split(%r{\s+}) + new(name: name, ensure: :present) + end + end + + def get_zpool_property(prop) + zpool(:get, prop, @resource[:name]).split("\n").reverse.map { |line| + name, _property, value, _source = line.split("\s") + value if name == @resource[:name] + }.shift + end + + def process_zpool_data(pool_array) + if pool_array == [] + return Hash.new(:absent) + end + # get the name and get rid of it + pool = {} + pool[:pool] = pool_array[0] + pool_array.shift + + tmp = [] + + # order matters here :( + pool_array.reverse_each do |value| + sym = nil + case value + when 'spares' + sym = :spare + when 'logs' + sym = :log + when 'cache' + sym = :cache + when %r{^mirror|^raidz1|^raidz2} + sym = (value =~ %r{^mirror}) ? :mirror : :raidz + pool[:raid_parity] = 'raidz2' if %r{^raidz2}.match?(value) + else + # get full drive name if the value is a partition (Linux only) + tmp << if Facter.value(:kernel) == 'Linux' && value =~ %r{/dev/(:?[a-z]+([0-9]+n[0-9]+p)?1|disk/by-id/.+-part1)$} + execute("lsblk -p -no pkname #{value}").chomp + else + value + end + sym = :disk if value == pool_array.first + end + + if sym + pool[sym] = pool[sym] ? pool[sym].unshift(tmp.reverse.join(' ')) : [tmp.reverse.join(' ')] + tmp.clear + end + end + + pool + end + + def get_pool_data + # https://docs.oracle.com/cd/E19082-01/817-2271/gbcve/index.html + # we could also use zpool iostat -v mypool for a (little bit) cleaner output + zpool_opts = case Facter.value(:kernel) + # use full device names ("-P") on Linux/ZOL to prevent + # mismatches between creation and display paths: + when 'Linux' + '-P' + else + '' + end + out = execute("zpool status #{zpool_opts} #{@resource[:pool]}", failonfail: false, combine: false) + zpool_data = out.lines.select { |line| line.index("\t") == 0 }.map { |l| l.strip.split("\s")[0] } + zpool_data.shift + zpool_data + end + + def current_pool + @current_pool = process_zpool_data(get_pool_data) unless defined?(@current_pool) && @current_pool + @current_pool + end + + def flush + @current_pool = nil + end + + # Adds log and spare + def build_named(name) + prop = @resource[name.to_sym] + if prop + [name] + prop.map { |p| p.split(' ') }.flatten + else + [] + end + end + + # query for parity and set the right string + def raidzarity + @resource[:raid_parity] ? @resource[:raid_parity] : 'raidz1' + end + + # handle mirror or raid + def handle_multi_arrays(prefix, array) + array.map { |a| [prefix] + a.split(' ') }.flatten + end + + # builds up the vdevs for create command + def build_vdevs + disk = @resource[:disk] + mirror = @resource[:mirror] + raidz = @resource[:raidz] + + if disk + disk.map { |d| d.split(' ') }.flatten + elsif mirror + handle_multi_arrays('mirror', mirror) + elsif raidz + handle_multi_arrays(raidzarity, raidz) + end + end + + def add_pool_properties + properties = [] + [:ashift, :autoexpand, :failmode].each do |property| + if (value = @resource[property]) && value != '' + properties << '-o' << "#{property}=#{value}" + end + end + properties + end + + def create + zpool(*([:create] + add_pool_properties + [@resource[:pool]] + build_vdevs + build_named('spare') + build_named('log') + build_named('cache'))) + end + + def destroy + zpool :destroy, @resource[:pool] + end + + def exists? + if current_pool[:pool] == :absent + false + else + true + end + end + + [:disk, :mirror, :raidz, :log, :spare, :cache].each do |field| + define_method(field) do + current_pool[field] + end + + # rubocop:disable Style/SignalException + define_method(field.to_s + '=') do |should| + fail "zpool #{field} can't be changed. should be #{should}, currently is #{current_pool[field]}" + end + end + + [:autoexpand, :failmode].each do |field| + define_method(field) do + get_zpool_property(field) + end + + define_method(field.to_s + '=') do |should| + zpool(:set, "#{field}=#{should}", @resource[:name]) + end + end + + # Borrow the code from the ZFS provider here so that we catch and return '-' + # as ashift is linux only. + # see lib/puppet/provider/zfs/zfs.rb + + PARAMETER_UNSET_OR_NOT_AVAILABLE = '-'.freeze unless defined? PARAMETER_UNSET_OR_NOT_AVAILABLE + + define_method(:ashift) do + get_zpool_property(:ashift) + rescue + PARAMETER_UNSET_OR_NOT_AVAILABLE + end + + define_method('ashift=') do |should| + zpool(:set, "ashift=#{should}", @resource[:name]) + rescue + PARAMETER_UNSET_OR_NOT_AVAILABLE + end +end diff --git a/internal/gentypes/testdata/env/external_modules/zfs_core/lib/puppet/type/zpool.rb b/internal/gentypes/testdata/env/external_modules/zfs_core/lib/puppet/type/zpool.rb new file mode 100644 index 0000000..955ab1d --- /dev/null +++ b/internal/gentypes/testdata/env/external_modules/zfs_core/lib/puppet/type/zpool.rb @@ -0,0 +1,127 @@ +# ZPool type +module Puppet + # Puppet::Property + class Property + # VDev class + class VDev < Property + # @param array the array to be flattened and sorted + # @return [Array] returns a flattened and sorted array + def flatten_and_sort(array) + array = [array] unless array.is_a? Array + array.map { |a| a.split(' ') }.flatten.sort + end + + # @param is the current state of the object + # @return [Boolean] if the resource is in sync with what it should be + def insync?(is) + return @should == [:absent] if is == :absent + + flatten_and_sort(is) == flatten_and_sort(@should) + end + end + + # MultiVDev class + class MultiVDev < VDev + # @param is the current state of the object + # @return [Boolean] if the resource is in sync with what it should be + def insync?(is) + return @should == [:absent] if is == :absent + + return false unless is.length == @should.length + + is.each_with_index { |list, i| return false unless flatten_and_sort(list) == flatten_and_sort(@should[i]) } + + # if we made it this far we are in sync + true + end + end + end + + Type.newtype(:zpool) do + desc <<-DESC + @summary Manage zpools. Create and delete zpools. The provider WILL NOT SYNC, only report differences. + + Supports vdevs with mirrors, raidz, logs, spares, and cache. + + @example Using zpool. + zpool { 'tstpool': + ensure => present, + disk => '/ztstpool/dsk', + } + DESC + + ensurable + + newproperty(:disk, array_matching: :all, parent: Puppet::Property::VDev) do + desc 'The disk(s) for this pool. Can be an array or a space separated string.' + end + + newproperty(:mirror, array_matching: :all, parent: Puppet::Property::MultiVDev) do + desc "List of all the devices to mirror for this pool. Each mirror should be a + space separated string: + + mirror => [\"disk1 disk2\", \"disk3 disk4\"], + + " + + validate do |value| + raise ArgumentError, _('mirror names must be provided as string separated, not a comma-separated list') if value.include?(',') + end + end + + newproperty(:raidz, array_matching: :all, parent: Puppet::Property::MultiVDev) do + desc "List of all the devices to raid for this pool. Should be an array of + space separated strings: + + raidz => [\"disk1 disk2\", \"disk3 disk4\"], + + " + + validate do |value| + raise ArgumentError, _('raid names must be provided as string separated, not a comma-separated list') if value.include?(',') + end + end + + newproperty(:spare, array_matching: :all, parent: Puppet::Property::VDev) do + desc 'Spare disk(s) for this pool.' + end + + newproperty(:log, array_matching: :all, parent: Puppet::Property::VDev) do + desc 'Log disks for this pool. This type does not currently support mirroring of log disks.' + end + + newproperty(:cache, array_matching: :all, parent: Puppet::Property::VDev) do + desc 'Cache disks for this pool.' + end + + newproperty(:ashift) do + desc 'The Alignment Shift for the vdevs in the given pool.' + + validate do |_value| + raise Puppet::Error _('This property is only supported on Linux') unless Facter.value(:kernel) == 'Linux' + end + end + + newproperty(:autoexpand) do + desc 'The autoexpand setting for the given pool. Valid values are `on` or `off`' + end + + newproperty(:failmode) do + desc 'The failmode setting for the given pool. Valid values are `wait`, `continue` or `panic`' + end + + newparam(:pool) do + desc 'The name for this pool.' + isnamevar + end + + newparam(:raid_parity) do + desc 'Determines parity when using the `raidz` parameter.' + end + + validate do + has_should = [:disk, :mirror, :raidz].select { |prop| should(prop) } + raise _('You cannot specify %{multiple_props} on this type (only one)') % { multiple_props: has_should.join(' and ') } if has_should.length > 1 + end + end +end diff --git a/internal/gentypes/testdata/golden/zpool.pp b/internal/gentypes/testdata/golden/zpool.pp new file mode 100644 index 0000000..ee6d818 --- /dev/null +++ b/internal/gentypes/testdata/golden/zpool.pp @@ -0,0 +1,75 @@ +# This file was automatically generated on 2026-11-08 22:32:40 +1100. +# Use the 'puppet generate types' command to regenerate this file. + +# @summary Manage zpools. Create and delete zpools. The provider WILL NOT SYNC, only report differences. +# +# Supports vdevs with mirrors, raidz, logs, spares, and cache. +# +# @example Using zpool. +# zpool { 'tstpool': +# ensure => present, +# disk => '/ztstpool/dsk', +# } +Puppet::Resource::ResourceType3.new( + 'zpool', + [ + # The basic property that the resource should be in. + # + # Valid values are `present`, `absent`. + Puppet::Resource::Param(Enum['present', 'absent'], 'ensure'), + + # The disk(s) for this pool. Can be an array or a space separated string. + Puppet::Resource::Param(Any, 'disk'), + + # List of all the devices to mirror for this pool. Each mirror should be a + # space separated string: + # + # mirror => ["disk1 disk2", "disk3 disk4"], + Puppet::Resource::Param(Any, 'mirror'), + + # List of all the devices to raid for this pool. Should be an array of + # space separated strings: + # + # raidz => ["disk1 disk2", "disk3 disk4"], + Puppet::Resource::Param(Any, 'raidz'), + + # Spare disk(s) for this pool. + Puppet::Resource::Param(Any, 'spare'), + + # Log disks for this pool. This type does not currently support mirroring of log disks. + Puppet::Resource::Param(Any, 'log'), + + # Cache disks for this pool. + Puppet::Resource::Param(Any, 'cache'), + + # The Alignment Shift for the vdevs in the given pool. + Puppet::Resource::Param(Any, 'ashift'), + + # The autoexpand setting for the given pool. Valid values are `on` or `off` + Puppet::Resource::Param(Any, 'autoexpand'), + + # The failmode setting for the given pool. Valid values are `wait`, `continue` or `panic` + Puppet::Resource::Param(Any, 'failmode') + ], + [ + # The name for this pool. + Puppet::Resource::Param(Any, 'pool', true), + + # Determines parity when using the `raidz` parameter. + Puppet::Resource::Param(Any, 'raid_parity'), + + # The specific backend to use for this `zpool` + # resource. You will seldom need to specify this --- OpenVox will usually + # discover the appropriate provider for your platform.Available providers are: + # + # zpool + # : Provider for zpool. + # + # * Required binaries: `zpool`. + Puppet::Resource::Param(Any, 'provider') + ], + { + /(?m-ix:(.*))/ => ['pool'] + }, + true, + false)