def _retrieve_vo_args(self, request): name = request.data.get('name') api_key = request.data.get('api_key') routing_key = request.data.get('routing_key') # validate format of VO args EMVictorOps.validate_format(name, api_key, routing_key) # check validity self._check_key_validity(api_key, routing_key) return name, api_key, routing_key
def handle_create(self, request): # Pull the data we will use to create a VO setting name, api_key, routing_key = self._retrieve_vo_args(request) # check for any VO setting existence all_vos = EMVictorOps.load() if len(all_vos): raise VictorOpsUsernameAlreadyExistsException( _('Cannot create more than one VictorOps settings') ) # check for duplicate VO setting existence existing_vo = EMVictorOps.get(name) if existing_vo: raise VictorOpsUsernameAlreadyExistsException( _('VictorOps setting with name %(name)s already exists') ) new_vo = EMVictorOps.create(name, api_key, routing_key) return new_vo
def handle_remove(self, request, vo_id): vo = EMVictorOps.get(vo_id) if not vo: raise VictorOpsNotExistException( _('VictorOps setting with name %(vo_id)s does not exist') ) vo.delete() return True
def handle_edit(self, request, vo_id): _unused, api_key, routing_key = self._retrieve_vo_args(request) vo = EMVictorOps.get(vo_id) if not vo: raise VictorOpsNotExistException( _('VictorOps setting with name %(vo_id)s does not exist') ) vo.update(api_key, routing_key) return vo
def handle_get(self, request, vo_id): vo = EMVictorOps.get(vo_id) return vo
def handle_list(self, request): all_vos = EMVictorOps.load() return all_vos
def __init__(self, session_key): EMVictorOps.setup(session_key)
def _fetch_vo_setting(self, session_key): EMVictorOps.setup(session_key) vo_list = EMVictorOps.load() if len(vo_list): return vo_list[0] raise VictorOpsNotExistException(_('VictorOps setting does not exist'))