def _find_alarm_by_name(client, name):
    # then try to get entity as name
    query = jsonutils.dumps({"=": {"name": name}})
    alarms = client.alarm.query(query)
    if len(alarms) > 1:
        msg = (_("Multiple alarms matches found for '%s', "
                 "use an ID to be more specific.") % name)
        raise exceptions.NoUniqueMatch(msg)
    elif not alarms:
        msg = (_("Alarm %s not found") % name)
        raise exceptions.NotFound(msg)
    else:
        return alarms[0]
Exemple #2
0
def _find_alarm_by_name(client, name, return_id=False):
    # then try to get entity as name
    query = jsonutils.dumps({"=": {"name": name}})
    alarms = client.list(query)
    if len(alarms) > 1:
        msg = (_("Multiple alarms matches found for '%s', "
                 "use an ID to be more specific.") % name)
        raise exceptions.NoUniqueMatch(msg)
    elif not alarms:
        msg = (_("Alarm %s not found") % name)
        raise exceptions.NotFound(404, msg)
    else:
        if return_id:
            return alarms[0]['alarm_id']
        return alarms[0]
Exemple #3
0
def _check_name_and_id(parsed_args, action):
    if parsed_args.id and parsed_args.alarm_name:
        raise exceptions.CommandError(
            "You should provide only one of "
            "alarm ID and alarm name(--alarm-name) "
            "to %s an alarm." % action)
    if not parsed_args.id and not parsed_args.alarm_name:
        msg = (_("You need to specify one of "
                 "alarm ID and alarm name(--alarm-name) "
                 "to %s an alarm.") % action)
        raise exceptions.CommandError(msg)
def _check_name_and_id_exist(parsed_args, action):
    if not parsed_args.id and not parsed_args.name:
        msg = (_("You need to specify one of "
                 "alarm ID and alarm name(--name) "
                 "to %s an alarm.") % action)
        raise exceptions.CommandError(msg)