本文整理汇总了Python中freenas.dispatcher.client.Client.login_token方法的典型用法代码示例。如果您正苦于以下问题:Python Client.login_token方法的具体用法?Python Client.login_token怎么用?Python Client.login_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freenas.dispatcher.client.Client
的用法示例。
在下文中一共展示了Client.login_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Context
# 需要导入模块: from freenas.dispatcher.client import Client [as 别名]
# 或者: from freenas.dispatcher.client.Client import login_token [as 别名]
#.........这里部分代码省略.........
i._login(self)
def __discover_plugin_dir(self, dir):
for i in glob.glob1(dir, "*.py"):
self.__try_load_plugin(os.path.join(dir, i))
def __try_load_plugin(self, path):
if path in self.plugins:
return
self.logger.debug(_("Loading plugin from %s"), path)
name, ext = os.path.splitext(os.path.basename(path))
plugin = imp.load_source(name, path)
if hasattr(plugin, '_init'):
plugin._init(self)
self.plugins[path] = plugin
def __try_reconnect(self):
output_lock.acquire()
self.ml.blank_readline()
output_msg(_('Connection lost! Trying to reconnect...'))
retries = 0
while True:
retries += 1
try:
time.sleep(2)
self.connect()
try:
if self.hostname == '127.0.0.1':
self.connection.login_user(getpass.getuser(), '')
else:
self.connection.login_token(self.connection.token)
self.connection.subscribe_events(*EVENT_MASKS)
except RpcException:
output_msg(_("Reauthentication failed (most likely token expired or server was restarted)"))
sys.exit(1)
break
except Exception as e:
output_msg(_('Cannot reconnect: {0}'.format(str(e))))
self.ml.restore_readline()
output_lock.release()
def attach_namespace(self, path, ns):
splitpath = path.split('/')
ptr = self.root_ns
ptr_namespaces = ptr.namespaces()
for n in splitpath[1:-1]:
if n not in list(ptr_namespaces().keys()):
self.logger.warn(_("Cannot attach to namespace %s"), path)
return
ptr = ptr_namespaces()[n]
ptr.register_namespace(ns)
def connection_error(self, event, **kwargs):
if event == ClientError.LOGOUT:
output_msg('Logged out from server.')
self.connection.disconnect()
sys.exit(0)