def addPort(self, bridge_name, port_name): if bridge_name not in \ [br.name for br in list(self.ovs_state.bridges.values())]: raise OVSExceptions.OVSNoSuchBridge(bridge_name) if port_name in \ [port.name for port in list(self.ovs_state.ports.values())]: raise OVSExceptions.OVSPortExists(port_name) transaction = Transaction(self.cur_id) for instance in list(self.ovs_state.bridges.values()) + list( self.ovs_state.ports.values()): transaction.addOperation(WaitOperation(instance)) switch = self.ovs_state.switch iface = OVSInterface(port_name) port = OVSPort(port_name, [iface]) transaction.addOperation(InsertOperation(iface)) transaction.addOperation(InsertOperation(port)) bridge = None for br in list(self.ovs_state.bridges.values()): if br.name == bridge_name: bridge = br break bridge.ports[port.uuid] = port transaction.addOperation(UpdateOperation(bridge, 'ports')) transaction.addOperation(MutateOperation(switch, 'next_cfg', '+=')) self.sock.send(bytes(json.dumps(transaction), 'utf-8')) del bridge.ports[port.uuid] responses = self.get_responses(self.sock.recv(self.BUFF_SIZE)) for response in responses: res = json.loads(response) transaction.handleResult(res) self.update_notification(res) self.cur_id += 1 return True
def removeBridge(self, bridge_name): switch = self.ovs_state.switch bridge = None if bridge_name in \ [br.name for br in list(switch.bridges.values())]: bridge = [ br for br in list(switch.bridges.values()) if br.name == bridge_name ][0] else: raise OVSExceptions.OVSNoSuchBridge(bridge_name) transaction = Transaction(self.cur_id) transaction.addOperation(WaitOperation(switch)) self.ovs_state.removeBridge(bridge.uuid) transaction.addOperation(UpdateOperation(switch, ['bridges'])) transaction.addOperation(MutateOperation(switch, 'next_cfg', '+=')) self.sock.send(bytes(json.dumps(transaction), 'utf-8')) responses = self.get_responses(self.sock.recv(self.BUFF_SIZE)) for response in responses: res = json.loads(response) transaction.handleResult(res) self.cur_id += 1