'"Find available QoS on the array.'

def find_available_qos(self, qos):

    qos_id = None
    lun_list = []
    extra_qos = [i for i in constants.EXTRA_QOS_KEYS if (i not in qos)]
    result = self.get_qos()
    if ('data' in result):
        for items in result['data']:
            qos_flag = 0
            extra_flag = False
            if (('LATENCY' not in qos) and (items['LATENCY'] != '0')):
                extra_flag = True
            else:
                for item in items:
                    if (item in extra_qos):
                        extra_flag = True
                        break
            for key in qos:
                if (key not in items):
                    break
                elif (qos[key] != items[key]):
                    break
                qos_flag = (qos_flag + 1)
            lun_num = len(items['LUNLIST'].split(','))
            qos_name = items['NAME']
            qos_status = items['RUNNINGSTATUS']
            if ((qos_flag == len(qos)) and (not extra_flag) and (lun_num < constants.MAX_LUN_NUM_IN_QOS) and qos_name.startswith(constants.QOS_NAME_PREFIX) and (qos_status == constants.STATUS_QOS_ACTIVE) and (items['FSLIST'] == '[""]')):
                qos_id = items['ID']
                lun_list = items['LUNLIST']
                break
    return (qos_id, lun_list)
