Skip to content

Commit

Permalink
Merge pull request #56353 from MTecknology/master
Browse files Browse the repository at this point in the history
[cherrybomb] MTecknology's Masterless Contributions
  • Loading branch information
dwoz authored Apr 24, 2020
2 parents 85261eb + 39af7c6 commit fc3fee1
Show file tree
Hide file tree
Showing 8 changed files with 1,384 additions and 1,190 deletions.
871 changes: 374 additions & 497 deletions doc/ref/states/requisites.rst

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions doc/topics/releases/3000.rst
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,16 @@ Module Changes
fixed to remove file system entries other than files, directories
and symbolic links properly.

- The :py:func:`debian_ip <salt.modules.debian_ip>` module used by the
:py:func:`network.managed <salt.states.network.managed>` state has been
heavily refactored. The order that options appear in inet/inet6 blocks may
produce cosmetic changes. Many options without an 'ipvX' prefix will now be
shared between inet and inet6 blocks. The options ``enable_ipv4`` and
``enabled_ipv6`` will now fully remove relevant inet/inet6 blocks. Overriding
options by prefixing them with 'ipvX' will now work with most options (i.e.
``dns`` can be overriden by ``ipv4dns`` or ``ipv6dns``). The ``proto`` option
is now required.


Enhancements to Engines
=======================
Expand Down
259 changes: 100 additions & 159 deletions salt/modules/debian_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def __space_delimited_list(value):
#
"network": __anything, # i don't know what this is
"test": __anything, # TODO
"enable_ipv4": __anything, # TODO
"enable_ipv6": __anything, # TODO
}

Expand Down Expand Up @@ -503,6 +504,7 @@ def __space_delimited_list(value):
#
"vlan-raw-device": __anything,
"test": __anything, # TODO
"enable_ipv4": __anything, # TODO
"enable_ipv6": __anything, # TODO
}

Expand Down Expand Up @@ -700,10 +702,13 @@ def _parse_interfaces(interface_files=None):
adapters.pop(iface_name)
continue
for opt in ["ethtool", "bonding", "bridging"]:
if "inet" in adapters[iface_name]["data"]:
if opt in adapters[iface_name]["data"]["inet"]:
opt_keys = sorted(adapters[iface_name]["data"]["inet"][opt].keys())
adapters[iface_name]["data"]["inet"][opt + "_keys"] = opt_keys
for inet in ["inet", "inet6"]:
if inet in adapters[iface_name]["data"]:
if opt in adapters[iface_name]["data"][inet]:
opt_keys = sorted(
adapters[iface_name]["data"][inet][opt].keys()
)
adapters[iface_name]["data"][inet][opt + "_keys"] = opt_keys

return adapters

Expand Down Expand Up @@ -1254,148 +1259,92 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
if opts.get("hotplug", False):
adapters[iface]["hotplug"] = True

# Defaults assume IPv4 (inet) interfaces unless enable_ipv6=True
def_addrfam = "inet"
dual_stack = False

# If enable_ipv6=True, then expet either IPv6-only or dual stack.
if "enable_ipv6" in opts and opts["enable_ipv6"]:
iface_data["inet6"]["addrfam"] = "inet6"
iface_data["inet6"]["netmask"] = "64" # defaults to 64
def_addrfam = "inet6"
if opts.get("enable_ipv6", None) and opts.get("iface_type", "") == "vlan":
iface_data["inet6"]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)

if "iface_type" in opts and opts["iface_type"] == "vlan":
iface_data["inet6"]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)

if "ipaddr" in opts and "ipv6ipaddr" in opts:
# If both 'ipaddr' and 'ipv6ipaddr' are present; expect dual stack
for addrfam in ["inet", "inet6"]:
if iface_type not in ["bridge"]:
tmp_ethtool = _parse_ethtool_opts(opts, iface)
if tmp_ethtool:
ethtool = {}
for item in tmp_ethtool:
ethtool[_ETHTOOL_CONFIG_OPTS[item]] = tmp_ethtool[item]

iface_data[addrfam]["ethtool"] = ethtool
# return a list of sorted keys to ensure consistent order
iface_data[addrfam]["ethtool_keys"] = sorted(ethtool)

if iface_type == "bridge":
bridging = _parse_bridge_opts(opts, iface)
if bridging:
iface_data[addrfam]["bridging"] = bridging
iface_data[addrfam]["bridging_keys"] = sorted(bridging)
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "bond":
bonding = _parse_settings_bond(opts, iface)
if bonding:
iface_data[addrfam]["bonding"] = bonding
iface_data[addrfam]["bonding"]["slaves"] = opts["slaves"]
iface_data[addrfam]["bonding_keys"] = sorted(bonding)
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "slave":
adapters[iface]["master"] = opts["master"]

opts["proto"] = "manual"
iface_data[addrfam]["master"] = adapters[iface]["master"]
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "vlan":
iface_data[addrfam]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "pppoe":
tmp_ethtool = _parse_ethtool_pppoe_opts(opts, iface)
if tmp_ethtool:
for item in tmp_ethtool:
adapters[iface]["data"][addrfam][
_DEB_CONFIG_PPPOE_OPTS[item]
] = tmp_ethtool[item]
iface_data[addrfam]["addrfam"] = addrfam

opts.pop("mode", None)

for opt, val in opts.items():
inet = None
if opt.startswith("ipv4"):
opt = opt[4:]
inet = "inet"
iface_data["inet"]["addrfam"] = "inet"
def_addrfam = "inet"
dual_stack = True

else:
# If enable_ipv6=False|None, IPv6 settings should not be set.
iface_data["inet"]["addrfam"] = "inet"

if iface_type not in ["bridge"]:
tmp_ethtool = _parse_ethtool_opts(opts, iface)
if tmp_ethtool:
ethtool = {}
for item in tmp_ethtool:
ethtool[_ETHTOOL_CONFIG_OPTS[item]] = tmp_ethtool[item]

iface_data[def_addrfam]["ethtool"] = ethtool
# return a list of sorted keys to ensure consistent order
iface_data[def_addrfam]["ethtool_keys"] = sorted(ethtool)

if iface_type == "bridge":
bridging = _parse_bridge_opts(opts, iface)
if bridging:
opts.pop("mode", None)
iface_data[def_addrfam]["bridging"] = bridging
iface_data[def_addrfam]["bridging_keys"] = sorted(bridging)
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "bond":
bonding = _parse_settings_bond(opts, iface)
if bonding:
opts.pop("mode", None)
iface_data[def_addrfam]["bonding"] = bonding
iface_data[def_addrfam]["bonding"]["slaves"] = opts["slaves"]
iface_data[def_addrfam]["bonding_keys"] = sorted(bonding)
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "slave":
adapters[iface]["master"] = opts["master"]

opts["proto"] = "manual"
iface_data[def_addrfam]["master"] = adapters[iface]["master"]
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "vlan":
iface_data[def_addrfam]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "pppoe":
tmp_ethtool = _parse_ethtool_pppoe_opts(opts, iface)
if tmp_ethtool:
for item in tmp_ethtool:
adapters[iface]["data"][def_addrfam][
_DEB_CONFIG_PPPOE_OPTS[item]
] = tmp_ethtool[item]
iface_data[def_addrfam]["addrfam"] = def_addrfam

for opt in opts:
# trim leading "ipv6" from option
if opt.startswith("ipv6"):
optname = opt[4:] # trim off the ipv6
v6only = True
else:
optname = opt
v6only = False

_optname = SALT_ATTR_TO_DEBIAN_ATTR_MAP.get(optname, optname)
if _attrmaps_contain_attr(_optname):
valuestr = opts[opt]

# default to 'static' if proto is 'none'
if optname == "proto" and valuestr == "none":
valuestr = "static"

# If option is v6-only, don't validate against inet and always set value
if v6only:
(valid, value, errmsg) = _validate_interface_option(
_optname, valuestr, addrfam="inet6"
)

if not valid:
_raise_error_iface(
iface, "'{0}' '{1}'".format(opt, valuestr), [errmsg]
)

# replace dashes with underscores for jinja
_optname = _optname.replace("-", "_")
iface_data["inet6"][_optname] = value

# Else, if it's a dual stack, the option may belong in both; apply v4 opt as v6 default
elif dual_stack:
valid_once = False
errmsg = None
for addrfam in ["inet", "inet6"]:
(valid, value, errmsg) = _validate_interface_option(
_optname, valuestr, addrfam=addrfam
)

if valid:
valid_once = True
# replace dashes with underscores for jinja
_optname = _optname.replace("-", "_")
# if a v6-only version of this option was set; don't override
# otherwise, if dual stack, use the v4 version as a default value for v6
# allows overriding with =None
if addrfam == "inet" or _optname not in iface_data["inet6"]:
iface_data[addrfam][_optname] = value

if not valid_once:
_raise_error_iface(
iface, "'{0}' '{1}'".format(opt, valuestr), [errmsg]
)

# Else, it goes in the default(only) addrfam
# Not assuming v4 allows a v6 block to be created without lots of "ipv6" prefixes
else:
(valid, value, errmsg) = _validate_interface_option(
_optname, valuestr, addrfam=def_addrfam
)
elif opt.startswith("ipv6"):
iface_data["inet6"]["addrfam"] = "inet6"
opt = opt[4:]
inet = "inet6"
elif opt in [
"ipaddr",
"address",
"ipaddresses",
"addresses",
"gateway",
"proto",
]:
iface_data["inet"]["addrfam"] = "inet"
inet = "inet"

if not valid:
_raise_error_iface(
iface, "'{0}' '{1}'".format(opt, valuestr), [errmsg]
)
_opt = SALT_ATTR_TO_DEBIAN_ATTR_MAP.get(opt, opt)
_debopt = _opt.replace("-", "_")

# replace dashes with underscores for jinja
_optname = _optname.replace("-", "_")
iface_data[def_addrfam][_optname] = value
for addrfam in ["inet", "inet6"]:
(valid, value, errmsg) = _validate_interface_option(
_opt, val, addrfam=addrfam
)
if not valid:
continue
if inet is None and _debopt not in iface_data[addrfam]:
iface_data[addrfam][_debopt] = value
elif inet == addrfam:
iface_data[addrfam][_debopt] = value

for opt in [
"up_cmds",
Expand All @@ -1406,15 +1355,14 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
"post_down_cmds",
]:
if opt in opts:
iface_data[def_addrfam][opt] = opts[opt]
iface_data["inet"][opt] = opts[opt]
iface_data["inet6"][opt] = opts[opt]

for addrfam in ["inet", "inet6"]:
if (
"addrfam" in iface_data[addrfam]
and iface_data[addrfam]["addrfam"] == addrfam
):
pass
else:
# Remove incomplete/disabled inet blocks
for (addrfam, opt) in [("inet", "enable_ipv4"), ("inet6", "enable_ipv6")]:
if opts.get(opt, None) is False:
iface_data.pop(addrfam)
elif iface_data[addrfam].get("addrfam", "") != addrfam:
iface_data.pop(addrfam)

return adapters
Expand Down Expand Up @@ -1733,9 +1681,6 @@ def build_interface(iface, iface_type, enabled, **settings):
if iface_type not in _IFACE_TYPES:
_raise_error_iface(iface, iface_type, _IFACE_TYPES)

if "proto" not in settings:
settings["proto"] = "static"

if iface_type == "slave":
settings["slave"] = "yes"
if "master" not in settings:
Expand Down Expand Up @@ -1835,8 +1780,7 @@ def down(iface, iface_type):
# Slave devices are controlled by the master.
# Source 'interfaces' aren't brought down.
if iface_type not in ["slave", "source"]:
cmd = ["ip", "link", "set", iface, "down"]
return __salt__["cmd.run"](cmd, python_shell=False)
return __salt__["cmd.run"](["ifdown", iface])
return None


Expand Down Expand Up @@ -1897,8 +1841,7 @@ def up(iface, iface_type): # pylint: disable=C0103
# Slave devices are controlled by the master.
# Source 'interfaces' aren't brought up.
if iface_type not in ("slave", "source"):
cmd = ["ip", "link", "set", iface, "up"]
return __salt__["cmd.run"](cmd, python_shell=False)
return __salt__["cmd.run"](["ifup", iface])
return None


Expand Down Expand Up @@ -1929,11 +1872,9 @@ def get_network_settings():

hostname = _parse_hostname()
domainname = _parse_domainname()
searchdomain = _parse_searchdomain()

settings["hostname"] = hostname
settings["domainname"] = domainname
settings["searchdomain"] = searchdomain

else:
settings = _parse_current_network_settings()
Expand Down
Loading

0 comments on commit fc3fee1

Please sign in to comment.