Пример #1
0
    def get_device_info(self, dev_name):
        # type: (str) -> FiberChannelLunStruct
        s = FiberChannelLunStruct()
        o = shell.call(
            "lsblk --pair -b -p -o NAME,VENDOR,MODEL,WWN,SERIAL,HCTL,TYPE,SIZE /dev/%s"
            % dev_name).strip().split("\n")[0]
        if o == "":
            raise Exception("can not get device information from %s" %
                            dev_name)

        def get_data(e):
            return e.split("=")[1].strip().strip('"')

        def get_wwids(dev):
            return shell.call(
                "udevadm info -n %s | grep 'by-id' | grep -v DEVLINKS | awk -F 'by-id/' '{print $2}'"
                % dev).strip().split()

        def get_path(dev):
            return shell.call(
                "udevadm info -n %s | grep 'by-path' | grep -v DEVLINKS | head -n1 | awk -F 'by-path/' '{print $2}'"
                % dev).strip()

        def get_storage_wwnn(hctl):
            o = shell.call(
                "systool -c fc_transport -A node_name | grep '\"target%s\"' -B2 | grep node_name | awk '{print $NF}'"
                % ":".join(hctl.split(":")[0:3]))
            return o.strip().strip('"')

        for entry in o.split('" '):  # type: str
            if entry.startswith("VENDOR"):
                s.vendor = get_data(entry)
            elif entry.startswith("MODEL"):
                s.model = get_data(entry)
            elif entry.startswith("WWN"):
                s.wwn = get_data(entry)
            elif entry.startswith("SERIAL"):
                s.serial = get_data(entry)
            elif entry.startswith('HCTL'):
                s.hctl = get_data(entry)
            elif entry.startswith('SIZE'):
                s.size = get_data(entry)
            elif entry.startswith('TYPE'):
                s.type = get_data(entry)

        s.wwids = get_wwids(dev_name)
        s.wwids.sort()
        s.path = get_path(dev_name)
        if lvm.is_slave_of_multipath("/dev/%s" % dev_name):
            s.type = "mpath"
            wwid = bash.bash_o(
                "multipath -l /dev/%s | head -n1 | awk '{print $2}'" %
                dev_name).strip().strip("()")
            s.wwids = [wwid] if wwid != "" else s.wwids
        s.storageWwnn = get_storage_wwnn(s.hctl)

        return s
Пример #2
0
    def get_device_info(self, dev_name):
        # type: (str) -> FiberChannelLunStruct
        s = FiberChannelLunStruct()
        o = shell.call(
            "lsblk --pair -b -p -o NAME,VENDOR,MODEL,WWN,SERIAL,HCTL,TYPE,SIZE /dev/%s" % dev_name).strip().split("\n")[0]
        if o == "":
            raise Exception("can not get device information from %s" % dev_name)

        def get_data(e):
            return e.split("=")[1].strip().strip('"')

        def get_wwids(dev):
            return shell.call(
                "udevadm info -n %s | grep 'by-id' | grep -v DEVLINKS | awk -F 'by-id/' '{print $2}'" % dev).strip().split()

        def get_path(dev):
            return shell.call(
                "udevadm info -n %s | grep 'by-path' | grep -v DEVLINKS | head -n1 | awk -F 'by-path/' '{print $2}'" % dev).strip()

        def get_storage_wwnn(hctl):
            o = shell.call(
                "systool -c fc_transport -A node_name | grep '\"target%s\"' -B2 | grep node_name | awk '{print $NF}'" % ":".join(hctl.split(":")[0:3]))
            return o.strip().strip('"')

        for entry in o.split('" '):  # type: str
            if entry.startswith("VENDOR"):
                s.vendor = get_data(entry)
            elif entry.startswith("MODEL"):
                s.model = get_data(entry)
            elif entry.startswith("WWN"):
                s.wwn = get_data(entry)
            elif entry.startswith("SERIAL"):
                s.serial = get_data(entry)
            elif entry.startswith('HCTL'):
                s.hctl = get_data(entry)
            elif entry.startswith('SIZE'):
                s.size = get_data(entry)
            elif entry.startswith('TYPE'):
                s.type = get_data(entry)

        s.wwids = get_wwids(dev_name)
        s.wwids.sort()
        s.path = get_path(dev_name)
        if lvm.is_slave_of_multipath("/dev/%s" % dev_name):
            s.type = "mpath"
            wwid = bash.bash_o("multipath -l /dev/%s | head -n1 | awk '{print $2}'" % dev_name).strip().strip("()")
            s.wwids = [wwid] if wwid != "" else s.wwids
        s.storageWwnn = get_storage_wwnn(s.hctl)

        return s
Пример #3
0
 def get_disk_info_by_path(path):
     # type: (str) -> IscsiLunStruct
     abs_path = bash.bash_o("readlink -e /dev/disk/by-path/%s" % path).strip()
     candidate_struct = lvm.get_device_info(abs_path.split("/")[-1])
     lun_struct = IscsiLunStruct()
     lun_struct.path = path
     lun_struct.size = candidate_struct.size
     lun_struct.hctl = candidate_struct.hctl
     lun_struct.serial = candidate_struct.serial
     lun_struct.model = candidate_struct.model
     lun_struct.vendor = candidate_struct.vendor
     lun_struct.type = candidate_struct.type
     lun_struct.wwn = candidate_struct.wwn
     lun_struct.wwids = candidate_struct.wwids
     if lvm.is_slave_of_multipath(abs_path):
         lun_struct.type = "mpath"
         mpath_wwid = bash.bash_o("multipath -l %s | head -n1 | awk '{print $2}'" % abs_path).strip("() \n")
         lun_struct.wwids = [mpath_wwid]
     return lun_struct
Пример #4
0
 def get_disk_info_by_path(path):
     # type: (str) -> IscsiLunStruct
     abs_path = bash.bash_o("readlink -e /dev/disk/by-path/%s" % path).strip()
     candidate_struct = lvm.get_device_info(abs_path.split("/")[-1])
     lun_struct = IscsiLunStruct()
     lun_struct.path = path
     lun_struct.size = candidate_struct.size
     lun_struct.hctl = candidate_struct.hctl
     lun_struct.serial = candidate_struct.serial
     lun_struct.model = candidate_struct.model
     lun_struct.vendor = candidate_struct.vendor
     lun_struct.type = candidate_struct.type
     lun_struct.wwn = candidate_struct.wwn
     lun_struct.wwids = candidate_struct.wwids
     if lvm.is_slave_of_multipath(abs_path):
         lun_struct.type = "mpath"
         mpath_wwid = bash.bash_o("multipath -l %s | head -n1 | awk '{print $2}'" % abs_path).strip("() \n")
         lun_struct.wwids = [mpath_wwid]
     return lun_struct
Пример #5
0
    def get_disk_info_by_path(path):
        # type: (str) -> IscsiLunStruct
        r = bash.bash_r(
            "multipath -l | grep -e '/multipath.conf' | grep -e 'line'")
        if r == 0:
            current_hostname = shell.call('hostname')
            current_hostname = current_hostname.strip(' \t\n\r')
            raise Exception(
                "The multipath.conf setting on host[%s] may be error, please check and try again"
                % current_hostname)

        abs_path = bash.bash_o("readlink -e /dev/disk/by-path/%s" %
                               path).strip()
        candidate_struct = lvm.get_device_info(abs_path.split("/")[-1])
        if candidate_struct is None:
            return None
        lun_struct = IscsiLunStruct()
        lun_struct.path = path
        lun_struct.size = candidate_struct.size
        lun_struct.hctl = candidate_struct.hctl
        lun_struct.serial = candidate_struct.serial
        lun_struct.model = candidate_struct.model
        lun_struct.vendor = candidate_struct.vendor
        lun_struct.type = candidate_struct.type
        lun_struct.wwn = candidate_struct.wwn
        lun_struct.wwids = candidate_struct.wwids
        if lvm.is_slave_of_multipath(abs_path):
            lun_struct.type = "mpath"
            if kvmagent.get_host_os_type() == "debian":
                mpath_wwid = bash.bash_o(
                    "multipath -l %s | head -n1 | awk '{print $1}'" %
                    abs_path).strip()
            else:
                mpath_wwid = bash.bash_o(
                    "multipath -l %s | head -n1 | awk '{print $2}'" %
                    abs_path).strip("() \n")
            lun_struct.wwids = [mpath_wwid]
        return lun_struct
Пример #6
0
    def get_device_info(self, dev_name, rescan):
        # type: (str) -> FiberChannelLunStruct
        s = FiberChannelLunStruct()

        # rescan disk size
        if rescan:
            _cmd = shell.ShellCmd("echo 1 > /sys/block/%s/device/rescan" %
                                  dev_name.strip())
            _cmd(is_exception=False)
            logger.debug(
                "rescaned disk %s, return code: %s, stdout %s, stderr: %s" %
                (dev_name, _cmd.return_code, _cmd.stdout, _cmd.stderr))

        r, o, e = bash.bash_roe(
            "lsblk --pair -b -p -o NAME,VENDOR,MODEL,WWN,SERIAL,HCTL,TYPE,SIZE /dev/%s"
            % dev_name, False)
        if r != 0 or o.strip() == "":
            logger.warn("can not get device information from %s" % dev_name)
            return None

        o = o.strip().splitlines()[0]

        def get_data(e):
            return e.split("=")[1].strip().strip('"')

        def get_wwids(dev):
            return shell.call(
                "udevadm info -n %s | grep 'by-id' | grep -v DEVLINKS | awk -F 'by-id/' '{print $2}'"
                % dev).strip().split()

        def get_path(dev):
            return shell.call(
                "udevadm info -n %s | grep 'by-path' | grep -v DEVLINKS | head -n1 | awk -F 'by-path/' '{print $2}'"
                % dev).strip()

        def get_storage_wwnn(hctl):
            o = shell.call(
                "systool -c fc_transport -A node_name | grep '\"target%s\"' -B2 | grep node_name | awk '{print $NF}'"
                % ":".join(hctl.split(":")[0:3]))
            return o.strip().strip('"')

        for entry in o.split('" '):  # type: str
            if entry.startswith("VENDOR"):
                s.vendor = get_data(entry)
            elif entry.startswith("MODEL"):
                s.model = get_data(entry)
            elif entry.startswith("WWN"):
                s.wwn = get_data(entry)
            elif entry.startswith("SERIAL"):
                s.serial = get_data(entry)
            elif entry.startswith('HCTL'):
                s.hctl = get_data(entry)
            elif entry.startswith('SIZE'):
                s.size = get_data(entry)
            elif entry.startswith('TYPE'):
                s.type = get_data(entry)

        s.wwids = get_wwids(dev_name)
        s.wwids.sort()
        s.path = get_path(dev_name)
        if lvm.is_slave_of_multipath("/dev/%s" % dev_name):
            s.type = "mpath"
            if kvmagent.get_host_os_type() == "debian":
                wwid = bash.bash_o(
                    "multipath -l /dev/%s | head -n1 | awk '{print $1}'" %
                    dev_name).strip()
            else:
                wwid = bash.bash_o(
                    "multipath -l /dev/%s | head -n1 | awk '{print $2}'" %
                    dev_name).strip().strip("()")
            s.wwids = [wwid] if wwid != "" else s.wwids
        s.storageWwnn = get_storage_wwnn(s.hctl)

        return s