def str2device(ns, device):
    if isinstance(device, LMIInstance):
        return device
    if not isinstance(device, str):
        raise TypeError("string or LMIInstance expected, got %s"
                % device.__class__.__name__)
    query = 'SELECT * FROM CIM_StorageExtent WHERE ' \
                'DeviceID="%(device)s" ' \
                'OR Name="%(device)s" ' \
                'OR ElementName="%(device)s"' % {'device': escape_cql(device)}
    devices = ns.wql(query)
    if not devices:
        raise LmiFailed("Device '%s' not found" % (device,))
    if len(devices) > 1:
        raise LmiFailed("Too many devices with name '%s' found" % (device,))

    LOG().debug("String %s translated to device '%s'.",
            device, devices[0].DeviceID)
    return devices[0]
Split long messages
dataset/ETHPy150Open openlmi/openlmi-scripts/commands/storage/lmi/scripts/storage/common.py/str2device--crossover with--dataset/ETHPy150Open gawel/irc3/irc3/utils.py/split_message