pyinfra 3.0.dev0__py2.py3-none-any.whl → 3.0.2__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 +115 -97
- pyinfra/api/arguments_typed.py +80 -0
- pyinfra/api/command.py +5 -3
- pyinfra/api/config.py +139 -39
- pyinfra/api/connectors.py +5 -2
- pyinfra/api/deploy.py +19 -19
- pyinfra/api/exceptions.py +35 -4
- pyinfra/api/facts.py +62 -86
- pyinfra/api/host.py +102 -15
- pyinfra/api/inventory.py +4 -0
- pyinfra/api/operation.py +188 -120
- pyinfra/api/operations.py +66 -113
- pyinfra/api/state.py +53 -34
- pyinfra/api/util.py +64 -33
- pyinfra/connectors/base.py +65 -20
- pyinfra/connectors/chroot.py +15 -13
- pyinfra/connectors/docker.py +62 -72
- pyinfra/connectors/dockerssh.py +20 -19
- pyinfra/connectors/local.py +32 -22
- pyinfra/connectors/ssh.py +162 -86
- pyinfra/connectors/sshuserclient/client.py +1 -1
- pyinfra/connectors/terraform.py +57 -39
- pyinfra/connectors/util.py +26 -27
- pyinfra/connectors/vagrant.py +27 -26
- pyinfra/context.py +1 -0
- pyinfra/facts/apk.py +7 -2
- pyinfra/facts/apt.py +15 -7
- pyinfra/facts/brew.py +28 -13
- pyinfra/facts/bsdinit.py +9 -6
- pyinfra/facts/cargo.py +6 -3
- pyinfra/facts/choco.py +8 -4
- pyinfra/facts/deb.py +21 -9
- pyinfra/facts/dnf.py +11 -6
- pyinfra/facts/docker.py +30 -5
- pyinfra/facts/files.py +49 -33
- pyinfra/facts/gem.py +7 -2
- pyinfra/facts/git.py +14 -21
- pyinfra/facts/gpg.py +4 -1
- pyinfra/facts/hardware.py +186 -138
- pyinfra/facts/launchd.py +7 -2
- pyinfra/facts/lxd.py +8 -2
- pyinfra/facts/mysql.py +19 -12
- pyinfra/facts/npm.py +3 -1
- pyinfra/facts/openrc.py +8 -2
- pyinfra/facts/pacman.py +13 -5
- pyinfra/facts/pip.py +2 -0
- pyinfra/facts/pkg.py +5 -1
- pyinfra/facts/pkgin.py +7 -2
- pyinfra/facts/postgres.py +170 -0
- pyinfra/facts/postgresql.py +5 -162
- pyinfra/facts/rpm.py +21 -15
- pyinfra/facts/runit.py +70 -0
- pyinfra/facts/selinux.py +12 -4
- pyinfra/facts/server.py +240 -82
- pyinfra/facts/snap.py +8 -2
- pyinfra/facts/systemd.py +37 -13
- pyinfra/facts/sysvinit.py +7 -4
- pyinfra/facts/upstart.py +7 -2
- pyinfra/facts/util/packaging.py +3 -2
- pyinfra/facts/vzctl.py +8 -4
- pyinfra/facts/xbps.py +7 -2
- pyinfra/facts/yum.py +10 -5
- pyinfra/facts/zypper.py +9 -4
- pyinfra/operations/apk.py +5 -3
- pyinfra/operations/apt.py +28 -25
- pyinfra/operations/brew.py +60 -29
- pyinfra/operations/bsdinit.py +6 -4
- pyinfra/operations/cargo.py +3 -1
- pyinfra/operations/choco.py +3 -1
- pyinfra/operations/dnf.py +16 -20
- pyinfra/operations/docker.py +339 -0
- pyinfra/operations/files.py +187 -168
- pyinfra/operations/gem.py +3 -1
- pyinfra/operations/git.py +23 -25
- pyinfra/operations/iptables.py +33 -25
- pyinfra/operations/launchd.py +5 -6
- pyinfra/operations/lxd.py +7 -4
- pyinfra/operations/mysql.py +59 -55
- pyinfra/operations/npm.py +8 -1
- pyinfra/operations/openrc.py +5 -3
- pyinfra/operations/pacman.py +6 -7
- pyinfra/operations/pip.py +19 -12
- pyinfra/operations/pkg.py +3 -1
- pyinfra/operations/pkgin.py +5 -3
- pyinfra/operations/postgres.py +349 -0
- pyinfra/operations/postgresql.py +18 -335
- pyinfra/operations/puppet.py +3 -1
- pyinfra/operations/python.py +8 -19
- pyinfra/operations/runit.py +182 -0
- pyinfra/operations/selinux.py +47 -29
- pyinfra/operations/server.py +138 -67
- pyinfra/operations/snap.py +3 -1
- pyinfra/operations/ssh.py +18 -16
- pyinfra/operations/systemd.py +18 -12
- pyinfra/operations/sysvinit.py +7 -5
- pyinfra/operations/upstart.py +7 -5
- pyinfra/operations/util/__init__.py +12 -0
- pyinfra/operations/util/docker.py +177 -0
- pyinfra/operations/util/files.py +24 -16
- pyinfra/operations/util/packaging.py +54 -38
- pyinfra/operations/util/service.py +39 -47
- pyinfra/operations/vzctl.py +12 -10
- pyinfra/operations/xbps.py +5 -3
- pyinfra/operations/yum.py +15 -19
- pyinfra/operations/zypper.py +9 -10
- pyinfra/version.py +5 -2
- {pyinfra-3.0.dev0.dist-info → pyinfra-3.0.2.dist-info}/METADATA +51 -58
- pyinfra-3.0.2.dist-info/RECORD +168 -0
- {pyinfra-3.0.dev0.dist-info → pyinfra-3.0.2.dist-info}/WHEEL +1 -1
- {pyinfra-3.0.dev0.dist-info → pyinfra-3.0.2.dist-info}/entry_points.txt +0 -3
- pyinfra_cli/__main__.py +4 -3
- pyinfra_cli/commands.py +3 -2
- pyinfra_cli/exceptions.py +75 -43
- pyinfra_cli/inventory.py +52 -31
- pyinfra_cli/log.py +10 -2
- pyinfra_cli/main.py +88 -65
- pyinfra_cli/prints.py +37 -109
- pyinfra_cli/util.py +15 -10
- tests/test_api/test_api.py +2 -0
- tests/test_api/test_api_arguments.py +9 -9
- tests/test_api/test_api_deploys.py +15 -19
- tests/test_api/test_api_facts.py +4 -5
- tests/test_api/test_api_operations.py +18 -20
- tests/test_api/test_api_util.py +41 -2
- tests/test_cli/test_cli.py +14 -50
- tests/test_cli/test_cli_deploy.py +17 -14
- tests/test_cli/test_cli_exceptions.py +50 -19
- tests/test_cli/test_cli_inventory.py +66 -0
- tests/test_cli/util.py +1 -1
- tests/test_connectors/test_dockerssh.py +11 -8
- tests/test_connectors/test_ssh.py +88 -23
- tests/test_connectors/test_sshuserclient.py +1 -1
- tests/test_connectors/test_terraform.py +11 -8
- tests/test_connectors/test_vagrant.py +6 -6
- pyinfra/connectors/ansible.py +0 -175
- pyinfra/connectors/mech.py +0 -189
- pyinfra/connectors/pyinfrawinrmsession/__init__.py +0 -28
- pyinfra/connectors/winrm.py +0 -312
- 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 -538
- pyinfra-3.0.dev0.dist-info/RECORD +0 -170
- tests/test_connectors/test_ansible.py +0 -64
- tests/test_connectors/test_mech.py +0 -126
- {pyinfra-3.0.dev0.dist-info → pyinfra-3.0.2.dist-info}/LICENSE.md +0 -0
- {pyinfra-3.0.dev0.dist-info → pyinfra-3.0.2.dist-info}/top_level.txt +0 -0
pyinfra/facts/windows.py
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
|
|
4
|
-
from dateutil.parser import parse as parse_date
|
|
5
|
-
|
|
6
|
-
from pyinfra.api import FactBase
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class Home(FactBase):
|
|
10
|
-
"""
|
|
11
|
-
Returns the home directory of the current user.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
command = "echo %HOMEPATH%"
|
|
15
|
-
shell_executable = "cmd"
|
|
16
|
-
|
|
17
|
-
@staticmethod
|
|
18
|
-
def process(output):
|
|
19
|
-
return "".join(output).replace("\n", "")
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class Hostname(FactBase):
|
|
23
|
-
"""
|
|
24
|
-
Returns the current hostname of the server.
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
command = "hostname"
|
|
28
|
-
|
|
29
|
-
@staticmethod
|
|
30
|
-
def process(output):
|
|
31
|
-
return "".join(output).replace("\n", "")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class LastReboot(FactBase):
|
|
35
|
-
"""
|
|
36
|
-
Returns the date and time of the last reboot.
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
command = (
|
|
40
|
-
"Get-CimInstance -ClassName Win32_OperatingSystem | "
|
|
41
|
-
"Select -ExpandProperty LastBootUptime"
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
@staticmethod
|
|
45
|
-
def process(output):
|
|
46
|
-
return "".join(output).replace("\n", "")
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class Os(FactBase):
|
|
50
|
-
"""
|
|
51
|
-
Returns the OS name according to ``systeminfo``.
|
|
52
|
-
"""
|
|
53
|
-
|
|
54
|
-
command = 'systeminfo.exe | findstr /c:"OS Name:"'
|
|
55
|
-
|
|
56
|
-
@staticmethod
|
|
57
|
-
def process(output):
|
|
58
|
-
new_output = ""
|
|
59
|
-
match = re.match("OS Name:[ ]*(.*)", output[0])
|
|
60
|
-
if match:
|
|
61
|
-
new_output = match.group(1)
|
|
62
|
-
return new_output
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class Bios(FactBase):
|
|
66
|
-
"""
|
|
67
|
-
Returns the BIOS info.
|
|
68
|
-
"""
|
|
69
|
-
|
|
70
|
-
command = "Get-CimInstance -ClassName Win32_BIOS"
|
|
71
|
-
|
|
72
|
-
@staticmethod
|
|
73
|
-
def process(output):
|
|
74
|
-
bios = {}
|
|
75
|
-
for line in output:
|
|
76
|
-
line_data = line.split(":")
|
|
77
|
-
if len(line_data) > 1:
|
|
78
|
-
bios.update({line_data[0].strip(): line_data[1].strip()})
|
|
79
|
-
return bios
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def _format_windows(output):
|
|
83
|
-
lines = {}
|
|
84
|
-
for line in output:
|
|
85
|
-
# split line on ':'
|
|
86
|
-
line_data = line.split(":")
|
|
87
|
-
if len(line_data) > 1:
|
|
88
|
-
# we have a data line
|
|
89
|
-
this_key = line_data[0].strip()
|
|
90
|
-
this_data = line_data[1].strip()
|
|
91
|
-
if len(line_data) > 2:
|
|
92
|
-
# there was a ':' in the data, so reconstitute the value
|
|
93
|
-
this_data = ":".join(line_data[1:]).strip()
|
|
94
|
-
lines[this_key] = this_data
|
|
95
|
-
return lines
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def _format_windows_for_key(primary_key, output, return_primary_key=True):
|
|
99
|
-
"""Format the windows powershell output that uses 'Format-Line'
|
|
100
|
-
into a dict of dicts.
|
|
101
|
-
"""
|
|
102
|
-
primary_key = primary_key.strip()
|
|
103
|
-
lines = {}
|
|
104
|
-
one_item = {}
|
|
105
|
-
key_value = ""
|
|
106
|
-
for line in output:
|
|
107
|
-
# split line on ':'
|
|
108
|
-
line_data = line.split(":")
|
|
109
|
-
if len(line_data) > 1:
|
|
110
|
-
# we have a data line
|
|
111
|
-
this_key = line_data[0].strip()
|
|
112
|
-
this_data = line_data[1].strip()
|
|
113
|
-
if len(line_data) > 2:
|
|
114
|
-
# there was a ':' in the data, so reconstitute the value
|
|
115
|
-
this_data = ":".join(line_data[1:]).strip()
|
|
116
|
-
if this_key != primary_key:
|
|
117
|
-
one_item.update({this_key: this_data})
|
|
118
|
-
else:
|
|
119
|
-
key_value = this_data
|
|
120
|
-
else:
|
|
121
|
-
if line == "":
|
|
122
|
-
if one_item:
|
|
123
|
-
lines[key_value] = one_item
|
|
124
|
-
one_item = {}
|
|
125
|
-
key_value = ""
|
|
126
|
-
else:
|
|
127
|
-
# append this_data to the existing entry
|
|
128
|
-
this_data = line.strip()
|
|
129
|
-
appended_data = one_item[this_key] + this_data
|
|
130
|
-
one_item.update({this_key: appended_data})
|
|
131
|
-
if return_primary_key:
|
|
132
|
-
return {primary_key: lines}
|
|
133
|
-
return lines
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
class Processors(FactBase):
|
|
137
|
-
"""
|
|
138
|
-
Returns the processors info.
|
|
139
|
-
"""
|
|
140
|
-
|
|
141
|
-
command = "Get-CimInstance -ClassName Win32_Processor | Format-List -Property *"
|
|
142
|
-
|
|
143
|
-
@staticmethod
|
|
144
|
-
def process(output):
|
|
145
|
-
return _format_windows_for_key("DeviceID", output)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
class OsVersion(FactBase):
|
|
149
|
-
"""
|
|
150
|
-
Returns the OS version according to ``systeminfo``.
|
|
151
|
-
"""
|
|
152
|
-
|
|
153
|
-
command = 'systeminfo | findstr /c:"OS Version:"'
|
|
154
|
-
|
|
155
|
-
@staticmethod
|
|
156
|
-
def process(output):
|
|
157
|
-
new_output = ""
|
|
158
|
-
match = re.match("OS Version:[ ]*(.*)", output[0])
|
|
159
|
-
if match:
|
|
160
|
-
new_output = match.group(1)
|
|
161
|
-
return new_output
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
class SystemType(FactBase):
|
|
165
|
-
"""
|
|
166
|
-
Returns the system type according to ``systeminfo``.
|
|
167
|
-
"""
|
|
168
|
-
|
|
169
|
-
command = 'systeminfo | findstr /c:"System Type:"'
|
|
170
|
-
|
|
171
|
-
@staticmethod
|
|
172
|
-
def process(output):
|
|
173
|
-
new_output = ""
|
|
174
|
-
match = re.match("System Type:[ ]*(.*)", output[0])
|
|
175
|
-
if match:
|
|
176
|
-
new_output = match.group(1)
|
|
177
|
-
return new_output
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
class Date(FactBase):
|
|
181
|
-
"""
|
|
182
|
-
Returns the current datetime on the server.
|
|
183
|
-
"""
|
|
184
|
-
|
|
185
|
-
command = "echo %date%-%time%"
|
|
186
|
-
shell_executable = "cmd"
|
|
187
|
-
default = datetime.now
|
|
188
|
-
|
|
189
|
-
@staticmethod
|
|
190
|
-
def process(output):
|
|
191
|
-
new_output = "".join(output)
|
|
192
|
-
return parse_date(new_output)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
class LocalGroups(FactBase):
|
|
196
|
-
"""
|
|
197
|
-
Returns a list of groups on the system.
|
|
198
|
-
"""
|
|
199
|
-
|
|
200
|
-
command = "net localgroup | findstr [^*]"
|
|
201
|
-
|
|
202
|
-
default = list
|
|
203
|
-
|
|
204
|
-
@staticmethod
|
|
205
|
-
def process(output):
|
|
206
|
-
groups = []
|
|
207
|
-
for group in output:
|
|
208
|
-
# Note: If run this command thru ps, there are headers/footer.
|
|
209
|
-
# remove empty groups and those groups that are not local
|
|
210
|
-
if group != "" and group[0] == "*":
|
|
211
|
-
groups.append(group)
|
|
212
|
-
return groups
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
class Where(FactBase):
|
|
216
|
-
"""
|
|
217
|
-
Returns the full path for a command, if available.
|
|
218
|
-
"""
|
|
219
|
-
|
|
220
|
-
shell_executable = "cmd"
|
|
221
|
-
|
|
222
|
-
@staticmethod
|
|
223
|
-
def command(name):
|
|
224
|
-
return "where {0}".format(name)
|
|
225
|
-
|
|
226
|
-
@staticmethod
|
|
227
|
-
def process(output):
|
|
228
|
-
return output[0].rstrip()
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
class Hotfixes(FactBase):
|
|
232
|
-
"""
|
|
233
|
-
Returns the Windows hotfixes.
|
|
234
|
-
"""
|
|
235
|
-
|
|
236
|
-
command = "Get-CimInstance -ClassName Win32_QuickFixEngineering | Format-List -Property *"
|
|
237
|
-
|
|
238
|
-
@staticmethod
|
|
239
|
-
def process(output):
|
|
240
|
-
return _format_windows_for_key("HotFixID", output)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
class LocalDrivesInfo(FactBase):
|
|
244
|
-
"""
|
|
245
|
-
Returns the Windows local drives info.
|
|
246
|
-
"""
|
|
247
|
-
|
|
248
|
-
command = (
|
|
249
|
-
'Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" '
|
|
250
|
-
"| Format-List -Property *"
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
@staticmethod
|
|
254
|
-
def process(output):
|
|
255
|
-
return _format_windows_for_key("DeviceID", output)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
class LoggedInUserInfo(FactBase):
|
|
259
|
-
"""
|
|
260
|
-
Returns the Windows user logged in info.
|
|
261
|
-
"""
|
|
262
|
-
|
|
263
|
-
command = (
|
|
264
|
-
"Get-CimInstance -ClassName Win32_ComputerSystem -Property UserName "
|
|
265
|
-
"| Format-List -Property *"
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
@staticmethod
|
|
269
|
-
def process(output):
|
|
270
|
-
return _format_windows_for_key("Name", output)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
class LogonSessionInfo(FactBase):
|
|
274
|
-
"""
|
|
275
|
-
Returns the Windows user logon session info.
|
|
276
|
-
"""
|
|
277
|
-
|
|
278
|
-
command = "Get-CimInstance -ClassName Win32_LogonSession | Format-List -Property *"
|
|
279
|
-
|
|
280
|
-
@staticmethod
|
|
281
|
-
def process(output):
|
|
282
|
-
return _format_windows_for_key("LogonId", output)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
class Aliases(FactBase):
|
|
286
|
-
"""
|
|
287
|
-
Returns the Windows aliases.
|
|
288
|
-
"""
|
|
289
|
-
|
|
290
|
-
command = "Get-Alias | Format-List -Property *"
|
|
291
|
-
|
|
292
|
-
@staticmethod
|
|
293
|
-
def process(output):
|
|
294
|
-
return _format_windows_for_key("Name", output)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
class Services(FactBase):
|
|
298
|
-
"""
|
|
299
|
-
Returns the Windows services.
|
|
300
|
-
"""
|
|
301
|
-
|
|
302
|
-
command = "Get-CimInstance -ClassName Win32_Service | Format-List -Property *"
|
|
303
|
-
|
|
304
|
-
@staticmethod
|
|
305
|
-
def process(output):
|
|
306
|
-
return _format_windows_for_key("Name", output)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
class Service(FactBase):
|
|
310
|
-
"""
|
|
311
|
-
Returns info about a Windows service.
|
|
312
|
-
"""
|
|
313
|
-
|
|
314
|
-
def command(self, name):
|
|
315
|
-
return "Get-Service -Name {} | Format-List -Property *".format(name)
|
|
316
|
-
|
|
317
|
-
def process(self, output):
|
|
318
|
-
return _format_windows_for_key("Name", output, return_primary_key=False)
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
class Processes(FactBase):
|
|
322
|
-
"""
|
|
323
|
-
Returns the Windows processes.
|
|
324
|
-
"""
|
|
325
|
-
|
|
326
|
-
command = "Get-Process | Format-List -Property *"
|
|
327
|
-
|
|
328
|
-
@staticmethod
|
|
329
|
-
def process(output):
|
|
330
|
-
return _format_windows_for_key("Id", output)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
class NetworkConfiguration(FactBase):
|
|
334
|
-
"""
|
|
335
|
-
Returns the Windows network configuration.
|
|
336
|
-
"""
|
|
337
|
-
|
|
338
|
-
command = "Get-CimInstance -Class Win32_NetworkAdapterConfiguration | Format-List -Property *"
|
|
339
|
-
|
|
340
|
-
@staticmethod
|
|
341
|
-
def process(output):
|
|
342
|
-
return _format_windows_for_key("Index", output)
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
class InstallerApplications(FactBase):
|
|
346
|
-
"""
|
|
347
|
-
Returns the Windows installer applications.
|
|
348
|
-
"""
|
|
349
|
-
|
|
350
|
-
command = "Get-CimInstance -Class Win32_Product | Format-List -Property *"
|
|
351
|
-
|
|
352
|
-
@staticmethod
|
|
353
|
-
def process(output):
|
|
354
|
-
return _format_windows_for_key("IdentifyingNumber", output)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
class ComputerInfo(FactBase):
|
|
358
|
-
"""
|
|
359
|
-
Returns the Windows info.
|
|
360
|
-
"""
|
|
361
|
-
|
|
362
|
-
command = "Get-ComputerInfo | Format-List -Property *"
|
|
363
|
-
|
|
364
|
-
@staticmethod
|
|
365
|
-
def process(output):
|
|
366
|
-
return _format_windows(output)
|
pyinfra/facts/windows_files.py
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
from pyinfra.api.facts import FactBase
|
|
2
|
-
|
|
3
|
-
from .util.win_files import parse_win_ls_output
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class File(FactBase):
|
|
7
|
-
# Types must match WIN_FLAG_TO_TYPE in .util.win_files.py
|
|
8
|
-
type = "file"
|
|
9
|
-
shell_executable = "ps"
|
|
10
|
-
|
|
11
|
-
def command(self, path):
|
|
12
|
-
self.path = path
|
|
13
|
-
return ('if (Test-Path "{0}") {{ Get-ItemProperty -Path "{0}" }}').format(path)
|
|
14
|
-
|
|
15
|
-
def process(self, output):
|
|
16
|
-
if len(output) < 7:
|
|
17
|
-
return None
|
|
18
|
-
|
|
19
|
-
# Note: The first 7 lines are header lines
|
|
20
|
-
return parse_win_ls_output(output[7], self.type)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class Link(File):
|
|
24
|
-
# Types must match WIN_FLAG_TO_TYPE in .util.win_files.py
|
|
25
|
-
type = "link"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class Directory(File):
|
|
29
|
-
# Types must match WIN_FLAG_TO_TYPE in .util.win_files.py
|
|
30
|
-
type = "directory"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class TempDir(FactBase):
|
|
34
|
-
# Types must match WIN_FLAG_TO_TYPE in .util.win_files.py
|
|
35
|
-
type = "directory"
|
|
36
|
-
shell_executable = "ps"
|
|
37
|
-
|
|
38
|
-
def command(self):
|
|
39
|
-
return "[System.IO.Path]::GetTempPath()"
|
|
40
|
-
|
|
41
|
-
def process(self, output):
|
|
42
|
-
return output[0]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class Sha1File(FactBase):
|
|
46
|
-
"""
|
|
47
|
-
Returns a SHA1 hash of a file.
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
shell_executable = "ps"
|
|
51
|
-
|
|
52
|
-
def command(self, path):
|
|
53
|
-
return (
|
|
54
|
-
'if (Test-Path "{0}") {{ ' '(Get-FileHash -Algorithm SHA1 "{0}").hash' " }}"
|
|
55
|
-
).format(path)
|
|
56
|
-
|
|
57
|
-
def process(self, output):
|
|
58
|
-
return output[0] if not output else None
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
class Sha256File(FactBase):
|
|
62
|
-
"""
|
|
63
|
-
Returns a SHA256 hash of a file.
|
|
64
|
-
"""
|
|
65
|
-
|
|
66
|
-
shell_executable = "ps"
|
|
67
|
-
|
|
68
|
-
def command(self, path):
|
|
69
|
-
return (
|
|
70
|
-
'if (Test-Path "{0}") {{ ' '(Get-FileHash -Algorithm SHA256 "{0}").hash' " }}"
|
|
71
|
-
).format(path)
|
|
72
|
-
|
|
73
|
-
def process(self, output):
|
|
74
|
-
return output[0] if len(output[0]) > 0 else None
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class Md5File(FactBase):
|
|
78
|
-
"""
|
|
79
|
-
Returns an MD5 hash of a file.
|
|
80
|
-
"""
|
|
81
|
-
|
|
82
|
-
shell_executable = "ps"
|
|
83
|
-
|
|
84
|
-
def command(self, path):
|
|
85
|
-
return ('if (Test-Path "{0}") {{ ' '(Get-FileHash -Algorithm MD5 "{0}").hash' " }}").format(
|
|
86
|
-
path,
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
def process(self, output):
|
|
90
|
-
return output[0] if len(output[0]) > 0 else None
|
pyinfra/operations/windows.py
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
The windows module handles misc windows operations.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from pyinfra.api import operation
|
|
6
|
-
|
|
7
|
-
# Tip: Use 'Get-Command -Noun Service' to search for what commands are available or
|
|
8
|
-
# simply 'Get-Command' to see what you can do...)
|
|
9
|
-
|
|
10
|
-
# Tip: To see the windows help page about a command, use 'Get-Help'.
|
|
11
|
-
# Might have to run 'Update-Help' if you want to use arguments like '-Examples'.
|
|
12
|
-
# ex: 'Get-Help Stop-Service'
|
|
13
|
-
# ex: 'Get-Help Stop-Service -Examples'
|
|
14
|
-
# ex: 'Get-Help Stop-Service -Detailed'
|
|
15
|
-
# ex: 'Get-Help Stop-Service -Full'
|
|
16
|
-
|
|
17
|
-
# FUTURE: add ability to stop processes (ex: "Stop-Process <id>")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@operation(is_idempotent=False)
|
|
21
|
-
def service(service, running=True, restart=False, suspend=False):
|
|
22
|
-
"""
|
|
23
|
-
Stop/Start a Windows service.
|
|
24
|
-
|
|
25
|
-
+ service: name of the service to manage
|
|
26
|
-
+ running: whether the the service should be running or stopped
|
|
27
|
-
+ restart: whether the the service should be restarted
|
|
28
|
-
+ suspend: whether the the service should be suspended
|
|
29
|
-
|
|
30
|
-
**Example:**
|
|
31
|
-
|
|
32
|
-
.. code:: python
|
|
33
|
-
|
|
34
|
-
windows.service(
|
|
35
|
-
name="Stop the spooler service",
|
|
36
|
-
service="service",
|
|
37
|
-
running=False,
|
|
38
|
-
)
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
if suspend or not running:
|
|
42
|
-
if suspend:
|
|
43
|
-
yield "Suspend-Service -Name {0}".format(service)
|
|
44
|
-
else:
|
|
45
|
-
yield "Stop-Service -Name {0}".format(service)
|
|
46
|
-
else:
|
|
47
|
-
if restart:
|
|
48
|
-
yield "Restart-Service -Name {0}".format(service)
|
|
49
|
-
else:
|
|
50
|
-
if running:
|
|
51
|
-
yield "Start-Service -Name {0}".format(service)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@operation(is_idempotent=False)
|
|
55
|
-
def reboot():
|
|
56
|
-
"""
|
|
57
|
-
Restart the server.
|
|
58
|
-
"""
|
|
59
|
-
yield "Restart-Computer -Force"
|