Пример #1
0
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Port', 'name',
                                         self.port)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port %s does not exist") % self.port
            raise RuntimeError(msg)
        if self.bridge:
            br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name',
                                       self.bridge)
        else:
            br = next(b for b in self.api._tables['Bridge'].rows.values()
                      if port in b.ports)

        if port.uuid not in br.ports and not self.if_exists:
            # TODO(twilson) Make real errors across both implementations
            msg = _("Port %(port)s does not exist on %(bridge)s!") % {
                'port': self.name, 'bridge': self.bridge
            }
            LOG.error(msg)
            raise RuntimeError(msg)

        br.verify('ports')
        ports = br.ports
        ports.remove(port)
        br.ports = ports

        # Also remove port/interface directly for indexing?
        port.verify('interfaces')
        for iface in port.interfaces:
            self.api._tables['Interface'].rows[iface.uuid].delete()
        self.api._tables['Port'].rows[port.uuid].delete()
Пример #2
0
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Port', 'name',
                                         self.port)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port %s does not exist") % self.port
            raise RuntimeError(msg)
        if self.bridge:
            br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name',
                                       self.bridge)
        else:
            br = next(b for b in self.api._tables['Bridge'].rows.values()
                      if port in b.ports)

        if port.uuid not in br.ports and not self.if_exists:
            # TODO(twilson) Make real errors across both implementations
            msg = _("Port %(port)s does not exist on %(bridge)s!") % {
                'port': self.name,
                'bridge': self.bridge
            }
            LOG.error(msg)
            raise RuntimeError(msg)

        br.verify('ports')
        ports = br.ports
        ports.remove(port)
        br.ports = ports

        # Also remove port/interface directly for indexing?
        port.verify('interfaces')
        for iface in port.interfaces:
            self.api._tables['Interface'].rows[iface.uuid].delete()
        self.api._tables['Port'].rows[port.uuid].delete()
Пример #3
0
 def _get_update_data_without_compare(self):
     lswitch_ovsdb_dict = {}
     for switch_name in self.lswitch_names:
         switch_name = utils.ovn_name(switch_name)
         lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                         'name', switch_name)
         lswitch_ovsdb_dict[switch_name] = lswitch
     if self.is_add_acl:
         acl_add_values_dict = {}
         for port in self.port_list:
             switch_name = utils.ovn_name(port['network_id'])
             if switch_name not in acl_add_values_dict:
                 acl_add_values_dict[switch_name] = []
             acl_add_values_dict[switch_name].append(
                 self.acl_new_values_dict[port['id']])
         acl_del_objs_dict = {}
     else:
         acl_add_values_dict = {}
         acl_del_objs_dict = {}
         del_acl_matches = []
         for acl_dict in self.acl_new_values_dict.values():
             del_acl_matches.append(acl_dict['match'])
         for switch_name, lswitch in six.iteritems(lswitch_ovsdb_dict):
             if switch_name not in acl_del_objs_dict:
                 acl_del_objs_dict[switch_name] = []
             lswitch.verify('acls')
             acls = getattr(lswitch, 'acls', [])
             for acl in acls:
                 if getattr(acl, 'match') in del_acl_matches:
                     acl_del_objs_dict[switch_name].append(acl)
     return lswitch_ovsdb_dict, acl_del_objs_dict, acl_add_values_dict
 def _get_update_data_without_compare(self):
     lswitch_ovsdb_dict = {}
     for switch_name in self.lswitch_names:
         switch_name = utils.ovn_name(switch_name)
         lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                         'name', switch_name)
         lswitch_ovsdb_dict[switch_name] = lswitch
     if self.is_add_acl:
         acl_add_values_dict = {}
         for port in self.port_list:
             switch_name = utils.ovn_name(port['network_id'])
             if switch_name not in acl_add_values_dict:
                 acl_add_values_dict[switch_name] = []
             acl_add_values_dict[switch_name].append(
                 self.acl_new_values_dict[port['id']])
         acl_del_objs_dict = {}
     else:
         acl_add_values_dict = {}
         acl_del_objs_dict = {}
         del_acl_matches = []
         for acl_dict in self.acl_new_values_dict.values():
             del_acl_matches.append(acl_dict['match'])
         for switch_name, lswitch in six.iteritems(lswitch_ovsdb_dict):
             if switch_name not in acl_del_objs_dict:
                 acl_del_objs_dict[switch_name] = []
             lswitch.verify('acls')
             acls = getattr(lswitch, 'acls', [])
             for acl in acls:
                 if getattr(acl, 'match') in del_acl_matches:
                     acl_del_objs_dict[switch_name].append(acl)
     return lswitch_ovsdb_dict, acl_del_objs_dict, acl_add_values_dict
Пример #5
0
    def run_idl(self, txn):
        interface = idlutils.row_by_value(self.api.idl, 'Interface', 'name',
                                          self.name)
        ports = self.api._tables['Port'].rows.values()
        pname = next(port for port in ports if interface in port.interfaces)

        bridges = self.api._tables['Bridge'].rows.values()
        self.result = next(br.name for br in bridges if pname in br.ports)
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Port',
                                          'name', self.lport)
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
            ports = getattr(lswitch, 'ports', [])
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        lswitch.verify('ports')

        ports.remove(lport)
        setattr(lswitch, 'ports', ports)
        self.api._tables['Logical_Port'].rows[lport.uuid].delete()
Пример #7
0
    def run_idl(self, txn):
        interface = idlutils.row_by_value(self.api.idl, 'Interface', 'name',
                                          self.name)
        ports = self.api._tables['Port'].rows.values()
        pname = next(
                port for port in ports if interface in port.interfaces)

        bridges = self.api._tables['Bridge'].rows.values()
        self.result = next(br.name for br in bridges if pname in br.ports)
Пример #8
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     controllers = []
     for target in self.targets:
         controller = txn.insert(self.api._tables['Controller'])
         controller.target = target
         controllers.append(controller)
     br.verify('controller')
     br.controller = controllers
Пример #9
0
 def run_idl(self, txn):
     # TODO(twilson) This is expensive!
     # This traversal of all ports could be eliminated by caching the bridge
     # name on the Port's external_id field
     # In fact, if we did that, the only place that uses to_br functions
     # could just add the external_id field to the conditions passed to find
     port = idlutils.row_by_value(self.api.idl, 'Port', 'name', self.name)
     bridges = self.api._tables['Bridge'].rows.values()
     self.result = next(br.name for br in bridges if port in br.ports)
Пример #10
0
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Port', 'name',
                                          self.lport)
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
            ports = getattr(lswitch, 'ports', [])
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        lswitch.verify('ports')

        ports.remove(lport)
        setattr(lswitch, 'ports', ports)
        self.api._tables['Logical_Port'].rows[lport.uuid].delete()
Пример #11
0
 def run_idl(self, txn):
     # TODO(twilson) This is expensive!
     # This traversal of all ports could be eliminated by caching the bridge
     # name on the Port's external_id field
     # In fact, if we did that, the only place that uses to_br functions
     # could just add the external_id field to the conditions passed to find
     port = idlutils.row_by_value(self.api.idl, 'Port', 'name', self.name)
     bridges = self.api._tables['Bridge'].rows.values()
     self.result = next(br.name for br in bridges if port in br.ports)
Пример #12
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     controllers = []
     for target in self.targets:
         controller = txn.insert(self.api._tables['Controller'])
         controller.target = target
         controllers.append(controller)
     br.verify('controller')
     br.controller = controllers
 def run_idl(self, txn):
     if self.may_exist:
         lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                         'name', self.name, None)
         if lswitch:
             return
     row = txn.insert(self.api._tables['Logical_Switch'])
     row.name = self.name
     for col, val in self.columns.items():
         setattr(row, col, val)
Пример #14
0
 def run_idl(self, txn):
     if self.may_exist:
         lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                         'name', self.name, None)
         if lswitch:
             return
     row = txn.insert(self.api._tables['Logical_Switch'])
     row.name = self.name
     for col, val in self.columns.items():
         setattr(row, col, val)
Пример #15
0
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.name)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch %s does not exist") % self.name
            raise RuntimeError(msg)

        self.api._tables['Logical_Switch'].rows[lswitch.uuid].delete()
Пример #16
0
    def run_idl(self, txn):
        br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
        if self.may_exist:
            port = idlutils.row_by_value(self.api.idl, 'Port', 'name',
                                         self.port, None)
            if port:
                return
        port = txn.insert(self.api._tables['Port'])
        port.name = self.port
        br.verify('ports')
        ports = getattr(br, 'ports', [])
        ports.append(port)
        br.ports = ports

        iface = txn.insert(self.api._tables['Interface'])
        iface.name = self.port
        port.verify('interfaces')
        ifaces = getattr(port, 'interfaces', [])
        ifaces.append(iface)
        port.interfaces = ifaces
Пример #17
0
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Port', 'name',
                                         self.lport)
        except idlutils.RowNotFound:
            msg = _("Logical Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        options = {'router-port': self.lrouter_port}
        setattr(port, 'options', options)
        setattr(port, 'type', 'router')
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.name)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch %s does not exist") % self.name
            raise RuntimeError(msg)

        self.api._tables['Logical_Switch'].rows[lswitch.uuid].delete()
Пример #19
0
    def run_idl(self, txn):
        br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
        if self.may_exist:
            port = idlutils.row_by_value(self.api.idl, 'Port', 'name',
                                         self.port, None)
            if port:
                return
        port = txn.insert(self.api._tables['Port'])
        port.name = self.port
        br.verify('ports')
        ports = getattr(br, 'ports', [])
        ports.append(port)
        br.ports = ports

        iface = txn.insert(self.api._tables['Interface'])
        iface.name = self.port
        port.verify('interfaces')
        ifaces = getattr(port, 'interfaces', [])
        ifaces.append(iface)
        port.interfaces = ifaces
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Port',
                                         'name', self.lport)
        except idlutils.RowNotFound:
            msg = _("Logical Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        options = {'router-port': self.lrouter_port}
        setattr(port, 'options', options)
        setattr(port, 'type', 'router')
Пример #21
0
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Port', 'name',
                                         self.lport)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        for col, val in self.columns.items():
            setattr(port, col, val)
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Port',
                                         'name', self.lport)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        for col, val in self.columns.items():
            setattr(port, col, val)
Пример #23
0
    def run_idl(self, txn):
        try:
            lrouter_port = idlutils.row_by_value(self.api.idl,
                                                 'Logical_Router_Port', 'name',
                                                 self.name)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router Port %s does not exist") % self.name
            raise RuntimeError(msg)
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)

        lrouter.verify('ports')
        lrouter_ports = getattr(lrouter, 'ports', [])
        if (lrouter_port in lrouter_ports):
            lrouter_ports.remove(lrouter_port)
            setattr(lrouter, 'ports', lrouter_ports)
    def run_idl(self, txn):
        try:
            lrouter_port = idlutils.row_by_value(self.api.idl,
                                                 'Logical_Router_Port',
                                                 'name', self.name)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router Port %s does not exist") % self.name
            raise RuntimeError(msg)
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)

        lrouter.verify('ports')
        lrouter_ports = getattr(lrouter, 'ports', [])
        if (lrouter_port in lrouter_ports):
            lrouter_ports.remove(lrouter_port)
            setattr(lrouter, 'ports', lrouter_ports)
    def run_idl(self, txn):
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.name, None)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router %s does not exist") % self.name
            raise RuntimeError(msg)

        if lrouter:
            for col, val in self.columns.items():
                setattr(lrouter, col, val)
            return
Пример #26
0
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
            ports = getattr(lswitch, 'ports', [])
        except idlutils.RowNotFound:
            msg = _("Logical Switch %s does not exist") % self.lswitch
            raise RuntimeError(msg)
        if self.may_exist:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Port', 'name',
                                         self.lport, None)
            if port:
                return

        lswitch.verify('ports')

        port = txn.insert(self.api._tables['Logical_Port'])
        port.name = self.lport
        for col, val in self.columns.items():
            setattr(port, col, val)
        # add the newly created port to existing lswitch
        ports.append(port.uuid)
        setattr(lswitch, 'ports', ports)
Пример #27
0
    def run_idl(self, txn):
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.name, None)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router %s does not exist") % self.name
            raise RuntimeError(msg)

        if lrouter:
            for col, val in self.columns.items():
                setattr(lrouter, col, val)
            return
Пример #28
0
    def run_idl(self, txn):

        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)
        try:
            idlutils.row_by_value(self.api.idl, 'Logical_Router_Port', 'name',
                                  self.name)
            # TODO(chandrav) This might be a case of multiple prefixes
            # on the same port. yet to figure out if and how OVN needs
            # to cater to this case
        except idlutils.RowNotFound:
            lrouter_port = txn.insert(self.api._tables['Logical_Router_Port'])
            lrouter_port.name = self.name
            for col, val in self.columns.items():
                setattr(lrouter_port, col, val)
            lrouter.verify('ports')
            lrouter_ports = getattr(lrouter, 'ports', [])
            if lrouter_port not in lrouter_ports:
                lrouter_ports.append(lrouter_port)
                setattr(lrouter, 'ports', lrouter_ports)
    def run_idl(self, txn):

        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)
        try:
            idlutils.row_by_value(self.api.idl, 'Logical_Router_Port',
                                  'name', self.name)
            # TODO(chandrav) This might be a case of multiple prefixes
            # on the same port. yet to figure out if and how OVN needs
            # to cater to this case
        except idlutils.RowNotFound:
            lrouter_port = txn.insert(self.api._tables['Logical_Router_Port'])
            lrouter_port.name = self.name
            for col, val in self.columns.items():
                setattr(lrouter_port, col, val)
            lrouter.verify('ports')
            lrouter_ports = getattr(lrouter, 'ports', [])
            if lrouter_port not in lrouter_ports:
                lrouter_ports.append(lrouter_port)
                setattr(lrouter, 'ports', lrouter_ports)
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
            ports = getattr(lswitch, 'ports', [])
        except idlutils.RowNotFound:
            msg = _("Logical Switch %s does not exist") % self.lswitch
            raise RuntimeError(msg)
        if self.may_exist:
            port = idlutils.row_by_value(self.api.idl,
                                         'Logical_Port', 'name',
                                         self.lport, None)
            if port:
                return

        lswitch.verify('ports')

        port = txn.insert(self.api._tables['Logical_Port'])
        port.name = self.lport
        for col, val in self.columns.items():
            setattr(port, col, val)
        # add the newly created port to existing lswitch
        ports.append(port.uuid)
        setattr(lswitch, 'ports', ports)
Пример #31
0
    def get_acls_for_lswitches(self, lswitch_names):
        """Get the existing set of acls that belong to the logical switches

        @param lswitch_names: List of logical switch names
        @type lswitch_names: []
        @var acl_values_dict: A dictionary indexed by port_id containing the
                              list of acl values in string format that belong
                              to that port
        @var acl_obj_dict: A dictionary indexed by acl value containing the
                           corresponding acl idl object.
        @var lswitch_ovsdb_dict: A dictionary mapping from logical switch
                                 name to lswitch idl object
        @return: (acl_values_dict, acl_obj_dict, lswitch_ovsdb_dict)
        """
        acl_values_dict = {}
        acl_obj_dict = {}
        lswitch_ovsdb_dict = {}
        for lswitch_name in lswitch_names:
            try:
                lswitch = idlutils.row_by_value(self.idl,
                                                'Logical_Switch',
                                                'name',
                                                utils.ovn_name(lswitch_name))
            except idlutils.RowNotFound:
                # It is possible for the logical switch to be deleted
                # while we are searching for it by name in idl.
                continue
            lswitch_ovsdb_dict[lswitch_name] = lswitch
            acls = getattr(lswitch, 'acls', [])

            # Iterate over each acl in a lswitch and store the acl in
            # a key:value representation for e.g. acl_string. This
            # key:value representation can invoke the code -
            # self._ovn.add_acl(**acl_string)
            for acl in acls:
                ext_ids = getattr(acl, 'external_ids', {})
                port_id = ext_ids.get('neutron:lport')
                acl_list = acl_values_dict.setdefault(port_id, [])
                acl_string = {'lport': port_id,
                              'lswitch': utils.ovn_name(lswitch_name)}
                for acl_key in six.iterkeys(getattr(acl, "_data", {})):
                    try:
                        acl_string[acl_key] = getattr(acl, acl_key)
                    except AttributeError:
                        pass
                acl_obj_dict[str(acl_string)] = acl
                acl_list.append(acl_string)
        return acl_values_dict, acl_obj_dict, lswitch_ovsdb_dict
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.name)

        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch %s does not exist") % self.name
            raise RuntimeError(msg)

        lswitch.verify('external_ids')

        external_ids = getattr(lswitch, 'external_ids', {})
        external_ids[self.field] = self.value
        lswitch.external_ids = external_ids
Пример #33
0
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.name)

        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch %s does not exist") % self.name
            raise RuntimeError(msg)

        lswitch.verify('external_ids')

        external_ids = getattr(lswitch, 'external_ids', {})
        external_ids[self.field] = self.value
        lswitch.external_ids = external_ids
Пример #34
0
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
        except idlutils.RowNotFound:
            msg = _("Logical Switch %s does not exist") % self.lswitch
            raise RuntimeError(msg)

        row = txn.insert(self.api._tables['ACL'])
        for col, val in self.columns.items():
            setattr(row, col, val)
        row.external_ids = {'neutron:lport': self.lport}
        lswitch.verify('acls')
        acls = getattr(lswitch, 'acls', [])
        acls.append(row.uuid)
        setattr(lswitch, 'acls', acls)
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
        except idlutils.RowNotFound:
            msg = _("Logical Switch %s does not exist") % self.lswitch
            raise RuntimeError(msg)

        row = txn.insert(self.api._tables['ACL'])
        for col, val in self.columns.items():
            setattr(row, col, val)
        row.external_ids = {'neutron:lport': self.lport}
        lswitch.verify('acls')
        acls = getattr(lswitch, 'acls', [])
        acls.append(row.uuid)
        setattr(lswitch, 'acls', acls)
Пример #36
0
 def run_idl(self, txn):
     try:
         br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name',
                                    self.name)
     except idlutils.RowNotFound:
         if self.if_exists:
             return
         else:
             msg = _("Bridge %s does not exist") % self.name
             LOG.error(msg)
             raise RuntimeError(msg)
     self.api._ovs.verify('bridges')
     for port in br.ports:
         cmd = DelPortCommand(self.api, port.name, self.name,
                              if_exists=True)
         cmd.run_idl(txn)
     bridges = self.api._ovs.bridges
     bridges.remove(br)
     self.api._ovs.bridges = bridges
     self.api._tables['Bridge'].rows[br.uuid].delete()
Пример #37
0
 def run_idl(self, txn):
     try:
         br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name',
                                    self.name)
     except idlutils.RowNotFound:
         if self.if_exists:
             return
         else:
             msg = _("Bridge %s does not exist") % self.name
             LOG.error(msg)
             raise RuntimeError(msg)
     self.api._ovs.verify('bridges')
     for port in br.ports:
         cmd = DelPortCommand(self.api,
                              port.name,
                              self.name,
                              if_exists=True)
         cmd.run_idl(txn)
     bridges = self.api._ovs.bridges
     bridges.remove(br)
     self.api._ovs.bridges = bridges
     self.api._tables['Bridge'].rows[br.uuid].delete()
Пример #38
0
    def run_idl(self, txn):
        if self.may_exist:
            br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name',
                                       self.name, None)
            if br:
                if self.datapath_type:
                    br.datapath_type = self.datapath_type
                return
        row = txn.insert(self.api._tables['Bridge'])
        row.name = self.name
        if self.datapath_type:
            row.datapath_type = self.datapath_type
        self.api._ovs.verify('bridges')
        self.api._ovs.bridges = self.api._ovs.bridges + [row]

        # Add the internal bridge port
        cmd = AddPortCommand(self.api, self.name, self.name, self.may_exist)
        cmd.run_idl(txn)

        cmd = DbSetCommand(self.api, 'Interface', self.name,
                           ('type', 'internal'))
        cmd.run_idl(txn)
Пример #39
0
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch %s does not exist") % self.lswitch
            raise RuntimeError(msg)

        lswitch.verify('acls')

        acls_to_del = []
        acls = getattr(lswitch, 'acls', [])
        for acl in acls:
            ext_ids = getattr(acl, 'external_ids', {})
            if ext_ids.get('neutron:lport') == self.lport:
                acls_to_del.append(acl)
        for acl in acls_to_del:
            acls.remove(acl)
            acl.delete()
        setattr(lswitch, 'acls', acls)
Пример #40
0
    def run_idl(self, txn):
        if self.may_exist:
            br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name',
                                       self.name, None)
            if br:
                if self.datapath_type:
                    br.datapath_type = self.datapath_type
                return
        row = txn.insert(self.api._tables['Bridge'])
        row.name = self.name
        if self.datapath_type:
            row.datapath_type = self.datapath_type
        self.api._ovs.verify('bridges')
        self.api._ovs.bridges = self.api._ovs.bridges + [row]

        # Add the internal bridge port
        cmd = AddPortCommand(self.api, self.name, self.name, self.may_exist)
        cmd.run_idl(txn)

        cmd = DbSetCommand(self.api, 'Interface', self.name,
                           ('type', 'internal'))
        cmd.run_idl(txn)
    def run_idl(self, txn):
        try:
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch %s does not exist") % self.lswitch
            raise RuntimeError(msg)

        lswitch.verify('acls')

        acls_to_del = []
        acls = getattr(lswitch, 'acls', [])
        for acl in acls:
            ext_ids = getattr(acl, 'external_ids', {})
            if ext_ids.get('neutron:lport') == self.lport:
                acls_to_del.append(acl)
        for acl in acls_to_del:
            acls.remove(acl)
            acl.delete()
        setattr(lswitch, 'acls', acls)
Пример #42
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     self.result = [i.name for p in br.ports if p.name != self.bridge
                    for i in p.interfaces]
Пример #43
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     br.controller = []
Пример #44
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     br.verify('controller')
     self.result = [c.target for c in br.controller]
Пример #45
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     br.verify('fail_mode')
     br.fail_mode = self.mode
Пример #46
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.name)
     self.result = br.external_ids[self.field]
Пример #47
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.name)
     external_ids = getattr(br, 'external_ids', {})
     external_ids[self.field] = self.value
     br.external_ids = external_ids
Пример #48
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.name)
     external_ids = getattr(br, 'external_ids', {})
     external_ids[self.field] = self.value
     br.external_ids = external_ids
Пример #49
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     br.controller = []
Пример #50
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     br.verify('controller')
     self.result = [c.target for c in br.controller]
Пример #51
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.name)
     self.result = br.external_ids[self.field]
Пример #52
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     self.result = [
         i.name for p in br.ports if p.name != self.bridge
         for i in p.interfaces
     ]
Пример #53
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     br.verify('fail_mode')
     br.fail_mode = self.mode
Пример #54
0
 def run_idl(self, txn):
     self.result = bool(idlutils.row_by_value(self.api.idl, 'Bridge',
                                              'name', self.name, None))
Пример #55
0
 def run_idl(self, txn):
     self.result = bool(
         idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.name,
                               None))