예제 #1
0
    def removePort(self, port_name):
        if port_name not in \
                [port.name for port in list(self.ovs_state.ports.values())]:
            raise OVSExceptions.OVSNoSuchPort(port_name)

        switch = self.ovs_state.switch
        transaction = Transaction(self.cur_id)
        for instance in list(self.ovs_state.bridges.values()) + list(
                self.ovs_state.ports.values()):
            transaction.addOperation(WaitOperation(instance))

        port = None
        for p in list(self.ovs_state.ports.values()):
            if p.name == port_name:
                port = p
                break
        bridge = self.ovs_state.removePort(port.uuid)
        transaction.addOperation(UpdateOperation(bridge, 'ports'))
        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
        return True
예제 #2
0
    def removePort(self, port_name):
        if port_name not in [port.name for port in list(self.ovs_state.ports.values())]:
            raise OVSExceptions.OVSNoSuchPort(port_name)

        switch = self.ovs_state.switch
        transaction = Transaction(self.cur_id)
        for instance in list(self.ovs_state.bridges.values()) + list(self.ovs_state.ports.values()):
            transaction.addOperation(WaitOperation(instance))

        port = None
        for p in list(self.ovs_state.ports.values()):
            if p.name == port_name:
                port = p
                break
        bridge = self.ovs_state.removePort(port.uuid)
        transaction.addOperation(UpdateOperation(bridge, "ports"))
        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
        return True
예제 #3
0
    def setPortProperty(self, port_name, option, value):
        port = self.getPort(port_name)
        if hasattr(port, option):
            setattr(port, option, value)
        t = Transaction(self.cur_id)
        t.addOperation(WaitOperation(port))
        t.addOperation(UpdateOperation(port))
        t.addOperation(MutateOperation(self.ovs_state.switch, 'next_cfg',
                                       '+='))
        self.sock.send(bytes(json.dumps(t), 'utf-8'))

        responses = self.get_responses(self.sock.recv(self.BUFF_SIZE))
        for response in responses:
            res = json.loads(response)
            t.handleResult(res)
            self.update_notification(res)
        self.cur_id += 1
예제 #4
0
    def setPortProperty(self, port_name, option, value):
        port = self.getPort(port_name)
        if hasattr(port, option):
            setattr(port, option, value)
        t = Transaction(self.cur_id)
        t.addOperation(WaitOperation(port))
        t.addOperation(UpdateOperation(port))
        t.addOperation(MutateOperation(self.ovs_state.switch, "next_cfg", "+="))
        self.sock.send(bytes(json.dumps(t), "utf-8"))

        responses = self.get_responses(self.sock.recv(self.BUFF_SIZE))
        for response in responses:
            res = json.loads(response)
            t.handleResult(res)
            self.update_notification(res)
        self.cur_id += 1
예제 #5
0
    def setBridgeProperty(self, bridge_name, option, value):
        bridge = self.getBridge(bridge_name)
        if hasattr(bridge, option):
            setattr(bridge, option, value)
        t = Transaction(self.cur_id)
        t.addOperation(WaitOperation(bridge))
        t.addOperation(UpdateOperation(bridge))
        t.addOperation(MutateOperation(self.ovs_state.switch, 'next_cfg', '+='))
        self.sock.send(bytes(json.dumps(t), 'utf-8'))

        responses = self.get_responses(self.sock.recv(self.BUFF_SIZE))
        for response in responses:
            res = json.loads(response)
            t.handleResult(res)
            self.update_notification(res)
        self.cur_id += 1
예제 #6
0
    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
예제 #7
0
    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
예제 #8
0
    def setInterfaceProperty(self, interface_name, option, value):
        interface = self.getInterface(interface_name)
        if hasattr(interface, option):
            print(('VALUE', value))
            setattr(interface, option, value)

        t = Transaction(self.cur_id)
        t.addOperation(UpdateOperation(interface))
        t.addOperation(MutateOperation(self.ovs_state.switch, 'next_cfg',
                                       '+='))
        self.sock.send(bytes(json.dumps(t), 'utf-8'))
        responses = self.get_responses(self.sock.recv(self.BUFF_SIZE))
        print(("OPTIONS:", interface.columns))
        for response in responses:
            res = json.loads(response)
            t.handleResult(res)
            self.update_notification(res)
        interface = self.getInterface(interface_name)
        self.cur_id += 1
예제 #9
0
    def setInterfaceProperty(self, interface_name, option, value):
        interface = self.getInterface(interface_name)
        if hasattr(interface, option):
            print(('VALUE', value))
            setattr(interface, option, value)

        t = Transaction(self.cur_id)
        t.addOperation(UpdateOperation(interface))
        t.addOperation(MutateOperation(self.ovs_state.switch, 'next_cfg', '+='))
        self.sock.send(bytes(json.dumps(t), 'utf-8'))
        responses = self.get_responses(self.sock.recv(self.BUFF_SIZE))
        print(("OPTIONS:", interface.columns))
        for response in responses:
            res = json.loads(response)
            t.handleResult(res)
            self.update_notification(res)
        interface = self.getInterface(interface_name)
        self.cur_id += 1
예제 #10
0
    def addBridge(self, bridge_name):
        switch = self.ovs_state.switch
        if bridge_name in \
                [br.name for br in list(self.ovs_state.bridges.values()) if br.name == bridge_name]:
            raise OVSExceptions.OVSBridgeExists(bridge_name)

        transaction = Transaction(self.cur_id)

        # Generate Wait operations
        for instance in list(self.ovs_state.ports.values()) + list(
                self.ovs_state.bridges.values()):
            transaction.addOperation(WaitOperation(instance))

        # Build sub-components of a bridge
        intern_if = OVSInterface(bridge_name)
        intern_if.type = 'internal'
        intern_port = OVSPort(bridge_name, [intern_if])
        bridge = OVSBridge(bridge_name, [intern_port])

        # Generate Insert Operations for built components
        transaction.addOperation(InsertOperation(intern_if))
        transaction.addOperation(InsertOperation(intern_port))
        transaction.addOperation(InsertOperation(bridge))

        switch.addBridge(bridge)
        transaction.addOperation(UpdateOperation(switch, ['bridges']))
        transaction.addOperation(MutateOperation(switch, 'next_cfg', '+='))
        self.sock.send(bytes(json.dumps(transaction), 'utf-8'))
        del switch.bridges[bridge.uuid]
        handled = False
        while not handled:
            responses = self.get_responses(self.sock.recv(self.BUFF_SIZE))
            for response in responses:
                res = json.loads(response)
                handled = transaction.handleResult(res)
                self.update_notification(res)
        self.cur_id += 1
예제 #11
0
    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
예제 #12
0
    def addBridge(self, bridge_name):
        switch = self.ovs_state.switch
        if bridge_name in [br.name for br in list(self.ovs_state.bridges.values()) if br.name == bridge_name]:
            raise OVSExceptions.OVSBridgeExists(bridge_name)

        transaction = Transaction(self.cur_id)

        # Generate Wait operations
        for instance in list(self.ovs_state.ports.values()) + list(self.ovs_state.bridges.values()):
            transaction.addOperation(WaitOperation(instance))

        # Build sub-components of a bridge
        intern_if = OVSInterface(bridge_name)
        intern_if.type = "internal"
        intern_port = OVSPort(bridge_name, [intern_if])
        bridge = OVSBridge(bridge_name, [intern_port])

        # Generate Insert Operations for built components
        transaction.addOperation(InsertOperation(intern_if))
        transaction.addOperation(InsertOperation(intern_port))
        transaction.addOperation(InsertOperation(bridge))

        switch.addBridge(bridge)
        transaction.addOperation(UpdateOperation(switch, ["bridges"]))
        transaction.addOperation(MutateOperation(switch, "next_cfg", "+="))
        self.sock.send(bytes(json.dumps(transaction), "utf-8"))
        del switch.bridges[bridge.uuid]
        handled = False
        while not handled:
            responses = self.get_responses(self.sock.recv(self.BUFF_SIZE))
            for response in responses:
                res = json.loads(response)
                handled = transaction.handleResult(res)
                self.update_notification(res)
        self.cur_id += 1
예제 #13
0
    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