def take_action(self, parsed_args):
     if parsed_args.query:
         if any([parsed_args.limit, parsed_args.sort, parsed_args.marker]):
             raise exceptions.CommandError(
                 "Query and pagination options are mutually "
                 "exclusive.")
         query = jsonutils.dumps(
             utils.search_query_builder(parsed_args.query))
         alarms = utils.get_client(self).alarm.query(query=query)
     else:
         filters = dict(parsed_args.filter) if parsed_args.filter else None
         alarms = utils.get_client(self).alarm.list(
             filters=filters, sorts=parsed_args.sort,
             limit=parsed_args.limit, marker=parsed_args.marker)
     return utils.list2cols(ALARM_LIST_COLS, alarms)
    def take_action(self, parsed_args):
        resource_quotas = []
        if parsed_args.alarm is not None:
            if parsed_args.alarm < -1:
                raise exceptions.CommandError(
                    'Quota limit cannot be less than -1.')
            resource_quotas.append({
                'resource': 'alarms',
                'limit': parsed_args.alarm
            })

        c = utils.get_client(self)
        quota = c.quota.create(parsed_args.project, resource_quotas)

        ret = {}
        for q in quota['quotas']:
            ret[q['resource']] = q['limit']

        return self.dict2columns(ret)
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)
def _check_name_and_id_coexist(parsed_args, action):
    if parsed_args.id and parsed_args.name:
        raise exceptions.CommandError(
            "You should provide only one of "
            "alarm ID and alarm name(--name) "
            "to %s an alarm." % action)