mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #41350 from lorengordon/issue-41341
Supports quoted values in /etc/sysconfig/network
This commit is contained in:
commit
88c28c18c3
@ -1153,7 +1153,10 @@ def mod_hostname(hostname):
|
||||
with salt.utils.fopen('/etc/sysconfig/network', 'w') as fh_:
|
||||
for net in network_c:
|
||||
if net.startswith('HOSTNAME'):
|
||||
fh_.write('HOSTNAME={0}\n'.format(hostname))
|
||||
old_hostname = net.split('=', 1)[1].rstrip()
|
||||
quote_type = salt.utils.is_quoted(old_hostname)
|
||||
fh_.write('HOSTNAME={1}{0}{1}\n'.format(
|
||||
salt.utils.dequote(hostname), quote_type))
|
||||
else:
|
||||
fh_.write(net)
|
||||
elif __grains__['os_family'] in ('Debian', 'NILinuxRT'):
|
||||
|
@ -787,21 +787,30 @@ def _parse_network_settings(opts, current):
|
||||
retain_settings = opts.get('retain_settings', False)
|
||||
result = current if retain_settings else {}
|
||||
|
||||
# Default quote type is an empty string, which will not quote values
|
||||
quote_type = ''
|
||||
|
||||
valid = _CONFIG_TRUE + _CONFIG_FALSE
|
||||
if 'enabled' not in opts:
|
||||
try:
|
||||
opts['networking'] = current['networking']
|
||||
# If networking option is quoted, use its quote type
|
||||
quote_type = salt.utils.is_quoted(opts['networking'])
|
||||
_log_default_network('networking', current['networking'])
|
||||
except ValueError:
|
||||
_raise_error_network('networking', valid)
|
||||
else:
|
||||
opts['networking'] = opts['enabled']
|
||||
|
||||
if opts['networking'] in valid:
|
||||
if opts['networking'] in _CONFIG_TRUE:
|
||||
result['networking'] = 'yes'
|
||||
elif opts['networking'] in _CONFIG_FALSE:
|
||||
result['networking'] = 'no'
|
||||
true_val = '{0}yes{0}'.format(quote_type)
|
||||
false_val = '{0}no{0}'.format(quote_type)
|
||||
|
||||
networking = salt.utils.dequote(opts['networking'])
|
||||
if networking in valid:
|
||||
if networking in _CONFIG_TRUE:
|
||||
result['networking'] = true_val
|
||||
elif networking in _CONFIG_FALSE:
|
||||
result['networking'] = false_val
|
||||
else:
|
||||
_raise_error_network('networking', valid)
|
||||
|
||||
@ -813,22 +822,25 @@ def _parse_network_settings(opts, current):
|
||||
_raise_error_network('hostname', ['server1.example.com'])
|
||||
|
||||
if opts['hostname']:
|
||||
result['hostname'] = opts['hostname']
|
||||
result['hostname'] = '{1}{0}{1}'.format(
|
||||
salt.utils.dequote(opts['hostname']), quote_type)
|
||||
else:
|
||||
_raise_error_network('hostname', ['server1.example.com'])
|
||||
|
||||
if 'nozeroconf' in opts:
|
||||
if opts['nozeroconf'] in valid:
|
||||
if opts['nozeroconf'] in _CONFIG_TRUE:
|
||||
result['nozeroconf'] = 'true'
|
||||
elif opts['nozeroconf'] in _CONFIG_FALSE:
|
||||
result['nozeroconf'] = 'false'
|
||||
nozeroconf = salt.utils.dequote(opts['nozerconf'])
|
||||
if nozeroconf in valid:
|
||||
if nozeroconf in _CONFIG_TRUE:
|
||||
result['nozeroconf'] = true_val
|
||||
elif nozeroconf in _CONFIG_FALSE:
|
||||
result['nozeroconf'] = false_val
|
||||
else:
|
||||
_raise_error_network('nozeroconf', valid)
|
||||
|
||||
for opt in opts:
|
||||
if opt not in ['networking', 'hostname', 'nozeroconf']:
|
||||
result[opt] = opts[opt]
|
||||
result[opt] = '{1}{0}{1}'.format(
|
||||
salt.utils.dequote(opts[opt]), quote_type)
|
||||
return result
|
||||
|
||||
|
||||
|
@ -3212,3 +3212,26 @@ def substr_in_list(string_to_search_for, list_to_search):
|
||||
string is present in any of the strings which comprise a list
|
||||
'''
|
||||
return any(string_to_search_for in s for s in list_to_search)
|
||||
|
||||
|
||||
def is_quoted(val):
|
||||
'''
|
||||
Return a single or double quote, if a string is wrapped in extra quotes.
|
||||
Otherwise return an empty string.
|
||||
'''
|
||||
ret = ''
|
||||
if (
|
||||
isinstance(val, six.string_types) and val[0] == val[-1] and
|
||||
val.startswith(('\'', '"'))
|
||||
):
|
||||
ret = val[0]
|
||||
return ret
|
||||
|
||||
|
||||
def dequote(val):
|
||||
'''
|
||||
Remove extra quotes around a string.
|
||||
'''
|
||||
if is_quoted(val):
|
||||
return val[1:-1]
|
||||
return val
|
||||
|
Loading…
Reference in New Issue
Block a user