def handle_delete(self, request, user, *args, **kwargs): """Trata uma requisição DELETE para excluir um port channel URL: /channel/delete/<channel_name>/ """ # Get request data and check permission try: self.log.info("Delete Channel") # User permission if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION): self.log.error(u'User does not have permission to perform the operation.') raise UserNotAuthorizedError(None) channel_name = kwargs.get('channel_name') channel = PortChannel.get_by_name(str(channel_name)) channel.delete(user) return self.response(dumps_networkapi({})) except InvalidValueError, e: return self.response_error(269, e.param, e.value)
def handle_get(self, request, user, *args, **kwargs): """Trata uma requisição PUT para alterar informações de um channel. URL: channel/get-by-name/ """ # Get request data and check permission try: self.log.info("Get Channel") # User permission if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION): self.log.error( u'User does not have permission to perform the operation.') raise UserNotAuthorizedError(None) # Get XML data xml_map, attrs_map = loads(request.raw_post_data) networkapi_map = xml_map.get('networkapi') if networkapi_map is None: return self.response_error(3, u'There is no networkapi tag in XML request.') channel_name = kwargs.get('channel_name') channel = PortChannel.get_by_name(channel_name) channel = model_to_dict(channel) return self.response(dumps_networkapi({'channel': channel})) except InvalidValueError, e: return self.response_error(269, e.param, e.value)
def handle_get(self, request, user, *args, **kwargs): """Trata uma requisição PUT para alterar informações de um channel. URL: channel/get-by-name/ """ # Get request data and check permission try: self.log.info('Get Channel') # User permission if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION): self.log.error( u'User does not have permission to perform the operation.') raise UserNotAuthorizedError(None) # Get XML data xml_map, attrs_map = loads(request.raw_post_data) networkapi_map = xml_map.get('networkapi') if networkapi_map is None: return self.response_error( 3, u'There is no networkapi tag in XML request.') channel_name = kwargs.get('channel_name') channel = PortChannel.get_by_name(channel_name) try: for ch in channel: channel = model_to_dict(ch) except: channel = model_to_dict(channel) pass return self.response(dumps_networkapi({'channel': channel})) except InvalidValueError, e: return self.response_error(269, e.param, e.value)
def retrieve(self, channel_name): """ Tries to retrieve a Port Channel based on its name """ channel = {} try: channel = PortChannel.get_by_name(channel_name) # Copied from old implementation. We really need to iterate? for ch in channel: channel = model_to_dict(ch) except InterfaceNotFoundError as err: return None except BaseException: channel = model_to_dict(channel) # We could do it on the model implementation. But because we need # compatibility with older version of the API this verification is # made here. Returning None means that no channel were found. if len(channel) == 0: return None return {"channel": channel}