Пример #1
0
def unbind():
    """Unbind the client.

    The result of this function is the same as :func:`current`.
    """
    client = flask.request.remote_addr
    RPCClient.call("unbind_client", client)
    return status(client)
Пример #2
0
def unbind():
    """Unbind the client.

    The result of this function is the same as :func:`current`.
    """
    client = flask.request.remote_addr
    RPCClient.call("unbind_client", client)
    return status(client)
Пример #3
0
 def expire(self):
     with self.lock:
         clients = self.clients.keys()
         current = time.time()
         for client in clients:
             if current - self.clients[client] > app.config['EXPIRE']:
                 # Expiration of `client`
                 del self.clients[client]
                 RPCClient.call("unbind_client", client)
Пример #4
0
 def expire(self):
     with self.lock:
         clients = self.clients.keys()
         current = time.time()
         for client in clients:
             if current - self.clients[client] > app.config['EXPIRE']:
                 # Expiration of `client`
                 del self.clients[client]
                 RPCClient.call("unbind_client", client)
Пример #5
0
def status(client):
    """Return the status of the given client"""
    current = RPCClient.call("client", client)
    if current is None: # Not bound
        return { 'ip': client }
    return {
        'ip': client,
        'interface': current[0],
        'qos': current[1]
        }
Пример #6
0
def bind(interface, qos):
    """Allow to set the current interface for the client.

    The result of this function is the same as :func:`current`. The
    client may have to provide a password. If a password is requested,
    we raise a 401 HTTP error. The password should be provided as a
    username, not as the password. The password part is ignored.

    :param interface: Output interface requested
    :param qos: QoS settings requested
    """
    client = flask.request.remote_addr
    auth   = flask.request.authorization
    password = auth and auth.username or None
    try:
        RPCClient.call("bind_client", client, interface, qos, password)
    except RPCException as e:
        if e.exception == "AssertionError":
            # The password is incorrect or not provided
            flask.abort(401)
        raise
    ping.refresh(client)
    return status(client)
Пример #7
0
def bind(interface, qos):
    """Allow to set the current interface for the client.

    The result of this function is the same as :func:`current`. The
    client may have to provide a password. If a password is requested,
    we raise a 401 HTTP error. The password should be provided as a
    username, not as the password. The password part is ignored.

    :param interface: Output interface requested
    :param qos: QoS settings requested
    """
    client = flask.request.remote_addr
    auth = flask.request.authorization
    password = auth and auth.username or None
    try:
        RPCClient.call("bind_client", client, interface, qos, password)
    except RPCException as e:
        if e.exception == "AssertionError":
            # The password is incorrect or not provided
            flask.abort(401)
        raise
    ping.refresh(client)
    return status(client)
Пример #8
0
 def test_reconnection(self):
     """Check if we can reconnect"""
     RPCClient.call("interfaces")
     self.tearDown()
     self.setUp()
     RPCClient.call("interfaces")
     self.tearDown()
     with self.assertRaises(IOError):
         RPCClient.call("interfaces")
     self.setUp()
Пример #9
0
 def test_reconnection(self):
     """Check if we can reconnect"""
     RPCClient.call("interfaces")
     self.tearDown()
     self.setUp()
     RPCClient.call("interfaces")
     self.tearDown()
     with self.assertRaises(IOError):
         RPCClient.call("interfaces")
     self.setUp()
Пример #10
0
def stats():
    """Return statistics for each interface.

    The return value exhibits the following format::

            {"eth1": {
                "clients": 5,
                "up": 45,
                "down": 457,
                "details": {
                  "172.16.10.14": {"up": 0, "down": 0},
                  "172.16.10.15": {"up": 0, "down": 0}
                }
            }}

    All fields are optional and may not appear.
    """
    stats = RPCClient.call("stats")
    return stats
Пример #11
0
def stats():
    """Return statistics for each interface.

    The return value exhibits the following format::

            {"eth1": {
                "clients": 5,
                "up": 45,
                "down": 457,
                "details": {
                  "172.16.10.14": {"up": 0, "down": 0},
                  "172.16.10.15": {"up": 0, "down": 0}
                }
            }}

    All fields are optional and may not appear.
    """
    stats = RPCClient.call("stats")
    return stats
Пример #12
0
def interfaces():
    """Return the list of available interfaces.

    The returned value exhibits the following format::

      {
        "eth2": {
          "name": "WAN", 
          "description": "My second interface",
          "qos": {
            "qos1": {
              "name": "100M", 
              "description": "My first QoS",
              "bandwidth": "100mbps"
            }, 
            "qos3": {
              "name": "1M", 
              "description": "My third QoS",
              "bandwidth": "1mbps"
            }
          }
        }, 
        "eth1": {
          "name": "LAN", 
          "description": "My first interface",
          "qos": {
            "qos1": {
              "name": "100M", 
              "description": "My first QoS",
              "bandwidth": "100mbps"
            }
          }
        }
      }
    """
    interfaces = RPCClient.call("interfaces")
    return interfaces
Пример #13
0
def interfaces():
    """Return the list of available interfaces.

    The returned value exhibits the following format::

      {
        "eth2": {
          "name": "WAN", 
          "description": "My second interface",
          "qos": {
            "qos1": {
              "name": "100M", 
              "description": "My first QoS",
              "bandwidth": "100mbps"
            }, 
            "qos3": {
              "name": "1M", 
              "description": "My third QoS",
              "bandwidth": "1mbps"
            }
          }
        }, 
        "eth1": {
          "name": "LAN", 
          "description": "My first interface",
          "qos": {
            "qos1": {
              "name": "100M", 
              "description": "My first QoS",
              "bandwidth": "100mbps"
            }
          }
        }
      }
    """
    interfaces = RPCClient.call("interfaces")
    return interfaces
Пример #14
0
 def work():
     RPCClient.call("interfaces")
     self.i = self.i + 1
Пример #15
0
def status(client):
    """Return the status of the given client"""
    current = RPCClient.call("client", client)
    if current is None:  # Not bound
        return {'ip': client}
    return {'ip': client, 'interface': current[0], 'qos': current[1]}
Пример #16
0
 def work():
     RPCClient.call("interfaces")
     self.i = self.i + 1
Пример #17
0
 def test_exception(self):
     """Check that we get exceptions"""
     with self.assertRaises(RPCException) as e:
         RPCClient.call("unknown")
     str(e.exception)
Пример #18
0
 def test_exception(self):
     """Check that we get exceptions"""
     with self.assertRaises(RPCException) as e:
         RPCClient.call("unknown")
     str(e.exception)