Exemple #1
0
 def _update_bridge(self, connection, protocol, bridge_uuid, vhost):
     try:
         method, params = ovsdb.transact(
             'Open_vSwitch',
             ovsdb.wait(
                 'Bridge',
                 [["_uuid", "==", ovsdb.uuid(bridge_uuid)]],
                 ["datapath_id"], [{
                     "datapath_id": ovsdb.oset()
                 }], False, 5000),
             ovsdb.select(
                 'Bridge',
                 [["_uuid", "==", ovsdb.uuid(bridge_uuid)]],
                 ["datapath_id", "name"]))
         for m in protocol.querywithreply(method, params, connection,
                                          self.apiroutine):
             yield m
         r = self.apiroutine.jsonrpc_result[0]
         if 'error' in r:
             raise JsonRPCErrorResultException(
                 'Error while acquiring datapath-id: ' + repr(r['error']))
         r = self.apiroutine.jsonrpc_result[1]
         if 'error' in r:
             raise JsonRPCErrorResultException(
                 'Error while acquiring datapath-id: ' + repr(r['error']))
         if r['rows']:
             r0 = r['rows'][0]
             name = r0['name']
             dpid = int(r0['datapath_id'], 16)
             if self.bridgenames is None or name in self.bridgenames:
                 self.managed_bridges[connection].append(
                     (vhost, dpid, name, bridge_uuid))
                 self.managed_conns[(vhost, dpid)] = connection
                 for m in self.apiroutine.waitForSend(
                         OVSDBBridgeSetup(OVSDBBridgeSetup.UP, dpid,
                                          connection.ovsdb_systemid, name,
                                          connection, connection.connmark,
                                          vhost, bridge_uuid)):
                     yield m
     except JsonRPCProtocolException:
         pass
Exemple #2
0
 def _update_bridge(self, connection, protocol, bridge_uuid, vhost):
     try:
         method, params = ovsdb.transact('Open_vSwitch',
                                         ovsdb.wait('Bridge', [["_uuid", "==", ovsdb.uuid(bridge_uuid)]],
                                                     ["datapath_id"], [{"datapath_id": ovsdb.oset()}], False, 5000),
                                         ovsdb.select('Bridge', [["_uuid", "==", ovsdb.uuid(bridge_uuid)]],
                                                                      ["datapath_id","name"]))
         for m in protocol.querywithreply(method, params, connection, self.apiroutine):
             yield m
         r = self.apiroutine.jsonrpc_result[0]
         if 'error' in r:
             raise JsonRPCErrorResultException('Error while acquiring datapath-id: ' + repr(r['error']))
         r = self.apiroutine.jsonrpc_result[1]
         if 'error' in r:
             raise JsonRPCErrorResultException('Error while acquiring datapath-id: ' + repr(r['error']))
         if r['rows']:
             r0 = r['rows'][0]
             name = r0['name']
             dpid = int(r0['datapath_id'], 16)
             if self.bridgenames is None or name in self.bridgenames:
                 self.managed_bridges[connection].append((vhost, dpid, name, bridge_uuid))
                 self.managed_conns[(vhost, dpid)] = connection
                 for m in self.apiroutine.waitForSend(OVSDBBridgeSetup(OVSDBBridgeSetup.UP,
                                                            dpid,
                                                            connection.ovsdb_systemid,
                                                            name,
                                                            connection,
                                                            connection.connmark,
                                                            vhost,
                                                            bridge_uuid)):
                     yield m
     except JsonRPCProtocolException:
         pass
Exemple #3
0
 def _get_interface_info(self, connection, protocol, buuid, interface_uuid,
                         port_uuid):
     try:
         method, params = ovsdb.transact(
             'Open_vSwitch',
             ovsdb.wait(
                 'Interface',
                 [["_uuid", "==", ovsdb.uuid(interface_uuid)]], ["ofport"],
                 [{
                     "ofport": ovsdb.oset()
                 }], False, 5000),
             ovsdb.wait(
                 'Interface',
                 [["_uuid", "==", ovsdb.uuid(interface_uuid)]], ["ofport"],
                 [{
                     "ofport": -1
                 }], False, 0),
             ovsdb.wait(
                 'Interface',
                 [["_uuid", "==", ovsdb.uuid(interface_uuid)]], ["ifindex"],
                 [{
                     "ifindex": ovsdb.oset()
                 }], False, 5000),
             ovsdb.select(
                 'Interface',
                 [["_uuid", "==", ovsdb.uuid(interface_uuid)]], [
                     "_uuid", "name", "ifindex", "ofport", "type",
                     "external_ids"
                 ]))
         for m in protocol.querywithreply(method, params, connection,
                                          self.apiroutine):
             yield m
         r = self.apiroutine.jsonrpc_result[0]
         if 'error' in r:
             raise JsonRPCErrorResultException(
                 'Error while acquiring interface: ' + repr(r['error']))
         r = self.apiroutine.jsonrpc_result[1]
         if 'error' in r:
             raise JsonRPCErrorResultException(
                 'Error while acquiring interface: ' + repr(r['error']))
         r = self.apiroutine.jsonrpc_result[2]
         if 'error' in r:
             # Ignore this port because it is in an error state
             self.apiroutine.retvalue = []
             return
         r = self.apiroutine.jsonrpc_result[3]
         if 'error' in r:
             raise JsonRPCErrorResultException(
                 'Error while acquiring interface: ' + repr(r['error']))
         if not r['rows']:
             self.apiroutine.retvalue = []
             return
         r0 = r['rows'][0]
         if r0['ofport'] < 0:
             # Ignore this port because it is in an error state
             self.apiroutine.retvalue = []
             return
         r0['_uuid'] = r0['_uuid'][1]
         r0['ifindex'] = ovsdb.getoptional(r0['ifindex'])
         r0['external_ids'] = ovsdb.getdict(r0['external_ids'])
         if buuid not in self.bridge_datapathid:
             self.apiroutine.retvalue = []
             return
         else:
             datapath_id = self.bridge_datapathid[buuid]
         if 'iface-id' in r0['external_ids']:
             eid = r0['external_ids']['iface-id']
             r0['id'] = eid
             id_ports = self.managed_ids.setdefault((protocol.vhost, eid),
                                                    [])
             id_ports.append((datapath_id, r0))
         else:
             r0['id'] = None
         self.managed_ports.setdefault((protocol.vhost, datapath_id),
                                       []).append((port_uuid, r0))
         notify = False
         if (protocol.vhost, datapath_id,
                 r0['ofport']) in self.wait_portnos:
             notify = True
             del self.wait_portnos[(protocol.vhost, datapath_id,
                                    r0['ofport'])]
         if (protocol.vhost, datapath_id, r0['name']) in self.wait_names:
             notify = True
             del self.wait_names[(protocol.vhost, datapath_id, r0['name'])]
         if (protocol.vhost, r0['id']) in self.wait_ids:
             notify = True
             del self.wait_ids[(protocol.vhost, r0['id'])]
         if notify:
             for m in self.apiroutine.waitForSend(
                     OVSDBPortUpNotification(connection,
                                             r0['name'],
                                             r0['ofport'],
                                             r0['id'],
                                             protocol.vhost,
                                             datapath_id,
                                             port=r0)):
                 yield m
         self.apiroutine.retvalue = [r0]
     except JsonRPCProtocolException:
         self.apiroutine.retvalue = []
Exemple #4
0
 def _get_interface_info(self, connection, protocol, buuid, interface_uuid, port_uuid):
     try:
         method, params = ovsdb.transact('Open_vSwitch',
                                         ovsdb.wait('Interface', [["_uuid", "==", ovsdb.uuid(interface_uuid)]],
                                                    ["ofport"], [{"ofport":ovsdb.oset()}], False, 5000),
                                         ovsdb.wait('Interface', [["_uuid", "==", ovsdb.uuid(interface_uuid)]],
                                                    ["ifindex"], [{"ifindex":ovsdb.oset()}], False, 5000),
                                         ovsdb.select('Interface', [["_uuid", "==", ovsdb.uuid(interface_uuid)]],
                                                                      ["_uuid", "name", "ifindex", "ofport", "type", "external_ids"]))
         for m in protocol.querywithreply(method, params, connection, self.apiroutine):
             yield m
         r = self.apiroutine.jsonrpc_result[0]
         if 'error' in r:
             raise JsonRPCErrorResultException('Error while acquiring interface: ' + repr(r['error']))            
         r = self.apiroutine.jsonrpc_result[1]
         if 'error' in r:
             raise JsonRPCErrorResultException('Error while acquiring interface: ' + repr(r['error']))            
         r = self.apiroutine.jsonrpc_result[2]
         if 'error' in r:
             raise JsonRPCErrorResultException('Error while acquiring interface: ' + repr(r['error']))
         if not r['rows']:
             self.apiroutine.retvalue = []
             return
         r0 = r['rows'][0]
         if r0['ofport'] < 0:
             # Ignore this port because it is in an error state
             self.apiroutine.retvalue = []
             return
         r0['_uuid'] = r0['_uuid'][1]
         r0['ifindex'] = ovsdb.getoptional(r0['ifindex'])
         r0['external_ids'] = ovsdb.getdict(r0['external_ids'])
         if buuid not in self.bridge_datapathid:
             self.apiroutine.retvalue = []
             return
         else:
             datapath_id = self.bridge_datapathid[buuid]
         if 'iface-id' in r0['external_ids']:
             eid = r0['external_ids']['iface-id']
             r0['id'] = eid
             id_ports = self.managed_ids.setdefault((protocol.vhost, eid), [])
             id_ports.append((datapath_id, r0))
         else:
             r0['id'] = None
         self.managed_ports.setdefault((protocol.vhost, datapath_id),[]).append((port_uuid, r0))
         notify = False
         if (protocol.vhost, datapath_id, r0['ofport']) in self.wait_portnos:
             notify = True
             del self.wait_portnos[(protocol.vhost, datapath_id, r0['ofport'])]
         if (protocol.vhost, datapath_id, r0['name']) in self.wait_names:
             notify = True
             del self.wait_names[(protocol.vhost, datapath_id, r0['name'])]
         if (protocol.vhost, r0['id']) in self.wait_ids:
             notify = True
             del self.wait_ids[(protocol.vhost, r0['id'])]
         if notify:
             for m in self.apiroutine.waitForSend(OVSDBPortUpNotification(connection, r0['name'],
                                                                          r0['ofport'], r0['id'],
                                                                          protocol.vhost, datapath_id,
                                                                          port = r0)):
                 yield m
         self.apiroutine.retvalue = [r0]
     except JsonRPCProtocolException:
         self.apiroutine.retvalue = []