Esempio n. 1
0
def get_dev_options(dev_byid, custom_options=""):
    """Returns device specific options for all smartctl commands.  Note that in
    most cases this requires looking up the base device via get_base_device but
    in some instances this is not required as in the case of devices behind
    some raid controllers. If custom_options contains known raid controller
    smartctl targets then these will be substituted for device name.

    :param dev_byid:  device name as per db entry, ie by-id type without a path
    :param custom_options: string of user entered custom smart options.
    :return: dev_options: list containing the device specific smart options and
    the appropriate smart device target with full path.

    """
    # Initially our custom_options parameter may be None, ie db default prior
    # to any changes having been made. Deal with this by adding a guard.
    if custom_options is None or custom_options == "":
        # Empty custom_options or they have never been set so just return
        # full path to base device as nothing else to do.
        dev_options = [
            get_device_path(get_base_device_byid(dev_byid, TESTMODE))
        ]
    else:
        # Convert string of custom options into a list ready for run_command
        # TODO: think this ascii should be utf-8 as that's kernel standard
        # TODO: or just use str(custom_options).split()
        dev_options = custom_options.encode("ascii").split()
        # Remove Rockstor native 'autodev' custom smart option raid dev target.
        # As we automatically add the full path by-id if a raid controller
        # target dev is not found, we can simply remove this option.
        # N.B. here we assume there is either 'autodev' or a specified target:
        # input validation was tested to reject both being entered.
        if "autodev" in dev_options:
            dev_options.remove("autodev")
        # If our custom options don't contain a raid controller target then add
        # the full path to our base device as our last device specific option.
        if re.search("/dev/tw|/dev/cciss/c|/dev/sg|/dev/sd",
                     custom_options) is None:
            # add full path to our custom options as we see no raid target dev
            dev_options += [
                get_device_path(get_base_device_byid(dev_byid, TESTMODE))
            ]
    # Note on raid controller target devices.  /dev/twe#, or /dev/twa#, or
    # /dev/twl# are 3ware controller targets devs respectively 3x-xxxx,
    # 3w-9xxx, and t2-sas (3ware/LSI 9750) drivers for respectively 6000, 7000,
    # 8000 or 9000 or 3ware/LSI 9750 controllers.  /dev/cciss/c0d0 is the first
    # HP/Compaq Smart Array Controller using the deprecated cciss driver
    # /dev/sg0 is the first hpsa or hpahcisr driver device for the same
    # adapter.  This same target device is also used by the Areca SATA RAID
    # controller except that the first device is /dev/sg2.
    return dev_options
Esempio n. 2
0
def get_dev_options(dev_byid, custom_options=''):
    """Returns device specific options for all smartctl commands.  Note that in
    most cases this requires looking up the base device via get_base_device but
    in some instances this is not required as in the case of devices behind
    some raid controllers. If custom_options contains known raid controller
    smartctl targets then these will be substituted for device name.

    :param dev_byid:  device name as per db entry, ie by-id type without a path
    :param custom_options: string of user entered custom smart options.
    :return: dev_options: list containing the device specific smart options and
    the appropriate smart device target with full path.

    """
    # Initially our custom_options parameter may be None, ie db default prior
    # to any changes having been made. Deal with this by adding a guard.
    if custom_options is None or custom_options == '':
        # Empty custom_options or they have never been set so just return
        # full path to base device as nothing else to do.
        dev_options = [
            get_device_path(get_base_device_byid(dev_byid, TESTMODE))]
    else:
        # Convert string of custom options into a list ready for run_command
        # TODO: think this ascii should be utf-8 as that's kernel standard
        # TODO: or just use str(custom_options).split()
        dev_options = custom_options.encode('ascii').split()
        # Remove Rockstor native 'autodev' custom smart option raid dev target.
        # As we automatically add the full path by-id if a raid controller
        # target dev is not found, we can simply remove this option.
        # N.B. here we assume there is either 'autodev' or a specified target:
        # input validation was tested to reject both being entered.
        if 'autodev' in dev_options:
            dev_options.remove('autodev')
        # If our custom options don't contain a raid controller target then add
        # the full path to our base device as our last device specific option.
        if (re.search('/dev/tw|/dev/cciss/c|/dev/sg|/dev/sd',
                      custom_options) is None):
            # add full path to our custom options as we see no raid target dev
            dev_options += [
                get_device_path(get_base_device_byid(dev_byid, TESTMODE))
            ]
    # Note on raid controller target devices.  /dev/twe#, or /dev/twa#, or
    # /dev/twl# are 3ware controller targets devs respectively 3x-xxxx,
    # 3w-9xxx, and t2-sas (3ware/LSI 9750) drivers for respectively 6000, 7000,
    # 8000 or 9000 or 3ware/LSI 9750 controllers.  /dev/cciss/c0d0 is the first
    # HP/Compaq Smart Array Controller using the deprecated cciss driver
    # /dev/sg0 is the first hpsa or hpahcisr driver device for the same
    # adapter.  This same target device is also used by the Areca SATA RAID
    # controller except that the first device is /dev/sg2.
    return dev_options
Esempio n. 3
0
def get_dev_options(dev_byid, custom_options=''):
    """
    Returns device specific options for all smartctl commands.
    Note that in most cases this requires looking up the base device via
    get_base_device but in some instances this is not required as in the case
    of devices behind some raid controllers. If custom_options contains known
    raid controller smartctl targets then these will be substituted for device
    name.
    :param dev_byid:  device name as per db entry, ie by-id type without a path
    :param custom_options: string of user entered custom smart options.
    :return: dev_options: list containing the device specific smart options and
    the appropriate smart device target with full path.
    """
    # Initially our custom_options parameter may be None, ie db default prior
    # to any changes having been made. Deal with this by adding a guard.
    if custom_options is None or custom_options == '':
        # Empty custom_options or they have never been set so just return
        # full path to base device as nothing else to do.
        dev_options = [
            '/dev/disk/by-id/%s' % get_base_device_byid(dev_byid, TESTMODE)
        ]
    else:
        # Convert string of custom options into a list ready for run_command
        # TODO: think this ascii should be utf-8 as that's kernel standard
        # TODO: or just use str(custom_options).split()
        dev_options = custom_options.encode('ascii').split()
        # If our custom options don't contain a raid controller target then add
        # the full path to our base device as our last device specific option.
        if (re.search('/dev/tw|/dev/cciss/c|/dev/sg', custom_options) is None):
            # add full path to our custom options as we see no raid target dev
            dev_options += [
                '/dev/disk/by-id/%s' %
                get_base_device_byid(dev_byid, TESTMODE)
            ]
    # Note on raid controller target devices.
    # /dev/twe#, or /dev/twa#, or /dev/twl# are 3ware controller targets devs
    # respectively 3x-xxxx, 3w-9xxx, and t2-sas (3ware/LSI 9750) drivers for
    # respectively 6000, 7000, 8000 or 9000 or 3ware/LSI 9750 controllers.
    # /dev/cciss/c0d0 is the first HP/Compaq Smart Array Controller using the
    # deprecated cciss driver
    # /dev/sg0 is the first hpsa or hpahcisr driver device for the same adapter.
    # This same target device is also used by the Areca SATA RAID controller
    # except that the first device is /dev/sg2.
    return dev_options