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
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
|
|
3
|
-
from os import path
|
|
4
|
-
from queue import Queue
|
|
5
|
-
from threading import Thread
|
|
6
|
-
|
|
7
|
-
from pyinfra import local, logger
|
|
8
|
-
from pyinfra.api.exceptions import InventoryError
|
|
9
|
-
from pyinfra.api.util import memoize
|
|
10
|
-
from pyinfra.progress import progress_spinner
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def _get_vagrant_ssh_config(queue, progress, target):
|
|
14
|
-
logger.debug('Loading SSH config for {0}'.format(target))
|
|
15
|
-
|
|
16
|
-
queue.put(local.shell(
|
|
17
|
-
'vagrant ssh-config {0}'.format(target),
|
|
18
|
-
splitlines=True,
|
|
19
|
-
))
|
|
20
|
-
|
|
21
|
-
progress(target)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@memoize
|
|
25
|
-
def get_vagrant_config(limit=None):
|
|
26
|
-
logger.info('Getting Vagrant config...')
|
|
27
|
-
|
|
28
|
-
if limit and not isinstance(limit, (list, tuple)):
|
|
29
|
-
limit = [limit]
|
|
30
|
-
|
|
31
|
-
with progress_spinner({'vagrant status'}) as progress:
|
|
32
|
-
output = local.shell(
|
|
33
|
-
'vagrant status --machine-readable',
|
|
34
|
-
splitlines=True,
|
|
35
|
-
)
|
|
36
|
-
progress('vagrant status')
|
|
37
|
-
|
|
38
|
-
targets = []
|
|
39
|
-
|
|
40
|
-
for line in output:
|
|
41
|
-
_, target, type_, data = line.split(',', 3)
|
|
42
|
-
|
|
43
|
-
# Skip anything not in the limit
|
|
44
|
-
if limit is not None and target not in limit:
|
|
45
|
-
continue
|
|
46
|
-
|
|
47
|
-
# For each running container - fetch it's SSH config in a thread - this
|
|
48
|
-
# is because Vagrant *really* slow to run each command.
|
|
49
|
-
if type_ == 'state' and data == 'running':
|
|
50
|
-
targets.append(target)
|
|
51
|
-
|
|
52
|
-
threads = []
|
|
53
|
-
config_queue = Queue()
|
|
54
|
-
|
|
55
|
-
with progress_spinner(targets) as progress:
|
|
56
|
-
for target in targets:
|
|
57
|
-
thread = Thread(
|
|
58
|
-
target=_get_vagrant_ssh_config,
|
|
59
|
-
args=(config_queue, progress, target),
|
|
60
|
-
)
|
|
61
|
-
threads.append(thread)
|
|
62
|
-
thread.start()
|
|
63
|
-
|
|
64
|
-
for thread in threads:
|
|
65
|
-
thread.join()
|
|
66
|
-
|
|
67
|
-
queue_items = list(config_queue.queue)
|
|
68
|
-
|
|
69
|
-
lines = []
|
|
70
|
-
for output in queue_items:
|
|
71
|
-
lines.extend(output)
|
|
72
|
-
|
|
73
|
-
return lines
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
@memoize
|
|
77
|
-
def get_vagrant_options():
|
|
78
|
-
if path.exists('@vagrant.json'):
|
|
79
|
-
with open('@vagrant.json', 'r') as f:
|
|
80
|
-
return json.loads(f.read())
|
|
81
|
-
return {}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def _make_name_data(host):
|
|
85
|
-
vagrant_options = get_vagrant_options()
|
|
86
|
-
vagrant_host = host['Host']
|
|
87
|
-
|
|
88
|
-
data = {
|
|
89
|
-
'ssh_hostname': host['HostName'],
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
for config_key, data_key in (
|
|
93
|
-
('Port', 'ssh_port'),
|
|
94
|
-
('User', 'ssh_user'),
|
|
95
|
-
('IdentityFile', 'ssh_key'),
|
|
96
|
-
):
|
|
97
|
-
if config_key in host:
|
|
98
|
-
data[data_key] = host[config_key]
|
|
99
|
-
|
|
100
|
-
# Update any configured JSON data
|
|
101
|
-
if vagrant_host in vagrant_options.get('data', {}):
|
|
102
|
-
data.update(vagrant_options['data'][vagrant_host])
|
|
103
|
-
|
|
104
|
-
# Work out groups
|
|
105
|
-
groups = vagrant_options.get('groups', {}).get(vagrant_host, [])
|
|
106
|
-
|
|
107
|
-
if '@vagrant' not in groups:
|
|
108
|
-
groups.append('@vagrant')
|
|
109
|
-
|
|
110
|
-
return '@vagrant/{0}'.format(host['Host']), data, groups
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def make_names_data(limit=None):
|
|
114
|
-
vagrant_ssh_info = get_vagrant_config(limit)
|
|
115
|
-
|
|
116
|
-
logger.debug('Got Vagrant SSH info: \n{0}'.format(vagrant_ssh_info))
|
|
117
|
-
|
|
118
|
-
hosts = []
|
|
119
|
-
current_host = None
|
|
120
|
-
|
|
121
|
-
for line in vagrant_ssh_info:
|
|
122
|
-
# Vagrant outputs an empty line between each host
|
|
123
|
-
if not line:
|
|
124
|
-
if current_host:
|
|
125
|
-
hosts.append(_make_name_data(current_host))
|
|
126
|
-
|
|
127
|
-
current_host = None
|
|
128
|
-
continue
|
|
129
|
-
|
|
130
|
-
key, value = line.split(' ', 1)
|
|
131
|
-
|
|
132
|
-
if key == 'Host':
|
|
133
|
-
if current_host:
|
|
134
|
-
hosts.append(_make_name_data(current_host))
|
|
135
|
-
|
|
136
|
-
# Set the new host
|
|
137
|
-
current_host = {
|
|
138
|
-
key: value,
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
elif current_host:
|
|
142
|
-
current_host[key] = value
|
|
143
|
-
|
|
144
|
-
else:
|
|
145
|
-
logger.debug('Extra Vagrant SSH key/value ({0}={1})'.format(
|
|
146
|
-
key, value,
|
|
147
|
-
))
|
|
148
|
-
|
|
149
|
-
if current_host:
|
|
150
|
-
hosts.append(_make_name_data(current_host))
|
|
151
|
-
|
|
152
|
-
if not hosts:
|
|
153
|
-
raise InventoryError('No running Vagrant instances found!')
|
|
154
|
-
|
|
155
|
-
return hosts
|
pyinfra/facts/init.py
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
|
|
3
|
-
from pyinfra.api import FactBase
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class UpstartStatus(FactBase):
|
|
7
|
-
'''
|
|
8
|
-
Returns a dict of name -> status for upstart managed services.
|
|
9
|
-
'''
|
|
10
|
-
|
|
11
|
-
command = 'initctl list'
|
|
12
|
-
regex = r'^([a-z\-]+) [a-z]+\/([a-z]+)'
|
|
13
|
-
default = dict
|
|
14
|
-
|
|
15
|
-
def process(self, output):
|
|
16
|
-
services = {}
|
|
17
|
-
|
|
18
|
-
for line in output:
|
|
19
|
-
matches = re.match(self.regex, line)
|
|
20
|
-
if matches:
|
|
21
|
-
services[matches.group(1)] = matches.group(2) == 'running'
|
|
22
|
-
|
|
23
|
-
return services
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class SystemdStatus(FactBase):
|
|
27
|
-
'''
|
|
28
|
-
Returns a dict of name -> status for systemd managed services.
|
|
29
|
-
'''
|
|
30
|
-
|
|
31
|
-
command = 'systemctl -alt service list-units'
|
|
32
|
-
regex = r'^([a-z\-0-9]+)\.service\s+[a-z\-]+\s+[a-z]+\s+([a-z]+)'
|
|
33
|
-
default = dict
|
|
34
|
-
|
|
35
|
-
def process(self, output):
|
|
36
|
-
services = {}
|
|
37
|
-
|
|
38
|
-
for line in output:
|
|
39
|
-
matches = re.match(self.regex, line)
|
|
40
|
-
if matches:
|
|
41
|
-
services[matches.group(1)] = matches.group(2) == 'running'
|
|
42
|
-
|
|
43
|
-
return services
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class SystemdEnabled(FactBase):
|
|
47
|
-
'''
|
|
48
|
-
Returns a dict of name -> whether enabled for systemd managed services.
|
|
49
|
-
'''
|
|
50
|
-
|
|
51
|
-
command = '''
|
|
52
|
-
systemctl --no-legend -alt service list-unit-files | while read -r SERVICE STATUS; do
|
|
53
|
-
if [ "$STATUS" = generated ] &&
|
|
54
|
-
systemctl is-enabled $SERVICE.service >/dev/null 2>&1; then
|
|
55
|
-
STATUS=enabled
|
|
56
|
-
fi
|
|
57
|
-
echo $SERVICE $STATUS
|
|
58
|
-
done
|
|
59
|
-
'''
|
|
60
|
-
|
|
61
|
-
regex = r'^([a-z\-]+)\.service\s+([a-z]+)'
|
|
62
|
-
default = dict
|
|
63
|
-
|
|
64
|
-
def process(self, output):
|
|
65
|
-
services = {}
|
|
66
|
-
|
|
67
|
-
for line in output:
|
|
68
|
-
matches = re.match(self.regex, line)
|
|
69
|
-
if matches:
|
|
70
|
-
services[matches.group(1)] = (
|
|
71
|
-
matches.group(2) in ('enabled', 'static')
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
return services
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class InitdStatus(FactBase):
|
|
78
|
-
'''
|
|
79
|
-
Low level check for every /etc/init.d/* script. Unfortunately many of these
|
|
80
|
-
mishehave and return exit status 0 while also displaying the help info/not
|
|
81
|
-
offering status support.
|
|
82
|
-
|
|
83
|
-
Returns a dict of name -> status.
|
|
84
|
-
|
|
85
|
-
Expected codes found at:
|
|
86
|
-
http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
|
|
87
|
-
'''
|
|
88
|
-
|
|
89
|
-
command = '''
|
|
90
|
-
for SERVICE in `ls /etc/init.d/`; do
|
|
91
|
-
_=`cat /etc/init.d/$SERVICE | grep "### BEGIN INIT INFO"`
|
|
92
|
-
|
|
93
|
-
if [ "$?" = "0" ]; then
|
|
94
|
-
STATUS=`/etc/init.d/$SERVICE status`
|
|
95
|
-
echo "$SERVICE=$?"
|
|
96
|
-
fi
|
|
97
|
-
done
|
|
98
|
-
'''
|
|
99
|
-
|
|
100
|
-
regex = r'([a-zA-Z0-9\-]+)=([0-9]+)'
|
|
101
|
-
default = dict
|
|
102
|
-
|
|
103
|
-
def process(self, output):
|
|
104
|
-
services = {}
|
|
105
|
-
|
|
106
|
-
for line in output:
|
|
107
|
-
matches = re.match(self.regex, line)
|
|
108
|
-
if matches:
|
|
109
|
-
status = int(matches.group(2))
|
|
110
|
-
|
|
111
|
-
# Exit code 0 = OK/running
|
|
112
|
-
if status == 0:
|
|
113
|
-
status = True
|
|
114
|
-
|
|
115
|
-
# Exit codes 1-3 = DOWN/not running
|
|
116
|
-
elif status < 4:
|
|
117
|
-
status = False
|
|
118
|
-
|
|
119
|
-
# Exit codes 4+ = unknown
|
|
120
|
-
else:
|
|
121
|
-
status = None
|
|
122
|
-
|
|
123
|
-
services[matches.group(1)] = status
|
|
124
|
-
|
|
125
|
-
return services
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
class RcdStatus(InitdStatus):
|
|
129
|
-
'''
|
|
130
|
-
Same as ``initd_status`` but for BSD (/etc/rc.d) systems. Unlike Linux/init.d,
|
|
131
|
-
BSD init scripts are well behaved and as such their output can be trusted.
|
|
132
|
-
'''
|
|
133
|
-
|
|
134
|
-
command = '''
|
|
135
|
-
for SERVICE in `ls /etc/rc.d/`; do
|
|
136
|
-
_=`cat /etc/rc.d/$SERVICE | grep "daemon="`
|
|
137
|
-
|
|
138
|
-
if [ "$?" = "0" ]; then
|
|
139
|
-
STATUS=`/etc/rc.d/$SERVICE check`
|
|
140
|
-
echo "$SERVICE=$?"
|
|
141
|
-
fi
|
|
142
|
-
done
|
|
143
|
-
'''
|
|
144
|
-
|
|
145
|
-
default = dict
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
class LaunchdStatus(FactBase):
|
|
149
|
-
'''
|
|
150
|
-
Returns a dict of name -> status for launchd managed services.
|
|
151
|
-
'''
|
|
152
|
-
|
|
153
|
-
command = 'launchctl list'
|
|
154
|
-
default = dict
|
|
155
|
-
|
|
156
|
-
def process(self, output):
|
|
157
|
-
services = {}
|
|
158
|
-
|
|
159
|
-
for line in output:
|
|
160
|
-
bits = line.split()
|
|
161
|
-
|
|
162
|
-
if not bits or bits[0] == 'PID':
|
|
163
|
-
continue
|
|
164
|
-
|
|
165
|
-
name = bits[2]
|
|
166
|
-
status = False
|
|
167
|
-
|
|
168
|
-
try:
|
|
169
|
-
int(bits[0])
|
|
170
|
-
status = True
|
|
171
|
-
except ValueError:
|
|
172
|
-
pass
|
|
173
|
-
|
|
174
|
-
services[name] = status
|
|
175
|
-
|
|
176
|
-
return services
|
pyinfra/facts/util/files.py
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
LS_REGEX = re.compile((
|
|
6
|
-
# Type flag
|
|
7
|
-
r'^[bcdlsp\-]'
|
|
8
|
-
# Permissions/ACL
|
|
9
|
-
r'([\-rwxsS]{9})[\.\+]?\s+'
|
|
10
|
-
# Links (unused)
|
|
11
|
-
r'[0-9]+\s+'
|
|
12
|
-
# User & group
|
|
13
|
-
r'([\w-]+)\s+([\w-]+)\s+'
|
|
14
|
-
# Size
|
|
15
|
-
r'([0-9]+)\s+'
|
|
16
|
-
# Date start options
|
|
17
|
-
r'((?:'
|
|
18
|
-
# BSD format
|
|
19
|
-
r'[a-zA-Z]{3}\s+[0-9]{1,2}\s+[0-9:]{8}\s+[0-9]{4}'
|
|
20
|
-
# Or Linux format (ISO)
|
|
21
|
-
r'|[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s+[0-9:]{5}'
|
|
22
|
-
# Date end
|
|
23
|
-
r'))\s+'
|
|
24
|
-
# Filename
|
|
25
|
-
r'[\w\/\.@-]+'
|
|
26
|
-
# Optional link target
|
|
27
|
-
r'\s?-?>?\s?([\w\/\.@-]*)'
|
|
28
|
-
))
|
|
29
|
-
|
|
30
|
-
FLAG_TO_TYPE = {
|
|
31
|
-
'b': 'block',
|
|
32
|
-
'c': 'character',
|
|
33
|
-
'd': 'directory',
|
|
34
|
-
'l': 'link',
|
|
35
|
-
's': 'socket',
|
|
36
|
-
'p': 'fifo',
|
|
37
|
-
'-': 'file',
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
SYMBOL_TO_OCTAL_PERMISSIONS = {
|
|
41
|
-
'rwx': '7',
|
|
42
|
-
'rw-': '6',
|
|
43
|
-
'r-x': '5',
|
|
44
|
-
'r--': '4',
|
|
45
|
-
'-wx': '3',
|
|
46
|
-
'-w-': '2',
|
|
47
|
-
'--x': '1',
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def _parse_mode(mode):
|
|
52
|
-
'''
|
|
53
|
-
Converts ls mode output (rwxrwxrwx) -> integer (755).
|
|
54
|
-
'''
|
|
55
|
-
|
|
56
|
-
result = ''
|
|
57
|
-
# owner, group, world
|
|
58
|
-
for group in [mode[0:3], mode[3:6], mode[6:9]]:
|
|
59
|
-
if group in SYMBOL_TO_OCTAL_PERMISSIONS:
|
|
60
|
-
result = '{0}{1}'.format(result, SYMBOL_TO_OCTAL_PERMISSIONS[group])
|
|
61
|
-
else:
|
|
62
|
-
result = '{0}0'.format(result)
|
|
63
|
-
|
|
64
|
-
# Return as an integer
|
|
65
|
-
return int(result)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def _parse_time(time):
|
|
69
|
-
# Try matching with BSD format
|
|
70
|
-
try:
|
|
71
|
-
return datetime.strptime(time, '%b %d %H:%M:%S %Y')
|
|
72
|
-
except ValueError:
|
|
73
|
-
pass
|
|
74
|
-
|
|
75
|
-
# Try matching ISO format
|
|
76
|
-
try:
|
|
77
|
-
return datetime.strptime(time, '%Y-%m-%d %H:%M')
|
|
78
|
-
except ValueError:
|
|
79
|
-
pass
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def parse_ls_output(output, wanted_type):
|
|
83
|
-
if output:
|
|
84
|
-
matches = re.match(LS_REGEX, output)
|
|
85
|
-
if matches:
|
|
86
|
-
type = FLAG_TO_TYPE[output[0]]
|
|
87
|
-
|
|
88
|
-
if type != wanted_type:
|
|
89
|
-
return False
|
|
90
|
-
|
|
91
|
-
out = {
|
|
92
|
-
'mode': _parse_mode(matches.group(1)),
|
|
93
|
-
'user': matches.group(2),
|
|
94
|
-
'group': matches.group(3),
|
|
95
|
-
'size': matches.group(4),
|
|
96
|
-
'mtime': _parse_time(matches.group(5)),
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if type == 'link':
|
|
100
|
-
out['link_target'] = matches.group(6)
|
|
101
|
-
|
|
102
|
-
return out
|
pyinfra/hook.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
from functools import wraps
|
|
2
|
-
|
|
3
|
-
from click import ClickException
|
|
4
|
-
|
|
5
|
-
from pyinfra.api.exceptions import PyinfraError
|
|
6
|
-
|
|
7
|
-
from . import pseudo_state
|
|
8
|
-
|
|
9
|
-
HOOKS = {
|
|
10
|
-
'before_connect': [],
|
|
11
|
-
'before_facts': [],
|
|
12
|
-
'before_deploy': [],
|
|
13
|
-
'after_deploy': [],
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class Error(PyinfraError, ClickException):
|
|
18
|
-
'''
|
|
19
|
-
Exception raised when encounting errors in deploy hooks.
|
|
20
|
-
'''
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def _make_hook_wrapper(hook_name):
|
|
24
|
-
def hook_func(func):
|
|
25
|
-
# Only add hooks when the state is not initialised
|
|
26
|
-
if pseudo_state.initialised:
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
HOOKS[hook_name].append(func)
|
|
30
|
-
|
|
31
|
-
@wraps(func)
|
|
32
|
-
def decorated(*args, **kwargs):
|
|
33
|
-
return func(*args, **kwargs)
|
|
34
|
-
|
|
35
|
-
return hook_func
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
before_connect = _make_hook_wrapper('before_connect')
|
|
39
|
-
before_facts = _make_hook_wrapper('before_facts')
|
|
40
|
-
before_deploy = _make_hook_wrapper('before_deploy')
|
|
41
|
-
after_deploy = _make_hook_wrapper('after_deploy')
|
pyinfra/modules/__init__.py
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
from glob import glob
|
|
2
|
-
from os import path
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module_filenames = glob(path.join(path.dirname(__file__), '*.py'))
|
|
6
|
-
module_names = [path.basename(name)[:-3] for name in module_filenames]
|
|
7
|
-
__all__ = [name for name in module_names if name != '__init__']
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# Actually triggers __all__ imports to builds operations index
|
|
11
|
-
from . import * # noqa
|
pyinfra/modules/apk.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Mange apk packages.
|
|
3
|
-
'''
|
|
4
|
-
|
|
5
|
-
from pyinfra.api import operation
|
|
6
|
-
|
|
7
|
-
from .util.packaging import ensure_packages
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@operation
|
|
11
|
-
def upgrade(state, host):
|
|
12
|
-
'''
|
|
13
|
-
Upgrades all apk packages.
|
|
14
|
-
'''
|
|
15
|
-
|
|
16
|
-
yield 'apk upgrade'
|
|
17
|
-
|
|
18
|
-
_upgrade = upgrade # noqa: E305
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@operation
|
|
22
|
-
def update(state, host):
|
|
23
|
-
'''
|
|
24
|
-
Updates apk repositories.
|
|
25
|
-
'''
|
|
26
|
-
|
|
27
|
-
yield 'apk update'
|
|
28
|
-
|
|
29
|
-
_update = update # 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 apk 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 apk update before installing packages
|
|
45
|
-
+ upgrade: run apk upgrade before installing packages
|
|
46
|
-
|
|
47
|
-
Versions:
|
|
48
|
-
Package versions can be pinned like apk: ``<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.apk_packages, present,
|
|
59
|
-
install_command='apk add',
|
|
60
|
-
uninstall_command='apk remove',
|
|
61
|
-
upgrade_command='apk upgrade',
|
|
62
|
-
version_join='=',
|
|
63
|
-
latest=latest,
|
|
64
|
-
)
|