Exemplo n.º 1
0
    def online_asmdisk(self, params={}):
        rc = msg_pds.ResponseCode()

        ret, dbs = asm.get_grid_env()
        if ret:
            logger.run.error("Parse oratab env failed: %s" % dbs)
            rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            return rc, None

        if dbs.has_key("grid_home"):
            grid_home = dbs["grid_home"]
        else:
            logger.run.error("Can not find Oracle grid home")
            rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            return rc, None

        sql = AsmOraSQLPlus(grid_home)
        if self.asmdisk_name:
            ret, result = sql.online_asm_disk(self.diskgroup_name,
                                              self.asmdisk_name)
        else:
            ret, result = sql.online_asm_disk(self.diskgroup_name,
                                              failgroup=self.failgroup)
        if ret:
            logger.run.error("ASMDisk online failed: %s" % result)
            rc.retcode = msg_mds.RC_MDS_ASMDISK_ONLINE_FAILED
            return rc, None

        logger.run.info("ASMDisk %s online success" % self.asmdisk_name)
        rc.retcode = msg_pds.RC_SUCCESS
        return rc, None
Exemplo n.º 2
0
    def INIT(self, request):
        self.response = MakeResponse(msg_mds.ASMDISK_DROP_RESPONSE, request)
        self.request = request
        self.request_body = request.body.Extensions[
            msg_mds.asmdisk_drop_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

        asmdisk_name = self.request_body.asmdisk_name
        rebalance_power = self.request_body.rebalance_power
        force = self.request_body.force
        asmdisk_info = common.GetASMDiskInfoByName(asmdisk_name)
        if not asmdisk_info:
            self.response.rc.retcode = msg_mds.RC_MDS_ASMDISK_NOT_EXIST
            self.response.rc.message = "ASMDisk %s not exist" % asmdisk_name
            self.SendResponse(self.response)
            return MS_FINISH
        diskgroup_info = common.GetDiskgroupInfoByID(asmdisk_info.diskgroup_id)
        diskgroup_name = diskgroup_info.diskgroup_name

        ret, dbs = asm.get_grid_env()
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Parse oratab env failed: %s" % dbs
            self.SendResponse(self.response)
            return MS_FINISH

        if dbs.has_key("grid_home"):
            grid_home = dbs["grid_home"]
        else:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Can not find Oracle grid home"
            self.SendResponse(self.response)
            return MS_FINISH

        sql = AsmOraSQLPlus(grid_home)
        ret, result = sql.drop_asm_disk(diskgroup_name, asmdisk_name, force)
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_ASMDISK_DROP_FAILED
            self.response.rc.message = "ASMDisk drop failed: %s" % result
            self.SendResponse(self.response)
            return MS_FINISH

        if rebalance_power:
            ret, result = sql.alter_asm_rebalance(diskgroup_name,
                                                  rebalance_power)
            if ret:
                self.response.rc.retcode = msg_mds.RC_MDS_DISKGROUP_REBALANCE_FAILED
                self.response.rc.message = "Alter diskgroup rebalance failed: %s" % result
                self.SendResponse(self.response)
                return MS_FINISH

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Exemplo n.º 3
0
    def INIT(self, request):
        self.response = MakeResponse(msg_mds.DISKGROUP_ADD_RESPONSE, request)
        self.request = request
        self.request_body = request.body.Extensions[
            msg_mds.diskgroup_add_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

        diskgroup_name = self.request_body.diskgroup_name
        asmdisk_paths = self.request_body.asmdisk_paths
        failgroups = self.request_body.failgroups
        redundancy = self.request_body.redundancy
        compatible_asm = self.request_body.compatible_asm
        compatible_rdbms = self.request_body.compatible_rdbms

        diskgroup_info = common.GetDiskgroupInfoByName(diskgroup_name)
        if diskgroup_info:
            self.response.rc.retcode = msg_mds.RC_MDS_DISKGROUP_ALREADY_EXIST
            self.response.rc.message = "Diskgroup %s already exist" % diskgroup_name
            self.SendResponse(self.response)
            return MS_FINISH

        ret, dbs = asm.get_grid_env()
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Parse oratab env failed: %s" % dbs
            self.SendResponse(self.response)
            return MS_FINISH

        if dbs.has_key("grid_home"):
            self.grid_home = dbs["grid_home"]
        else:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Can not find Oracle grid home"
            self.SendResponse(self.response)
            return MS_FINISH

        sql = AsmOraSQLPlus(self.grid_home)
        ret, result = sql.add_asm_group(diskgroup_name, asmdisk_paths,
                                        failgroups, redundancy, compatible_asm,
                                        compatible_rdbms)
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_DISKGROUP_ADD_FAILED
            self.response.rc.message = "Diskgroup add failed: %s" % result
            self.SendResponse(self.response)
            return MS_FINISH

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Exemplo n.º 4
0
    def INIT(self, request):
        self.response = MakeResponse(msg_mds.DISKGROUP_UMOUNT_RESPONSE,
                                     request)
        self.request = request
        self.request_body = request.body.Extensions[
            msg_mds.diskgroup_umount_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

        diskgroup_name = self.request_body.diskgroup_name
        diskgroup_info = common.GetDiskgroupInfoByName(diskgroup_name)
        if not diskgroup_info:
            self.response.rc.retcode = msg_mds.RC_MDS_DISKGROUP_NOT_EXIST
            self.response.rc.message = "Diskgroup %s not exist" % diskgroup_name
            self.SendResponse(self.response)
            return MS_FINISH
        if diskgroup_info.state == "DISMOUNTED":
            self.response.rc.retcode = msg_mds.RC_MDS_DISKGROUP_ALREADY_UMOUNTED
            self.response.rc.message = "Diskgroup %s is not mounted" % diskgroup_name
            self.SendResponse(self.response)
            return MS_FINISH

        ret, dbs = asm.get_grid_env()
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Parse oratab env failed: %s" % dbs
            self.SendResponse(self.response)
            return MS_FINISH

        if dbs.has_key("grid_home"):
            grid_home = dbs["grid_home"]
        else:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Can not find Oracle grid home"
            self.SendResponse(self.response)
            return MS_FINISH

        sql = AsmOraSQLPlus(grid_home)
        ret, result = sql.umount_asm_group(diskgroup_name)
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_DISKGROUP_UMOUNT_FAILED
            self.response.rc.message = "Umount asm diskgroup failed: %s" % result
            self.SendResponse(self.response)
            return MS_FINISH

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Exemplo n.º 5
0
    def INIT(self, request):
        self.response     = MakeResponse(msg_mds.ASMDISK_OFFLINE_RESPONSE, request)
        self.request      = request
        self.request_body = request.body.Extensions[msg_mds.asmdisk_offline_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

        asmdisk_name = ""
        if self.request_body.HasField('asmdisk_name'):
            asmdisk_name = self.request_body.asmdisk_name
            asmdisk_info = common.GetASMDiskInfoByName(asmdisk_name)
            if not asmdisk_info:
                self.response.rc.retcode = msg_mds.RC_MDS_ASMDISK_NOT_EXIST
                self.response.rc.message = "ASMDisk %s not exist" % asmdisk_name
                self.SendResponse(self.response)
                return MS_FINISH
            if asmdisk_info.mode_status == "OFFLINE":
                self.response.rc.retcode = msg_mds.RC_MDS_ASMDISK_ALREADY_OFFLINE
                self.response.rc.message = "ASMDisk %s is already offline state" % asmdisk_name
                self.SendResponse(self.response)
                return MS_FINISH
            diskgroup_info = common.GetDiskgroupInfoByID(asmdisk_info.diskgroup_id)
            diskgroup_name = diskgroup_info.diskgroup_name
        elif self.request_body.HasField('diskgroup_name') and self.request_body.HasField('failgroup'):
            diskgroup_name = self.request_body.diskgroup_name
            diskgroup_info = common.GetDiskgroupInfoByName(diskgroup_name)
            if not diskgroup_info:
                self.response.rc.retcode = msg_mds.RC_MDS_DISKGROUP_NOT_EXIST
                self.response.rc.message = "Diskgroup %s not exist" % diskgroup_name
                self.SendResponse(self.response)
                return MS_FINISH

            failgroup = self.request_body.failgroup.upper()
            failgroup_list = [asmdisk_info.failgroup for asmdisk_info in g.asmdisk_list.asmdisk_infos if asmdisk_info.diskgroup_id == diskgroup_info.diskgroup_id]
            if failgroup not in failgroup_list:
                self.response.rc.retcode = msg_mds.RC_MDS_FAILGROUP_NOT_IN_DISKGROUP
                self.response.rc.message = "Failgroup %s not in diskgroup %s" % (failgroup, diskgroup_name)
                self.SendResponse(self.response)
                return MS_FINISH
        else:
            self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS
            self.response.rc.message = "Miss asmdisk/diskgroup/failgroup name"
            self.SendResponse(self.response)
            return MS_FINISH

        ret, dbs = asm.get_grid_env()
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Parse oratab env failed: %s" %dbs
            self.SendResponse(self.response)
            return MS_FINISH

        if dbs.has_key("grid_home"):
            grid_home = dbs["grid_home"]
        else:
            self.response.rc.retcode = msg_mds.RC_MDS_GET_GRID_ENV_FAILED
            self.response.rc.message = "Can not find Oracle grid home"
            self.SendResponse(self.response)
            return MS_FINISH

        sql = AsmOraSQLPlus(grid_home)
        if asmdisk_name:
            ret, result = sql.offline_asm_disk(diskgroup_name, asmdisk_name)
        else:
            ret, result = sql.offline_asm_disk(diskgroup_name, failgroup=failgroup)
        if ret:
            self.response.rc.retcode = msg_mds.RC_MDS_ASMDISK_ONLINE_FAILED
            self.response.rc.message = "ASMDisk offline failed: %s" % result
            self.SendResponse(self.response)
            return MS_FINISH

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Exemplo n.º 6
0
    def INIT(self):
        mds_storage_request = MakeRequest(
            msg_mds.HEARTBEAT_ASMDISK_LIST_REQUEST)

        if g.is_ready == False:
            logger.run.debug("HeartBeatASMDiskList MDS service is not ready")
            return MS_FINISH

        if g.platform['sys_mode'] == "storage":
            return MS_FINISH

        ret, dbs = asm.get_grid_env()
        if ret:
            logger.run.error("Parse oratab env failed: %s" % dbs)
            return self.refresh_empty_asmdisk()

        if dbs.has_key("grid_home"):
            self.grid_home = dbs["grid_home"]
        else:
            logger.run.error("Can not find Oracle grid home")
            return self.refresh_empty_asmdisk()

        self.ip = g.listen_ip
        self.port = config.safe_get('oracle', 'port')
        self.uid = config.safe_get('oracle', 'user')
        self.passwd = config.safe_get('oracle', 'password')
        self.servicename = config.safe_get('oracle', 'servicename')
        sql = OraSQLPlus(self.servicename, self.ip, self.port, self.uid,
                         self.passwd)
        ret, disk_list = sql.list_asm_disks()
        if ret:
            logger.run.error("Get asm disklist failed: %s" % disk_list)
            return self.refresh_empty_asmdisk()

        # 获取asmdisk_name为空的asmdisk对应的dskname
        dsk = []
        for disk in disk_list:
            if disk["name"]:
                continue
            e, info = self.get_info_by_kfed(disk['path'])
            if e:
                logger.run.error("Command kfed failed: %s" % info)
                return MS_FINISH
            if info and info["kfbh_type"] == "KFBTYP_DISKHEAD":
                found = False
                for i, dsk_info in enumerate(dsk):
                    # 相同dskname的asmdisk则取crestmp_hi和crestmp_lo较大的
                    if info["dskname"] == dsk_info["dskname"]:
                        found = True
                        if int(info["crestmp_hi"]) > int(
                                dsk_info["crestmp_hi"]) and int(
                                    info["crestmp_lo"] > int(
                                        dsk_info["crestmp_lo"])):
                            del dsk[i]
                            dsk_info = {}
                            dsk_info["path"] = disk["path"]
                            dsk_info["dskname"] = info["dskname"]
                            dsk_info["crestmp_hi"] = info["crestmp_hi"]
                            dsk_info["crestmp_lo"] = info["crestmp_lo"]
                            dsk.append(dsk_info)
                if not found:
                    dsk_info = {}
                    dsk_info["path"] = disk["path"]
                    dsk_info["dskname"] = info["dskname"]
                    dsk_info["crestmp_hi"] = info["crestmp_hi"]
                    dsk_info["crestmp_lo"] = info["crestmp_lo"]
                    dsk.append(dsk_info)
        for disk in disk_list:
            for dsk_info in dsk:
                if disk["path"] == dsk_info["path"]:
                    disk["dskname"] = dsk_info["dskname"]

        # 更新asmdisk列表
        g.asmdisk_list.Clear()
        for disk in disk_list:
            asmdisk_info = msg_pds.ASMDiskInfo()
            asmdisk_info.asmdisk_name = disk["name"] or ""
            asmdisk_info.asmdisk_id = str(disk["disk_number"])
            asmdisk_info.diskgroup_id = str(disk["group_number"])
            asmdisk_info.state = disk["state"]
            asmdisk_info.mode_status = disk["mode_status"]
            asmdisk_info.path = disk["path"] or ""
            asmdisk_info.failgroup = disk["failgroup"] or ""
            asmdisk_info.total_mb = int(disk["total_mb"])
            asmdisk_info.free_mb = int(disk["free_mb"])

            if disk.has_key("dskname"):
                asmdisk_info.dskname = disk["dskname"]

            g.asmdisk_list.asmdisk_infos.add().CopyFrom(asmdisk_info)
            mds_storage_request.body.Extensions[
                msg_mds.heartbeat_asmdisk_list_request].asmdisk_infos.add(
                ).CopyFrom(asmdisk_info)

        mds_storage_request.body.Extensions[
            msg_mds.
            heartbeat_asmdisk_list_request].node_name = g.node_info.node_name
        # 向集群内的所有存储节点发送
        for node_info in g.nsnode_list.nsnode_infos:
            if node_info.sys_mode != "database":
                self.SendRequest(node_info.listen_ip, node_info.listen_port,
                                 mds_storage_request,
                                 self.Entry_HeartbeatASMDiskList)

        ret, diskgroup_list = sql.list_asm_group()
        if ret:
            logger.run.error("Get asm diskgroup failed: %s" % diskgroup_list)
            return MS_FINISH
        # 更新磁盘组列表
        g.diskgroup_list.Clear()
        for dg in diskgroup_list:
            diskgroup_info = msg_pds.DiskgroupInfo()
            diskgroup_info.diskgroup_name = dg["name"]
            diskgroup_info.diskgroup_id = str(dg["group_number"])
            diskgroup_info.type = dg["type"] or ""
            diskgroup_info.state = dg["state"]
            diskgroup_info.offline_disks = int(dg["offline_disks"])
            diskgroup_info.total_mb = int(dg["total_mb"])
            diskgroup_info.free_mb = int(dg["free_mb"])
            diskgroup_info.usable_file_mb = int(dg["usable_file_mb"])
            g.diskgroup_list.diskgroup_infos.add().CopyFrom(diskgroup_info)

        return MS_CONTINUE