'Implements SetAlarmState API action.'

def set_alarm_state(self, req):

    self._enforce(req, 'SetAlarmState')
    state_map = {'OK': rpc_api.WATCH_STATE_OK, 'ALARM': rpc_api.WATCH_STATE_ALARM, 'INSUFFICIENT_DATA': rpc_api.WATCH_STATE_NODATA}
    con = req.context
    parms = dict(req.params)
    name = api_utils.get_param_value(parms, 'AlarmName')
    state = api_utils.get_param_value(parms, 'StateValue')
    if (state not in state_map):
        msg = (_('Invalid    state    %(state)s,    expecting    one    of    %(expect)s') % {'state': state, 'expect': list(state_map.keys())})
        LOG.error(msg)
        return exception.HeatInvalidParameterValueError(msg)
    LOG.debug(('setting    %(name)s    to    %(state)s' % {'name': name, 'state': state_map[state]}))
    try:
        self.rpc_client.set_watch_state(con, watch_name=name, state=state_map[state])
    except messaging.RemoteError as ex:
        return exception.map_remote_error(ex)
    return api_utils.format_response('SetAlarmState', '')
