-
-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add manage_network to manage networks in code #340
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# @summary Generate network file from template | ||
# | ||
# @api public | ||
# | ||
# @see systemd.network(5) | ||
# | ||
# @example network file | ||
# systemd::manage_network { 'eth0': | ||
# ensure => present, | ||
# match_entry => 'eth0', | ||
# network_entry => { | ||
# address => '1.2.3.4', | ||
# gateway => '7.8.9.0', | ||
# dns => '1.1.1.1' | ||
# } | ||
# } | ||
# | ||
# @param name [Pattern['^[^/]+\.(network|netdev|link)$']] | ||
# The target unit file to create | ||
# | ||
# @param ensure The state of the unit file to ensure | ||
# @param path The main systemd configuration path | ||
# @param owner The owner to set on the unit file | ||
# @param group The group to set on the unit file | ||
# @param mode The mode to set on the unit file | ||
# @param show_diff Whether to show the diff when updating unit file | ||
# @param restart_service if netword should be restarted. | ||
# @param match_entry key value pairs for [Match] section of the unit file | ||
# @param network_entry key value pairs for [Network] section of the unit file | ||
# @param address_entry key value pairs for [Address] section of the unit file | ||
# | ||
define systemd::manage_network ( | ||
Enum['file', 'absent'] $ensure = 'file', | ||
Stdlib::Absolutepath $path = '/etc/systemd/system', | ||
String $owner = 'root', | ||
String $group = 'root', | ||
Stdlib::Filemode $mode = '0444', | ||
Boolean $show_diff = true, | ||
Boolean $restart_service = true, | ||
Optional[Hash] $match_entry = undef, | ||
Optional[Hash] $network_entry = undef, | ||
Optional[Hash] $address_entry = undef, | ||
) { | ||
assert_type(Systemd::Network, $name) | ||
|
||
systemd::network { $name: | ||
ensure => $ensure, | ||
path => $path, | ||
owner => $owner, | ||
group => $group, | ||
mode => $mode, | ||
show_diff => $show_diff, | ||
restart_service => $restart_service, | ||
content => epp('systemd/network.epp', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than a new template the existing You would get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but wouldn't it get to overloaded, with dropin, units and networks? the initial 3 *_entry are only a subset, netword offers a lot more. so i thought better have it separated. otherwise you will never get a PR done if you have to check alle the influence you change could have? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Easier to deal with the interaction in a common layer. Template does need refactoring to loop over the section rather than enumerate them but that just strengthens case for one template. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ¯_(ツ)_/¯ i also can add my stuff there, if this is whats needed to merge this in the end. i'm personally just not a big fand off such über-templates. |
||
match_entry => $match_entry, | ||
network_entry => $network_entry, | ||
address_entry => $address_entry, | ||
}), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<%- | | ||
Optional[Hash] $match_entry, | ||
Optional[Hash] $network_entry, | ||
Optional[Hash] $address_entry, | ||
| -%> | ||
<% if $match_entry { -%> | ||
|
||
[Match] | ||
<% $match_entry.each | $_key, $_value | { -%> | ||
<% Array($_value, true).each | $_subvalue | { -%> | ||
<%= $_key %>=<%= $_subvalue %> | ||
<% } -%> | ||
<% } -%> | ||
<% } -%> | ||
<% if $network_entry { -%> | ||
|
||
[Network] | ||
<% $network_entry.each | $_key, $_value | { -%> | ||
<% Array($_value, true).each | $_subvalue | { -%> | ||
<%= $_key %>=<%= $_subvalue %> | ||
<% } -%> | ||
<% } -%> | ||
<% } -%> | ||
<% if $address_entry { -%> | ||
|
||
[Address] | ||
<% $address_entry.each | $_key, $_value | { -%> | ||
<% Array($_value, true).each | $_subvalue | { -%> | ||
<%= $_key %>=<%= $_subvalue %> | ||
<% } -%> | ||
<% } -%> | ||
<% } -%> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @summary custom datatype that validates filenames/paths for valid systemd network files | ||
type Systemd::Network = Pattern[/^[a-zA-Z0-9:\-_.\\@]+\.(network|netdev|link)$/] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of module uses
present
andabsent
. The fact it a file is a hidden detail.