Merge pull request #15163 from garethgreenaway/apply_hostname

Changes to modules debian_ip and rh_ip, and the network.py state
This commit is contained in:
Thomas S Hatch 2014-08-22 12:13:18 -06:00
commit 26f6acc1d0
3 changed files with 56 additions and 4 deletions

View File

@ -1741,16 +1741,33 @@ def apply_network_settings(**settings):
if 'require_reboot' not in settings:
settings['require_reboot'] = False
if 'apply_hostname' not in settings:
settings['apply_hostname'] = False
hostname_res = True
if settings['apply_hostname'] in _CONFIG_TRUE:
if 'hostname' in settings:
hostname_res = __salt__['network.mod_hostname'](settings['hostname'])
else:
log.warning(
'The network state sls is trying to apply hostname '
'changes but no hostname is defined.'
)
hostname_res = False
res = True
if settings['require_reboot'] in _CONFIG_TRUE:
log.warning(
'The network state sls is requiring a reboot of the system to '
'properly apply network configuration.'
)
return True
res = True
else:
stop = __salt__['service.stop']('networking')
time.sleep(2)
return stop and __salt__['service.start']('networking')
res = stop and __salt__['service.start']('networking')
return hostname_res and res
def build_network_settings(**settings):
@ -1808,6 +1825,7 @@ def build_network_settings(**settings):
# Only write the hostname if it has changed
if not opts['hostname'] == current_network_settings['hostname']:
# TODO replace wiht a call to network.mod_hostname instead
_write_file_network(hostname, _DEB_HOSTNAME_FILE)
new_domain = False

View File

@ -1041,14 +1041,31 @@ def apply_network_settings(**settings):
if 'require_reboot' not in settings:
settings['require_reboot'] = False
if 'apply_hostname' not in settings:
settings['apply_hostname'] = False
hostname_res = True
if settings['apply_hostname'] in _CONFIG_TRUE:
if 'hostname' in settings:
hostname_res = __salt__['network.mod_hostname'](settings['hostname'])
else:
log.warning(
'The network state sls is trying to apply hostname '
'changes but no hostname is defined.'
)
hostname_res = False
res = True
if settings['require_reboot'] in _CONFIG_TRUE:
log.warning(
'The network state sls is requiring a reboot of the system to '
'properly apply network configuration.'
)
return True
res = True
else:
return __salt__['service.restart']('network')
res = __salt__['service.restart']('network')
return hostname_res and res
def build_network_settings(**settings):

View File

@ -153,6 +153,23 @@ all interfaces are ignored unless specified.
- network: eth4
- require:
- network: eth4
system:
network.system:
- enabled: True
- hostname: server1.example.com
- gateway: 192.168.0.1
- gatewaydev: eth0
- nozeroconf: True
- nisdomain: example.com
- require_reboot: True
- apply_hostname: True
.. note::
Apply changes to hostname immediately.
.. versionadded:: Lithium
'''
# Import python libs