Skip to content

Commit 4ec1368

Browse files
authored
Merge branch 'master' into schedule_modify_no_function_fix
2 parents 86693ef + ba07d56 commit 4ec1368

File tree

11 files changed

+205
-55
lines changed

11 files changed

+205
-55
lines changed

salt/engines/stalekey.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
have been recently connected and remove their keys if they have not been
55
connected for a certain period of time.
66
7-
Requires that the minion_data_cache option be enabled.
7+
Requires that the :conf_master:`minion_data_cache` option be enabled.
88
99
.. versionadded: 2017.7.0
1010
1111
:configuration:
1212
13-
Example configuration
13+
Example configuration:
14+
15+
.. code-block:: yaml
16+
1417
engines:
1518
- stalekey:
1619
interval: 3600

salt/modules/disk.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,34 @@ def percent(args=None):
268268

269269

270270
@salt.utils.decorators.path.which('blkid')
271-
def blkid(device=None):
271+
def blkid(device=None, token=None):
272272
'''
273273
Return block device attributes: UUID, LABEL, etc. This function only works
274274
on systems where blkid is available.
275275
276+
device
277+
Device name from the system
278+
279+
token
280+
Any valid token used for the search
281+
276282
CLI Example:
277283
278284
.. code-block:: bash
279285
280286
salt '*' disk.blkid
281287
salt '*' disk.blkid /dev/sda
288+
salt '*' disk.blkid token='UUID=6a38ee5-7235-44e7-8b22-816a403bad5d'
289+
salt '*' disk.blkid token='TYPE=ext4'
282290
'''
283-
args = ""
291+
cmd = ['blkid']
284292
if device:
285-
args = " " + device
293+
cmd.append(device)
294+
elif token:
295+
cmd.extend(['-t', token])
286296

287297
ret = {}
288-
blkid_result = __salt__['cmd.run_all']('blkid' + args, python_shell=False)
298+
blkid_result = __salt__['cmd.run_all'](cmd, python_shell=False)
289299

290300
if blkid_result['retcode'] > 0:
291301
return ret

salt/modules/virt.py

+44-3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
from salt.exceptions import CommandExecutionError, SaltInvocationError
113113
from salt.ext import six
114114
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
115+
from salt._compat import ipaddress
115116

116117
log = logging.getLogger(__name__)
117118

@@ -663,7 +664,8 @@ def _gen_net_xml(name,
663664
bridge,
664665
forward,
665666
vport,
666-
tag=None):
667+
tag=None,
668+
ip_configs=None):
667669
'''
668670
Generate the XML string to define a libvirt network
669671
'''
@@ -673,6 +675,10 @@ def _gen_net_xml(name,
673675
'forward': forward,
674676
'vport': vport,
675677
'tag': tag,
678+
'ip_configs': [{
679+
'address': ipaddress.ip_network(config['cidr']),
680+
'dhcp_ranges': config.get('dhcp_ranges', []),
681+
} for config in ip_configs or []],
676682
}
677683
fn_ = 'libvirt_network.jinja'
678684
try:
@@ -4402,7 +4408,12 @@ def cpu_baseline(full=False, migratable=False, out='libvirt', **kwargs):
44024408
return cpu.toxml()
44034409

44044410

4405-
def network_define(name, bridge, forward, **kwargs):
4411+
def network_define(name,
4412+
bridge,
4413+
forward,
4414+
ipv4_config=None,
4415+
ipv6_config=None,
4416+
**kwargs):
44064417
'''
44074418
Create libvirt network.
44084419
@@ -4413,10 +4424,38 @@ def network_define(name, bridge, forward, **kwargs):
44134424
:param tag: Vlan tag
44144425
:param autostart: Network autostart (default True)
44154426
:param start: Network start (default True)
4427+
:param ipv4_config: IP v4 configuration
4428+
Dictionary describing the IP v4 setup like IP range and
4429+
a possible DHCP configuration. The structure is documented
4430+
in net-define-ip_.
4431+
4432+
..versionadded:: Neon
4433+
:type ipv4_config: dict or None
4434+
4435+
:param ipv6_config: IP v6 configuration
4436+
Dictionary describing the IP v6 setup like IP range and
4437+
a possible DHCP configuration. The structure is documented
4438+
in net-define-ip_.
4439+
4440+
..versionadded:: Neon
4441+
:type ipv6_config: dict or None
4442+
44164443
:param connection: libvirt connection URI, overriding defaults
44174444
:param username: username to connect with, overriding defaults
44184445
:param password: password to connect with, overriding defaults
44194446
4447+
.. _net-define-ip:
4448+
4449+
** IP configuration definition
4450+
4451+
Both the IPv4 and IPv6 configuration dictionaries can contain the following properties:
4452+
4453+
cidr
4454+
CIDR notation for the network. For example '192.168.124.0/24'
4455+
4456+
dhcp_ranges
4457+
A list of dictionary with ``'start'`` and ``'end'`` properties.
4458+
44204459
CLI Example:
44214460
44224461
.. code-block:: bash
@@ -4430,12 +4469,14 @@ def network_define(name, bridge, forward, **kwargs):
44304469
tag = kwargs.get('tag', None)
44314470
autostart = kwargs.get('autostart', True)
44324471
starting = kwargs.get('start', True)
4472+
44334473
net_xml = _gen_net_xml(
44344474
name,
44354475
bridge,
44364476
forward,
44374477
vport,
4438-
tag,
4478+
tag=tag,
4479+
ip_configs=[config for config in [ipv4_config, ipv6_config] if config],
44394480
)
44404481
try:
44414482
conn.networkDefineXML(net_xml)

salt/modules/zfs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1145,8 +1145,8 @@ def set(*dataset, **kwargs):
11451145
res = __salt__['cmd.run_all'](
11461146
__utils__['zfs.zfs_command'](
11471147
command='set',
1148-
property_name=filesystem_properties.keys(),
1149-
property_value=filesystem_properties.values(),
1148+
property_name=list(filesystem_properties.keys()),
1149+
property_value=list(filesystem_properties.values()),
11501150
target=list(dataset),
11511151
),
11521152
python_shell=False,

salt/runners/cloud.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ def create(provider, instances, opts=None, **kwargs):
179179
180180
.. code-block:: bash
181181
182-
salt-run cloud.create my-ec2-config myinstance \
183-
image=ami-1624987f size='t1.micro' ssh_username=ec2-user \
182+
salt-run cloud.create my-ec2-config myinstance \\
183+
image=ami-1624987f size='t1.micro' ssh_username=ec2-user \\
184184
securitygroup=default delvol_on_destroy=True
185185
'''
186186
client = _get_client()

salt/states/network.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
- max_bonds: 1
165165
- updelay: 0
166166
- use_carrier: on
167-
- xmit_hash_policy: layer2
167+
- hashing-algorithm: layer2
168168
- mtu: 9000
169169
- autoneg: on
170170
- speed: 1000

salt/states/virt.py

+38
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,34 @@ def network_running(name,
658658
forward,
659659
vport=None,
660660
tag=None,
661+
ipv4_config=None,
662+
ipv6_config=None,
661663
autostart=True,
662664
connection=None,
663665
username=None,
664666
password=None):
665667
'''
666668
Defines and starts a new network with specified arguments.
667669
670+
:param bridge: Bridge name
671+
:param forward: Forward mode(bridge, router, nat)
672+
:param vport: Virtualport type (Default: ``'None'``)
673+
:param tag: Vlan tag (Default: ``'None'``)
674+
:param ipv4_config:
675+
IPv4 network configuration. See the :py:func`virt.network_define
676+
<salt.modules.virt.network_define>` function corresponding parameter documentation
677+
for more details on this dictionary.
678+
(Default: None).
679+
680+
.. versionadded:: neon
681+
:param ipv6_config:
682+
IPv6 network configuration. See the :py:func`virt.network_define
683+
<salt.modules.virt.network_define>` function corresponding parameter documentation
684+
for more details on this dictionary.
685+
(Default: None).
686+
687+
.. versionadded:: neon
688+
:param autostart: Network autostart (default ``'True'``)
668689
:param connection: libvirt connection URI, overriding defaults
669690
670691
.. versionadded:: 2019.2.0
@@ -690,6 +711,21 @@ def network_running(name,
690711
- tag: 180
691712
- autostart: True
692713
714+
.. code-block:: yaml
715+
716+
network_name:
717+
virt.network_define:
718+
- bridge: natted
719+
- forward: nat
720+
- ipv4_config:
721+
cidr: 192.168.42.0/24
722+
dhcp_ranges:
723+
- start: 192.168.42.10
724+
end: 192.168.42.25
725+
- start: 192.168.42.100
726+
end: 192.168.42.150
727+
- autostart: True
728+
693729
'''
694730
ret = {'name': name,
695731
'changes': {},
@@ -712,6 +748,8 @@ def network_running(name,
712748
forward,
713749
vport=vport,
714750
tag=tag,
751+
ipv4_config=ipv4_config,
752+
ipv6_config=ipv6_config,
715753
autostart=autostart,
716754
start=True,
717755
connection=connection,

salt/templates/virt/libvirt_network.jinja

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@
66
<vlan>
77
<tag id='{{ tag }}'/>
88
</vlan>{% endif %}
9-
</network>
9+
{% for ip_config in ip_configs %}
10+
<ip family='ipv{{ ip_config.address.version }}'
11+
address='{{ ip_config.address.network_address }}'
12+
prefix='{{ ip_config.address.prefixlen }}'>
13+
<dhcp>
14+
{% for range in ip_config.dhcp_ranges %}
15+
<range start='{{ range.start }}' end='{{ range.end }}' />
16+
{% endfor %}
17+
</dhcp>
18+
</ip>
19+
{% endfor %}
20+
</network>

salt/utils/roster_matcher.py

+35-40
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
from __future__ import absolute_import, print_function, unicode_literals
66

77
# Import python libs
8+
import copy
89
import fnmatch
10+
import functools
911
import logging
1012
import re
11-
import copy
1213

1314
# Try to import range from https://github.com/ytoolshed/range
1415
HAS_RANGE = False
@@ -31,6 +32,18 @@ def targets(conditioned_raw, tgt, tgt_type, ipv='ipv4'):
3132
return rmatcher.targets()
3233

3334

35+
def _tgt_set(tgt):
36+
'''
37+
Return the tgt as a set of literal names
38+
'''
39+
try:
40+
# A comma-delimited string
41+
return set(tgt.split(','))
42+
except AttributeError:
43+
# Assume tgt is already a non-string iterable.
44+
return set(tgt)
45+
46+
3447
class RosterMatcher(object):
3548
'''
3649
Matcher for the roster data structure
@@ -50,59 +63,47 @@ def targets(self):
5063
except AttributeError:
5164
return {}
5265

53-
def ret_glob_minions(self):
66+
def _ret_minions(self, filter_):
5467
'''
55-
Return minions that match via glob
68+
Filter minions by a generic filter.
5669
'''
5770
minions = {}
58-
for minion in self.raw:
59-
if fnmatch.fnmatch(minion, self.tgt):
60-
data = self.get_data(minion)
61-
if data:
62-
minions[minion] = data.copy()
71+
for minion in filter_(self.raw):
72+
data = self.get_data(minion)
73+
if data:
74+
minions[minion] = data.copy()
6375
return minions
6476

77+
def ret_glob_minions(self):
78+
'''
79+
Return minions that match via glob
80+
'''
81+
fnfilter = functools.partial(fnmatch.filter, pat=self.tgt)
82+
return self._ret_minions(fnfilter)
83+
6584
def ret_pcre_minions(self):
6685
'''
6786
Return minions that match via pcre
6887
'''
69-
minions = {}
70-
for minion in self.raw:
71-
if re.match(self.tgt, minion):
72-
data = self.get_data(minion)
73-
if data:
74-
minions[minion] = data.copy()
75-
return minions
88+
tgt = re.compile(self.tgt)
89+
refilter = functools.partial(filter, tgt.match)
90+
return self._ret_minions(refilter)
7691

7792
def ret_list_minions(self):
7893
'''
7994
Return minions that match via list
8095
'''
81-
minions = {}
82-
if not isinstance(self.tgt, list):
83-
self.tgt = self.tgt.split(',')
84-
for minion in self.raw:
85-
if minion in self.tgt:
86-
data = self.get_data(minion)
87-
if data:
88-
minions[minion] = data.copy()
89-
return minions
96+
tgt = _tgt_set(self.tgt)
97+
return self._ret_minions(tgt.intersection)
9098

9199
def ret_nodegroup_minions(self):
92100
'''
93101
Return minions which match the special list-only groups defined by
94102
ssh_list_nodegroups
95103
'''
96-
minions = {}
97104
nodegroup = __opts__.get('ssh_list_nodegroups', {}).get(self.tgt, [])
98-
if not isinstance(nodegroup, list):
99-
nodegroup = nodegroup.split(',')
100-
for minion in self.raw:
101-
if minion in nodegroup:
102-
data = self.get_data(minion)
103-
if data:
104-
minions[minion] = data.copy()
105-
return minions
105+
nodegroup = _tgt_set(nodegroup)
106+
return self._ret_minions(nodegroup.intersection)
106107

107108
def ret_range_minions(self):
108109
'''
@@ -113,13 +114,7 @@ def ret_range_minions(self):
113114

114115
minions = {}
115116
range_hosts = _convert_range_to_list(self.tgt, __opts__['range_server'])
116-
117-
for minion in self.raw:
118-
if minion in range_hosts:
119-
data = self.get_data(minion)
120-
if data:
121-
minions[minion] = data.copy()
122-
return minions
117+
return self._ret_minions(range_hosts.__contains__)
123118

124119
def get_data(self, minion):
125120
'''

0 commit comments

Comments
 (0)