pyinfra 0.11.dev3__py3-none-any.whl → 3.5.1__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 +18 -3
- pyinfra/api/arguments.py +406 -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 +67 -18
- pyinfra/api/facts.py +253 -202
- pyinfra/api/host.py +413 -50
- pyinfra/api/inventory.py +121 -160
- pyinfra/api/operation.py +432 -262
- pyinfra/api/operations.py +273 -260
- pyinfra/api/state.py +302 -248
- pyinfra/api/util.py +291 -368
- pyinfra/connectors/base.py +173 -0
- pyinfra/connectors/chroot.py +212 -0
- pyinfra/connectors/docker.py +381 -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 +670 -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 +410 -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 +630 -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 +746 -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 +98 -0
- pyinfra/operations/apt.py +488 -0
- pyinfra/operations/brew.py +231 -0
- pyinfra/operations/bsdinit.py +59 -0
- pyinfra/operations/cargo.py +45 -0
- pyinfra/operations/choco.py +61 -0
- pyinfra/operations/crontab.py +191 -0
- pyinfra/operations/dnf.py +210 -0
- pyinfra/operations/docker.py +446 -0
- pyinfra/operations/files.py +1939 -0
- pyinfra/operations/flatpak.py +94 -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 +47 -0
- pyinfra/operations/git.py +419 -0
- pyinfra/operations/iptables.py +311 -0
- pyinfra/operations/launchd.py +45 -0
- pyinfra/operations/lxd.py +68 -0
- pyinfra/operations/mysql.py +609 -0
- pyinfra/operations/npm.py +57 -0
- pyinfra/operations/openrc.py +63 -0
- pyinfra/operations/opkg.py +88 -0
- pyinfra/operations/pacman.py +81 -0
- pyinfra/operations/pip.py +205 -0
- pyinfra/operations/pipx.py +102 -0
- pyinfra/operations/pkg.py +70 -0
- pyinfra/operations/pkgin.py +91 -0
- pyinfra/operations/postgres.py +436 -0
- pyinfra/operations/postgresql.py +30 -0
- pyinfra/operations/puppet.py +40 -0
- pyinfra/operations/python.py +72 -0
- pyinfra/operations/runit.py +184 -0
- pyinfra/operations/selinux.py +189 -0
- pyinfra/operations/server.py +1099 -0
- pyinfra/operations/snap.py +117 -0
- pyinfra/operations/ssh.py +216 -0
- pyinfra/operations/systemd.py +149 -0
- pyinfra/operations/sysvinit.py +141 -0
- pyinfra/operations/upstart.py +68 -0
- pyinfra/operations/util/__init__.py +12 -0
- pyinfra/operations/util/docker.py +251 -0
- pyinfra/operations/util/files.py +247 -0
- pyinfra/operations/util/packaging.py +336 -0
- pyinfra/operations/util/service.py +46 -0
- pyinfra/operations/vzctl.py +137 -0
- pyinfra/operations/xbps.py +77 -0
- pyinfra/operations/yum.py +210 -0
- pyinfra/operations/zfs.py +175 -0
- pyinfra/operations/zypper.py +192 -0
- pyinfra/progress.py +44 -32
- pyinfra/py.typed +0 -0
- pyinfra/version.py +9 -1
- pyinfra-3.5.1.dist-info/METADATA +141 -0
- pyinfra-3.5.1.dist-info/RECORD +159 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info}/WHEEL +1 -2
- pyinfra-3.5.1.dist-info/entry_points.txt +12 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info/licenses}/LICENSE.md +1 -1
- pyinfra_cli/__init__.py +1 -0
- pyinfra_cli/cli.py +780 -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/modules/util/files.py
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
def ensure_mode_int(mode):
|
|
2
|
-
# Already an int (/None)?
|
|
3
|
-
if isinstance(mode, int) or mode is None:
|
|
4
|
-
return mode
|
|
5
|
-
|
|
6
|
-
try:
|
|
7
|
-
# Try making an int ('700' -> 700)
|
|
8
|
-
return int(mode)
|
|
9
|
-
|
|
10
|
-
except (TypeError, ValueError):
|
|
11
|
-
pass
|
|
12
|
-
|
|
13
|
-
# Return as-is (ie +x which we don't need to normalise, it always gets run)
|
|
14
|
-
return mode
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def sed_replace(filename, line, replace, flags=None):
|
|
18
|
-
flags = ''.join(flags) if flags else ''
|
|
19
|
-
|
|
20
|
-
line = line.replace('/', r'\/')
|
|
21
|
-
replace = replace.replace('/', r'\/')
|
|
22
|
-
|
|
23
|
-
return 'sed -i="" "s/{0}/{1}/{2}" {3}'.format(
|
|
24
|
-
line, replace, flags, filename,
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def chmod(target, mode, recursive=False):
|
|
29
|
-
return 'chmod {0}{1} {2}'.format(('-R ' if recursive else ''), mode, target)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def chown(target, user, group=None, recursive=False, dereference=True):
|
|
33
|
-
command = 'chown'
|
|
34
|
-
user_group = None
|
|
35
|
-
|
|
36
|
-
if user and group:
|
|
37
|
-
user_group = '{0}:{1}'.format(user, group)
|
|
38
|
-
|
|
39
|
-
elif user:
|
|
40
|
-
user_group = user
|
|
41
|
-
|
|
42
|
-
elif group:
|
|
43
|
-
command = 'chgrp'
|
|
44
|
-
user_group = group
|
|
45
|
-
|
|
46
|
-
return '{0}{1}{2} {3} {4}'.format(
|
|
47
|
-
command,
|
|
48
|
-
' -R' if recursive else '',
|
|
49
|
-
' -h' if not dereference else '',
|
|
50
|
-
user_group,
|
|
51
|
-
target,
|
|
52
|
-
)
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
def ensure_packages(
|
|
4
|
-
packages, current_packages, present,
|
|
5
|
-
install_command, uninstall_command,
|
|
6
|
-
latest=False, upgrade_command=None,
|
|
7
|
-
version_join=None, lower=True,
|
|
8
|
-
):
|
|
9
|
-
'''
|
|
10
|
-
Handles this common scenario:
|
|
11
|
-
|
|
12
|
-
+ We have a list of packages(/versions) to ensure
|
|
13
|
-
+ We have a map of existing package -> versions
|
|
14
|
-
+ We have the common command bits (install, uninstall, version "joiner")
|
|
15
|
-
+ Outputs commands to ensure our desired packages/versions
|
|
16
|
-
+ Optionally upgrades packages w/o specified version when present
|
|
17
|
-
|
|
18
|
-
Args:
|
|
19
|
-
packages (list): list of packages or package/versions
|
|
20
|
-
current_packages (fact): fact returning dict of package names -> version
|
|
21
|
-
present (bool): whether packages should exist or not
|
|
22
|
-
install_command (str): command to prefix to list of packages to install
|
|
23
|
-
uninstall_command (str): as above for uninstalling packages
|
|
24
|
-
latest (bool): whether to upgrade installed packages when present
|
|
25
|
-
upgrade_command (str): as above for upgrading
|
|
26
|
-
version_join (str): the package manager specific "joiner", ie ``=`` for \
|
|
27
|
-
``<apt_pkg>=<version>``
|
|
28
|
-
lower (bool): whether to lowercase package names
|
|
29
|
-
'''
|
|
30
|
-
|
|
31
|
-
if packages is None:
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
# Accept a single package as string
|
|
35
|
-
if isinstance(packages, str):
|
|
36
|
-
packages = [packages]
|
|
37
|
-
|
|
38
|
-
# Lowercase packaging?
|
|
39
|
-
if lower:
|
|
40
|
-
packages = [
|
|
41
|
-
package.lower()
|
|
42
|
-
for package in packages
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
# Version support?
|
|
46
|
-
if version_join:
|
|
47
|
-
# Split where versions present
|
|
48
|
-
packages = [
|
|
49
|
-
package.rsplit(version_join, 1)
|
|
50
|
-
for package in packages
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
# Covert to either string or list
|
|
54
|
-
packages = [
|
|
55
|
-
package[0] if len(package) == 1
|
|
56
|
-
else package
|
|
57
|
-
for package in packages
|
|
58
|
-
]
|
|
59
|
-
|
|
60
|
-
# Diff the ensured packages against the remote state/fact
|
|
61
|
-
diff_packages = []
|
|
62
|
-
|
|
63
|
-
# Packages to upgrade? (install only)
|
|
64
|
-
upgrade_packages = []
|
|
65
|
-
|
|
66
|
-
# Installing?
|
|
67
|
-
if present is True:
|
|
68
|
-
for package in packages:
|
|
69
|
-
# Tuple/version, check not in existing OR incorrect version
|
|
70
|
-
if isinstance(package, list) and (
|
|
71
|
-
package[0] not in current_packages
|
|
72
|
-
or package[1] not in current_packages[package[0]]
|
|
73
|
-
):
|
|
74
|
-
diff_packages.append(package)
|
|
75
|
-
|
|
76
|
-
# String version, just check if not existing
|
|
77
|
-
if isinstance(package, str) and package not in current_packages:
|
|
78
|
-
diff_packages.append(package)
|
|
79
|
-
|
|
80
|
-
# Present packages w/o version spec ified - for upgrade if latest
|
|
81
|
-
if isinstance(package, str) and package in current_packages:
|
|
82
|
-
upgrade_packages.append(package)
|
|
83
|
-
|
|
84
|
-
# Uninstalling?
|
|
85
|
-
else:
|
|
86
|
-
for package in packages:
|
|
87
|
-
# Tuple/version, heck existing AND correct version
|
|
88
|
-
if isinstance(package, list) and (
|
|
89
|
-
package[0] in current_packages
|
|
90
|
-
and package[1] in current_packages[package[0]]
|
|
91
|
-
):
|
|
92
|
-
diff_packages.append(package)
|
|
93
|
-
|
|
94
|
-
# String version, just check if existing
|
|
95
|
-
if isinstance(package, str) and package in current_packages:
|
|
96
|
-
diff_packages.append(package)
|
|
97
|
-
|
|
98
|
-
# Convert packages back to string(/version)
|
|
99
|
-
diff_packages = [
|
|
100
|
-
version_join.join(package)
|
|
101
|
-
if isinstance(package, list)
|
|
102
|
-
else package
|
|
103
|
-
for package in diff_packages
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
if diff_packages:
|
|
107
|
-
command = install_command if present else uninstall_command
|
|
108
|
-
|
|
109
|
-
yield '{0} {1}'.format(
|
|
110
|
-
command,
|
|
111
|
-
' '.join(diff_packages),
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
if latest and upgrade_command and upgrade_packages:
|
|
115
|
-
yield '{0} {1}'.format(
|
|
116
|
-
upgrade_command,
|
|
117
|
-
' '.join(upgrade_packages),
|
|
118
|
-
)
|
pyinfra/modules/vzctl.py
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Manage OpenVZ containers with ``vzctl``.
|
|
3
|
-
'''
|
|
4
|
-
|
|
5
|
-
from pyinfra.api import operation, OperationError
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@operation
|
|
9
|
-
def start(state, host, ctid, force=False):
|
|
10
|
-
'''
|
|
11
|
-
Start OpenVZ containers.
|
|
12
|
-
|
|
13
|
-
+ ctid: CTID of the container to start
|
|
14
|
-
+ force: whether to force container start
|
|
15
|
-
'''
|
|
16
|
-
|
|
17
|
-
args = ['{0}'.format(ctid)]
|
|
18
|
-
|
|
19
|
-
if force:
|
|
20
|
-
args.append('--force')
|
|
21
|
-
|
|
22
|
-
yield 'vzctl start {0}'.format(' '.join(args))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@operation
|
|
26
|
-
def stop(state, host, ctid):
|
|
27
|
-
'''
|
|
28
|
-
Stop OpenVZ containers.
|
|
29
|
-
|
|
30
|
-
+ ctid: CTID of the container to stop
|
|
31
|
-
'''
|
|
32
|
-
|
|
33
|
-
args = ['{0}'.format(ctid)]
|
|
34
|
-
|
|
35
|
-
yield 'vzctl stop {0}'.format(' '.join(args))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@operation
|
|
39
|
-
def restart(state, host, ctid, force=False):
|
|
40
|
-
'''
|
|
41
|
-
Restart OpenVZ containers.
|
|
42
|
-
|
|
43
|
-
+ ctid: CTID of the container to restart
|
|
44
|
-
+ force: whether to force container start
|
|
45
|
-
'''
|
|
46
|
-
|
|
47
|
-
yield stop(state, host, ctid)
|
|
48
|
-
yield start(state, host, ctid, force=force)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
@operation
|
|
52
|
-
def mount(state, host, ctid):
|
|
53
|
-
'''
|
|
54
|
-
Mount OpenVZ container filesystems.
|
|
55
|
-
|
|
56
|
-
+ ctid: CTID of the container to mount
|
|
57
|
-
'''
|
|
58
|
-
|
|
59
|
-
yield 'vzctl mount {0}'.format(ctid)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@operation
|
|
63
|
-
def unmount(state, host, ctid):
|
|
64
|
-
'''
|
|
65
|
-
Unmount OpenVZ container filesystems.
|
|
66
|
-
|
|
67
|
-
+ ctid: CTID of the container to unmount
|
|
68
|
-
'''
|
|
69
|
-
|
|
70
|
-
yield 'vzctl umount {0}'.format(ctid)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
@operation
|
|
74
|
-
def delete(state, host, ctid):
|
|
75
|
-
'''
|
|
76
|
-
Delete OpenVZ containers.
|
|
77
|
-
|
|
78
|
-
+ ctid: CTID of the container to delete
|
|
79
|
-
'''
|
|
80
|
-
|
|
81
|
-
yield 'vzctl delete {0}'.format(ctid)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@operation
|
|
85
|
-
def create(state, host, ctid, template=None):
|
|
86
|
-
'''
|
|
87
|
-
Create OpenVZ containers.
|
|
88
|
-
|
|
89
|
-
+ ctid: CTID of the container to create
|
|
90
|
-
'''
|
|
91
|
-
|
|
92
|
-
# Check we don't already have a container with this CTID
|
|
93
|
-
current_containers = host.fact.openvz_containers
|
|
94
|
-
if ctid in current_containers:
|
|
95
|
-
raise OperationError(
|
|
96
|
-
'An OpenVZ container with CTID {0} already exists'.format(ctid),
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
args = ['{0}'.format(ctid)]
|
|
100
|
-
|
|
101
|
-
if template:
|
|
102
|
-
args.append('--ostemplate {0}'.format(template))
|
|
103
|
-
|
|
104
|
-
yield 'vzctl create {0}'.format(' '.join(args))
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
@operation
|
|
108
|
-
def set(state, host, ctid, save=True, **settings):
|
|
109
|
-
'''
|
|
110
|
-
Set OpenVZ container details.
|
|
111
|
-
|
|
112
|
-
+ ctid: CTID of the container to set
|
|
113
|
-
+ save: whether to save the changes
|
|
114
|
-
+ settings: settings/arguments to apply to the container
|
|
115
|
-
|
|
116
|
-
Settings/arguments:
|
|
117
|
-
these are mapped directly to ``vztctl`` arguments, eg
|
|
118
|
-
``hostname='my-host.net'`` becomes ``--hostname my-host.net``.
|
|
119
|
-
'''
|
|
120
|
-
|
|
121
|
-
args = ['{0}'.format(ctid)]
|
|
122
|
-
|
|
123
|
-
if save:
|
|
124
|
-
args.append('--save')
|
|
125
|
-
|
|
126
|
-
for key, value in settings.items():
|
|
127
|
-
# Handle list values (eg --nameserver X --nameserver X)
|
|
128
|
-
if isinstance(value, list):
|
|
129
|
-
args.extend('--{0} {1}'.format(key, v) for v in value)
|
|
130
|
-
else:
|
|
131
|
-
args.append('--{0} {1}'.format(key, value))
|
|
132
|
-
|
|
133
|
-
yield 'vzctl set {0}'.format(' '.join(args))
|
pyinfra/modules/yum.py
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Manage yum packages and repositories. Note that yum package names are case-sensitive.
|
|
3
|
-
'''
|
|
4
|
-
|
|
5
|
-
from io import StringIO
|
|
6
|
-
from urllib.parse import urlparse
|
|
7
|
-
|
|
8
|
-
from pyinfra.api import operation
|
|
9
|
-
|
|
10
|
-
from . import files
|
|
11
|
-
from .util.packaging import ensure_packages
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@operation
|
|
15
|
-
def key(state, host, key):
|
|
16
|
-
'''
|
|
17
|
-
Add yum gpg keys with ``rpm``.
|
|
18
|
-
|
|
19
|
-
+ key: filename or URL
|
|
20
|
-
|
|
21
|
-
Note:
|
|
22
|
-
always returns one command, not state checking
|
|
23
|
-
'''
|
|
24
|
-
|
|
25
|
-
yield 'rpm --import {0}'.format(key)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@operation
|
|
29
|
-
def repo(
|
|
30
|
-
state, host, name, baseurl,
|
|
31
|
-
present=True, description=None, enabled=True, gpgcheck=True, gpgkey=None,
|
|
32
|
-
):
|
|
33
|
-
'''
|
|
34
|
-
Add/remove/update yum repositories.
|
|
35
|
-
|
|
36
|
-
+ name: filename for the repo (in ``/etc/yum/repos.d/``)
|
|
37
|
-
+ baseurl: the baseurl of the repo
|
|
38
|
-
+ present: whether the ``.repo`` file should be present
|
|
39
|
-
+ description: optional verbose description
|
|
40
|
-
+ gpgcheck: whether set ``gpgcheck=1``
|
|
41
|
-
+ gpgkey: the URL to the gpg key for this repo
|
|
42
|
-
'''
|
|
43
|
-
|
|
44
|
-
# Description defaults to name
|
|
45
|
-
description = description or name
|
|
46
|
-
|
|
47
|
-
filename = '/etc/yum.repos.d/{0}.repo'.format(name)
|
|
48
|
-
|
|
49
|
-
# If we don't want the repo, just remove any existing file
|
|
50
|
-
if not present:
|
|
51
|
-
yield files.file(state, host, filename, present=False)
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
# Build the repo file from string
|
|
55
|
-
repo_lines = [
|
|
56
|
-
'[{0}]'.format(name),
|
|
57
|
-
'name={0}'.format(description),
|
|
58
|
-
'baseurl={0}'.format(baseurl),
|
|
59
|
-
'enabled={0}'.format(1 if enabled else 0),
|
|
60
|
-
'gpgcheck={0}'.format(1 if gpgcheck else 0),
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
if gpgkey:
|
|
64
|
-
repo_lines.append('gpgkey={0}'.format(gpgkey))
|
|
65
|
-
|
|
66
|
-
repo_lines.append('')
|
|
67
|
-
repo = '\n'.join(repo_lines)
|
|
68
|
-
repo = StringIO(repo)
|
|
69
|
-
|
|
70
|
-
# Ensure this is the file on the server
|
|
71
|
-
yield files.put(state, host, repo, filename)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@operation
|
|
75
|
-
def rpm(state, host, source, present=True):
|
|
76
|
-
'''
|
|
77
|
-
Add/remove ``.rpm`` file packages.
|
|
78
|
-
|
|
79
|
-
+ source: filename or URL of the ``.rpm`` package
|
|
80
|
-
+ present: whether ore not the package should exist on the system
|
|
81
|
-
|
|
82
|
-
URL sources with ``present=False``:
|
|
83
|
-
If the ``.rpm`` file isn't downloaded, pyinfra can't remove any existing
|
|
84
|
-
package as the file won't exist until mid-deploy.
|
|
85
|
-
'''
|
|
86
|
-
|
|
87
|
-
# If source is a url
|
|
88
|
-
if urlparse(source).scheme:
|
|
89
|
-
# Generate a temp filename (with .rpm extension to please yum)
|
|
90
|
-
temp_filename = '{0}.rpm'.format(state.get_temp_filename(source))
|
|
91
|
-
|
|
92
|
-
# Ensure it's downloaded
|
|
93
|
-
yield files.download(state, host, source, temp_filename)
|
|
94
|
-
|
|
95
|
-
# Override the source with the downloaded file
|
|
96
|
-
source = temp_filename
|
|
97
|
-
|
|
98
|
-
# Check for file .rpm information
|
|
99
|
-
info = host.fact.rpm_package(source)
|
|
100
|
-
exists = False
|
|
101
|
-
|
|
102
|
-
# We have info!
|
|
103
|
-
if info:
|
|
104
|
-
current_packages = host.fact.rpm_packages
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
info['name'] in current_packages
|
|
108
|
-
and info['version'] in current_packages[info['name']]
|
|
109
|
-
):
|
|
110
|
-
exists = True
|
|
111
|
-
|
|
112
|
-
# Package does not exist and we want?
|
|
113
|
-
if present and not exists:
|
|
114
|
-
# If we had info, always install
|
|
115
|
-
if info:
|
|
116
|
-
yield 'rpm -U {0}'.format(source)
|
|
117
|
-
|
|
118
|
-
# This happens if we download the package mid-deploy, so we have no info
|
|
119
|
-
# but also don't know if it's installed. So check at runtime, otherwise
|
|
120
|
-
# the install will fail.
|
|
121
|
-
else:
|
|
122
|
-
yield 'rpm -qa | grep `rpm -qp {0}` || rpm -U {0}'.format(source)
|
|
123
|
-
|
|
124
|
-
# Package exists but we don't want?
|
|
125
|
-
if exists and not present:
|
|
126
|
-
yield 'yum remove -y {0}'.format(info['name'])
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
@operation
|
|
130
|
-
def update(state, host):
|
|
131
|
-
'''
|
|
132
|
-
Updates all yum packages.
|
|
133
|
-
'''
|
|
134
|
-
|
|
135
|
-
yield 'yum update -y'
|
|
136
|
-
|
|
137
|
-
_update = update # noqa: E305 (for use below where update is a kwarg)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
@operation
|
|
141
|
-
def packages(
|
|
142
|
-
state, host, packages=None,
|
|
143
|
-
present=True, latest=False, update=False, clean=False,
|
|
144
|
-
):
|
|
145
|
-
'''
|
|
146
|
-
Install/remove/update yum packages & updates.
|
|
147
|
-
|
|
148
|
-
+ packages: list of packages to ensure
|
|
149
|
-
+ present: whether the packages should be installed
|
|
150
|
-
+ latest: whether to upgrade packages without a specified version
|
|
151
|
-
+ update: run yum update
|
|
152
|
-
+ clean: run yum clean
|
|
153
|
-
|
|
154
|
-
Versions:
|
|
155
|
-
Package versions can be pinned like yum: ``<pkg>-<version>``
|
|
156
|
-
'''
|
|
157
|
-
|
|
158
|
-
if clean:
|
|
159
|
-
yield 'yum clean all'
|
|
160
|
-
|
|
161
|
-
if update:
|
|
162
|
-
yield _update(state, host)
|
|
163
|
-
|
|
164
|
-
yield ensure_packages(
|
|
165
|
-
packages, host.fact.rpm_packages, present,
|
|
166
|
-
install_command='yum install -y',
|
|
167
|
-
uninstall_command='yum remove -y',
|
|
168
|
-
upgrade_command='yum update -y',
|
|
169
|
-
version_join='-',
|
|
170
|
-
latest=latest,
|
|
171
|
-
)
|
pyinfra/pseudo_modules.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
These three pseudo modules (state, inventory, host) are used throughout pyinfra
|
|
3
|
-
and provide the magic that means "from pyinfra import host" inside a deploy
|
|
4
|
-
file always represents the *current* host being executed, ie these modules are
|
|
5
|
-
dynamic and change during execution of pyinfra.
|
|
6
|
-
|
|
7
|
-
Although CLI only when in use, these are bundled into the main pyinfra package
|
|
8
|
-
as they are utilised throughout (to determine the current state/host when
|
|
9
|
-
executing in CLI mode).
|
|
10
|
-
'''
|
|
11
|
-
|
|
12
|
-
import sys
|
|
13
|
-
|
|
14
|
-
import pyinfra
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class PseudoModule(object):
|
|
18
|
-
_module = None
|
|
19
|
-
|
|
20
|
-
def __getattr__(self, key):
|
|
21
|
-
return getattr(self._module, key)
|
|
22
|
-
|
|
23
|
-
def __setattr__(self, key, value):
|
|
24
|
-
if key == '_module':
|
|
25
|
-
return object.__setattr__(self, key, value)
|
|
26
|
-
|
|
27
|
-
setattr(self._module, key, value)
|
|
28
|
-
|
|
29
|
-
def __getitem__(self, key):
|
|
30
|
-
return self._module[key]
|
|
31
|
-
|
|
32
|
-
def __iter__(self):
|
|
33
|
-
return iter(self._module)
|
|
34
|
-
|
|
35
|
-
def __len__(self):
|
|
36
|
-
return len(self._module)
|
|
37
|
-
|
|
38
|
-
def __eq__(self, other):
|
|
39
|
-
return self._module == other
|
|
40
|
-
|
|
41
|
-
def set(self, module):
|
|
42
|
-
self._module = module
|
|
43
|
-
|
|
44
|
-
def reset(self):
|
|
45
|
-
self._module = None
|
|
46
|
-
|
|
47
|
-
def isset(self):
|
|
48
|
-
return self._module is not None
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# The current deploy state
|
|
52
|
-
sys.modules['pyinfra.pseudo_state'] = sys.modules['pyinfra.state'] = \
|
|
53
|
-
pyinfra.pseudo_state = pyinfra.state = \
|
|
54
|
-
PseudoModule()
|
|
55
|
-
|
|
56
|
-
# The current deploy inventory
|
|
57
|
-
sys.modules['pyinfra.pseudo_inventory'] = sys.modules['pyinfra.inventory'] = \
|
|
58
|
-
pyinfra.pseudo_inventory = pyinfra.inventory = \
|
|
59
|
-
PseudoModule()
|
|
60
|
-
|
|
61
|
-
# The current target host
|
|
62
|
-
sys.modules['pyinfra.pseudo_host'] = sys.modules['pyinfra.host'] = \
|
|
63
|
-
pyinfra.pseudo_host = pyinfra.host = \
|
|
64
|
-
PseudoModule()
|
|
Binary file
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: pyinfra
|
|
3
|
-
Version: 0.11.dev3
|
|
4
|
-
Summary: pyinfra automates/provisions/manages/deploys infrastructure.
|
|
5
|
-
Home-page: http://github.com/Fizzadar/pyinfra
|
|
6
|
-
Author: Nick / Fizzadar
|
|
7
|
-
Author-email: pointlessrambler@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Platform: UNKNOWN
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: Environment :: Console
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Intended Audience :: System Administrators
|
|
14
|
-
Classifier: Intended Audience :: Information Technology
|
|
15
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
-
Classifier: Operating System :: OS Independent
|
|
17
|
-
Classifier: Programming Language :: Python :: 2
|
|
18
|
-
Classifier: Programming Language :: Python :: 3
|
|
19
|
-
Classifier: Topic :: System :: Systems Administration
|
|
20
|
-
Classifier: Topic :: System :: Installation/Setup
|
|
21
|
-
Classifier: Topic :: Utilities
|
|
22
|
-
Description-Content-Type: text/markdown
|
|
23
|
-
Requires-Dist: gevent (!=1.5a1,<2,>1)
|
|
24
|
-
Requires-Dist: paramiko (<3,>1)
|
|
25
|
-
Requires-Dist: click (>2)
|
|
26
|
-
Requires-Dist: colorama (<1)
|
|
27
|
-
Requires-Dist: jinja2 (<3,>2)
|
|
28
|
-
Requires-Dist: python-dateutil (<3,>2)
|
|
29
|
-
Requires-Dist: setuptools
|
|
30
|
-
Requires-Dist: configparser
|
|
31
|
-
Provides-Extra: dev
|
|
32
|
-
Requires-Dist: pytest (==4.6.6) ; extra == 'dev'
|
|
33
|
-
Requires-Dist: pytest-cov (==2.8.1) ; extra == 'dev'
|
|
34
|
-
Requires-Dist: jsontest (==1.4) ; extra == 'dev'
|
|
35
|
-
Requires-Dist: coverage (==4.5.4) ; extra == 'dev'
|
|
36
|
-
Requires-Dist: mock (==3.0.5) ; extra == 'dev'
|
|
37
|
-
Requires-Dist: codecov (==2.0.15) ; extra == 'dev'
|
|
38
|
-
Requires-Dist: flake8 ; extra == 'dev'
|
|
39
|
-
Requires-Dist: flake8-commas ; extra == 'dev'
|
|
40
|
-
Requires-Dist: flake8-quotes ; extra == 'dev'
|
|
41
|
-
Requires-Dist: flake8-import-order ; extra == 'dev'
|
|
42
|
-
Requires-Dist: sphinx (==2.2.1) ; extra == 'dev'
|
|
43
|
-
Requires-Dist: sphinx-autobuild (==0.7.1) ; extra == 'dev'
|
|
44
|
-
Requires-Dist: guzzle-sphinx-theme (==0.7.11) ; extra == 'dev'
|
|
45
|
-
Requires-Dist: recommonmark (==0.5.0) ; extra == 'dev'
|
|
46
|
-
Requires-Dist: wheel ; extra == 'dev'
|
|
47
|
-
Requires-Dist: twine (==3.1.0) ; extra == 'dev'
|
|
48
|
-
Requires-Dist: ipdb (==0.10.3) ; extra == 'dev'
|
|
49
|
-
Requires-Dist: ipdbplugin (==1.4.5) ; extra == 'dev'
|
|
50
|
-
Provides-Extra: docs
|
|
51
|
-
Requires-Dist: sphinx (==2.2.1) ; extra == 'docs'
|
|
52
|
-
Requires-Dist: sphinx-autobuild (==0.7.1) ; extra == 'docs'
|
|
53
|
-
Requires-Dist: guzzle-sphinx-theme (==0.7.11) ; extra == 'docs'
|
|
54
|
-
Requires-Dist: recommonmark (==0.5.0) ; extra == 'docs'
|
|
55
|
-
Provides-Extra: test
|
|
56
|
-
Requires-Dist: pytest (==4.6.6) ; extra == 'test'
|
|
57
|
-
Requires-Dist: pytest-cov (==2.8.1) ; extra == 'test'
|
|
58
|
-
Requires-Dist: jsontest (==1.4) ; extra == 'test'
|
|
59
|
-
Requires-Dist: coverage (==4.5.4) ; extra == 'test'
|
|
60
|
-
Requires-Dist: mock (==3.0.5) ; extra == 'test'
|
|
61
|
-
Requires-Dist: codecov (==2.0.15) ; extra == 'test'
|
|
62
|
-
Requires-Dist: flake8 ; extra == 'test'
|
|
63
|
-
Requires-Dist: flake8-commas ; extra == 'test'
|
|
64
|
-
Requires-Dist: flake8-quotes ; extra == 'test'
|
|
65
|
-
Requires-Dist: flake8-import-order ; extra == 'test'
|
|
66
|
-
|
|
67
|
-
<h1>
|
|
68
|
-
<a href="https://pyinfra.com">
|
|
69
|
-
<img src="https://raw.githubusercontent.com/Fizzadar/pyinfra/master/docs/static/logo_full.png" height="48px" />
|
|
70
|
-
</a>
|
|
71
|
-
</h1>
|
|
72
|
-
|
|
73
|
-
[](https://pypi.python.org/pypi/pyinfra)
|
|
74
|
-
[](https://pyinfra.readthedocs.io)
|
|
75
|
-
[](https://travis-ci.org/Fizzadar/pyinfra)
|
|
76
|
-
[](https://codecov.io/github/Fizzadar/pyinfra)
|
|
77
|
-
[](https://github.com/Fizzadar/pyinfra/blob/develop/LICENSE.md)
|
|
78
|
-
|
|
79
|
-
pyinfra automates/provisions/manages/deploys infrastructure super fast at massive scale. It can be used for ad-hoc command execution, service deployment, configuration management and more. Core design features include:
|
|
80
|
-
|
|
81
|
-
+ 🚀 **Super fast** execution over thousands of targets with predictable performance.
|
|
82
|
-
+ 🚨 **Instant debugging** with stdout + stderr output on error, and `-v` to print it always.
|
|
83
|
-
+ 💻 **Agentless execution** by speaking native SSH/Docker/subprocess depending on the target.
|
|
84
|
-
+ ❗️ **Two stage process** that enables `--dry` runs before making any changes.
|
|
85
|
-
+ 📦 **Extendable** with _any_ Python package as configured & written in standard Python.
|
|
86
|
-
+ 🔌 **Integrated** with Docker, Vagrant & Ansible out of the box.
|
|
87
|
-
|
|
88
|
-
When you run pyinfra you'll see something like ([non animated version](https://raw.githubusercontent.com/Fizzadar/pyinfra/master/docs/static/example_deploy.png)):
|
|
89
|
-
|
|
90
|
-
<img width="100%" src="https://raw.githubusercontent.com/Fizzadar/pyinfra/master/docs/static/example_deploy.gif" />
|
|
91
|
-
|
|
92
|
-
## Quickstart
|
|
93
|
-
|
|
94
|
-
pyinfra can be installed via pip:
|
|
95
|
-
|
|
96
|
-
```sh
|
|
97
|
-
pip install pyinfra
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Now you can execute commands & operations over SSH:
|
|
101
|
-
|
|
102
|
-
```sh
|
|
103
|
-
# Execute an abitrary shell command
|
|
104
|
-
pyinfra my-server.net exec -- echo "hello world"
|
|
105
|
-
|
|
106
|
-
# Install iftop apt package if not present
|
|
107
|
-
pyinfra my-server.net apt.packages iftop sudo=true
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
These can then be saved to a _deploy file_, let's call it `deploy.py`:
|
|
111
|
-
|
|
112
|
-
```py
|
|
113
|
-
from pyinfra.modules import apt
|
|
114
|
-
|
|
115
|
-
apt.packages(
|
|
116
|
-
{'Install iftop'},
|
|
117
|
-
'iftop',
|
|
118
|
-
sudo=True,
|
|
119
|
-
)
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
And executed with:
|
|
123
|
-
|
|
124
|
-
```sh
|
|
125
|
-
pyinfra my-server.net deploy.py
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## [Documentation](https://pyinfra.readthedocs.io)
|
|
129
|
-
|
|
130
|
-
+ [Getting started](https://pyinfra.readthedocs.io/page/getting_started.html)
|
|
131
|
-
+ [Writing deploys](https://pyinfra.readthedocs.io/page/deploys.html)
|
|
132
|
-
+ [Using the CLI](https://pyinfra.readthedocs.io/page/cli.html)
|
|
133
|
-
+ [Connectors](https://pyinfra.readthedocs.io/page/connectors.html)
|
|
134
|
-
|
|
135
|
-
|