コード例 #1
0
ファイル: get_node_list.py プロジェクト: WuxV/tianjimgr-v2
    def INIT(self, request):
        self.response = MakeResponse(msg_mds.GET_NODE_LIST_RESPONSE, request)
        self.request = request
        self.request_body = request.body.Extensions[
            msg_mds.get_node_list_request]

        if g.is_ready == False:
            self.response.rc.retcode = msg_mds.RC_MDS_SERVICE_IS_NOT_READY
            self.response.rc.message = "MDS service is not ready"
            self.SendResponse(self.response)
            return MS_FINISH

        # 已经配置的uuid列表
        uuids_conf = {}

        # 广播的uuid列表
        uuids_broadcast = []

        for node in g.nsnode_conf_list.nsnode_infos:
            uuids_conf[node.node_uuid] = node.node_info.node_index

        local_ip = g.listen_ip
        for nsnode_info in g.nsnode_list.nsnode_infos:
            if not nsnode_info.HasField(
                    "listen_ip") or not nsnode_info.HasField(
                        "broadcast_ip") or not nsnode_info.HasField(
                            "node_uuid"):
                continue

            if self.request_body.HasField('is_remove_smartmon'):
                if nsnode_info.is_smartmon == True:
                    continue

            if nsnode_info.node_uuid in uuids_conf.keys():
                nsnode_info.node_status = msg_pds.NODE_CONFIGURED
                nsnode_info.node_index = uuids_conf[nsnode_info.node_uuid]
            else:
                nsnode_info.node_status = msg_pds.NODE_UNCONFIGURED

            uuids_broadcast.append(nsnode_info.node_uuid)
            self.response.body.Extensions[
                msg_mds.get_node_list_response].nsnode_infos.add().CopyFrom(
                    nsnode_info)

        for node in g.nsnode_conf_list.nsnode_infos:
            if node.node_uuid not in uuids_broadcast:
                nodeinfo = msg_pds.NSNodeInfo()
                nodeinfo.node_status = msg_pds.NODE_MISSING
                nodeinfo.node_index = node.node_info.node_index
                nodeinfo.node_name = node.node_info.node_name
                nodeinfo.listen_ip = node.node_info.listen_ip
                nodeinfo.listen_port = node.node_info.listen_port
                self.response.body.Extensions[
                    msg_mds.get_node_list_response].nsnode_infos.add(
                    ).CopyFrom(nodeinfo)

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
コード例 #2
0
ファイル: create_broadcast.py プロジェクト: WuxV/tianjimgr-v2
    def server(self):
        host = "%s.0" % ".".join(self.host.split(".")[:3])
        address = (host, self.port)
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        sock.bind(address)

        while True:
            time.sleep(0.1)
            try:
                data = ""
                while True:
                    _data, addr = sock.recvfrom(1024)
                    data += _data
                    if len(data) >= (pkSize +
                                     struct.unpack('I', data[:pkSize])[0]):
                        break
                data = data[pkSize:len(data)]

                logger.run.debug("Recv broadcast request %s from %s:%s" %
                                 (json.loads(data), addr[0], addr[1]))
                _data = json.loads(data)
                if _data['action'] == "discover":
                    if _data.has_key("broadcast_version"):
                        nsnode_info = msg_pds.NSNodeInfo()
                        if _data['broadcast_version'] == g.broadcast_version:
                            nsnode_info.node_uuid = g.node_uuid
                        nsnode_info.node_name = g.node_info.node_name
                        nsnode_info.sys_mode = g.platform['sys_mode']
                        nsnode_info.platform = g.platform['platform']
                        nsnode_info.host_name = socket.gethostname()
                        nsnode_info.listen_ip = config.safe_get(
                            'network', 'listen-ip')
                        nsnode_info.listen_port = config.safe_get_int(
                            'network', 'listen-port')
                        nsnode_info.broadcast_ip = self.host
                        nsnode_info.ibguids.extend(g.ibguids)
                        nsnode_info.is_smartmon = g.is_smartmon
                        data = nsnode_info.SerializeToString()
                        data = struct.pack('I', len(data)) + data
                        ret = sock.sendto(data, addr)
                        logger.run.debug(
                            "Send broadcast response %s to %s:%s ret %s" %
                            (nsnode_info, addr[0], addr[1], ret))
                    if _data.has_key("smartmon_ip"):
                        g.smartmon_ip = _data["smartmon_ip"]
                else:
                    logger.run.error("Not support")
                    assert (0)
            except (KeyboardInterrupt, SystemExit):
                raise
            except socket.timeout as e:
                pass
            except Exception as e:
                logger.run.error("recv udp error:%s" % e)
コード例 #3
0
    def Entry_Broadcast(self, result):
        rc, data_nsnode = result

        # 更新节点时间
        g.nsnode_list.Clear()
        for data in data_nsnode:
            nsnode_info = msg_pds.NSNodeInfo()
            try:
                nsnode_info.ParseFromString(data)
            except:
                continue

            # 每次都更新不需要跳过
            #key = "%s.%s.%s" % (nsnode_info.listen_ip, nsnode_info.listen_port, nsnode_info.sys_mode)
            #flag = False
            #for _nsnode_info in g.nsnode_list.nsnode_infos:
            #    if key == "%s.%s.%s" % (_nsnode_info.listen_ip, _nsnode_info.listen_port, _nsnode_info.sys_mode):
            #        print key
            #        _nsnode_info.last_broadcast_time = int(time.time())
            #        flag = True
            #        break
            #if flag == False:
            #    _nsnode_info = g.nsnode_list.nsnode_infos.add()
            #    _nsnode_info.CopyFrom(nsnode_info)
            #    _nsnode_info.last_broadcast_time = int(time.time())
            #    # 存储节点上线, 需要置刷新标记
            #    if nsnode_info.sys_mode != "database":
            #        g.srp_rescan_flag = True

            _nsnode_info = g.nsnode_list.nsnode_infos.add()
            _nsnode_info.CopyFrom(nsnode_info)
            _nsnode_info.last_broadcast_time = int(time.time())
            # 存储节点上线, 需要置刷新标记
            if nsnode_info.sys_mode != "database":
                g.srp_rescan_flag = True

        # 清除超时节点
        nsnode_list = msg_mds.G_NSNodeList()
        for nsnode_info in g.nsnode_list.nsnode_infos:
            if int(time.time(
            )) - nsnode_info.last_broadcast_time < MAX_NSNODE_ACTIVE_TIME:
                nsnode_list.nsnode_infos.add().CopyFrom(nsnode_info)
            else:
                # 存储节点离线, 需要置刷新标记
                if nsnode_info.sys_mode != "database":
                    g.srp_rescan_flag = True
        g.nsnode_list = nsnode_list
        return MS_FINISH
コード例 #4
0
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
from pdsframe import *
import message.pds_pb2 as msg_pds
import message.ios_pb2 as msg_ios

# 平台信息
platform = None

# 服务状态
is_ready = False

# 最后更新时间
last_modify_time = 0

# 需要进行健康检查的磁盘列表
todo_check_disk = []

# 健康检查的磁盘列表结果
cache_disk_list_healthy = {}

# mds 服务信息
mds_service = msg_pds.NSNodeInfo()
mds_service.listen_ip   = config.safe_get('network', 'listen-ip')
mds_service.listen_port = config.safe_get_int('network', 'mds-listen-port')