mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
improve master.status to work with host fqdns/hostnames as well as ips
The former version only worked with IPs which is kind of limited and has been reported as bugs.
This commit is contained in:
parent
f01ce36e89
commit
d74e7eb33f
@ -657,7 +657,7 @@ class Minion(MinionBase):
|
||||
'seconds': opts['master_alive_interval'],
|
||||
'jid_include': True,
|
||||
'maxrunning': 1,
|
||||
'kwargs': {'master_ip': self.opts['master'],
|
||||
'kwargs': {'master': self.opts['master'],
|
||||
'connected': True}
|
||||
}
|
||||
})
|
||||
@ -1595,7 +1595,7 @@ class Minion(MinionBase):
|
||||
'seconds': self.opts['master_alive_interval'],
|
||||
'jid_include': True,
|
||||
'maxrunning': 2,
|
||||
'kwargs': {'master_ip': self.opts['master'],
|
||||
'kwargs': {'master': self.opts['master'],
|
||||
'connected': False}
|
||||
}
|
||||
self.schedule.modify_job(name='__master_alive',
|
||||
@ -1633,7 +1633,7 @@ class Minion(MinionBase):
|
||||
'seconds': self.opts['master_alive_interval'],
|
||||
'jid_include': True,
|
||||
'maxrunning': 2,
|
||||
'kwargs': {'master_ip': self.opts['master'],
|
||||
'kwargs': {'master': self.opts['master'],
|
||||
'connected': True}
|
||||
}
|
||||
self.schedule.modify_job(name='__master_alive',
|
||||
@ -1651,7 +1651,7 @@ class Minion(MinionBase):
|
||||
'seconds': self.opts['master_alive_interval'],
|
||||
'jid_include': True,
|
||||
'maxrunning': 2,
|
||||
'kwargs': {'master_ip': self.opts['master'],
|
||||
'kwargs': {'master': self.opts['master'],
|
||||
'connected': True}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ from salt.ext.six.moves import range
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
from salt.utils.network import remote_port_tcp as _remote_port_tcp
|
||||
from salt.utils.network import host_to_ip as _host_to_ip
|
||||
import salt.utils.event
|
||||
import salt.config
|
||||
|
||||
@ -555,12 +556,14 @@ def version():
|
||||
return ret
|
||||
|
||||
|
||||
def master(master_ip=None, connected=True):
|
||||
def master(master=None, connected=True):
|
||||
'''
|
||||
.. versionadded:: 2014.7.0
|
||||
|
||||
Fire an event if the minion gets disconnected from its master. This
|
||||
function is meant to be run via a scheduled job from the minion
|
||||
function is meant to be run via a scheduled job from the minion. If
|
||||
master_ip is an FQDN/Hostname, is must be resolvable to a valid IPv4
|
||||
address.
|
||||
|
||||
CLI Example:
|
||||
|
||||
@ -571,17 +574,26 @@ def master(master_ip=None, connected=True):
|
||||
|
||||
# the default publishing port
|
||||
port = 4505
|
||||
master_ip = None
|
||||
|
||||
if __salt__['config.get']('publish_port') != '':
|
||||
port = int(__salt__['config.get']('publish_port'))
|
||||
|
||||
# Check if we have FQDN/hostname defined as master
|
||||
# address and try resolving it first. _remote_port_tcp
|
||||
# only works with IP-addresses.
|
||||
if master is not None:
|
||||
tmp_ip = _host_to_ip(master)
|
||||
if tmp_ip is not None:
|
||||
master_ip = tmp_ip
|
||||
|
||||
ips = _remote_port_tcp(port)
|
||||
|
||||
if connected:
|
||||
if master_ip not in ips:
|
||||
event = salt.utils.event.get_event('minion', opts=__opts__, listen=False)
|
||||
event.fire_event({'master': master_ip}, '__master_disconnected')
|
||||
event.fire_event({'master': master}, '__master_disconnected')
|
||||
else:
|
||||
if master_ip in ips:
|
||||
event = salt.utils.event.get_event('minion', opts=__opts__, listen=False)
|
||||
event.fire_event({'master': master_ip}, '__master_connected')
|
||||
event.fire_event({'master': master}, '__master_connected')
|
||||
|
Loading…
Reference in New Issue
Block a user