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
@@ -1,178 +0,0 @@
1
- import os
2
-
3
- from tempfile import mkstemp
4
-
5
- import click
6
-
7
- import pyinfra
8
-
9
- from pyinfra import local, logger
10
- from pyinfra.api.exceptions import InventoryError
11
- from pyinfra.api.util import get_file_io, memoize
12
- from pyinfra.progress import progress_spinner
13
-
14
- from .local import run_shell_command as run_local_shell_command
15
-
16
-
17
- @memoize
18
- def show_warning():
19
- logger.warning('The @docker connector is in Alpha!')
20
-
21
-
22
- def make_names_data(image=None):
23
- if not image:
24
- raise InventoryError('No docker base image provided!')
25
-
26
- show_warning()
27
-
28
- # Save the image as the hostname, no data, @docker group
29
- yield image, {}, ['@docker']
30
-
31
-
32
- def connect(state, host, for_fact=None):
33
- if 'docker_container_id' in host.host_data: # user can provide a docker_container_id
34
- return True
35
-
36
- with progress_spinner({'docker run'}):
37
- container_id = local.shell(
38
- 'docker run -d {0} sleep 10000'.format(host.name),
39
- splitlines=True,
40
- )[-1] # last line is the container ID
41
-
42
- host.host_data['docker_container_id'] = container_id
43
- return True
44
-
45
-
46
- def disconnect(state, host):
47
- if not pyinfra.is_cli:
48
- return
49
-
50
- container_id = host.host_data['docker_container_id'][:12]
51
-
52
- with progress_spinner({'docker commit'}):
53
- image_id = local.shell(
54
- 'docker commit {0}'.format(container_id),
55
- splitlines=True,
56
- )[-1][7:19] # last line is the image ID, get sha256:[XXXXXXXXXX]...
57
-
58
- with progress_spinner({'docker rm'}):
59
- local.shell(
60
- 'docker rm -f {0}'.format(container_id),
61
- )
62
-
63
- logger.info('{0}docker build complete, image ID: {1}'.format(
64
- host.print_prefix, click.style(image_id, bold=True),
65
- ))
66
-
67
-
68
- def run_shell_command(
69
- state, host, command,
70
- timeout=None, print_output=False,
71
- return_combined_output=False,
72
- **kwargs # ignored (sudo/etc)
73
- ):
74
- container_id = host.host_data['docker_container_id']
75
- docker_command = 'docker exec {0} sh -c "{1}"'.format(container_id, command)
76
-
77
- return run_local_shell_command(
78
- state, host, docker_command,
79
- timeout=timeout,
80
- print_output=print_output,
81
- return_combined_output=return_combined_output,
82
- )
83
-
84
-
85
- def put_file(
86
- state, host, filename_or_io, remote_filename,
87
- print_output=False,
88
- **kwargs # ignored (sudo/etc)
89
- ):
90
- '''
91
- Upload a file/IO object to the target Docker container by copying it to a
92
- temporary location and then uploading it into the container using ``docker cp``.
93
- '''
94
-
95
- _, temp_filename = mkstemp()
96
-
97
- try:
98
- # Load our file or IO object and write it to the temporary file
99
- with get_file_io(filename_or_io) as file_io:
100
- with open(temp_filename, 'wb') as temp_f:
101
- data = file_io.read()
102
-
103
- if isinstance(data, str):
104
- data = data.encode()
105
-
106
- temp_f.write(data)
107
-
108
- docker_id = host.host_data['docker_container_id']
109
- docker_command = 'docker cp {0} {1}:{2}'.format(
110
- temp_filename,
111
- docker_id,
112
- remote_filename,
113
- )
114
-
115
- status, _, stderr = run_local_shell_command(
116
- state, host, docker_command,
117
- print_output=print_output,
118
- )
119
- finally:
120
- os.remove(temp_filename)
121
-
122
- if not status:
123
- raise IOError('\n'.join(stderr))
124
-
125
- if print_output:
126
- print('{0}file uploaded to container: {1}'.format(
127
- host.print_prefix, remote_filename,
128
- ))
129
-
130
- return status
131
-
132
-
133
- def get_file(
134
- state, host, remote_filename, filename_or_io,
135
- print_output=False,
136
- **kwargs # ignored (sudo/etc)
137
- ):
138
- '''
139
- Download a file from the target Docker container by copying it to a temporary
140
- location and then reading that into our final file/IO object.
141
- '''
142
-
143
- _, temp_filename = mkstemp()
144
-
145
- try:
146
- docker_id = host.host_data['docker_container_id']
147
- docker_command = 'docker cp {0}:{1} {2}'.format(
148
- docker_id,
149
- remote_filename,
150
- temp_filename,
151
- )
152
-
153
- status, _, stderr = run_local_shell_command(
154
- state, host, docker_command,
155
- print_output=print_output,
156
- )
157
-
158
- # Load the temporary file and write it to our file or IO object
159
- with open(temp_filename) as temp_f:
160
- with get_file_io(filename_or_io, 'wb') as file_io:
161
- data = temp_f.read()
162
-
163
- if isinstance(data, str):
164
- data = data.encode()
165
-
166
- file_io.write(data)
167
- finally:
168
- os.remove(temp_filename)
169
-
170
- if not status:
171
- raise IOError('\n'.join(stderr))
172
-
173
- if print_output:
174
- print('{0}file downloaded from container: {1}'.format(
175
- host.print_prefix, remote_filename,
176
- ))
177
-
178
- return status
@@ -1,169 +0,0 @@
1
- import os
2
-
3
- from subprocess import PIPE, Popen
4
- from tempfile import mkstemp
5
-
6
- import click
7
-
8
- from pyinfra import logger
9
- from pyinfra.api.util import get_file_io, make_command
10
-
11
- from .util import read_buffers_into_queue, split_combined_output
12
-
13
-
14
- def connect(state, host, for_fact=None):
15
- # Log
16
- log_message = '{0}{1}'.format(
17
- host.print_prefix,
18
- click.style('Connected', 'green'),
19
- )
20
-
21
- if for_fact:
22
- log_message = '{0}{1}'.format(
23
- log_message,
24
- ' (for {0} fact)'.format(for_fact),
25
- )
26
-
27
- logger.info(log_message)
28
-
29
- return True
30
-
31
-
32
- def run_shell_command(
33
- state, host, command,
34
- get_pty=False, timeout=None, print_output=False,
35
- return_combined_output=False,
36
- **command_kwargs
37
- ):
38
- '''
39
- Execute a command on the local machine.
40
-
41
- Args:
42
- state (``pyinfra.api.State`` obj): state object for this command
43
- hostname (string): hostname of the target
44
- command (string): actual command to execute
45
- sudo (boolean): whether to wrap the command with sudo
46
- sudo_user (string): user to sudo to
47
- get_pty (boolean): whether to get a PTY before executing the command
48
- env (dict): envrionment variables to set
49
- timeout (int): timeout for this command to complete before erroring
50
-
51
- Returns:
52
- tuple: (exit_code, stdout, stderr)
53
- stdout and stderr are both lists of strings from each buffer.
54
- '''
55
-
56
- command = make_command(command, **command_kwargs)
57
-
58
- logger.debug('--> Running command on localhost: {0}'.format(command))
59
-
60
- if print_output:
61
- print('{0}>>> {1}'.format(host.print_prefix, command))
62
-
63
- process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
64
-
65
- combined_output = read_buffers_into_queue(
66
- host,
67
- process.stdout,
68
- process.stderr,
69
- timeout=timeout,
70
- print_output=print_output,
71
- )
72
-
73
- logger.debug('--> Waiting for exit status...')
74
- process.wait()
75
- logger.debug('--> Command exit status: {0}'.format(process.returncode))
76
-
77
- # Close any open file descriptors
78
- process.stdout.close()
79
- process.stderr.close()
80
-
81
- status = process.returncode == 0
82
-
83
- if return_combined_output:
84
- return status, combined_output
85
-
86
- stdout, stderr = split_combined_output(combined_output)
87
- return status, stdout, stderr
88
-
89
-
90
- def put_file(
91
- state, host, filename_or_io, remote_filename,
92
- print_output=False,
93
- **command_kwargs
94
- ):
95
- '''
96
- Upload a local file or IO object by copying it to a temporary directory
97
- and then writing it to the upload location.
98
- '''
99
-
100
- _, temp_filename = mkstemp()
101
-
102
- try:
103
- # Load our file or IO object and write it to the temporary file
104
- with get_file_io(filename_or_io) as file_io:
105
- with open(temp_filename, 'wb') as temp_f:
106
- data = file_io.read()
107
-
108
- if isinstance(data, str):
109
- data = data.encode()
110
-
111
- temp_f.write(data)
112
-
113
- # Copy the file using `cp` such that we support sudo/su
114
- status, _, stderr = run_shell_command(
115
- state, host, 'cp {0} {1}'.format(temp_filename, remote_filename),
116
- print_output=print_output,
117
- **command_kwargs
118
- )
119
-
120
- if not status:
121
- raise IOError('\n'.join(stderr))
122
- finally:
123
- os.remove(temp_filename)
124
-
125
- if print_output:
126
- print('{0}file copied: {1}'.format(host.print_prefix, remote_filename))
127
-
128
- return status
129
-
130
-
131
- def get_file(
132
- state, host, remote_filename, filename_or_io,
133
- print_output=False,
134
- **command_kwargs
135
- ):
136
- '''
137
- Download a local file by copying it to a temporary location and then writing
138
- it to our filename or IO object.
139
- '''
140
-
141
- _, temp_filename = mkstemp()
142
-
143
- try:
144
- # Copy the file using `cp` such that we support sudo/su
145
- status, _, stderr = run_shell_command(
146
- state, host, 'cp {0} {1}'.format(remote_filename, temp_filename),
147
- print_output=print_output,
148
- **command_kwargs
149
- )
150
-
151
- if not status:
152
- raise IOError('\n'.join(stderr))
153
-
154
- # Load our file or IO object and write it to the temporary file
155
- with open(temp_filename) as temp_f:
156
- with get_file_io(filename_or_io, 'wb') as file_io:
157
- data = temp_f.read()
158
-
159
- if isinstance(data, str):
160
- data = data.encode()
161
-
162
- file_io.write(data)
163
- finally:
164
- os.remove(temp_filename)
165
-
166
- if print_output:
167
- print('{0}file copied: {1}'.format(host.print_prefix, remote_filename))
168
-
169
- return True