Пример #1
0
 def _manage_conns(self):
     try:
         self.apiroutine.subroutine(self._manage_existing())
         vb = self.vhostbind
         if vb is not None:
             conn_up = JsonRPCConnectionStateEvent.createMatcher(
                 state=JsonRPCConnectionStateEvent.CONNECTION_UP,
                 _ismatch=lambda x: x.createby.vhost in vb)
             conn_down = JsonRPCConnectionStateEvent.createMatcher(
                 state=JsonRPCConnectionStateEvent.CONNECTION_DOWN,
                 _ismatch=lambda x: x.createby.vhost in vb)
         else:
             conn_up = JsonRPCConnectionStateEvent.createMatcher(
                 state=JsonRPCConnectionStateEvent.CONNECTION_UP)
             conn_down = JsonRPCConnectionStateEvent.createMatcher(
                 state=JsonRPCConnectionStateEvent.CONNECTION_DOWN)
         while True:
             yield (conn_up, conn_down)
             if self.apiroutine.matcher is conn_up:
                 if not hasattr(self.apiroutine.event.connection,
                                '_ovsdb_manager_get_bridges'):
                     self.apiroutine.event.connection._ovsdb_manager_get_bridges = self.apiroutine.subroutine(
                         self._get_bridges(self.apiroutine.event.connection,
                                           self.apiroutine.event.createby))
             else:
                 e = self.apiroutine.event
                 conn = e.connection
                 bridges = self.managed_bridges.get(conn)
                 if bridges is not None:
                     del self.managed_systemids[(e.createby.vhost,
                                                 conn.ovsdb_systemid)]
                     del self.managed_bridges[conn]
                     for vhost, dpid, name, buuid in bridges:
                         del self.managed_conns[(vhost, dpid)]
                         self.scheduler.emergesend(
                             OVSDBBridgeSetup(OVSDBBridgeSetup.DOWN, dpid,
                                              conn.ovsdb_systemid, name,
                                              conn, conn.connmark,
                                              e.createby.vhost, buuid))
                     econns = self.endpoint_conns.get(_get_endpoint(conn))
                     if econns is not None:
                         try:
                             econns.remove(conn)
                         except ValueError:
                             pass
     finally:
         for c in self.managed_bridges.keys():
             if hasattr(c, '_ovsdb_manager_get_bridges'):
                 c._ovsdb_manager_get_bridges.close()
             bridges = self.managed_bridges.get(c)
             if bridges is not None:
                 for vhost, dpid, name, buuid in bridges:
                     del self.managed_conns[(vhost, dpid)]
                     self.scheduler.emergesend(
                         OVSDBBridgeSetup(OVSDBBridgeSetup.DOWN, dpid,
                                          c.ovsdb_systemid, name, c,
                                          c.connmark, c.protocol.vhost,
                                          buuid))
Пример #2
0
 def _manage_conns(self):
     try:
         self.apiroutine.subroutine(self._manage_existing())
         vb = self.vhostbind
         if vb is not None:
             conn_up = JsonRPCConnectionStateEvent.createMatcher(state = JsonRPCConnectionStateEvent.CONNECTION_UP,
                                                                  _ismatch = lambda x: x.createby.vhost in vb)
             conn_down = JsonRPCConnectionStateEvent.createMatcher(state = JsonRPCConnectionStateEvent.CONNECTION_DOWN,
                                                                  _ismatch = lambda x: x.createby.vhost in vb)
         else:
             conn_up = JsonRPCConnectionStateEvent.createMatcher(state = JsonRPCConnectionStateEvent.CONNECTION_UP)
             conn_down = JsonRPCConnectionStateEvent.createMatcher(state = JsonRPCConnectionStateEvent.CONNECTION_DOWN)
         while True:
             yield (conn_up, conn_down)
             if self.apiroutine.matcher is conn_up:
                 if not hasattr(self.apiroutine.event.connection, '_ovsdb_manager_get_bridges'):
                     self.apiroutine.event.connection._ovsdb_manager_get_bridges = self.apiroutine.subroutine(self._get_bridges(self.apiroutine.event.connection, self.apiroutine.event.createby))
             else:
                 e = self.apiroutine.event
                 conn = e.connection
                 bridges = self.managed_bridges.get(conn)
                 if bridges is not None:
                     del self.managed_systemids[(e.createby.vhost, conn.ovsdb_systemid)]
                     del self.managed_bridges[conn]
                     for vhost, dpid, name, buuid in bridges:
                         del self.managed_conns[(vhost, dpid)]
                         self.scheduler.emergesend(OVSDBBridgeSetup(OVSDBBridgeSetup.DOWN,
                                                                    dpid,
                                                                    conn.ovsdb_systemid,
                                                                    name,
                                                                    conn,
                                                                    conn.connmark,
                                                                    e.createby.vhost,
                                                                    buuid))
                     econns = self.endpoint_conns.get(_get_endpoint(conn))
                     if econns is not None:
                         try:
                             econns.remove(conn)
                         except ValueError:
                             pass
     finally:
         for c in self.managed_bridges.keys():
             if hasattr(c, '_ovsdb_manager_get_bridges'):
                 c._ovsdb_manager_get_bridges.close()
             bridges = self.managed_bridges.get(c)
             if bridges is not None:
                 for vhost, dpid, name, buuid in bridges:
                     del self.managed_conns[(vhost, dpid)]
                     self.scheduler.emergesend(OVSDBBridgeSetup(OVSDBBridgeSetup.DOWN,
                                                                dpid, 
                                                                c.ovsdb_systemid, 
                                                                name, 
                                                                c, 
                                                                c.connmark, 
                                                                c.protocol.vhost,
                                                                buuid))
Пример #3
0
 def waitbridge(self, connection, name, timeout=30):
     "Wait for bridge with specified name appears and return the datapath-id"
     bnames = self.bridgenames
     if bnames is not None and name not in bnames:
         raise OVSDBBridgeNotAppearException(
             'Bridge ' + repr(name) +
             ' does not appear: it is not in the selected bridge names')
     for m in self.getbridge(connection, name):
         yield m
     if self.apiroutine.retvalue is None:
         bridge_setup = OVSDBBridgeSetup.createMatcher(
             OVSDBBridgeSetup.UP, None, None, name, connection)
         conn_down = JsonRPCConnectionStateEvent.createMatcher(
             JsonRPCConnectionStateEvent.CONNECTION_DOWN, connection,
             connection.connmark)
         for m in self.apiroutine.waitWithTimeout(timeout, bridge_setup,
                                                  conn_down):
             yield m
         if self.apiroutine.timeout:
             raise OVSDBBridgeNotAppearException('Bridge ' + repr(name) +
                                                 ' does not appear')
         elif self.apiroutine.matcher is conn_down:
             raise ConnectionResetException(
                 'Connection is down before bridge ' + repr(name) +
                 ' appears')
         else:
             self.apiroutine.retvalue = self.apiroutine.event.datapathid
Пример #4
0
 async def waitbridge(self, connection, name, timeout=30):
     "Wait for bridge with specified name appears and return the datapath-id"
     bnames = self.bridgenames
     if bnames is not None and name not in bnames:
         raise OVSDBBridgeNotAppearException(
             'Bridge ' + repr(name) +
             ' does not appear: it is not in the selected bridge names')
     dpid = await self.getbridge(connection, name)
     if dpid is None:
         bridge_setup = OVSDBBridgeSetup.createMatcher(
             OVSDBBridgeSetup.UP, None, None, name, connection)
         conn_down = JsonRPCConnectionStateEvent.createMatcher(
             JsonRPCConnectionStateEvent.CONNECTION_DOWN, connection,
             connection.connmark)
         timeout_, ev, m = await self.apiroutine.wait_with_timeout(
             timeout, bridge_setup, conn_down)
         if timeout_:
             raise OVSDBBridgeNotAppearException('Bridge ' + repr(name) +
                                                 ' does not appear')
         elif m is conn_down:
             raise ConnectionResetException(
                 'Connection is down before bridge ' + repr(name) +
                 ' appears')
         else:
             return ev.datapathid
     else:
         return dpid
Пример #5
0
 def waitbridge(self, connection, name, timeout = 30):
     "Wait for bridge with specified name appears and return the datapath-id"
     bnames = self.bridgenames
     if bnames is not None and name not in bnames:
         raise OVSDBBridgeNotAppearException('Bridge ' + repr(name) + ' does not appear: it is not in the selected bridge names')
     for m in self.getbridge(connection, name):
         yield m
     if self.apiroutine.retvalue is None:
         bridge_setup = OVSDBBridgeSetup.createMatcher(OVSDBBridgeSetup.UP,
                                                      None,
                                                      None,
                                                      name,
                                                      connection
                                                      )
         conn_down = JsonRPCConnectionStateEvent.createMatcher(JsonRPCConnectionStateEvent.CONNECTION_DOWN,
                                                               connection,
                                                               connection.connmark)
         for m in self.apiroutine.waitWithTimeout(timeout, bridge_setup, conn_down):
             yield m
         if self.apiroutine.timeout:
             raise OVSDBBridgeNotAppearException('Bridge ' + repr(name) + ' does not appear')
         elif self.apiroutine.matcher is conn_down:
             raise ConnectionResetException('Connection is down before bridge ' + repr(name) + ' appears')
         else:
             self.apiroutine.retvalue = self.apiroutine.event.datapathid
Пример #6
0
 async def main(self):
     connected = JsonRPCConnectionStateEvent.createMatcher(
         state=JsonRPCConnectionStateEvent.CONNECTION_UP)
     ev = await connected
     connection = ev.connection
     result, error = await jsonrpc.querywithreply('list_dbs', [],
                                                  connection, self)
     if error:
         pprint(error)
     else:
         pprint(result)
     dbname = result[0]
     result, error = await jsonrpc.querywithreply('get_schema', [dbname],
                                                  connection, self)
     if error:
         pprint(error)
     else:
         pprint(result)
     await connection.shutdown()
Пример #7
0
 def main(self):
     connected = JsonRPCConnectionStateEvent.createMatcher(state = JsonRPCConnectionStateEvent.CONNECTION_UP)
     yield (connected,)
     connection = self.event.connection
     for m in jsonrpc.querywithreply('list_dbs', [], connection, self):
         yield m
     if self.jsonrpc_error:
         pprint(self.jsonrpc_error)
     else:
         pprint(self.jsonrpc_result)
     dbname = self.jsonrpc_result[0]
     for m in jsonrpc.querywithreply('get_schema', [dbname], connection, self):
         yield m
     if self.jsonrpc_error:
         pprint(self.jsonrpc_error)
     else:
         pprint(self.jsonrpc_result)
     for m in connection.shutdown():
         yield m
Пример #8
0
 def waitbridgebyuuid(self, connection, uuid, timeout = 30):
     "Wait for bridge with specified _uuid appears and return the datapath-id"
     for m in self.getbridgebyuuid(connection, uuid):
         yield m
     if self.apiroutine.retvalue is None:
         bridge_setup = OVSDBBridgeSetup.createMatcher(state = OVSDBBridgeSetup.UP,
                                                      connection = connection,
                                                      bridgeuuid = uuid
                                                      )
         conn_down = JsonRPCConnectionStateEvent.createMatcher(JsonRPCConnectionStateEvent.CONNECTION_DOWN,
                                                               connection,
                                                               connection.connmark)
         for m in self.apiroutine.waitWithTimeout(timeout, bridge_setup, conn_down):
             yield m
         if self.apiroutine.timeout:
             raise OVSDBBridgeNotAppearException('Bridge ' + repr(uuid) + ' does not appear')
         elif self.apiroutine.matcher is conn_down:
             raise ConnectionResetException('Connection is down before bridge ' + repr(uuid) + ' appears')
         else:
             self.apiroutine.retvalue = self.apiroutine.event.datapathid
Пример #9
0
 def waitbridgebyuuid(self, connection, uuid, timeout = 30):
     "Wait for bridge with specified _uuid appears and return the datapath-id"
     for m in self.getbridgebyuuid(connection, uuid):
         yield m
     if self.apiroutine.retvalue is None:
         bridge_setup = OVSDBBridgeSetup.createMatcher(state = OVSDBBridgeSetup.UP,
                                                      connection = connection,
                                                      bridgeuuid = uuid
                                                      )
         conn_down = JsonRPCConnectionStateEvent.createMatcher(JsonRPCConnectionStateEvent.CONNECTION_DOWN,
                                                               connection,
                                                               connection.connmark)
         for m in self.apiroutine.waitWithTimeout(timeout, bridge_setup, conn_down):
             yield m
         if self.apiroutine.timeout:
             raise OVSDBBridgeNotAppearException('Bridge ' + repr(uuid) + ' does not appear')
         elif self.apiroutine.matcher is conn_down:
             raise ConnectionResetException('Connection is down before bridge ' + repr(uuid) + ' appears')
         else:
             self.apiroutine.retvalue = self.apiroutine.event.datapathid
Пример #10
0
 async def waitbridgebyuuid(self, connection, uuid, timeout=30):
     "Wait for bridge with specified _uuid appears and return the datapath-id"
     dpid = await self.getbridgebyuuid(connection, uuid)
     if dpid is None:
         bridge_setup = OVSDBBridgeSetup.createMatcher(
             state=OVSDBBridgeSetup.UP,
             connection=connection,
             bridgeuuid=uuid)
         conn_down = JsonRPCConnectionStateEvent.createMatcher(
             JsonRPCConnectionStateEvent.CONNECTION_DOWN, connection,
             connection.connmark)
         timeout_, ev, m = await self.apiroutine.wait_with_timeout(
             timeout, bridge_setup, conn_down)
         if timeout_:
             raise OVSDBBridgeNotAppearException('Bridge ' + repr(uuid) +
                                                 ' does not appear')
         elif m is conn_down:
             raise ConnectionResetException(
                 'Connection is down before bridge ' + repr(uuid) +
                 ' appears')
         else:
             return ev.datapathid
     else:
         return dpid