コード例 #1
0
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: api.py プロジェクト: vincentbernat/Kitero
 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
ファイル: api.py プロジェクト: vincentbernat/Kitero
 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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: test_rpc.py プロジェクト: vincentbernat/Kitero
 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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: test_rpc.py プロジェクト: vincentbernat/Kitero
 def work():
     RPCClient.call("interfaces")
     self.i = self.i + 1
コード例 #15
0
ファイル: api.py プロジェクト: vincentbernat/Kitero
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
ファイル: test_rpc.py プロジェクト: vincentbernat/Kitero
 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)