Skip to content

Commit

Permalink
Use new types Systemd::Unit::Amount, Systemd::Unit::Percent and Syste…
Browse files Browse the repository at this point in the history
…md::Unit::AmountOrPerecnt
  • Loading branch information
traylenator committed Mar 4, 2024
1 parent fca90f2 commit 12d3822
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 24 deletions.
57 changes: 45 additions & 12 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)$/]`

### <a name="Systemd--Unit--Amount"></a>`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']]`

### <a name="Systemd--Unit--AmountOrPercent"></a>`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]`

### <a name="Systemd--Unit--Install"></a>`Systemd::Unit::Install`

Possible keys for the [Install] section of a unit file
Expand Down Expand Up @@ -2376,6 +2399,16 @@ Struct[{
}]
```

### <a name="Systemd--Unit--Percent"></a>`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']`

### <a name="Systemd--Unit--Service"></a>`Systemd::Unit::Service`

Possible keys for the [Service] section of a unit file
Expand Down Expand Up @@ -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,
}]
```

Expand Down
14 changes: 14 additions & 0 deletions spec/type_aliases/systemd_unit_amount_spec.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/type_aliases/systemd_unit_amountorpercent_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/type_aliases/systemd_unit_percent_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/type_aliases/systemd_unit_slice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
5 changes: 5 additions & 0 deletions types/unit/amount.pp
Original file line number Diff line number Diff line change
@@ -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']]
5 changes: 5 additions & 0 deletions types/unit/amountorpercent.pp
Original file line number Diff line number Diff line change
@@ -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]
5 changes: 5 additions & 0 deletions types/unit/percent.pp
Original file line number Diff line number Diff line change
@@ -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']
24 changes: 12 additions & 12 deletions types/unit/slice.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
]

0 comments on commit 12d3822

Please sign in to comment.