本文整理汇总了Python中freenasUI.common.freenasldap.FreeNAS_ActiveDirectory.port_is_listening方法的典型用法代码示例。如果您正苦于以下问题:Python FreeNAS_ActiveDirectory.port_is_listening方法的具体用法?Python FreeNAS_ActiveDirectory.port_is_listening怎么用?Python FreeNAS_ActiveDirectory.port_is_listening使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freenasUI.common.freenasldap.FreeNAS_ActiveDirectory
的用法示例。
在下文中一共展示了FreeNAS_ActiveDirectory.port_is_listening方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_ad_gcname
# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import port_is_listening [as 别名]
def clean_ad_gcname(self):
ad_gcname = self.cleaned_data.get('ad_gcname')
ad_gcport = self.get_gcport()
if not ad_gcname:
return None
parts = ad_gcname.split(':')
ad_gcname = parts[0]
errors = []
try:
ret = FreeNAS_ActiveDirectory.port_is_listening(
host=ad_gcname, port=ad_gcport, errors=errors
)
if ret is False:
raise Exception(
'Invalid Host/Port: %s' % errors[0]
)
except Exception as e:
raise forms.ValidationError('%s.' % e)
return self.cleaned_data.get('ad_gcname')
示例2: clean_ad_gcname
# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import port_is_listening [as 别名]
def clean_ad_gcname(self):
ad_gcname = self.cleaned_data.get('ad_gcname')
ad_gcport = 3268
ad_ssl = self.cleaned_data.get('ad_ssl')
if ad_ssl == 'on':
ad_gcport = 3269
if not ad_gcname:
return None
parts = ad_gcname.split(':')
ad_gcname = parts[0]
if len(parts) > 1 and parts[1].isdigit():
ad_gcport = long(parts[1])
errors = []
try:
ret = FreeNAS_ActiveDirectory.port_is_listening(
host=ad_gcname, port=ad_gcport, errors=errors)
if ret is False:
raise Exception('Invalid Host/Port: %s' % errors[0])
except Exception as e:
raise forms.ValidationError('%s.' % e)
return self.cleaned_data.get('ad_gcname')
示例3: tryConnect
# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import port_is_listening [as 别名]
def tryConnect(self, host, port):
max_tries = 3
connected = False
sm_timeout = _fs().middlewared.plugins.service_monitor.socket_timeout
host_list = []
if self.name == 'activedirectory':
for i in range(0, max_tries):
# Make max_tries attempts to get SRV records from DNS
host_list = FreeNAS_ActiveDirectory.get_ldap_servers(host)
if host_list:
break
else:
self.logger.debug(f'[ServiceMonitorThread] Attempt {i} to query SRV records failed')
if not host_list:
self.logger.debug(f'[ServiceMonitorThread] Query for SRV records for {host} failed')
return False
for h in host_list:
port_is_listening = FreeNAS_ActiveDirectory.port_is_listening(str(h.target), h.port, errors=[], timeout=sm_timeout)
if port_is_listening:
return True
else:
self.logger.debug(f'[ServiceMonitorThread] Cannot connect: {h.target}:{h.port}')
connected = False
return connected
else:
self.logger.debug(f'[ServiceMonitorThread] no monitoring has been written for {self.name}')
return False