Exemplo n.º 1
0
    def delete_subscriber_from_hlr(self, imsi):
        """Removes a subscriber from the system.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        return self._hlr_query(lambda s: s.delete(imsi),
                               lambda: SubscriberNotFound(imsi))
Exemplo n.º 2
0
    def get_caller_id(self, imsi):
        """Get a subscriber's caller_id.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        return self._hlr_query(lambda s: s.show('imsi', imsi)['extension'],
                               lambda: SubscriberNotFound(imsi))
Exemplo n.º 3
0
 def delete_subscriber_from_hlr(self, imsi):
     """Removes a subscriber from the system."""
     try:
         return self.sip_auth_serve.delete_subscriber(imsi)
     except InvalidRequestError as e:
         raise SubscriberNotFound(imsi)
     except Exception as e:
         exc_type, exc_value, exc_trace = sys.exc_info()
         raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 4
0
    def get_caller_id(self, imsi):
        """Get a subscriber's caller_id.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            return self._hlr[imsi]['numbers'][0]
        except KeyError:
            raise SubscriberNotFound(imsi)
Exemplo n.º 5
0
    def get_imsi_from_number(self, number, canonicalize=True):
        """Gets the IMSI associated with a number.

           Raises:
              SubscriberNotFound if IMSI is not found
        """
        if canonicalize:
            number = number_utilities.canonicalize(number)
        return self._hlr_query(
            lambda s: 'IMSI' + s.show('extension', number)['imsi'],
            lambda: SubscriberNotFound('MSISDN %s' % (number, )))
Exemplo n.º 6
0
    def add_number(self, imsi, number):
        """Associate another number with an IMSI.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            sub = self._hlr[imsi]
            sub.update('numbers', sub['numbers'] + [number])
        except KeyError:
            raise SubscriberNotFound(imsi)
Exemplo n.º 7
0
    def get_port(self, imsi):
        """Get a subscriber's port.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            return self.sip_auth_serve.get_openbts_port(imsi)
        except InvalidRequestError:
            raise SubscriberNotFound(imsi)
        except Exception:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError("%s: %s" % (exc_type, exc_value)).with_traceback(exc_trace)
Exemplo n.º 8
0
    def get_numbers_from_imsi(self, imsi):
        """Gets numbers associated with a subscriber.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            return self.sip_auth_serve.get_numbers(imsi)
        except InvalidRequestError as e:
            raise SubscriberNotFound(imsi)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 9
0
    def add_number(self, imsi, number):
        """Associate another number with an IMSI.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            return self.sip_auth_serve.add_number(imsi, number)
        except InvalidRequestError as e:
            raise SubscriberNotFound(imsi)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 10
0
    def get_caller_id(self, imsi):
        """Get a subscriber's caller_id.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            return self.sip_auth_serve.get_caller_id(imsi)
        except InvalidRequestError as e:
            raise SubscriberNotFound(imsi)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 11
0
    def get_caller_id(self, imsi):
        """Get a subscriber's caller_id.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            with self.subscribers as s:
                try:
                    return s.show('imsi', imsi)['extension']
                except ValueError as e:
                    raise SubscriberNotFound(imsi)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 12
0
    def get_numbers_from_imsi(self, imsi):
        """Gets numbers associated with a subscriber.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            with self.subscribers as s:
                try:
                    return [s.show('imsi', imsi)['extension']]
                except ValueError as e:
                    raise SubscriberNotFound(imsi)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 13
0
    def get_imsi_from_number(self, number, canonicalize=True):
        """Gets the IMSI associated with a number.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        if canonicalize:
            number = number_utilities.canonicalize(number)
        try:
            return self.sip_auth_serve.get_imsi_from_number(number)
        except InvalidRequestError as e:
            raise SubscriberNotFound('MSISDN %s' % number)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 14
0
    def delete_subscriber_from_hlr(self, imsi):
        """Removes a subscriber from the system.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        try:
            with self.subscribers as s:
                try:
                    return s.delete(imsi)
                except ValueError as e:
                    raise SubscriberNotFound(imsi)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 15
0
    def get_imsi_from_number(self, number, canonicalize=True):
        """Gets the IMSI associated with a number.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        if canonicalize:
            number = number_utilities.canonicalize(number)
        try:
            with self.subscribers as s:
                try:
                    return 'IMSI' + s.show('extension', number)['imsi']
                except ValueError as e:
                    raise SubscriberNotFound('MSISDN %s' % number)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Exemplo n.º 16
0
    def delete_number(self, imsi, number):
        """Disassociate a number with an IMSI.

           Raises:
              SubscriberNotFound if imsi is not found
              ValueError if number doesn't belong to IMSI
                  or this is the sub's last number
        """
        sub = self._hlr.get(imsi)
        if not sub:
            raise SubscriberNotFound(imsi)
        numbers = sub['numbers']
        if len(sub < 2):
            raise ValueError("cannot remove %s from %s" % (number, imsi))
        new_numbers = [n for n in numbers if n != number]
        if len(new_numbers) == len(numbers):
            raise ValueError("%s not associated with %s" % (number, imsi))
        sub['numbers'] = new_numbers
Exemplo n.º 17
0
    def delete_number(self, imsi, number):
        """Disassociate a number with an IMSI.

           Raises:
              SubscriberNotFound if imsi is not found
              ValueError if number doesn't belong to IMSI
                  or this is the sub's last number
        """
        try:
            self.get_caller_id(imsi)  # raise InvalidRequestError when sub doesnt exist
            return self.sip_auth_serve.delete_number(imsi, number)
        except InvalidRequestError:
            raise SubscriberNotFound(imsi)
        except ValueError as e:
            # this is raised when a number doesn't belong to a sub
            # also raised when this is the subs last number
            raise e
        except Exception:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError("%s: %s" % (exc_type, exc_value)).with_traceback(exc_trace)
Exemplo n.º 18
0
    def get_gprs_usage(self, target_imsi=None):
        """Get all available GPRS data, or that of a specific IMSI (experimental).

        Will return a dict of the form: {
          'ipaddr': '192.168.99.1',
          'downloaded_bytes': 200,
          'uploaded_bytes': 100,
        }

        Or, if no IMSI is specified, multiple dicts like the one above will be
        returned as part of a larger dict, keyed by IMSI.

        Args:
          target_imsi: the subsciber-of-interest
        """
        try:
            res = self.sip_auth_serve.get_gprs_usage(target_imsi)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
        if not res:
            raise SubscriberNotFound(target_imsi)
        return res
Exemplo n.º 19
0
 def delete_subscriber_from_hlr(self, imsi):
     """Removes a subscriber from the system."""
     try:
         del self._hlr[imsi]
     except KeyError:
         raise SubscriberNotFound(imsi)