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.
Files changed (204) hide show
  1. pyinfra/__init__.py +9 -12
  2. pyinfra/__main__.py +4 -0
  3. pyinfra/api/__init__.py +19 -3
  4. pyinfra/api/arguments.py +413 -0
  5. pyinfra/api/arguments_typed.py +79 -0
  6. pyinfra/api/command.py +274 -0
  7. pyinfra/api/config.py +222 -28
  8. pyinfra/api/connect.py +33 -13
  9. pyinfra/api/connectors.py +27 -0
  10. pyinfra/api/deploy.py +65 -66
  11. pyinfra/api/exceptions.py +73 -18
  12. pyinfra/api/facts.py +267 -200
  13. pyinfra/api/host.py +416 -50
  14. pyinfra/api/inventory.py +121 -160
  15. pyinfra/api/metadata.py +69 -0
  16. pyinfra/api/operation.py +432 -262
  17. pyinfra/api/operations.py +273 -260
  18. pyinfra/api/state.py +302 -248
  19. pyinfra/api/util.py +309 -369
  20. pyinfra/connectors/base.py +173 -0
  21. pyinfra/connectors/chroot.py +212 -0
  22. pyinfra/connectors/docker.py +405 -0
  23. pyinfra/connectors/dockerssh.py +297 -0
  24. pyinfra/connectors/local.py +238 -0
  25. pyinfra/connectors/scp/__init__.py +1 -0
  26. pyinfra/connectors/scp/client.py +204 -0
  27. pyinfra/connectors/ssh.py +727 -0
  28. pyinfra/connectors/ssh_util.py +114 -0
  29. pyinfra/connectors/sshuserclient/client.py +309 -0
  30. pyinfra/connectors/sshuserclient/config.py +102 -0
  31. pyinfra/connectors/terraform.py +135 -0
  32. pyinfra/connectors/util.py +417 -0
  33. pyinfra/connectors/vagrant.py +183 -0
  34. pyinfra/context.py +145 -0
  35. pyinfra/facts/__init__.py +7 -6
  36. pyinfra/facts/apk.py +22 -7
  37. pyinfra/facts/apt.py +117 -60
  38. pyinfra/facts/brew.py +100 -15
  39. pyinfra/facts/bsdinit.py +23 -0
  40. pyinfra/facts/cargo.py +37 -0
  41. pyinfra/facts/choco.py +47 -0
  42. pyinfra/facts/crontab.py +195 -0
  43. pyinfra/facts/deb.py +94 -0
  44. pyinfra/facts/dnf.py +48 -0
  45. pyinfra/facts/docker.py +96 -23
  46. pyinfra/facts/efibootmgr.py +113 -0
  47. pyinfra/facts/files.py +629 -58
  48. pyinfra/facts/flatpak.py +77 -0
  49. pyinfra/facts/freebsd.py +70 -0
  50. pyinfra/facts/gem.py +19 -6
  51. pyinfra/facts/git.py +59 -14
  52. pyinfra/facts/gpg.py +150 -0
  53. pyinfra/facts/hardware.py +313 -167
  54. pyinfra/facts/iptables.py +72 -62
  55. pyinfra/facts/launchd.py +44 -0
  56. pyinfra/facts/lxd.py +17 -4
  57. pyinfra/facts/mysql.py +122 -86
  58. pyinfra/facts/npm.py +17 -9
  59. pyinfra/facts/openrc.py +71 -0
  60. pyinfra/facts/opkg.py +246 -0
  61. pyinfra/facts/pacman.py +50 -7
  62. pyinfra/facts/pip.py +24 -7
  63. pyinfra/facts/pipx.py +82 -0
  64. pyinfra/facts/pkg.py +15 -6
  65. pyinfra/facts/pkgin.py +35 -0
  66. pyinfra/facts/podman.py +54 -0
  67. pyinfra/facts/postgres.py +178 -0
  68. pyinfra/facts/postgresql.py +6 -147
  69. pyinfra/facts/rpm.py +105 -0
  70. pyinfra/facts/runit.py +77 -0
  71. pyinfra/facts/selinux.py +161 -0
  72. pyinfra/facts/server.py +762 -285
  73. pyinfra/facts/snap.py +88 -0
  74. pyinfra/facts/systemd.py +139 -0
  75. pyinfra/facts/sysvinit.py +59 -0
  76. pyinfra/facts/upstart.py +35 -0
  77. pyinfra/facts/util/__init__.py +17 -0
  78. pyinfra/facts/util/databases.py +4 -6
  79. pyinfra/facts/util/packaging.py +37 -6
  80. pyinfra/facts/util/units.py +30 -0
  81. pyinfra/facts/util/win_files.py +99 -0
  82. pyinfra/facts/vzctl.py +20 -13
  83. pyinfra/facts/xbps.py +35 -0
  84. pyinfra/facts/yum.py +34 -40
  85. pyinfra/facts/zfs.py +77 -0
  86. pyinfra/facts/zypper.py +42 -0
  87. pyinfra/local.py +45 -83
  88. pyinfra/operations/__init__.py +12 -0
  89. pyinfra/operations/apk.py +99 -0
  90. pyinfra/operations/apt.py +496 -0
  91. pyinfra/operations/brew.py +232 -0
  92. pyinfra/operations/bsdinit.py +59 -0
  93. pyinfra/operations/cargo.py +45 -0
  94. pyinfra/operations/choco.py +61 -0
  95. pyinfra/operations/crontab.py +194 -0
  96. pyinfra/operations/dnf.py +213 -0
  97. pyinfra/operations/docker.py +492 -0
  98. pyinfra/operations/files.py +2014 -0
  99. pyinfra/operations/flatpak.py +95 -0
  100. pyinfra/operations/freebsd/__init__.py +12 -0
  101. pyinfra/operations/freebsd/freebsd_update.py +70 -0
  102. pyinfra/operations/freebsd/pkg.py +219 -0
  103. pyinfra/operations/freebsd/service.py +116 -0
  104. pyinfra/operations/freebsd/sysrc.py +92 -0
  105. pyinfra/operations/gem.py +48 -0
  106. pyinfra/operations/git.py +420 -0
  107. pyinfra/operations/iptables.py +312 -0
  108. pyinfra/operations/launchd.py +45 -0
  109. pyinfra/operations/lxd.py +69 -0
  110. pyinfra/operations/mysql.py +610 -0
  111. pyinfra/operations/npm.py +57 -0
  112. pyinfra/operations/openrc.py +63 -0
  113. pyinfra/operations/opkg.py +89 -0
  114. pyinfra/operations/pacman.py +82 -0
  115. pyinfra/operations/pip.py +206 -0
  116. pyinfra/operations/pipx.py +103 -0
  117. pyinfra/operations/pkg.py +71 -0
  118. pyinfra/operations/pkgin.py +92 -0
  119. pyinfra/operations/postgres.py +437 -0
  120. pyinfra/operations/postgresql.py +30 -0
  121. pyinfra/operations/puppet.py +41 -0
  122. pyinfra/operations/python.py +73 -0
  123. pyinfra/operations/runit.py +184 -0
  124. pyinfra/operations/selinux.py +190 -0
  125. pyinfra/operations/server.py +1100 -0
  126. pyinfra/operations/snap.py +118 -0
  127. pyinfra/operations/ssh.py +217 -0
  128. pyinfra/operations/systemd.py +150 -0
  129. pyinfra/operations/sysvinit.py +142 -0
  130. pyinfra/operations/upstart.py +68 -0
  131. pyinfra/operations/util/__init__.py +12 -0
  132. pyinfra/operations/util/docker.py +407 -0
  133. pyinfra/operations/util/files.py +247 -0
  134. pyinfra/operations/util/packaging.py +338 -0
  135. pyinfra/operations/util/service.py +46 -0
  136. pyinfra/operations/vzctl.py +137 -0
  137. pyinfra/operations/xbps.py +78 -0
  138. pyinfra/operations/yum.py +213 -0
  139. pyinfra/operations/zfs.py +176 -0
  140. pyinfra/operations/zypper.py +193 -0
  141. pyinfra/progress.py +44 -32
  142. pyinfra/py.typed +0 -0
  143. pyinfra/version.py +9 -1
  144. pyinfra-3.6.dist-info/METADATA +142 -0
  145. pyinfra-3.6.dist-info/RECORD +160 -0
  146. {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info}/WHEEL +1 -2
  147. pyinfra-3.6.dist-info/entry_points.txt +12 -0
  148. {pyinfra-0.11.dev3.dist-info → pyinfra-3.6.dist-info/licenses}/LICENSE.md +1 -1
  149. pyinfra_cli/__init__.py +1 -0
  150. pyinfra_cli/cli.py +793 -0
  151. pyinfra_cli/commands.py +66 -0
  152. pyinfra_cli/exceptions.py +155 -65
  153. pyinfra_cli/inventory.py +233 -89
  154. pyinfra_cli/log.py +39 -43
  155. pyinfra_cli/main.py +26 -495
  156. pyinfra_cli/prints.py +215 -156
  157. pyinfra_cli/util.py +172 -105
  158. pyinfra_cli/virtualenv.py +25 -20
  159. pyinfra/api/connectors/__init__.py +0 -21
  160. pyinfra/api/connectors/ansible.py +0 -99
  161. pyinfra/api/connectors/docker.py +0 -178
  162. pyinfra/api/connectors/local.py +0 -169
  163. pyinfra/api/connectors/ssh.py +0 -402
  164. pyinfra/api/connectors/sshuserclient/client.py +0 -105
  165. pyinfra/api/connectors/sshuserclient/config.py +0 -90
  166. pyinfra/api/connectors/util.py +0 -63
  167. pyinfra/api/connectors/vagrant.py +0 -155
  168. pyinfra/facts/init.py +0 -176
  169. pyinfra/facts/util/files.py +0 -102
  170. pyinfra/hook.py +0 -41
  171. pyinfra/modules/__init__.py +0 -11
  172. pyinfra/modules/apk.py +0 -64
  173. pyinfra/modules/apt.py +0 -272
  174. pyinfra/modules/brew.py +0 -122
  175. pyinfra/modules/files.py +0 -711
  176. pyinfra/modules/gem.py +0 -30
  177. pyinfra/modules/git.py +0 -115
  178. pyinfra/modules/init.py +0 -344
  179. pyinfra/modules/iptables.py +0 -271
  180. pyinfra/modules/lxd.py +0 -45
  181. pyinfra/modules/mysql.py +0 -347
  182. pyinfra/modules/npm.py +0 -47
  183. pyinfra/modules/pacman.py +0 -60
  184. pyinfra/modules/pip.py +0 -99
  185. pyinfra/modules/pkg.py +0 -43
  186. pyinfra/modules/postgresql.py +0 -245
  187. pyinfra/modules/puppet.py +0 -20
  188. pyinfra/modules/python.py +0 -37
  189. pyinfra/modules/server.py +0 -524
  190. pyinfra/modules/ssh.py +0 -150
  191. pyinfra/modules/util/files.py +0 -52
  192. pyinfra/modules/util/packaging.py +0 -118
  193. pyinfra/modules/vzctl.py +0 -133
  194. pyinfra/modules/yum.py +0 -171
  195. pyinfra/pseudo_modules.py +0 -64
  196. pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
  197. pyinfra-0.11.dev3.dist-info/METADATA +0 -135
  198. pyinfra-0.11.dev3.dist-info/RECORD +0 -95
  199. pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
  200. pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
  201. pyinfra_cli/__main__.py +0 -40
  202. pyinfra_cli/config.py +0 -92
  203. /pyinfra/{modules/util → connectors}/__init__.py +0 -0
  204. /pyinfra/{api/connectors → connectors}/sshuserclient/__init__.py +0 -0
pyinfra/modules/apt.py DELETED
@@ -1,272 +0,0 @@
1
- '''
2
- Manage apt packages and repositories.
3
- '''
4
-
5
- from datetime import timedelta
6
- from urllib.parse import urlparse
7
-
8
- from pyinfra.api import operation
9
- from pyinfra.facts.apt import parse_apt_repo
10
-
11
- from . import files
12
- from .util.packaging import ensure_packages
13
-
14
- APT_UPDATE_FILENAME = '/var/lib/apt/periodic/update-success-stamp'
15
-
16
-
17
- def noninteractive_apt(command, force=False):
18
- args = ['DEBIAN_FRONTEND=noninteractive apt-get -y']
19
-
20
- if force:
21
- args.append('--force-yes')
22
-
23
- args.extend((
24
- '-o Dpkg::Options::="--force-confdef"',
25
- '-o Dpkg::Options::="--force-confold"',
26
- command,
27
- ))
28
-
29
- return ' '.join(args)
30
-
31
-
32
- @operation
33
- def key(state, host, key=None, keyserver=None, keyid=None):
34
- '''
35
- Add apt gpg keys with ``apt-key``.
36
-
37
- + key: filename or URL
38
- + keyserver: URL of keyserver to fetch key from
39
- + keyid: key identifier when using keyserver
40
-
41
- Note:
42
- Always returns an add command, not state checking.
43
-
44
- keyserver/id:
45
- These must be provided together.
46
- '''
47
-
48
- if key:
49
- # If URL, wget the key to stdout and pipe into apt-key, because the "adv"
50
- # apt-key passes to gpg which doesn't always support https!
51
- if urlparse(key).scheme:
52
- yield 'wget -O- {0} | apt-key add -'.format(key)
53
- else:
54
- yield 'apt-key add {0}'.format(key)
55
-
56
- if keyserver and keyid:
57
- yield 'apt-key adv --keyserver {0} --recv-keys {1}'.format(keyserver, keyid)
58
-
59
-
60
- @operation
61
- def repo(state, host, name, present=True, filename=None):
62
- '''
63
- Add/remove apt repositories.
64
-
65
- + name: apt source string eg ``deb http://X hardy main``
66
- + present: whether the repo should exist on the system
67
- + filename: optional filename to use ``/etc/apt/sources.list.d/<filename>.list``. By
68
- default uses ``/etc/apt/sources.list``.
69
- '''
70
-
71
- # Get the target .list file to manage
72
- if filename:
73
- filename = '/etc/apt/sources.list.d/{0}.list'.format(filename)
74
- else:
75
- filename = '/etc/apt/sources.list'
76
-
77
- # Work out if the repo exists already
78
- apt_sources = host.fact.apt_sources
79
-
80
- is_present = False
81
- repo = parse_apt_repo(name)
82
- if repo and repo in apt_sources:
83
- is_present = True
84
-
85
- # Doesn't exist and we want it
86
- if not is_present and present:
87
- yield files.line(
88
- state, host, filename, name,
89
- )
90
-
91
- # Exists and we don't want it
92
- if is_present and not present:
93
- yield files.line(
94
- state, host, filename, name,
95
- present=False,
96
- )
97
-
98
-
99
- @operation
100
- def ppa(state, host, name, present=True):
101
- '''
102
- Add/remove Ubuntu ppa repositories.
103
-
104
- + name: the PPA name (full ppa:user/repo format)
105
- + present: whether it should exist
106
-
107
- Note:
108
- requires ``apt-add-repository`` on the remote host
109
- '''
110
-
111
- if present:
112
- yield 'apt-add-repository -y "{0}"'.format(name)
113
-
114
- if not present:
115
- yield 'apt-add-repository -y --remove "{0}"'.format(name)
116
-
117
-
118
- @operation
119
- def deb(state, host, source, present=True, force=False):
120
- '''
121
- Add/remove ``.deb`` file packages.
122
-
123
- + source: filename or URL of the ``.deb`` file
124
- + present: whether or not the package should exist on the system
125
- + force: whether to force the package install by passing `--force-yes` to apt
126
-
127
- Note:
128
- When installing, ``apt-get install -f`` will be run to install any unmet
129
- dependencies.
130
-
131
- URL sources with ``present=False``:
132
- If the ``.deb`` file isn't downloaded, pyinfra can't remove any existing
133
- package as the file won't exist until mid-deploy.
134
- '''
135
-
136
- # If source is a url
137
- if urlparse(source).scheme:
138
- # Generate a temp filename
139
- temp_filename = state.get_temp_filename(source)
140
-
141
- # Ensure it's downloaded
142
- yield files.download(state, host, source, temp_filename)
143
-
144
- # Override the source with the downloaded file
145
- source = temp_filename
146
-
147
- # Check for file .deb information (if file is present)
148
- info = host.fact.deb_package(source)
149
-
150
- exists = False
151
-
152
- # We have deb info! Check against installed packages
153
- if info:
154
- current_packages = host.fact.deb_packages
155
-
156
- if (
157
- info['name'] in current_packages
158
- and info.get('version') in current_packages[info['name']]
159
- ):
160
- exists = True
161
-
162
- # Package does not exist and we want?
163
- if present and not exists:
164
- # Install .deb file - ignoring failure (on unmet dependencies)
165
- yield 'dpkg --force-confdef --force-confold -i {0} || true'.format(source)
166
- # Attempt to install any missing dependencies
167
- yield '{0} -f'.format(noninteractive_apt('install', force=force))
168
- # Now reinstall, and critically configure, the package - if there are still
169
- # missing deps, now we error
170
- yield 'dpkg --force-confdef --force-confold -i {0}'.format(source)
171
-
172
- # Package exists but we don't want?
173
- if exists and not present:
174
- yield '{0} {1}'.format(
175
- noninteractive_apt('remove', force=force),
176
- info['name'],
177
- )
178
-
179
-
180
- @operation
181
- def update(state, host, cache_time=None, touch_periodic=False):
182
- '''
183
- Updates apt repositories.
184
-
185
- + cache_time: cache updates for this many seconds
186
- + touch_periodic: touch ``/var/lib/apt/periodic/update-success-stamp`` after update
187
- '''
188
-
189
- # If cache_time check when apt was last updated, prevent updates if within time
190
- if cache_time:
191
- # Ubuntu provides this handy file
192
- cache_info = host.fact.file(APT_UPDATE_FILENAME)
193
-
194
- # Time on files is not tz-aware, and will be the same tz as the server's time,
195
- # so we can safely remove the tzinfo from host.fact.date before comparison.
196
- host_cache_time = host.fact.date.replace(tzinfo=None) - timedelta(seconds=cache_time)
197
- if cache_info and cache_info['mtime'] and cache_info['mtime'] > host_cache_time:
198
- return
199
-
200
- yield 'apt-get update'
201
-
202
- # Some apt systems (Debian) have the /var/lib/apt/periodic directory, but
203
- # don't bother touching anything in there - so pyinfra does it, enabling
204
- # cache_time to work.
205
- if cache_time:
206
- yield 'touch {0}'.format(APT_UPDATE_FILENAME)
207
-
208
- _update = update # noqa: E305
209
-
210
-
211
- @operation
212
- def upgrade(state, host):
213
- '''
214
- Upgrades all apt packages.
215
- '''
216
-
217
- yield noninteractive_apt('upgrade')
218
-
219
- _upgrade = upgrade # noqa: E305 (for use below where update is a kwarg)
220
-
221
-
222
- @operation
223
- def packages(
224
- state, host,
225
- packages=None, present=True, latest=False,
226
- update=False, cache_time=None, upgrade=False,
227
- force=False, no_recommends=False,
228
- allow_downgrades=False,
229
- ):
230
- '''
231
- Install/remove/update packages & update apt.
232
-
233
- + packages: list of packages to ensure
234
- + present: whether the packages should be installed
235
- + latest: whether to upgrade packages without a specified version
236
- + update: run apt update before installing packages
237
- + cache_time: when used with update, cache for this many seconds
238
- + upgrade: run apt upgrade before installing packages
239
- + force: whether to force package installs by passing `--force-yes` to apt
240
- + no_recommends: don't install recommended packages
241
- + allow_downgrades: allow downgrading packages with version (--allow-downgrades)
242
-
243
- Versions:
244
- Package versions can be pinned like apt: ``<pkg>=<version>``
245
-
246
- Cache time:
247
- When ``cache_time`` is set the ``/var/lib/apt/periodic/update-success-stamp`` file
248
- is touched upon successful update. Some distros already do this (Ubuntu), but others
249
- simply leave the periodic directory empty (Debian).
250
- '''
251
-
252
- if update:
253
- yield _update(state, host, cache_time=cache_time)
254
-
255
- if upgrade:
256
- yield _upgrade(state, host)
257
-
258
- install_command = 'install'
259
- if no_recommends is True:
260
- install_command += ' --no-install-recommends'
261
- if allow_downgrades:
262
- install_command += ' --allow-downgrades'
263
-
264
- # Compare/ensure packages are present/not
265
- yield ensure_packages(
266
- packages, host.fact.deb_packages, present,
267
- install_command=noninteractive_apt(install_command, force=force),
268
- uninstall_command=noninteractive_apt('remove', force=force),
269
- upgrade_command=noninteractive_apt(install_command, force=force),
270
- version_join='=',
271
- latest=latest,
272
- )
pyinfra/modules/brew.py DELETED
@@ -1,122 +0,0 @@
1
- '''
2
- Mange brew packages.
3
- '''
4
-
5
- from pyinfra.api import operation
6
-
7
- from .util.packaging import ensure_packages
8
-
9
-
10
- @operation
11
- def update(state, host):
12
- '''
13
- Updates brew repositories.
14
- '''
15
-
16
- yield 'brew update'
17
-
18
- _update = update # noqa: E305
19
-
20
-
21
- @operation
22
- def upgrade(state, host):
23
- '''
24
- Upgrades all brew packages.
25
- '''
26
-
27
- yield 'brew upgrade'
28
-
29
- _upgrade = upgrade # noqa: E305
30
-
31
-
32
- @operation
33
- def packages(
34
- state, host,
35
- packages=None, present=True, latest=False,
36
- update=False, upgrade=False,
37
- ):
38
- '''
39
- Add/remove/update brew packages.
40
-
41
- + packages: list of packages to ensure
42
- + present: whether the packages should be installed
43
- + latest: whether to upgrade packages without a specified version
44
- + update: run brew update before installing packages
45
- + upgrade: run brew upgrade before installing packages
46
-
47
- Versions:
48
- Package versions can be pinned like brew: ``<pkg>@<version>``.
49
- '''
50
-
51
- if update:
52
- yield _update(state, host)
53
-
54
- if upgrade:
55
- yield _upgrade(state, host)
56
-
57
- yield ensure_packages(
58
- packages, host.fact.brew_packages, present,
59
- install_command='brew install',
60
- uninstall_command='brew uninstall',
61
- upgrade_command='brew upgrade',
62
- version_join='@',
63
- latest=latest,
64
- )
65
-
66
-
67
- @operation
68
- def cask_upgrade(state, host):
69
- '''
70
- Upgrades all brew casks.
71
- '''
72
-
73
- yield 'brew cask upgrade'
74
-
75
-
76
- @operation
77
- def casks(
78
- state, host,
79
- packages=None, present=True, latest=False, upgrade=False,
80
- ):
81
- '''
82
- Add/remove/update brew casks.
83
-
84
- + packages: list of packages to ensure
85
- + present: whether the packages should be installed
86
- + latest: whether to upgrade packages without a specified version
87
- + upgrade: run brew cask upgrade before installing packages
88
-
89
- Versions:
90
- Package versions can be pinned like brew: ``<pkg>@<version>``.
91
- '''
92
-
93
- if upgrade:
94
- yield cask_upgrade(state, host)
95
-
96
- yield ensure_packages(
97
- packages, host.fact.brew_casks, present,
98
- install_command='brew cask install',
99
- uninstall_command='brew cask uninstall',
100
- upgrade_command='brew cask upgrade',
101
- version_join='@',
102
- latest=latest,
103
- )
104
-
105
-
106
- @operation
107
- def tap(state, host, name, present=True):
108
- '''
109
- Add/remove brew taps.
110
-
111
- + name: the name of the tasp
112
- + present: whether this tap should be present or not
113
- '''
114
-
115
- taps = host.fact.brew_taps
116
- is_tapped = name in taps
117
-
118
- if present and not is_tapped:
119
- yield 'brew tap {0}'.format(name)
120
-
121
- elif not present and is_tapped:
122
- yield 'brew untap {0}'.format(name)