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/api/inventory.py
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
from
|
|
1
|
+
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from collections import defaultdict
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Iterator
|
|
4
5
|
|
|
5
|
-
from .connectors import
|
|
6
|
-
ALL_CONNECTORS,
|
|
7
|
-
EXECUTION_CONNECTORS,
|
|
8
|
-
INVENTORY_CONNECTORS,
|
|
9
|
-
)
|
|
6
|
+
from .connectors import get_all_connectors, get_execution_connectors
|
|
10
7
|
from .exceptions import NoConnectorError, NoGroupError, NoHostError
|
|
11
8
|
from .host import Host
|
|
12
|
-
from .util import FallbackDict
|
|
13
9
|
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from pyinfra.api.state import State
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
def extract_name_data(names: list[Any]):
|
|
16
15
|
for name in names:
|
|
17
16
|
data = {}
|
|
18
17
|
|
|
@@ -23,48 +22,32 @@ def extract_name_data(names):
|
|
|
23
22
|
yield name, data
|
|
24
23
|
|
|
25
24
|
|
|
26
|
-
class Inventory
|
|
27
|
-
|
|
25
|
+
class Inventory:
|
|
26
|
+
"""
|
|
28
27
|
Represents a collection of target hosts. Stores and provides access to group data,
|
|
29
28
|
host data and default data for these hosts.
|
|
30
29
|
|
|
31
30
|
Args:
|
|
32
31
|
names_data: tuple of ``(names, data)``
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
):
|
|
32
|
+
override_data: dictionary of data overrides
|
|
33
|
+
ssh_*: deprecated, use ``override_data.ssh_*``
|
|
34
|
+
winrm_*: deprecated, use ``override_data.winrm_*``
|
|
35
|
+
**groups: map of group name -> ``(names, data)``
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
state: "State"
|
|
39
|
+
groups: dict[str, list[Host]]
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def empty():
|
|
43
|
+
return Inventory(([], {}))
|
|
44
|
+
|
|
45
|
+
def __init__(self, names_data, override_data=None, **groups):
|
|
48
46
|
# Setup basics
|
|
49
47
|
self.groups = defaultdict(list) # lists of Host objects
|
|
50
|
-
self.host_data = defaultdict(dict) # dict of name -> data
|
|
51
|
-
self.group_data = defaultdict(dict) # dict of name -> data
|
|
52
|
-
|
|
53
|
-
# In CLI mode these are --user, --key, etc
|
|
54
|
-
override_data = {
|
|
55
|
-
'ssh_user': ssh_user,
|
|
56
|
-
'ssh_key': ssh_key,
|
|
57
|
-
'ssh_key_password': ssh_key_password,
|
|
58
|
-
'ssh_port': ssh_port,
|
|
59
|
-
'ssh_password': ssh_password,
|
|
60
|
-
}
|
|
61
|
-
# Strip None values
|
|
62
|
-
override_data = {
|
|
63
|
-
key: value
|
|
64
|
-
for key, value in override_data.items()
|
|
65
|
-
if value is not None
|
|
66
|
-
}
|
|
67
|
-
self.override_data = override_data
|
|
48
|
+
self.host_data: dict[str, dict] = defaultdict(dict) # dict of name -> data
|
|
49
|
+
self.group_data: dict[str, dict] = defaultdict(dict) # dict of name -> data
|
|
50
|
+
self.override_data = override_data or {}
|
|
68
51
|
|
|
69
52
|
names, data = names_data
|
|
70
53
|
|
|
@@ -72,11 +55,14 @@ class Inventory(object):
|
|
|
72
55
|
self.data = data
|
|
73
56
|
|
|
74
57
|
# Create the actual host instances and groups
|
|
75
|
-
self.
|
|
58
|
+
self.make_hosts_and_groups(names, groups)
|
|
59
|
+
|
|
60
|
+
def make_hosts_and_groups(self, names, groups) -> None:
|
|
61
|
+
all_connectors = get_all_connectors()
|
|
62
|
+
execution_connectors = get_execution_connectors()
|
|
76
63
|
|
|
77
|
-
def make_hosts_and_groups(self, names, groups):
|
|
78
64
|
# Map name -> data
|
|
79
|
-
name_to_data = defaultdict(dict)
|
|
65
|
+
name_to_data: dict[str, dict] = defaultdict(dict)
|
|
80
66
|
# Map name -> group names
|
|
81
67
|
name_to_group_names = defaultdict(list)
|
|
82
68
|
|
|
@@ -94,82 +80,61 @@ class Inventory(object):
|
|
|
94
80
|
for name, data in extract_name_data(names):
|
|
95
81
|
name_to_data[name].update(data)
|
|
96
82
|
|
|
97
|
-
# Now, use the above to fill self.host_data and populate
|
|
98
|
-
|
|
83
|
+
# Now, use the above to fill self.host_data and populate names_connectors
|
|
84
|
+
names_connectors = []
|
|
99
85
|
|
|
100
86
|
for name, _ in extract_name_data(names):
|
|
101
87
|
host_data = name_to_data[name]
|
|
102
88
|
|
|
103
89
|
# Default to executing commands with the ssh connector
|
|
104
|
-
|
|
90
|
+
connector_cls = execution_connectors["ssh"]
|
|
105
91
|
|
|
106
|
-
|
|
107
|
-
if name[0] == '@':
|
|
92
|
+
if name[0] == "@":
|
|
108
93
|
connector_name = name[1:]
|
|
109
94
|
arg_string = None
|
|
110
95
|
|
|
111
|
-
if
|
|
112
|
-
connector_name, arg_string = connector_name.split(
|
|
96
|
+
if "/" in connector_name:
|
|
97
|
+
connector_name, arg_string = connector_name.split("/", 1)
|
|
113
98
|
|
|
114
|
-
if connector_name not in
|
|
99
|
+
if connector_name not in get_all_connectors():
|
|
115
100
|
raise NoConnectorError(
|
|
116
|
-
|
|
101
|
+
"Invalid connector: {0}".format(connector_name),
|
|
117
102
|
)
|
|
118
103
|
|
|
119
|
-
# Execution connector? Simple, just set it for
|
|
120
|
-
if connector_name in
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
self.host_data[name] = host_data
|
|
146
|
-
names_executors.append((name, executor))
|
|
104
|
+
# Execution connector? Simple, just set it for their host
|
|
105
|
+
if connector_name in execution_connectors:
|
|
106
|
+
connector_cls = execution_connectors[connector_name]
|
|
107
|
+
|
|
108
|
+
names_data = all_connectors[connector_name].make_names_data(arg_string)
|
|
109
|
+
connector_inventory_name = name
|
|
110
|
+
else:
|
|
111
|
+
names_data = [(name, {}, [])]
|
|
112
|
+
connector_inventory_name = None
|
|
113
|
+
|
|
114
|
+
for sub_name, sub_data, sub_groups in names_data:
|
|
115
|
+
# Update any connector data with a copy of the host data (so that
|
|
116
|
+
# host data can override connector data).
|
|
117
|
+
sub_data.update(host_data.copy())
|
|
118
|
+
|
|
119
|
+
# Assign the name/data/groups from the connector
|
|
120
|
+
self.host_data[sub_name] = sub_data
|
|
121
|
+
names_connectors.append((sub_name, connector_cls))
|
|
122
|
+
name_to_group_names[sub_name].extend(sub_groups)
|
|
123
|
+
|
|
124
|
+
# If we have a connector inventory name, copy any groups attached
|
|
125
|
+
# to the newly generated host name.
|
|
126
|
+
if connector_inventory_name:
|
|
127
|
+
name_to_group_names[sub_name].extend(
|
|
128
|
+
name_to_group_names[connector_inventory_name],
|
|
129
|
+
)
|
|
147
130
|
|
|
148
131
|
# Now we can actually make Host instances
|
|
149
|
-
hosts = {}
|
|
132
|
+
hosts: dict[str, "Host"] = {}
|
|
150
133
|
|
|
151
|
-
for name,
|
|
134
|
+
for name, connector_cls in names_connectors:
|
|
152
135
|
host_groups = name_to_group_names[name]
|
|
153
136
|
|
|
154
|
-
|
|
155
|
-
host_data = FallbackDict(
|
|
156
|
-
self.get_override_data(),
|
|
157
|
-
self.get_host_data(name),
|
|
158
|
-
self.get_groups_data(host_groups),
|
|
159
|
-
self.get_data(),
|
|
160
|
-
# Pass the method, rather than data, as this comes from the
|
|
161
|
-
# state and can change during deploy(s).
|
|
162
|
-
self.get_deploy_data,
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
# Create the Host object
|
|
166
|
-
host = Host(
|
|
167
|
-
name,
|
|
168
|
-
inventory=self,
|
|
169
|
-
groups=name_to_group_names.get(name),
|
|
170
|
-
data=host_data,
|
|
171
|
-
executor=executor,
|
|
172
|
-
)
|
|
137
|
+
host = Host(name, inventory=self, groups=host_groups, connector_cls=connector_cls)
|
|
173
138
|
hosts[name] = host
|
|
174
139
|
|
|
175
140
|
# And push into any groups
|
|
@@ -177,101 +142,107 @@ class Inventory(object):
|
|
|
177
142
|
if host not in self.groups[group_name]:
|
|
178
143
|
self.groups[group_name].append(host)
|
|
179
144
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
def __len__(self):
|
|
183
|
-
'''
|
|
184
|
-
Returns the number of active inventory hosts.
|
|
185
|
-
'''
|
|
145
|
+
self.hosts = hosts
|
|
186
146
|
|
|
187
|
-
|
|
188
|
-
|
|
147
|
+
def __len__(self) -> int:
|
|
148
|
+
"""
|
|
149
|
+
Returns the number of inventory hosts.
|
|
150
|
+
"""
|
|
189
151
|
|
|
190
|
-
return len(self.
|
|
152
|
+
return len(self.hosts)
|
|
191
153
|
|
|
192
|
-
def __iter__(self):
|
|
193
|
-
|
|
194
|
-
Iterates over
|
|
195
|
-
|
|
154
|
+
def __iter__(self) -> Iterator["Host"]:
|
|
155
|
+
"""
|
|
156
|
+
Iterates over all inventory hosts.
|
|
157
|
+
"""
|
|
196
158
|
|
|
197
|
-
|
|
198
|
-
return self.iter_all_hosts()
|
|
159
|
+
return iter(self.hosts.values())
|
|
199
160
|
|
|
161
|
+
def iter_active_hosts(self) -> Iterator["Host"]:
|
|
162
|
+
"""
|
|
163
|
+
Iterates over active inventory hosts.
|
|
164
|
+
"""
|
|
200
165
|
return iter(self.state.active_hosts)
|
|
201
166
|
|
|
202
|
-
def
|
|
203
|
-
|
|
204
|
-
Returns the number of
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return len(self.hosts)
|
|
167
|
+
def len_active_hosts(self) -> int:
|
|
168
|
+
"""
|
|
169
|
+
Returns the number of active inventory hosts.
|
|
170
|
+
"""
|
|
171
|
+
return len(self.state.active_hosts)
|
|
208
172
|
|
|
209
|
-
def
|
|
210
|
-
|
|
211
|
-
Iterates over
|
|
212
|
-
|
|
173
|
+
def iter_activated_hosts(self) -> Iterator["Host"]:
|
|
174
|
+
"""
|
|
175
|
+
Iterates over activated inventory hosts.
|
|
176
|
+
"""
|
|
177
|
+
return iter(self.state.activated_hosts)
|
|
213
178
|
|
|
214
|
-
|
|
179
|
+
def len_activated_hosts(self) -> int:
|
|
180
|
+
"""
|
|
181
|
+
Returns the number of activated inventory hosts.
|
|
182
|
+
"""
|
|
183
|
+
return len(self.state.activated_hosts)
|
|
215
184
|
|
|
216
|
-
def get_host(self, name, default=NoHostError):
|
|
217
|
-
|
|
185
|
+
def get_host(self, name: str, default=NoHostError) -> Host:
|
|
186
|
+
"""
|
|
218
187
|
Get a single host by name.
|
|
219
|
-
|
|
188
|
+
"""
|
|
220
189
|
|
|
221
190
|
if name in self.hosts:
|
|
222
191
|
return self.hosts[name]
|
|
223
192
|
|
|
224
193
|
if default is NoHostError:
|
|
225
|
-
raise NoHostError(
|
|
194
|
+
raise NoHostError("No such host: {0}".format(name))
|
|
226
195
|
|
|
196
|
+
# TODO: remove default here?
|
|
227
197
|
return default
|
|
228
198
|
|
|
229
|
-
def get_group(self, name, default=NoGroupError):
|
|
230
|
-
|
|
199
|
+
def get_group(self, name: str, default=NoGroupError) -> list[Host]:
|
|
200
|
+
"""
|
|
231
201
|
Get a list of hosts belonging to a group.
|
|
232
|
-
|
|
202
|
+
"""
|
|
233
203
|
|
|
234
204
|
if name in self.groups:
|
|
235
205
|
return self.groups[name]
|
|
236
206
|
|
|
237
207
|
if default is NoGroupError:
|
|
238
|
-
raise NoGroupError(
|
|
208
|
+
raise NoGroupError("No such group: {0}".format(name))
|
|
239
209
|
|
|
210
|
+
# TODO: remove default here?
|
|
240
211
|
return default
|
|
241
212
|
|
|
242
213
|
def get_data(self):
|
|
243
|
-
|
|
214
|
+
"""
|
|
244
215
|
Get the base/all data attached to this inventory.
|
|
245
|
-
|
|
216
|
+
"""
|
|
246
217
|
|
|
247
218
|
return self.data
|
|
248
219
|
|
|
249
220
|
def get_override_data(self):
|
|
250
|
-
|
|
221
|
+
"""
|
|
251
222
|
Get override data for this inventory.
|
|
252
|
-
|
|
223
|
+
"""
|
|
253
224
|
|
|
254
225
|
return self.override_data
|
|
255
226
|
|
|
256
|
-
def get_host_data(self, hostname):
|
|
257
|
-
|
|
227
|
+
def get_host_data(self, hostname: str):
|
|
228
|
+
"""
|
|
258
229
|
Get data for a single host in this inventory.
|
|
259
|
-
|
|
230
|
+
"""
|
|
260
231
|
|
|
261
232
|
return self.host_data.get(hostname, {})
|
|
262
233
|
|
|
263
234
|
def get_group_data(self, group):
|
|
264
|
-
|
|
235
|
+
"""
|
|
265
236
|
Get data for a single group in this inventory.
|
|
266
|
-
|
|
237
|
+
"""
|
|
267
238
|
|
|
268
239
|
return self.group_data.get(group, {})
|
|
269
240
|
|
|
270
241
|
def get_groups_data(self, groups):
|
|
271
|
-
|
|
242
|
+
"""
|
|
272
243
|
Gets aggregated data from a list of groups. Vars are collected in order so, for
|
|
273
244
|
any groups which define the same var twice, the last group's value will hold.
|
|
274
|
-
|
|
245
|
+
"""
|
|
275
246
|
|
|
276
247
|
data = {}
|
|
277
248
|
|
|
@@ -279,13 +250,3 @@ class Inventory(object):
|
|
|
279
250
|
data.update(self.get_group_data(group))
|
|
280
251
|
|
|
281
252
|
return data
|
|
282
|
-
|
|
283
|
-
def get_deploy_data(self):
|
|
284
|
-
'''
|
|
285
|
-
Gets any default data attached to the current deploy, if any.
|
|
286
|
-
'''
|
|
287
|
-
|
|
288
|
-
if self.state and self.state.deploy_data:
|
|
289
|
-
return self.state.deploy_data
|
|
290
|
-
|
|
291
|
-
return {}
|