diff --git a/REFERENCE.md b/REFERENCE.md
index 4711d82e..e05d7c29 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -61,8 +61,11 @@
* [`Systemd::OomdSettings`](#Systemd--OomdSettings): Configurations for oomd.conf
* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Matches Systemd Service Limit Struct
* [`Systemd::Unit`](#Systemd--Unit): custom datatype that validates different filenames for systemd units and unit templates
+* [`Systemd::Unit::Amount`](#Systemd--Unit--Amount): Systemd definition of amount, often bytes or united bytes
+* [`Systemd::Unit::AmountOrPercent`](#Systemd--Unit--AmountOrPercent): Systemd definition of amount, often bytes or united bytes
* [`Systemd::Unit::Install`](#Systemd--Unit--Install): Possible keys for the [Install] section of a unit file
* [`Systemd::Unit::Path`](#Systemd--Unit--Path): Possible keys for the [Path] section of a unit file
+* [`Systemd::Unit::Percent`](#Systemd--Unit--Percent): Systemd definition of a percentage
* [`Systemd::Unit::Service`](#Systemd--Unit--Service): Possible keys for the [Service] section of a unit file
* [`Systemd::Unit::Service::Exec`](#Systemd--Unit--Service--Exec): Possible strings for ExecStart, ExecStartPrep, ...
* [`Systemd::Unit::Slice`](#Systemd--Unit--Slice): Possible keys for the [Slice] section of a unit file
@@ -2334,6 +2337,26 @@ custom datatype that validates different filenames for systemd units and unit te
Alias of `Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]`
+### `Systemd::Unit::Amount`
+
+Systemd definition of amount, often bytes or united bytes
+
+* **See also**
+ * https://www.freedesktop.org/software/systemd/man/systemd.service.html
+ * https://www.freedesktop.org/software/systemd/man/systemd.slice.html
+
+Alias of `Variant[Integer[0], Pattern['\A(infinity|\d+(K|M|G|T)?(:\d+(K|M|G|T)?)?)\z']]`
+
+### `Systemd::Unit::AmountOrPercent`
+
+Systemd definition of amount, often bytes or united bytes
+
+* **See also**
+ * https://www.freedesktop.org/software/systemd/man/systemd.service.html
+ * https://www.freedesktop.org/software/systemd/man/systemd.slice.html
+
+Alias of `Variant[Systemd::Unit::Amount, Systemd::Unit::Percent]`
+
### `Systemd::Unit::Install`
Possible keys for the [Install] section of a unit file
@@ -2376,6 +2399,16 @@ Struct[{
}]
```
+### `Systemd::Unit::Percent`
+
+Systemd definition of a percentage
+
+* **See also**
+ * https://www.freedesktop.org/software/systemd/man/systemd.service.html
+ * https://www.freedesktop.org/software/systemd/man/systemd.slice.html
+
+Alias of `Pattern['\A([0-9][0-9]?|100)%\z']`
+
### `Systemd::Unit::Service`
Possible keys for the [Service] section of a unit file
@@ -2543,28 +2576,28 @@ Struct[{
Optional['CPUShares'] => Integer[2,262144],
Optional['CPUWeight'] => Variant[Enum['idle'],Integer[1,10000]],
Optional['Delegate'] => Boolean,
- Optional['DeviceAllow'] => String[1],
+ Optional['DeviceAllow'] => Pattern['^(/dev/)|(char-)|(block-).*$'],
Optional['DevicePolicy'] => Enum['auto','closed','strict'],
Optional['IOAccounting'] => Boolean,
Optional['IODeviceWeight'] => Array[Hash[Stdlib::Absolutepath, Integer[1,10000], 1, 1]],
- Optional['IOReadBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
- Optional['IOReadIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
+ Optional['IOReadBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
+ Optional['IOReadIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
Optional['IOWeight'] => Integer[1,10000],
- Optional['IOWriteBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
- Optional['IOWriteIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
+ Optional['IOWriteBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
+ Optional['IOWriteIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
Optional['IPAccounting'] => Boolean,
Optional['MemoryAccounting'] => Boolean,
- Optional['MemoryHigh'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemoryLimit'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'], # dep'd in systemd
- Optional['MemoryLow'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemoryMax'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemoryMin'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemorySwapMax'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
+ Optional['MemoryHigh'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemoryLimit'] => Systemd::Unit::AmountOrPercent, # depprecated in systemd
+ Optional['MemoryLow'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemoryMax'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemoryMin'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemorySwapMax'] => Systemd::Unit::AmountOrPercent,
Optional['Slice'] => String[1],
Optional['StartupCPUShares'] => Integer[2,262144],
Optional['StartupIOWeight'] => Integer[1,10000],
Optional['TasksAccounting'] => Boolean,
- Optional['TasksMax'] => Variant[Integer[1],Pattern['^(infinity|([1-9][0-9]?$|^100)%)$']],
+ Optional['TasksMax'] => Systemd::Unit::AmountOrPercent,
}]
```
diff --git a/spec/type_aliases/systemd_unit_amount_spec.rb b/spec/type_aliases/systemd_unit_amount_spec.rb
new file mode 100644
index 00000000..436d72b9
--- /dev/null
+++ b/spec/type_aliases/systemd_unit_amount_spec.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Systemd::Unit::Amount' do
+ it { is_expected.to allow_value(100) }
+ it { is_expected.to allow_value('200') }
+ it { is_expected.to allow_value('8G') }
+ it { is_expected.to allow_value('1T') }
+ it { is_expected.to allow_value('infinity') }
+
+ it { is_expected.not_to allow_value('1P') }
+ it { is_expected.not_to allow_value('10%') }
+end
diff --git a/spec/type_aliases/systemd_unit_amountorpercent_spec.rb b/spec/type_aliases/systemd_unit_amountorpercent_spec.rb
new file mode 100644
index 00000000..33a32ae8
--- /dev/null
+++ b/spec/type_aliases/systemd_unit_amountorpercent_spec.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Systemd::Unit::AmountOrPercent' do
+ it { is_expected.to allow_value(100) }
+ it { is_expected.to allow_value('200') }
+ it { is_expected.to allow_value('8G') }
+ it { is_expected.to allow_value('1T') }
+ it { is_expected.to allow_value('infinity') }
+ it { is_expected.to allow_value('10%') }
+
+ it { is_expected.not_to allow_value('1P') }
+end
diff --git a/spec/type_aliases/systemd_unit_percent_spec.rb b/spec/type_aliases/systemd_unit_percent_spec.rb
new file mode 100644
index 00000000..7bb6aae4
--- /dev/null
+++ b/spec/type_aliases/systemd_unit_percent_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Systemd::Unit::Percent' do
+ it { is_expected.to allow_value('1%') }
+ it { is_expected.to allow_value('100%') }
+
+ it { is_expected.not_to allow_value(1) }
+ it { is_expected.not_to allow_value('105%') }
+end
diff --git a/spec/type_aliases/systemd_unit_slice_spec.rb b/spec/type_aliases/systemd_unit_slice_spec.rb
index a8fafa7c..1845b065 100644
--- a/spec/type_aliases/systemd_unit_slice_spec.rb
+++ b/spec/type_aliases/systemd_unit_slice_spec.rb
@@ -10,6 +10,10 @@
it { is_expected.to allow_value({ 'IOAccounting' => false }) }
it { is_expected.to allow_value({ 'IOWeight' => 100 }) }
+ it { is_expected.to allow_value({ 'DeviceAllow' => '/dev/sda1' }) }
+ it { is_expected.to allow_value({ 'DeviceAllow' => 'block-loop' }) }
+ it { is_expected.not_to allow_value({ 'DeviceAllow' => 'random' }) }
+
it {
is_expected.to allow_value(
{
diff --git a/types/unit/amount.pp b/types/unit/amount.pp
new file mode 100644
index 00000000..c4f458b2
--- /dev/null
+++ b/types/unit/amount.pp
@@ -0,0 +1,5 @@
+# @summary Systemd definition of amount, often bytes or united bytes
+# @see https://www.freedesktop.org/software/systemd/man/systemd.service.html
+# @see https://www.freedesktop.org/software/systemd/man/systemd.slice.html
+#
+type Systemd::Unit::Amount = Variant[Integer[0],Pattern['\A(infinity|\d+(K|M|G|T)?(:\d+(K|M|G|T)?)?)\z']]
diff --git a/types/unit/amountorpercent.pp b/types/unit/amountorpercent.pp
new file mode 100644
index 00000000..33781229
--- /dev/null
+++ b/types/unit/amountorpercent.pp
@@ -0,0 +1,5 @@
+# @summary Systemd definition of amount, often bytes or united bytes
+# @see https://www.freedesktop.org/software/systemd/man/systemd.service.html
+# @see https://www.freedesktop.org/software/systemd/man/systemd.slice.html
+#
+type Systemd::Unit::AmountOrPercent = Variant[Systemd::Unit::Amount,Systemd::Unit::Percent]
diff --git a/types/unit/percent.pp b/types/unit/percent.pp
new file mode 100644
index 00000000..8bf44563
--- /dev/null
+++ b/types/unit/percent.pp
@@ -0,0 +1,5 @@
+# @summary Systemd definition of a percentage
+# @see https://www.freedesktop.org/software/systemd/man/systemd.service.html
+# @see https://www.freedesktop.org/software/systemd/man/systemd.slice.html
+#
+type Systemd::Unit::Percent = Pattern['\A([0-9][0-9]?|100)%\z']
diff --git a/types/unit/slice.pp b/types/unit/slice.pp
index 70110425..e18984cf 100644
--- a/types/unit/slice.pp
+++ b/types/unit/slice.pp
@@ -9,27 +9,27 @@
Optional['CPUShares'] => Integer[2,262144],
Optional['CPUWeight'] => Variant[Enum['idle'],Integer[1,10000]],
Optional['Delegate'] => Boolean,
- Optional['DeviceAllow'] => String[1],
+ Optional['DeviceAllow'] => Pattern['^(/dev/)|(char-)|(block-).*$'],
Optional['DevicePolicy'] => Enum['auto','closed','strict'],
Optional['IOAccounting'] => Boolean,
Optional['IODeviceWeight'] => Array[Hash[Stdlib::Absolutepath, Integer[1,10000], 1, 1]],
- Optional['IOReadBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
- Optional['IOReadIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
+ Optional['IOReadBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
+ Optional['IOReadIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
Optional['IOWeight'] => Integer[1,10000],
- Optional['IOWriteBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
- Optional['IOWriteIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Pattern['^(\d+(K|M|G|T)?)$'], 1, 1]],
+ Optional['IOWriteBandwidthMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
+ Optional['IOWriteIOPSMax'] => Array[Hash[Stdlib::Absolutepath, Systemd::Unit::Amount], 1, 1],
Optional['IPAccounting'] => Boolean,
Optional['MemoryAccounting'] => Boolean,
- Optional['MemoryHigh'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemoryLimit'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'], # dep'd in systemd
- Optional['MemoryLow'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemoryMax'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemoryMin'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
- Optional['MemorySwapMax'] => Pattern['\A(infinity|\d+(K|M|G|T|%)?(:\d+(K|M|G|T|%)?)?)\z'],
+ Optional['MemoryHigh'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemoryLimit'] => Systemd::Unit::AmountOrPercent, # depprecated in systemd
+ Optional['MemoryLow'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemoryMax'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemoryMin'] => Systemd::Unit::AmountOrPercent,
+ Optional['MemorySwapMax'] => Systemd::Unit::AmountOrPercent,
Optional['Slice'] => String[1],
Optional['StartupCPUShares'] => Integer[2,262144],
Optional['StartupIOWeight'] => Integer[1,10000],
Optional['TasksAccounting'] => Boolean,
- Optional['TasksMax'] => Variant[Integer[1],Pattern['^(infinity|([1-9][0-9]?$|^100)%)$']],
+ Optional['TasksMax'] => Systemd::Unit::AmountOrPercent,
}
]