Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
fda1085d
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fda1085d
编写于
11月 01, 2014
作者:
N
Nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add netifaces optionnal dependancy
上级
e4a3b936
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
19 deletion
+49
-19
glances/core/glances_autodiscover.py
glances/core/glances_autodiscover.py
+49
-19
未找到文件。
glances/core/glances_autodiscover.py
浏览文件 @
fda1085d
...
...
@@ -21,6 +21,11 @@
# Import system libs
import
socket
try
:
import
netifaces
netifaces_tag
=
True
except
ImportError
:
netifaces_tag
=
True
try
:
from
zeroconf
import
ServiceBrowser
,
ServiceInfo
,
Zeroconf
zeroconf_tag
=
True
...
...
@@ -28,13 +33,14 @@ except ImportError:
zeroconf_tag
=
False
# Import Glances libs
from
glances.core.glances_globals
import
appname
,
version
,
logger
from
glances.core.glances_globals
import
appname
,
logger
# Global var
zeroconf_type
=
"_%s._tcp."
%
appname
class
AutoDiscovered
(
object
):
"""Class to manage the auto discovered servers dict"""
def
__init__
(
self
):
...
...
@@ -59,6 +65,7 @@ class AutoDiscovered(object):
class
GlancesAutoDiscoverListener
(
object
):
"""Zeroconf listener for Glances server"""
def
__init__
(
self
):
...
...
@@ -89,18 +96,22 @@ class GlancesAutoDiscoverListener(object):
# Add server to the global dict
self
.
servers
.
add_server
(
srv_name
,
new_server_ip
,
new_server_port
)
logger
.
info
(
"New Glances server detected (%s from %s:%s)"
%
(
srv_name
,
new_server_ip
,
new_server_port
))
logger
.
info
(
"New Glances server detected (%s from %s:%s)"
%
(
srv_name
,
new_server_ip
,
new_server_port
))
else
:
logger
.
warning
(
"New Glances server detected, but Zeroconf info failed to be grabbed"
)
logger
.
warning
(
"New Glances server detected, but Zeroconf info failed to be grabbed"
)
return
True
def
removeService
(
self
,
zeroconf
,
srv_type
,
srv_name
):
# Remove the server from the list
self
.
servers
.
remove_server
(
srv_name
)
logger
.
info
(
"Glances server %s removed from the autodetect list"
%
srv_name
)
logger
.
info
(
"Glances server %s removed from the autodetect list"
%
srv_name
)
class
GlancesAutoDiscoverServer
(
object
):
"""Implementation of the Zeroconf protocol (server side for the Glances client)"""
def
__init__
(
self
,
args
=
None
):
...
...
@@ -108,9 +119,11 @@ class GlancesAutoDiscoverServer(object):
logger
.
info
(
"Init autodiscover mode (Zeroconf protocol)"
)
self
.
zeroconf
=
Zeroconf
()
self
.
listener
=
GlancesAutoDiscoverListener
()
self
.
browser
=
ServiceBrowser
(
self
.
zeroconf
,
zeroconf_type
,
self
.
listener
)
self
.
browser
=
ServiceBrowser
(
self
.
zeroconf
,
zeroconf_type
,
self
.
listener
)
else
:
logger
.
error
(
"Can not start autodiscover mode (Zeroconf lib is not installed)"
)
logger
.
error
(
"Can not start autodiscover mode (Zeroconf lib is not installed)"
)
def
get_servers_list
(
self
):
"""Return the current server list (dict of dict)"""
...
...
@@ -125,23 +138,40 @@ class GlancesAutoDiscoverServer(object):
class
GlancesAutoDiscoverClient
(
object
):
"""Implementation of the Zeroconf protocol (client side for the Glances server)"""
def
__init__
(
self
,
hostname
,
args
=
None
):
if
zeroconf_tag
:
logger
.
info
(
"Announce the Glances server on the local area network"
)
self
.
zeroconf
=
Zeroconf
()
self
.
info
=
ServiceInfo
(
zeroconf_type
,
hostname
+
'.'
+
zeroconf_type
,
address
=
socket
.
inet_aton
(
args
.
bind_address
),
port
=
args
.
port
,
weight
=
0
,
priority
=
0
,
properties
=
{},
server
=
hostname
)
self
.
zeroconf
.
registerService
(
self
.
info
)
if
netifaces_tag
:
# !!! TO BE REFACTOR
# OK with server: LANGUAGE=en_US.utf8 python -m glances -s -d -B 192.168.176.128
# KO with server: LANGUAGE=en_US.utf8 python -m glances -s -d
try
:
zeroconf_bind_address
=
socket
.
inet_aton
(
netifaces
.
ifaddresses
(
netifaces
.
interfaces
()[
1
])[
netifaces
.
AF_INET
][
0
][
'addr'
])
except
:
zeroconf_bind_address
=
socket
.
inet_aton
(
args
.
bind_address
)
# /!!!
if
zeroconf_tag
:
logger
.
info
(
"Announce the Glances server on the local area network (using %s IP address)"
%
zeroconf_bind_address
)
self
.
zeroconf
=
Zeroconf
()
self
.
info
=
ServiceInfo
(
zeroconf_type
,
hostname
+
'.'
+
zeroconf_type
,
address
=
zeroconf_bind_address
,
port
=
args
.
port
,
weight
=
0
,
priority
=
0
,
properties
=
{},
server
=
hostname
)
self
.
zeroconf
.
registerService
(
self
.
info
)
else
:
logger
.
error
(
"Can not announce Glances server on the network (Zeroconf lib is not installed)"
)
else
:
logger
.
error
(
"Can not announce Glances server on the network (Zeroconf lib is not installed)"
)
logger
.
error
(
"Can not announce Glances server on the network (Netifaces lib is not installed)"
)
def
close
(
self
):
if
zeroconf_tag
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录