46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'manifests/network.pp', line 46
define podman::network (
Enum['present', 'absent'] $ensure = 'present',
Enum['bridge', 'macvlan'] $driver = 'bridge',
Boolean $disable_dns = false,
Array[String] $opts = [],
Optional[String] $gateway = undef,
Boolean $internal = false,
Optional[String] $ip_range = undef,
Hash[String,String] $labels = {},
Optional[String] $subnet = undef,
Boolean $ipv6 = false,
String $user = '',
) {
require podman::install
$_disable_dns = $disable_dns ? {
true => '--disable-dns',
default => '',
}
# Convert opts list to command arguments
$_opts = $opts.reduce('') |$mem, $opt| {
"${mem} --flag ${opt}"
}
# Convert $labels hash to command arguments
$_labels = $labels.reduce('') |$mem, $label| {
if $label[1] =~ String {
"${mem} --label ${label[0]} '${label[1]}'"
} else {
$dup = $label[1].reduce('') |$mem2, $value| {
"${mem2} --${label[0]} '${value}'"
}
"${mem} ${dup}"
}
}
$_gateway = $gateway ? {
undef => '',
default => "--gateway ${gateway}",
}
$_internal = $internal ? {
true => '--internal',
default => '',
}
$_ip_range = $ip_range ? {
undef => '',
default => "--ip-range ${ip_range}"
}
$_subnet = $subnet ? {
undef => '',
default => "--subnet ${subnet}",
}
$_ipv6 = $ipv6 ? {
true => '--ipv6',
default => '',
}
# A rootless container network will be defined as the defined user
if $user != '' {
# Set default execution environment for the rootless user
$exec_defaults = {
user => $user,
environment => [
"HOME=${User[$user]['home']}",
"XDG_RUNTIME_DIR=/run/user/${User[$user]['uid']}",
"DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${User[$user]['uid']}/bus",
],
cwd => User[$user]['home'],
}
$requires = [
Podman::Rootless[$user],
Service['podman systemd-logind'],
]
} else {
$exec_defaults = {}
$requires = []
}
case $ensure {
'present': {
exec { "podman_create_network_${title}":
command => @("END"/L),
podman network create ${title} --driver ${driver} ${_opts} \
${_gateway} ${_internal} ${_ip_range} ${_labels} ${_subnet} ${_ipv6}
|END
unless => "podman network exists ${title}",
path => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
require => $requires,
* => $exec_defaults,
}
}
'absent': {
exec { "podman_remove_network_${title}":
command => "podman network rm ${title}",
onlyif => "podman network exists ${title}",
path => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
require => $requires,
* => $exec_defaults,
}
}
default: {
fail('"ensure" must be "present" or "absent"')
}
}
}
|