pyinfra 2.9.2__py2.py3-none-any.whl → 3.0b1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyinfra/api/__init__.py +3 -0
- pyinfra/api/arguments.py +261 -255
- pyinfra/api/arguments_typed.py +77 -0
- pyinfra/api/command.py +66 -53
- pyinfra/api/config.py +27 -22
- pyinfra/api/connect.py +1 -1
- pyinfra/api/connectors.py +2 -24
- pyinfra/api/deploy.py +21 -52
- pyinfra/api/exceptions.py +33 -8
- pyinfra/api/facts.py +77 -113
- pyinfra/api/host.py +150 -82
- pyinfra/api/inventory.py +17 -25
- pyinfra/api/operation.py +232 -198
- pyinfra/api/operations.py +102 -148
- pyinfra/api/state.py +137 -79
- pyinfra/api/util.py +55 -70
- pyinfra/connectors/base.py +150 -0
- pyinfra/connectors/chroot.py +160 -169
- pyinfra/connectors/docker.py +227 -237
- pyinfra/connectors/dockerssh.py +231 -253
- pyinfra/connectors/local.py +195 -207
- pyinfra/connectors/ssh.py +528 -615
- pyinfra/connectors/ssh_util.py +114 -0
- pyinfra/connectors/sshuserclient/client.py +5 -3
- pyinfra/connectors/terraform.py +86 -65
- pyinfra/connectors/util.py +212 -137
- pyinfra/connectors/vagrant.py +55 -48
- pyinfra/context.py +3 -2
- pyinfra/facts/docker.py +1 -0
- pyinfra/facts/files.py +45 -32
- pyinfra/facts/git.py +3 -1
- pyinfra/facts/gpg.py +1 -1
- pyinfra/facts/hardware.py +4 -2
- pyinfra/facts/iptables.py +5 -3
- pyinfra/facts/mysql.py +1 -0
- pyinfra/facts/postgres.py +168 -0
- pyinfra/facts/postgresql.py +5 -161
- pyinfra/facts/selinux.py +3 -1
- pyinfra/facts/server.py +77 -30
- pyinfra/facts/systemd.py +29 -12
- pyinfra/facts/sysvinit.py +10 -10
- pyinfra/facts/util/packaging.py +4 -2
- pyinfra/local.py +4 -5
- pyinfra/operations/apk.py +3 -3
- pyinfra/operations/apt.py +25 -47
- pyinfra/operations/brew.py +7 -14
- pyinfra/operations/bsdinit.py +4 -4
- pyinfra/operations/cargo.py +1 -1
- pyinfra/operations/choco.py +1 -1
- pyinfra/operations/dnf.py +4 -4
- pyinfra/operations/files.py +108 -321
- pyinfra/operations/gem.py +1 -1
- pyinfra/operations/git.py +6 -37
- pyinfra/operations/iptables.py +2 -10
- pyinfra/operations/launchd.py +1 -1
- pyinfra/operations/lxd.py +1 -9
- pyinfra/operations/mysql.py +5 -28
- pyinfra/operations/npm.py +1 -1
- pyinfra/operations/openrc.py +1 -1
- pyinfra/operations/pacman.py +3 -3
- pyinfra/operations/pip.py +14 -15
- pyinfra/operations/pkg.py +1 -1
- pyinfra/operations/pkgin.py +3 -3
- pyinfra/operations/postgres.py +347 -0
- pyinfra/operations/postgresql.py +17 -380
- pyinfra/operations/python.py +2 -17
- pyinfra/operations/selinux.py +5 -28
- pyinfra/operations/server.py +59 -84
- pyinfra/operations/snap.py +1 -3
- pyinfra/operations/ssh.py +8 -23
- pyinfra/operations/systemd.py +7 -7
- pyinfra/operations/sysvinit.py +3 -12
- pyinfra/operations/upstart.py +4 -4
- pyinfra/operations/util/__init__.py +12 -0
- pyinfra/operations/util/files.py +2 -2
- pyinfra/operations/util/packaging.py +6 -24
- pyinfra/operations/util/service.py +18 -37
- pyinfra/operations/vzctl.py +2 -2
- pyinfra/operations/xbps.py +3 -3
- pyinfra/operations/yum.py +4 -4
- pyinfra/operations/zypper.py +4 -4
- {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/METADATA +19 -22
- pyinfra-3.0b1.dist-info/RECORD +163 -0
- pyinfra-3.0b1.dist-info/entry_points.txt +11 -0
- pyinfra_cli/__main__.py +2 -0
- pyinfra_cli/commands.py +7 -2
- pyinfra_cli/exceptions.py +83 -42
- pyinfra_cli/inventory.py +19 -4
- pyinfra_cli/log.py +17 -3
- pyinfra_cli/main.py +133 -90
- pyinfra_cli/prints.py +93 -129
- pyinfra_cli/util.py +60 -29
- tests/test_api/test_api.py +2 -0
- tests/test_api/test_api_arguments.py +13 -13
- tests/test_api/test_api_deploys.py +28 -29
- tests/test_api/test_api_facts.py +60 -98
- tests/test_api/test_api_operations.py +100 -200
- tests/test_cli/test_cli.py +18 -49
- tests/test_cli/test_cli_deploy.py +11 -37
- tests/test_cli/test_cli_exceptions.py +50 -19
- tests/test_cli/util.py +1 -1
- tests/test_connectors/test_chroot.py +6 -6
- tests/test_connectors/test_docker.py +4 -4
- tests/test_connectors/test_dockerssh.py +38 -50
- tests/test_connectors/test_local.py +11 -12
- tests/test_connectors/test_ssh.py +66 -107
- tests/test_connectors/test_terraform.py +9 -15
- tests/test_connectors/test_util.py +24 -46
- tests/test_connectors/test_vagrant.py +4 -4
- pyinfra/api/operation.pyi +0 -117
- pyinfra/connectors/ansible.py +0 -171
- pyinfra/connectors/mech.py +0 -186
- pyinfra/connectors/pyinfrawinrmsession/__init__.py +0 -28
- pyinfra/connectors/winrm.py +0 -320
- pyinfra/facts/windows.py +0 -366
- pyinfra/facts/windows_files.py +0 -90
- pyinfra/operations/windows.py +0 -59
- pyinfra/operations/windows_files.py +0 -551
- pyinfra-2.9.2.dist-info/RECORD +0 -170
- pyinfra-2.9.2.dist-info/entry_points.txt +0 -14
- tests/test_connectors/test_ansible.py +0 -64
- tests/test_connectors/test_mech.py +0 -126
- tests/test_connectors/test_winrm.py +0 -76
- {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/LICENSE.md +0 -0
- {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/WHEEL +0 -0
- {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/top_level.txt +0 -0
pyinfra/operations/postgresql.py
CHANGED
|
@@ -1,391 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
The PostgreSQL modules manage PostgreSQL databases, users and privileges.
|
|
1
|
+
from pyinfra.api import operation
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
from . import postgres
|
|
5
4
|
|
|
6
|
-
All operations in this module take four optional arguments:
|
|
7
|
-
+ ``psql_user``: the username to connect to postgresql to
|
|
8
|
-
+ ``psql_password``: the password for the connecting user
|
|
9
|
-
+ ``psql_host``: the hostname of the server to connect to
|
|
10
|
-
+ ``psql_port``: the port of the server to connect to
|
|
11
5
|
|
|
12
|
-
|
|
6
|
+
@operation(is_idempotent=False, is_deprecated=True, deprecated_for="postgres.sql")
|
|
7
|
+
def sql(*args, **kwargs):
|
|
8
|
+
yield from postgres.sql._inner(*args, **kwargs)
|
|
13
9
|
|
|
14
|
-
"""
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
from
|
|
19
|
-
PostgresqlDatabases,
|
|
20
|
-
PostgresqlRoles,
|
|
21
|
-
make_execute_psql_command,
|
|
22
|
-
make_psql_command,
|
|
23
|
-
)
|
|
11
|
+
@operation(is_idempotent=False, is_deprecated=True, deprecated_for="postgres.role")
|
|
12
|
+
def role(*args, **kwargs):
|
|
13
|
+
yield from postgres.role._inner(*args, **kwargs)
|
|
24
14
|
|
|
25
|
-
LEGACY_ARG_MAP = {
|
|
26
|
-
"postgresql_user": "psql_user",
|
|
27
|
-
"postgresql_password": "psql_password",
|
|
28
|
-
"postgresql_host": "psql_host",
|
|
29
|
-
"postgresql_port": "psql_port",
|
|
30
|
-
}
|
|
31
15
|
|
|
16
|
+
@operation(is_idempotent=False, is_deprecated=True)
|
|
17
|
+
def database(*args, **kwargs):
|
|
18
|
+
yield from postgres.database._inner(*args, **kwargs)
|
|
32
19
|
|
|
33
|
-
def _translate_legacy_args(func):
|
|
34
|
-
def decorated_func(*args, **kwargs):
|
|
35
|
-
for legacy_key, key in LEGACY_ARG_MAP.items():
|
|
36
|
-
if legacy_key in kwargs:
|
|
37
|
-
kwargs[key] = kwargs.pop(legacy_key)
|
|
38
|
-
logger.warning(
|
|
39
|
-
(
|
|
40
|
-
f"The `{legacy_key}` has been replaced "
|
|
41
|
-
f"by `{key}` in `postgresql.*` operations."
|
|
42
|
-
),
|
|
43
|
-
)
|
|
44
|
-
return func(*args, **kwargs)
|
|
45
20
|
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
@operation(is_idempotent=False, is_deprecated=True)
|
|
22
|
+
def dump(*args, **kwargs):
|
|
23
|
+
yield from postgres.dump._inner(*args, **kwargs)
|
|
48
24
|
|
|
49
25
|
|
|
50
|
-
@operation(is_idempotent=False)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
sql,
|
|
54
|
-
database=None,
|
|
55
|
-
# Details for speaking to PostgreSQL via `psql` CLI
|
|
56
|
-
psql_user=None,
|
|
57
|
-
psql_password=None,
|
|
58
|
-
psql_host=None,
|
|
59
|
-
psql_port=None,
|
|
60
|
-
):
|
|
61
|
-
"""
|
|
62
|
-
Execute arbitrary SQL against PostgreSQL.
|
|
63
|
-
|
|
64
|
-
+ sql: SQL command(s) to execute
|
|
65
|
-
+ database: optional database to execute against
|
|
66
|
-
+ psql_*: global module arguments, see above
|
|
67
|
-
"""
|
|
68
|
-
|
|
69
|
-
yield make_execute_psql_command(
|
|
70
|
-
sql,
|
|
71
|
-
database=database,
|
|
72
|
-
user=psql_user,
|
|
73
|
-
password=psql_password,
|
|
74
|
-
host=psql_host,
|
|
75
|
-
port=psql_port,
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
@operation
|
|
80
|
-
@_translate_legacy_args
|
|
81
|
-
def role(
|
|
82
|
-
role,
|
|
83
|
-
present=True,
|
|
84
|
-
password=None,
|
|
85
|
-
login=True,
|
|
86
|
-
superuser=False,
|
|
87
|
-
inherit=False,
|
|
88
|
-
createdb=False,
|
|
89
|
-
createrole=False,
|
|
90
|
-
replication=False,
|
|
91
|
-
connection_limit=None,
|
|
92
|
-
# Details for speaking to PostgreSQL via `psql` CLI
|
|
93
|
-
psql_user=None,
|
|
94
|
-
psql_password=None,
|
|
95
|
-
psql_host=None,
|
|
96
|
-
psql_port=None,
|
|
97
|
-
):
|
|
98
|
-
"""
|
|
99
|
-
Add/remove PostgreSQL roles.
|
|
100
|
-
|
|
101
|
-
+ role: name of the role
|
|
102
|
-
+ present: whether the role should be present or absent
|
|
103
|
-
+ password: the password for the role
|
|
104
|
-
+ login: whether the role can login
|
|
105
|
-
+ superuser: whether role will be a superuser
|
|
106
|
-
+ inherit: whether the role inherits from other roles
|
|
107
|
-
+ createdb: whether the role is allowed to create databases
|
|
108
|
-
+ createrole: whether the role is allowed to create new roles
|
|
109
|
-
+ replication: whether this role is allowed to replicate
|
|
110
|
-
+ connection_limit: the connection limit for the role
|
|
111
|
-
+ psql_*: global module arguments, see above
|
|
112
|
-
|
|
113
|
-
Updates:
|
|
114
|
-
pyinfra will not attempt to change existing roles - it will either
|
|
115
|
-
create or drop roles, but not alter them (if the role exists this
|
|
116
|
-
operation will make no changes).
|
|
117
|
-
|
|
118
|
-
**Example:**
|
|
119
|
-
|
|
120
|
-
.. code:: python
|
|
121
|
-
|
|
122
|
-
postgresql.role(
|
|
123
|
-
name="Create the pyinfra PostgreSQL role",
|
|
124
|
-
role="pyinfra",
|
|
125
|
-
password="somepassword",
|
|
126
|
-
superuser=True,
|
|
127
|
-
login=True,
|
|
128
|
-
sudo_user="postgres",
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
"""
|
|
132
|
-
|
|
133
|
-
roles = host.get_fact(
|
|
134
|
-
PostgresqlRoles,
|
|
135
|
-
psql_user=psql_user,
|
|
136
|
-
psql_password=psql_password,
|
|
137
|
-
psql_host=psql_host,
|
|
138
|
-
psql_port=psql_port,
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
is_present = role in roles
|
|
142
|
-
|
|
143
|
-
# User not wanted?
|
|
144
|
-
if not present:
|
|
145
|
-
if is_present:
|
|
146
|
-
yield make_execute_psql_command(
|
|
147
|
-
'DROP ROLE "{0}"'.format(role),
|
|
148
|
-
user=psql_user,
|
|
149
|
-
password=psql_password,
|
|
150
|
-
host=psql_host,
|
|
151
|
-
port=psql_port,
|
|
152
|
-
)
|
|
153
|
-
roles.pop(role)
|
|
154
|
-
else:
|
|
155
|
-
host.noop("postgresql role {0} does not exist".format(role))
|
|
156
|
-
return
|
|
157
|
-
|
|
158
|
-
# If we want the user and they don't exist
|
|
159
|
-
if not is_present:
|
|
160
|
-
sql_bits = ['CREATE ROLE "{0}"'.format(role)]
|
|
161
|
-
|
|
162
|
-
for key, value in (
|
|
163
|
-
("LOGIN", login),
|
|
164
|
-
("SUPERUSER", superuser),
|
|
165
|
-
("INHERIT", inherit),
|
|
166
|
-
("CREATEDB", createdb),
|
|
167
|
-
("CREATEROLE", createrole),
|
|
168
|
-
("REPLICATION", replication),
|
|
169
|
-
):
|
|
170
|
-
if value:
|
|
171
|
-
sql_bits.append(key)
|
|
172
|
-
|
|
173
|
-
if connection_limit:
|
|
174
|
-
sql_bits.append("CONNECTION LIMIT {0}".format(connection_limit))
|
|
175
|
-
|
|
176
|
-
if password:
|
|
177
|
-
sql_bits.append(MaskString("PASSWORD '{0}'".format(password)))
|
|
178
|
-
|
|
179
|
-
yield make_execute_psql_command(
|
|
180
|
-
StringCommand(*sql_bits),
|
|
181
|
-
user=psql_user,
|
|
182
|
-
password=psql_password,
|
|
183
|
-
host=psql_host,
|
|
184
|
-
port=psql_port,
|
|
185
|
-
)
|
|
186
|
-
roles[role] = {
|
|
187
|
-
"super": superuser,
|
|
188
|
-
"createdb": createdb,
|
|
189
|
-
"createrole": createrole,
|
|
190
|
-
}
|
|
191
|
-
else:
|
|
192
|
-
host.noop("postgresql role {0} exists".format(role))
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
@operation
|
|
196
|
-
@_translate_legacy_args
|
|
197
|
-
def database(
|
|
198
|
-
database,
|
|
199
|
-
present=True,
|
|
200
|
-
owner=None,
|
|
201
|
-
template=None,
|
|
202
|
-
encoding=None,
|
|
203
|
-
lc_collate=None,
|
|
204
|
-
lc_ctype=None,
|
|
205
|
-
tablespace=None,
|
|
206
|
-
connection_limit=None,
|
|
207
|
-
# Details for speaking to PostgreSQL via `psql` CLI
|
|
208
|
-
psql_user=None,
|
|
209
|
-
psql_password=None,
|
|
210
|
-
psql_host=None,
|
|
211
|
-
psql_port=None,
|
|
212
|
-
):
|
|
213
|
-
"""
|
|
214
|
-
Add/remove PostgreSQL databases.
|
|
215
|
-
|
|
216
|
-
+ name: name of the database
|
|
217
|
-
+ present: whether the database should exist or not
|
|
218
|
-
+ owner: the PostgreSQL role that owns the database
|
|
219
|
-
+ template: name of the PostgreSQL template to use
|
|
220
|
-
+ encoding: encoding of the database
|
|
221
|
-
+ lc_collate: lc_collate of the database
|
|
222
|
-
+ lc_ctype: lc_ctype of the database
|
|
223
|
-
+ tablespace: the tablespace to use for the template
|
|
224
|
-
+ connection_limit: the connection limit to apply to the database
|
|
225
|
-
+ psql_*: global module arguments, see above
|
|
226
|
-
|
|
227
|
-
Updates:
|
|
228
|
-
pyinfra will not attempt to change existing databases - it will either
|
|
229
|
-
create or drop databases, but not alter them (if the db exists this
|
|
230
|
-
operation will make no changes).
|
|
231
|
-
|
|
232
|
-
**Example:**
|
|
233
|
-
|
|
234
|
-
.. code:: python
|
|
235
|
-
|
|
236
|
-
postgresql.database(
|
|
237
|
-
name="Create the pyinfra_stuff database",
|
|
238
|
-
database="pyinfra_stuff",
|
|
239
|
-
owner="pyinfra",
|
|
240
|
-
encoding="UTF8",
|
|
241
|
-
sudo_user="postgres",
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
"""
|
|
245
|
-
|
|
246
|
-
current_databases = host.get_fact(
|
|
247
|
-
PostgresqlDatabases,
|
|
248
|
-
psql_user=psql_user,
|
|
249
|
-
psql_password=psql_password,
|
|
250
|
-
psql_host=psql_host,
|
|
251
|
-
psql_port=psql_port,
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
is_present = database in current_databases
|
|
255
|
-
|
|
256
|
-
if not present:
|
|
257
|
-
if is_present:
|
|
258
|
-
yield make_execute_psql_command(
|
|
259
|
-
'DROP DATABASE "{0}"'.format(database),
|
|
260
|
-
user=psql_user,
|
|
261
|
-
password=psql_password,
|
|
262
|
-
host=psql_host,
|
|
263
|
-
port=psql_port,
|
|
264
|
-
)
|
|
265
|
-
current_databases.pop(database)
|
|
266
|
-
else:
|
|
267
|
-
host.noop("postgresql database {0} does not exist".format(database))
|
|
268
|
-
return
|
|
269
|
-
|
|
270
|
-
# We want the database but it doesn't exist
|
|
271
|
-
if present and not is_present:
|
|
272
|
-
sql_bits = ['CREATE DATABASE "{0}"'.format(database)]
|
|
273
|
-
|
|
274
|
-
for key, value in (
|
|
275
|
-
("OWNER", '"{0}"'.format(owner) if owner else owner),
|
|
276
|
-
("TEMPLATE", template),
|
|
277
|
-
("ENCODING", encoding),
|
|
278
|
-
("LC_COLLATE", lc_collate),
|
|
279
|
-
("LC_CTYPE", lc_ctype),
|
|
280
|
-
("TABLESPACE", tablespace),
|
|
281
|
-
("CONNECTION LIMIT", connection_limit),
|
|
282
|
-
):
|
|
283
|
-
if value:
|
|
284
|
-
sql_bits.append("{0} {1}".format(key, value))
|
|
285
|
-
|
|
286
|
-
yield make_execute_psql_command(
|
|
287
|
-
StringCommand(*sql_bits),
|
|
288
|
-
user=psql_user,
|
|
289
|
-
password=psql_password,
|
|
290
|
-
host=psql_host,
|
|
291
|
-
port=psql_port,
|
|
292
|
-
)
|
|
293
|
-
current_databases[database] = {
|
|
294
|
-
"template": template,
|
|
295
|
-
"encoding": encoding,
|
|
296
|
-
"lc_collate": lc_collate,
|
|
297
|
-
"lc_ctype": lc_ctype,
|
|
298
|
-
"tablespace": tablespace,
|
|
299
|
-
"connection_limit": connection_limit,
|
|
300
|
-
}
|
|
301
|
-
else:
|
|
302
|
-
host.noop("postgresql database {0} exists".format(database))
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
@operation(is_idempotent=False)
|
|
306
|
-
@_translate_legacy_args
|
|
307
|
-
def dump(
|
|
308
|
-
dest,
|
|
309
|
-
database=None,
|
|
310
|
-
# Details for speaking to PostgreSQL via `psql` CLI
|
|
311
|
-
psql_user=None,
|
|
312
|
-
psql_password=None,
|
|
313
|
-
psql_host=None,
|
|
314
|
-
psql_port=None,
|
|
315
|
-
):
|
|
316
|
-
"""
|
|
317
|
-
Dump a PostgreSQL database into a ``.sql`` file. Requires ``pg_dump``.
|
|
318
|
-
|
|
319
|
-
+ dest: name of the file to dump the SQL to
|
|
320
|
-
+ database: name of the database to dump
|
|
321
|
-
+ psql_*: global module arguments, see above
|
|
322
|
-
|
|
323
|
-
**Example:**
|
|
324
|
-
|
|
325
|
-
.. code:: python
|
|
326
|
-
|
|
327
|
-
postgresql.dump(
|
|
328
|
-
name="Dump the pyinfra_stuff database",
|
|
329
|
-
dest="/tmp/pyinfra_stuff.dump",
|
|
330
|
-
database="pyinfra_stuff",
|
|
331
|
-
sudo_user="postgres",
|
|
332
|
-
)
|
|
333
|
-
|
|
334
|
-
"""
|
|
335
|
-
|
|
336
|
-
yield StringCommand(
|
|
337
|
-
make_psql_command(
|
|
338
|
-
executable="pg_dump",
|
|
339
|
-
database=database,
|
|
340
|
-
user=psql_user,
|
|
341
|
-
password=psql_password,
|
|
342
|
-
host=psql_host,
|
|
343
|
-
port=psql_port,
|
|
344
|
-
),
|
|
345
|
-
">",
|
|
346
|
-
dest,
|
|
347
|
-
)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
@operation(is_idempotent=False)
|
|
351
|
-
@_translate_legacy_args
|
|
352
|
-
def load(
|
|
353
|
-
src,
|
|
354
|
-
database=None,
|
|
355
|
-
# Details for speaking to PostgreSQL via `psql` CLI
|
|
356
|
-
psql_user=None,
|
|
357
|
-
psql_password=None,
|
|
358
|
-
psql_host=None,
|
|
359
|
-
psql_port=None,
|
|
360
|
-
):
|
|
361
|
-
"""
|
|
362
|
-
Load ``.sql`` file into a database.
|
|
363
|
-
|
|
364
|
-
+ src: the filename to read from
|
|
365
|
-
+ database: name of the database to import into
|
|
366
|
-
+ psql_*: global module arguments, see above
|
|
367
|
-
|
|
368
|
-
**Example:**
|
|
369
|
-
|
|
370
|
-
.. code:: python
|
|
371
|
-
|
|
372
|
-
postgresql.load(
|
|
373
|
-
name="Import the pyinfra_stuff dump into pyinfra_stuff_copy",
|
|
374
|
-
src="/tmp/pyinfra_stuff.dump",
|
|
375
|
-
database="pyinfra_stuff_copy",
|
|
376
|
-
sudo_user="postgres",
|
|
377
|
-
)
|
|
378
|
-
|
|
379
|
-
"""
|
|
380
|
-
|
|
381
|
-
yield StringCommand(
|
|
382
|
-
make_psql_command(
|
|
383
|
-
database=database,
|
|
384
|
-
user=psql_user,
|
|
385
|
-
password=psql_password,
|
|
386
|
-
host=psql_host,
|
|
387
|
-
port=psql_port,
|
|
388
|
-
),
|
|
389
|
-
"<",
|
|
390
|
-
src,
|
|
391
|
-
)
|
|
26
|
+
@operation(is_idempotent=False, is_deprecated=True)
|
|
27
|
+
def load(*args, **kwargs):
|
|
28
|
+
yield from postgres.load._inner(*args, **kwargs)
|
pyinfra/operations/python.py
CHANGED
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
The Python module allows you to execute Python code within the context of a deploy.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from inspect import getfullargspec
|
|
6
|
-
|
|
7
|
-
from pyinfra import logger
|
|
8
5
|
from pyinfra.api import FunctionCommand, operation
|
|
9
|
-
from pyinfra.api.util import get_call_location
|
|
10
6
|
|
|
11
7
|
|
|
12
|
-
@operation(is_idempotent=False)
|
|
8
|
+
@operation(is_idempotent=False, _set_in_op=False)
|
|
13
9
|
def call(function, *args, **kwargs):
|
|
14
10
|
"""
|
|
15
11
|
Execute a Python function within a deploy.
|
|
@@ -43,19 +39,10 @@ def call(function, *args, **kwargs):
|
|
|
43
39
|
|
|
44
40
|
"""
|
|
45
41
|
|
|
46
|
-
argspec = getfullargspec(function)
|
|
47
|
-
if "state" in argspec.args and "host" in argspec.args:
|
|
48
|
-
logger.warning(
|
|
49
|
-
"Callback functions used in `python.call` operations no "
|
|
50
|
-
f"longer take `state` and `host` arguments: {get_call_location(frame_offset=3)}",
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
kwargs.pop("state", None)
|
|
54
|
-
kwargs.pop("host", None)
|
|
55
42
|
yield FunctionCommand(function, args, kwargs)
|
|
56
43
|
|
|
57
44
|
|
|
58
|
-
@operation(is_idempotent=False)
|
|
45
|
+
@operation(is_idempotent=False, _set_in_op=False)
|
|
59
46
|
def raise_exception(exception, *args, **kwargs):
|
|
60
47
|
"""
|
|
61
48
|
Raise a Python exception within a deploy.
|
|
@@ -78,6 +65,4 @@ def raise_exception(exception, *args, **kwargs):
|
|
|
78
65
|
def raise_exc(*args, **kwargs): # pragma: no cover
|
|
79
66
|
raise exception(*args, **kwargs)
|
|
80
67
|
|
|
81
|
-
kwargs.pop("state", None)
|
|
82
|
-
kwargs.pop("host", None)
|
|
83
68
|
yield FunctionCommand(raise_exc, args, kwargs)
|
pyinfra/operations/selinux.py
CHANGED
|
@@ -7,9 +7,7 @@ from pyinfra.facts.selinux import FileContext, FileContextMapping, SEBoolean, SE
|
|
|
7
7
|
from pyinfra.facts.server import Which
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
@operation(
|
|
11
|
-
pipeline_facts={"seboolean": "bool_name"},
|
|
12
|
-
)
|
|
10
|
+
@operation()
|
|
13
11
|
def boolean(bool_name, value, persistent=False):
|
|
14
12
|
"""
|
|
15
13
|
Set the specified SELinux boolean to the desired state.
|
|
@@ -41,14 +39,11 @@ def boolean(bool_name, value, persistent=False):
|
|
|
41
39
|
if host.get_fact(SEBoolean, boolean=bool_name) != value:
|
|
42
40
|
persist = "-P " if persistent else ""
|
|
43
41
|
yield StringCommand("setsebool", f"{persist}{bool_name}", value)
|
|
44
|
-
host.create_fact(SEBoolean, kwargs={"boolean": bool_name}, data=value)
|
|
45
42
|
else:
|
|
46
43
|
host.noop(f"boolean '{bool_name}' already had the value '{value}'")
|
|
47
44
|
|
|
48
45
|
|
|
49
|
-
@operation(
|
|
50
|
-
pipeline_facts={"filecontext": "path"},
|
|
51
|
-
)
|
|
46
|
+
@operation()
|
|
52
47
|
def file_context(path, se_type):
|
|
53
48
|
"""
|
|
54
49
|
Set the SELinux type for the specified path to the specified value.
|
|
@@ -70,18 +65,11 @@ def file_context(path, se_type):
|
|
|
70
65
|
current = host.get_fact(FileContext, path=path) or {}
|
|
71
66
|
if se_type != current.get("type", ""):
|
|
72
67
|
yield StringCommand("chcon", "-t", se_type, QuoteString(path))
|
|
73
|
-
host.create_fact(
|
|
74
|
-
FileContext,
|
|
75
|
-
kwargs={"path": path},
|
|
76
|
-
data=dict(current, **{"type": se_type}),
|
|
77
|
-
)
|
|
78
68
|
else:
|
|
79
69
|
host.noop(f"file_context: '{path}' already had type '{se_type}'")
|
|
80
70
|
|
|
81
71
|
|
|
82
|
-
@operation(
|
|
83
|
-
pipeline_facts={"filecontextmapping": "target"},
|
|
84
|
-
)
|
|
72
|
+
@operation()
|
|
85
73
|
def file_context_mapping(target, se_type=None, present=True):
|
|
86
74
|
"""
|
|
87
75
|
Set the SELinux file context mapping for paths matching the target.
|
|
@@ -108,29 +96,20 @@ def file_context_mapping(target, se_type=None, present=True):
|
|
|
108
96
|
raise ValueError("se_type must have a valid value if present is set")
|
|
109
97
|
|
|
110
98
|
current = host.get_fact(FileContextMapping, target=target)
|
|
111
|
-
kwargs = {"target": target}
|
|
112
99
|
if present:
|
|
113
100
|
option = "-a" if len(current) == 0 else ("-m" if current.get("type") != se_type else "")
|
|
114
101
|
if option != "":
|
|
115
102
|
yield StringCommand("semanage", "fcontext", option, "-t", se_type, QuoteString(target))
|
|
116
|
-
host.create_fact(
|
|
117
|
-
FileContextMapping,
|
|
118
|
-
kwargs=kwargs,
|
|
119
|
-
data=dict(current, **{"type": se_type}),
|
|
120
|
-
)
|
|
121
103
|
else:
|
|
122
104
|
host.noop(f"mapping for '{target}' -> '{se_type}' already present")
|
|
123
105
|
else:
|
|
124
106
|
if len(current) > 0:
|
|
125
107
|
yield StringCommand("semanage", "fcontext", "-d", QuoteString(target))
|
|
126
|
-
host.create_fact(FileContextMapping, kwargs=kwargs, data={})
|
|
127
108
|
else:
|
|
128
109
|
host.noop(f"no existing mapping for '{target}'")
|
|
129
110
|
|
|
130
111
|
|
|
131
|
-
@operation(
|
|
132
|
-
pipeline_facts={"which": "sepolicy"},
|
|
133
|
-
)
|
|
112
|
+
@operation()
|
|
134
113
|
def port(protocol, port_num, se_type=None, present=True):
|
|
135
114
|
"""
|
|
136
115
|
Set the SELinux type for the specified protocol and port.
|
|
@@ -178,9 +157,7 @@ def port(protocol, port_num, se_type=None, present=True):
|
|
|
178
157
|
host.noop(f"setype for '{protocol}/{port_num}' is already unset")
|
|
179
158
|
|
|
180
159
|
if (present and (option != "")) or (not present and (current != "")):
|
|
181
|
-
if direct_get:
|
|
182
|
-
host.create_fact(SEPort, kwargs={"protocol": protocol, "port": port_num}, data=new_type)
|
|
183
|
-
else:
|
|
160
|
+
if not direct_get:
|
|
184
161
|
if protocol not in port_info:
|
|
185
162
|
port_info[protocol] = {}
|
|
186
163
|
port_info[protocol][str(port_num)] = new_type
|