pyinfra 0.11.dev3__py3-none-any.whl → 3.6__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/__init__.py +9 -12
- pyinfra/__main__.py +4 -0
- pyinfra/api/__init__.py +19 -3
- pyinfra/api/arguments.py +413 -0
- pyinfra/api/arguments_typed.py +79 -0
- pyinfra/api/command.py +274 -0
- pyinfra/api/config.py +222 -28
- pyinfra/api/connect.py +33 -13
- pyinfra/api/connectors.py +27 -0
- pyinfra/api/deploy.py +65 -66
- pyinfra/api/exceptions.py +73 -18
- pyinfra/api/facts.py +267 -200
- pyinfra/api/host.py +416 -50
- pyinfra/api/inventory.py +121 -160
- pyinfra/api/metadata.py +69 -0
- pyinfra/api/operation.py +432 -262
- pyinfra/api/operations.py +273 -260
- pyinfra/api/state.py +302 -248
- pyinfra/api/util.py +309 -369
- pyinfra/connectors/base.py +173 -0
- pyinfra/connectors/chroot.py +212 -0
- pyinfra/connectors/docker.py +405 -0
- pyinfra/connectors/dockerssh.py +297 -0
- pyinfra/connectors/local.py +238 -0
- pyinfra/connectors/scp/__init__.py +1 -0
- pyinfra/connectors/scp/client.py +204 -0
- pyinfra/connectors/ssh.py +727 -0
- pyinfra/connectors/ssh_util.py +114 -0
- pyinfra/connectors/sshuserclient/client.py +309 -0
- pyinfra/connectors/sshuserclient/config.py +102 -0
- pyinfra/connectors/terraform.py +135 -0
- pyinfra/connectors/util.py +417 -0
- pyinfra/connectors/vagrant.py +183 -0
- pyinfra/context.py +145 -0
- pyinfra/facts/__init__.py +7 -6
- pyinfra/facts/apk.py +22 -7
- pyinfra/facts/apt.py +117 -60
- pyinfra/facts/brew.py +100 -15
- pyinfra/facts/bsdinit.py +23 -0
- pyinfra/facts/cargo.py +37 -0
- pyinfra/facts/choco.py +47 -0
- pyinfra/facts/crontab.py +195 -0
- pyinfra/facts/deb.py +94 -0
- pyinfra/facts/dnf.py +48 -0
- pyinfra/facts/docker.py +96 -23
- pyinfra/facts/efibootmgr.py +113 -0
- pyinfra/facts/files.py +629 -58
- pyinfra/facts/flatpak.py +77 -0
- pyinfra/facts/freebsd.py +70 -0
- pyinfra/facts/gem.py +19 -6
- pyinfra/facts/git.py +59 -14
- pyinfra/facts/gpg.py +150 -0
- pyinfra/facts/hardware.py +313 -167
- pyinfra/facts/iptables.py +72 -62
- pyinfra/facts/launchd.py +44 -0
- pyinfra/facts/lxd.py +17 -4
- pyinfra/facts/mysql.py +122 -86
- pyinfra/facts/npm.py +17 -9
- pyinfra/facts/openrc.py +71 -0
- pyinfra/facts/opkg.py +246 -0
- pyinfra/facts/pacman.py +50 -7
- pyinfra/facts/pip.py +24 -7
- pyinfra/facts/pipx.py +82 -0
- pyinfra/facts/pkg.py +15 -6
- pyinfra/facts/pkgin.py +35 -0
- pyinfra/facts/podman.py +54 -0
- pyinfra/facts/postgres.py +178 -0
- pyinfra/facts/postgresql.py +6 -147
- pyinfra/facts/rpm.py +105 -0
- pyinfra/facts/runit.py +77 -0
- pyinfra/facts/selinux.py +161 -0
- pyinfra/facts/server.py +762 -285
- pyinfra/facts/snap.py +88 -0
- pyinfra/facts/systemd.py +139 -0
- pyinfra/facts/sysvinit.py +59 -0
- pyinfra/facts/upstart.py +35 -0
- pyinfra/facts/util/__init__.py +17 -0
- pyinfra/facts/util/databases.py +4 -6
- pyinfra/facts/util/packaging.py +37 -6
- pyinfra/facts/util/units.py +30 -0
- pyinfra/facts/util/win_files.py +99 -0
- pyinfra/facts/vzctl.py +20 -13
- pyinfra/facts/xbps.py +35 -0
- pyinfra/facts/yum.py +34 -40
- pyinfra/facts/zfs.py +77 -0
- pyinfra/facts/zypper.py +42 -0
- pyinfra/local.py +45 -83
- pyinfra/operations/__init__.py +12 -0
- pyinfra/operations/apk.py +99 -0
- pyinfra/operations/apt.py +496 -0
- pyinfra/operations/brew.py +232 -0
- pyinfra/operations/bsdinit.py +59 -0
- pyinfra/operations/cargo.py +45 -0
- pyinfra/operations/choco.py +61 -0
- pyinfra/operations/crontab.py +194 -0
- pyinfra/operations/dnf.py +213 -0
- pyinfra/operations/docker.py +492 -0
- pyinfra/operations/files.py +2014 -0
- pyinfra/operations/flatpak.py +95 -0
- pyinfra/operations/freebsd/__init__.py +12 -0
- pyinfra/operations/freebsd/freebsd_update.py +70 -0
- pyinfra/operations/freebsd/pkg.py +219 -0
- pyinfra/operations/freebsd/service.py +116 -0
- pyinfra/operations/freebsd/sysrc.py +92 -0
- pyinfra/operations/gem.py +48 -0
- pyinfra/operations/git.py +420 -0
- pyinfra/operations/iptables.py +312 -0
- pyinfra/operations/launchd.py +45 -0
- pyinfra/operations/lxd.py +69 -0
- pyinfra/operations/mysql.py +610 -0
- pyinfra/operations/npm.py +57 -0
- pyinfra/operations/openrc.py +63 -0
- pyinfra/operations/opkg.py +89 -0
- pyinfra/operations/pacman.py +82 -0
- pyinfra/operations/pip.py +206 -0
- pyinfra/operations/pipx.py +103 -0
- pyinfra/operations/pkg.py +71 -0
- pyinfra/operations/pkgin.py +92 -0
- pyinfra/operations/postgres.py +437 -0
- pyinfra/operations/postgresql.py +30 -0
- pyinfra/operations/puppet.py +41 -0
- pyinfra/operations/python.py +73 -0
- pyinfra/operations/runit.py +184 -0
- pyinfra/operations/selinux.py +190 -0
- pyinfra/operations/server.py +1100 -0
- pyinfra/operations/snap.py +118 -0
- pyinfra/operations/ssh.py +217 -0
- pyinfra/operations/systemd.py +150 -0
- pyinfra/operations/sysvinit.py +142 -0
- pyinfra/operations/upstart.py +68 -0
- pyinfra/operations/util/__init__.py +12 -0
- pyinfra/operations/util/docker.py +407 -0
- pyinfra/operations/util/files.py +247 -0
- pyinfra/operations/util/packaging.py +338 -0
- pyinfra/operations/util/service.py +46 -0
- pyinfra/operations/vzctl.py +137 -0
- pyinfra/operations/xbps.py +78 -0
- pyinfra/operations/yum.py +213 -0
- pyinfra/operations/zfs.py +176 -0
- pyinfra/operations/zypper.py +193 -0
- pyinfra/progress.py +44 -32
- pyinfra/py.typed +0 -0
- pyinfra/version.py +9 -1
- pyinfra-3.6.dist-info/METADATA +142 -0
- pyinfra-3.6.dist-info/RECORD +160 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info}/WHEEL +1 -2
- pyinfra-3.6.dist-info/entry_points.txt +12 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info/licenses}/LICENSE.md +1 -1
- pyinfra_cli/__init__.py +1 -0
- pyinfra_cli/cli.py +793 -0
- pyinfra_cli/commands.py +66 -0
- pyinfra_cli/exceptions.py +155 -65
- pyinfra_cli/inventory.py +233 -89
- pyinfra_cli/log.py +39 -43
- pyinfra_cli/main.py +26 -495
- pyinfra_cli/prints.py +215 -156
- pyinfra_cli/util.py +172 -105
- pyinfra_cli/virtualenv.py +25 -20
- pyinfra/api/connectors/__init__.py +0 -21
- pyinfra/api/connectors/ansible.py +0 -99
- pyinfra/api/connectors/docker.py +0 -178
- pyinfra/api/connectors/local.py +0 -169
- pyinfra/api/connectors/ssh.py +0 -402
- pyinfra/api/connectors/sshuserclient/client.py +0 -105
- pyinfra/api/connectors/sshuserclient/config.py +0 -90
- pyinfra/api/connectors/util.py +0 -63
- pyinfra/api/connectors/vagrant.py +0 -155
- pyinfra/facts/init.py +0 -176
- pyinfra/facts/util/files.py +0 -102
- pyinfra/hook.py +0 -41
- pyinfra/modules/__init__.py +0 -11
- pyinfra/modules/apk.py +0 -64
- pyinfra/modules/apt.py +0 -272
- pyinfra/modules/brew.py +0 -122
- pyinfra/modules/files.py +0 -711
- pyinfra/modules/gem.py +0 -30
- pyinfra/modules/git.py +0 -115
- pyinfra/modules/init.py +0 -344
- pyinfra/modules/iptables.py +0 -271
- pyinfra/modules/lxd.py +0 -45
- pyinfra/modules/mysql.py +0 -347
- pyinfra/modules/npm.py +0 -47
- pyinfra/modules/pacman.py +0 -60
- pyinfra/modules/pip.py +0 -99
- pyinfra/modules/pkg.py +0 -43
- pyinfra/modules/postgresql.py +0 -245
- pyinfra/modules/puppet.py +0 -20
- pyinfra/modules/python.py +0 -37
- pyinfra/modules/server.py +0 -524
- pyinfra/modules/ssh.py +0 -150
- pyinfra/modules/util/files.py +0 -52
- pyinfra/modules/util/packaging.py +0 -118
- pyinfra/modules/vzctl.py +0 -133
- pyinfra/modules/yum.py +0 -171
- pyinfra/pseudo_modules.py +0 -64
- pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
- pyinfra-0.11.dev3.dist-info/METADATA +0 -135
- pyinfra-0.11.dev3.dist-info/RECORD +0 -95
- pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
- pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
- pyinfra_cli/__main__.py +0 -40
- pyinfra_cli/config.py +0 -92
- /pyinfra/{modules/util → connectors}/__init__.py +0 -0
- /pyinfra/{api/connectors → connectors}/sshuserclient/__init__.py +0 -0
pyinfra/api/deploy.py
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
"""
|
|
2
2
|
Deploys come in two forms: on-disk, eg deploy.py, and @deploy wrapped functions.
|
|
3
3
|
The latter enable re-usable (across CLI and API based execution) pyinfra extension
|
|
4
4
|
creation (eg pyinfra-openstack).
|
|
5
|
-
|
|
5
|
+
"""
|
|
6
6
|
|
|
7
7
|
from functools import wraps
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Callable, Optional, cast
|
|
8
9
|
|
|
9
|
-
from
|
|
10
|
-
from pyinfra.pseudo_modules import PseudoModule
|
|
10
|
+
from typing_extensions import ParamSpec
|
|
11
11
|
|
|
12
|
+
import pyinfra
|
|
13
|
+
from pyinfra import context
|
|
14
|
+
from pyinfra.context import ctx_host, ctx_state
|
|
15
|
+
|
|
16
|
+
from .arguments import pop_global_arguments
|
|
17
|
+
from .arguments_typed import PyinfraOperation
|
|
12
18
|
from .exceptions import PyinfraError
|
|
13
19
|
from .host import Host
|
|
14
|
-
from .
|
|
15
|
-
|
|
20
|
+
from .util import get_call_location
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from pyinfra.api.state import State
|
|
16
24
|
|
|
17
25
|
|
|
18
|
-
def add_deploy(state, deploy_func, *args, **kwargs):
|
|
19
|
-
|
|
26
|
+
def add_deploy(state: "State", deploy_func: Callable[..., Any], *args, **kwargs) -> None:
|
|
27
|
+
"""
|
|
20
28
|
Prepare & add an deploy to pyinfra.state by executing it on all hosts.
|
|
21
29
|
|
|
22
30
|
Args:
|
|
@@ -24,75 +32,66 @@ def add_deploy(state, deploy_func, *args, **kwargs):
|
|
|
24
32
|
deploy_func (function): the operation function from one of the modules,
|
|
25
33
|
ie ``server.user``
|
|
26
34
|
args/kwargs: passed to the operation function
|
|
27
|
-
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
if pyinfra.is_cli:
|
|
38
|
+
raise PyinfraError(
|
|
39
|
+
(
|
|
40
|
+
"`add_deploy` should not be called when pyinfra is executing in CLI mode! ({0})"
|
|
41
|
+
).format(get_call_location()),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
hosts = kwargs.pop("host", state.inventory.iter_active_hosts())
|
|
45
|
+
if isinstance(hosts, Host):
|
|
46
|
+
hosts = [hosts]
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
48
|
+
with ctx_state.use(state):
|
|
49
|
+
for deploy_host in hosts:
|
|
50
|
+
with ctx_host.use(deploy_host):
|
|
51
|
+
deploy_func(*args, **kwargs)
|
|
31
52
|
|
|
32
|
-
for host in state.inventory:
|
|
33
|
-
deploy_func(state, host, *args, **kwargs)
|
|
34
53
|
|
|
54
|
+
P = ParamSpec("P")
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
|
|
57
|
+
def deploy(
|
|
58
|
+
name: Optional[str] = None, data_defaults: Optional[dict] = None
|
|
59
|
+
) -> Callable[[Callable[P, Any]], PyinfraOperation[P]]:
|
|
60
|
+
"""
|
|
38
61
|
Decorator that takes a deploy function (normally from a pyinfra_* package)
|
|
39
62
|
and wraps any operations called inside with any deploy-wide kwargs/data.
|
|
40
|
-
|
|
63
|
+
"""
|
|
41
64
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
65
|
+
if name and not isinstance(name, str):
|
|
66
|
+
raise PyinfraError(
|
|
67
|
+
(
|
|
68
|
+
"The `deploy` decorator must be called, ie `@deploy()`, "
|
|
69
|
+
"see: https://docs.pyinfra.com/en/3.x/compatibility.html#upgrading-pyinfra-from-2-x-3-x" # noqa
|
|
70
|
+
)
|
|
71
|
+
)
|
|
45
72
|
|
|
46
|
-
|
|
47
|
-
|
|
73
|
+
def decorator(func: Callable[P, Any]) -> PyinfraOperation[P]:
|
|
74
|
+
func.deploy_name = name or func.__name__ # type: ignore[attr-defined]
|
|
75
|
+
if data_defaults:
|
|
76
|
+
func.deploy_data = data_defaults # type: ignore[attr-defined]
|
|
77
|
+
return _wrap_deploy(func)
|
|
48
78
|
|
|
49
|
-
|
|
50
|
-
setattr(f, 'deploy_data', data_defaults)
|
|
79
|
+
return decorator
|
|
51
80
|
|
|
52
|
-
return deploy(f)
|
|
53
81
|
|
|
54
|
-
|
|
82
|
+
def _wrap_deploy(func: Callable[P, Any]) -> PyinfraOperation[P]:
|
|
83
|
+
@wraps(func)
|
|
84
|
+
def decorated_func(*args: P.args, **kwargs: P.kwargs) -> Any:
|
|
85
|
+
deploy_kwargs, _ = pop_global_arguments(context.state, context.host, kwargs)
|
|
55
86
|
|
|
56
|
-
|
|
57
|
-
func = func_or_name
|
|
87
|
+
deploy_data = getattr(func, "deploy_data", None)
|
|
58
88
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if len(args) < 2 or not (
|
|
64
|
-
isinstance(args[0], (State, PseudoModule))
|
|
65
|
-
and isinstance(args[1], (Host, PseudoModule))
|
|
89
|
+
with context.host.deploy(
|
|
90
|
+
name=func.deploy_name, # type: ignore[attr-defined]
|
|
91
|
+
kwargs=deploy_kwargs,
|
|
92
|
+
data=deploy_data,
|
|
66
93
|
):
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
raise PyinfraError((
|
|
72
|
-
'Nested deploy called without state/host: {0}'
|
|
73
|
-
).format(func))
|
|
74
|
-
|
|
75
|
-
# Otherwise (API mode) we just trim off the commands
|
|
76
|
-
else:
|
|
77
|
-
args_copy = list(args)
|
|
78
|
-
state, host = args[0], args[1]
|
|
79
|
-
args = args_copy[2:]
|
|
80
|
-
|
|
81
|
-
# In API mode we have the kwarg - if a nested deploy we actually
|
|
82
|
-
# want the frame of the caller (ie inside the deploy package).
|
|
83
|
-
frameinfo = kwargs.pop('frameinfo', get_caller_frameinfo())
|
|
84
|
-
logger.debug('Adding deploy, called @ {0}:{1}'.format(
|
|
85
|
-
frameinfo.filename, frameinfo.lineno,
|
|
86
|
-
))
|
|
87
|
-
|
|
88
|
-
deploy_kwargs = pop_op_kwargs(state, kwargs)
|
|
89
|
-
|
|
90
|
-
# Name the deploy
|
|
91
|
-
deploy_name = getattr(func, 'deploy_name', func.__name__)
|
|
92
|
-
deploy_data = getattr(func, 'deploy_data', None)
|
|
93
|
-
|
|
94
|
-
with state.deploy(deploy_name, deploy_kwargs, deploy_data, frameinfo.lineno):
|
|
95
|
-
# Execute the deploy, passing state and host
|
|
96
|
-
func(state, host, *args, **kwargs)
|
|
97
|
-
|
|
98
|
-
return decorated_func
|
|
94
|
+
return func(*args, **kwargs)
|
|
95
|
+
|
|
96
|
+
decorated_func._inner = func # type: ignore[attr-defined]
|
|
97
|
+
return cast(PyinfraOperation[P], decorated_func)
|
pyinfra/api/exceptions.py
CHANGED
|
@@ -1,41 +1,96 @@
|
|
|
1
1
|
class PyinfraError(Exception):
|
|
2
|
-
|
|
2
|
+
"""
|
|
3
3
|
Generic pyinfra exception.
|
|
4
|
-
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ConnectError(PyinfraError):
|
|
8
|
+
"""
|
|
9
|
+
Exception raised when connecting fails.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FactError(PyinfraError):
|
|
14
|
+
"""
|
|
15
|
+
Exception raised during fact gathering staging if a fact is unable to
|
|
16
|
+
generate output/change state.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class FactTypeError(FactError, TypeError):
|
|
21
|
+
"""
|
|
22
|
+
Exception raised when a fact is passed invalid argument types.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class FactValueError(FactError, ValueError):
|
|
27
|
+
"""
|
|
28
|
+
Exception raised when a fact is passed invalid argument values.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class FactProcessError(FactError, RuntimeError):
|
|
33
|
+
"""
|
|
34
|
+
Exception raised when the data gathered for a fact cannot be processed.
|
|
35
|
+
"""
|
|
5
36
|
|
|
6
37
|
|
|
7
38
|
class OperationError(PyinfraError):
|
|
8
|
-
|
|
39
|
+
"""
|
|
9
40
|
Exception raised during fact gathering staging if an operation is unable to
|
|
10
41
|
generate output/change state.
|
|
11
|
-
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class OperationTypeError(OperationError, TypeError):
|
|
46
|
+
"""
|
|
47
|
+
Exception raised when an operation is passed invalid argument types.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class OperationValueError(OperationError, ValueError):
|
|
52
|
+
"""
|
|
53
|
+
Exception raised when an operation is passed invalid argument values.
|
|
54
|
+
"""
|
|
12
55
|
|
|
13
56
|
|
|
14
57
|
class DeployError(PyinfraError):
|
|
15
|
-
|
|
58
|
+
"""
|
|
16
59
|
User exception for raising in deploys or sub deploys.
|
|
17
|
-
|
|
60
|
+
"""
|
|
18
61
|
|
|
19
62
|
|
|
20
63
|
class InventoryError(PyinfraError):
|
|
21
|
-
|
|
64
|
+
"""
|
|
22
65
|
Exception raised for inventory related errors.
|
|
23
|
-
|
|
66
|
+
"""
|
|
24
67
|
|
|
25
68
|
|
|
26
|
-
class NoConnectorError(PyinfraError,
|
|
27
|
-
|
|
69
|
+
class NoConnectorError(PyinfraError, ValueError):
|
|
70
|
+
"""
|
|
28
71
|
Raised when a requested connector is missing.
|
|
29
|
-
|
|
72
|
+
"""
|
|
30
73
|
|
|
31
74
|
|
|
32
|
-
class NoHostError(PyinfraError,
|
|
33
|
-
|
|
75
|
+
class NoHostError(PyinfraError, KeyError):
|
|
76
|
+
"""
|
|
34
77
|
Raised when an inventory is missing a host.
|
|
35
|
-
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class NoGroupError(PyinfraError, KeyError):
|
|
82
|
+
"""
|
|
83
|
+
Raised when an inventory is missing a group.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ConnectorDataTypeError(PyinfraError, TypeError):
|
|
88
|
+
"""
|
|
89
|
+
Raised when host connector data has invalid types.
|
|
90
|
+
"""
|
|
36
91
|
|
|
37
92
|
|
|
38
|
-
class
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
93
|
+
class ArgumentTypeError(PyinfraError, TypeError):
|
|
94
|
+
"""
|
|
95
|
+
Raised when global arguments are passed with invalid types.
|
|
96
|
+
"""
|