예제 #1
0
    def run_idl(self, txn):
        try:
            port_chain = idlutils.row_by_value(self.api.idl,
                                               'Logical_Port_Chain',
                                               'name', self.lport_chain)
            fc = getattr(port_chain, 'flow_classifier', [])
        except idlutils.RowNotFound:
            msg = _("Logical port chain %s does not exist") % self.lport_chain
            raise RuntimeError(msg)
        if self.may_exist:
            flow_classifier = idlutils.row_by_value(
                self.api.idl, 'Logical_Flow_Classifier', 'name',
                self.lflow_classifier, None)
            if flow_classifier:
                return
        port_chain.verify('flow_classifier')

        flow_classifier = txn.insert(
            self.api._tables['Logical_Flow_Classifier'])
        flow_classifier.name = self.lflow_classifier
        for col, val in self.columns.items():
            setattr(flow_classifier, col, val)
        # add the newly created flow_classifier to existing lswitch
        fc.append(flow_classifier.uuid)
        setattr(port_chain, 'flow_classifier', fc)
예제 #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 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)
            # The LRP entry with certain name has already exist, raise an
            # exception to notice caller. It's caller's responsibility to
            # call UpdateLRouterPortCommand to get LRP entry processed
            # correctly.
            msg = _("Logical Router Port with name \"%s\" "
                    "already exists.") % self.name
            raise RuntimeError(msg)
        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)
예제 #4
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)
        if self.may_exist:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                         'name', self.lport, None)
            if port:
                return

        port = txn.insert(self.api._tables['Logical_Switch_Port'])
        port.name = self.lport
        dhcpv4_options = self.columns.pop('dhcpv4_options', [])
        if isinstance(dhcpv4_options, list):
            port.dhcpv4_options = dhcpv4_options
        else:
            port.dhcpv4_options = [dhcpv4_options.result]
        dhcpv6_options = self.columns.pop('dhcpv6_options', [])
        if isinstance(dhcpv6_options, list):
            port.dhcpv6_options = dhcpv6_options
        else:
            port.dhcpv6_options = [dhcpv6_options.result]
        for col, val in self.columns.items():
            setattr(port, col, val)
        # add the newly created port to existing lswitch
        _addvalue_to_list(lswitch, 'ports', port.uuid)
        self.result = port.uuid
예제 #5
0
파일: commands.py 프로젝트: coreycb/neutron
    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()
예제 #6
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)
            # The LRP entry with certain name has already exist, raise an
            # exception to notice caller. It's caller's responsibility to
            # call UpdateLRouterPortCommand to get LRP entry processed
            # correctly.
            msg = _("Logical Router Port with name \"%s\" "
                    "already exists.") % self.name
            raise RuntimeError(msg)
        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)
예제 #7
0
 def check_for_row_by_value_and_retry(self, table, column, match):
     try:
         idlutils.row_by_value(self.idl, table, column, match)
     except idlutils.RowNotFound:
         msg = (_("%(match)s does not exist in %(column)s of %(table)s")
                % {'match': match, 'column': column, 'table': table})
         raise RuntimeError(msg)
예제 #8
0
    def run_idl(self, txn):
        try:
            lport_pair = idlutils.row_by_value(self.api.idl,
                                               'Logical_Port_Pair',
                                               'name', self.lport_pair)
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
            lppg = idlutils.row_by_value(self.api.idl,
                                         'Logical_Port_Pair_Group',
                                         'name', self.lport_pair_group) 
            port_pairs = getattr(lswitch, 'port_pairs', [])
            port_pairs_ppg = getattr(lppg, 'port_pairs', [])
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port Pair %s does not exist") % self.lport_pair
            raise RuntimeError(msg)

        lswitch.verify('port_pairs')
        lppg.verify('port_pairs')

        port_pairs.remove(lport_pair)
        port_pairs_ppg.remove(lport_pair)
        setattr(lswitch, 'port_pairs', port_pairs)
        setattr(lppg, 'port_pairs', port_pairs_ppg)
        self.api._tables['Logical_Port_Pair'].rows[lport_pair.uuid].delete()
예제 #9
0
    def run_idl(self, txn):
        try:
            lport_chain = idlutils.row_by_value(self.api.idl,
                                                'Logical_Port_Chain',
                                                'name', self.lport_chain)
            port_pair_groups = getattr(lport_chain,
                                       'port_pair_groups', [])
        except idlutils.RowNotFound:
            msg = _("Logical Port Chain %s does not exist") % self.lport_chain
            raise RuntimeError(msg)
        if self.may_exist:
            port_pair_group = idlutils.row_by_value(
                self.api.idl, 'Logical_Port_Pair_Group', 'name',
                self.lport_pair_group, None)
            if port_pair_group:
                return

        lport_chain.verify('port_pair_groups')

        port_pair_group = txn.insert(
            self.api._tables['Logical_Port_Pair_Group'])
        port_pair_group.name = self.lport_pair_group
        for col, val in self.columns.items():
            setattr(port_pair_group, col, val)
        # add the newly created port_pair to existing lswitch
        port_pair_groups.append(port_pair_group.uuid)
        setattr(lport_chain, 'port_pair_groups', port_pair_groups)
예제 #10
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)
        if self.may_exist:
            port = idlutils.row_by_value(self.api.idl,
                                         'Logical_Switch_Port', 'name',
                                         self.lport, None)
            if port:
                return

        port = txn.insert(self.api._tables['Logical_Switch_Port'])
        port.name = self.lport
        dhcpv4_options = self.columns.pop('dhcpv4_options', [])
        if isinstance(dhcpv4_options, list):
            port.dhcpv4_options = dhcpv4_options
        else:
            port.dhcpv4_options = [dhcpv4_options.result]
        dhcpv6_options = self.columns.pop('dhcpv6_options', [])
        if isinstance(dhcpv6_options, list):
            port.dhcpv6_options = dhcpv6_options
        else:
            port.dhcpv6_options = [dhcpv6_options.result]
        for col, val in self.columns.items():
            setattr(port, col, val)
        # add the newly created port to existing lswitch
        _addvalue_to_list(lswitch, 'ports', port.uuid)
예제 #11
0
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                          'name', self.lport)
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        _delvalue_from_list(lswitch, 'ports', lport)
        self.api._tables['Logical_Switch_Port'].rows[lport.uuid].delete()
예제 #12
0
파일: commands.py 프로젝트: dingboopt/wqq
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                          'name', self.lport)
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        _delvalue_from_list(lswitch, 'ports', lport)
        self.api._tables['Logical_Switch_Port'].rows[lport.uuid].delete()
예제 #13
0
    def get_logical_routers_rports(self, lrouter_name):
        """Get logical Router ports associated with logical Router

        @param lrouter_name: name (string)
        @return: list of dict, each dict has key-value:
                 - 'name': port name(string).
                 - 'cidr': cidr

        """
        def network_to_cidr(network):
            """ip/mask_len to standard cidr format."""
            ip_string = network.split('/')[0]
            mask_len = network.split('/')[1]
            ip_address = netaddr.ip.IPAddress(ip_string)
            net = netaddr.ip.IPAddress(ip_address.value
                                       & (~0x01 << 31 - int(mask_len)))
            cidr = str(net) + '/' + mask_len
            return cidr

        result = []
        try:
            lrouter = idlutils.row_by_value(self.idl, 'Logical_Router', 'name',
                                            lrouter_name)
        except idlutils.RowNotFound:
            pass
        for lrport in getattr(lrouter, 'ports', []):
            if not str(lrport.name).startswith('dvr-to-transit-'):
                cidr = network_to_cidr(lrport.networks[0])
                result.append({'name': lrport.name, 'cidr': cidr})
        return result
예제 #14
0
    def add_tunnel_port(self, chassis):
        bridge = idlutils.row_by_value(self.idl, "Bridge", "name", "br-int")

        txn = idl.Transaction(self.idl)
        port_name = "df-" + chassis.get_name()

        interface = txn.insert(self.idl.tables["Interface"])
        interface.name = port_name
        interface.type = chassis.get_encap_type()
        options_dict = getattr(interface, "options", {})
        options_dict["remote_ip"] = chassis.get_ip()
        options_dict["key"] = "flow"
        interface.options = options_dict

        port = txn.insert(self.idl.tables["Port"])
        port.name = port_name
        port.verify("interfaces")
        ifaces = getattr(port, "interfaces", [])
        ifaces.append(interface)
        port.interfaces = ifaces
        external_ids_dict = getattr(interface, "external_ids", {})
        external_ids_dict["df-chassis-id"] = chassis.get_name()
        port.external_ids = external_ids_dict

        bridge.verify("ports")
        ports = getattr(bridge, "ports", [])
        ports.append(port)
        bridge.ports = ports

        status = txn.commit_block()
        return status
예제 #15
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
        try:
            self.api._ovs.addvalue('bridges', row)
        except AttributeError:  # OVS < 2.6
            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)
예제 #16
0
    def _verify_dhcp_option_row_for_port(self, port_id,
                                         expected_lsp_dhcpv4_options,
                                         expected_lsp_dhcpv6_options=None):
        lsp = idlutils.row_by_value(self.monitor_nb_db_idl,
                                    'Logical_Switch_Port', 'name', port_id,
                                    None)

        if lsp.dhcpv4_options:
            observed_lsp_dhcpv4_options = {
                'cidr': lsp.dhcpv4_options[0].cidr,
                'external_ids': lsp.dhcpv4_options[0].external_ids,
                'options': lsp.dhcpv4_options[0].options}
        else:
            observed_lsp_dhcpv4_options = {}

        if lsp.dhcpv6_options:
            observed_lsp_dhcpv6_options = {
                'cidr': lsp.dhcpv6_options[0].cidr,
                'external_ids': lsp.dhcpv6_options[0].external_ids,
                'options': lsp.dhcpv6_options[0].options}
        else:
            observed_lsp_dhcpv6_options = {}

        if expected_lsp_dhcpv6_options is None:
            expected_lsp_dhcpv6_options = {}

        self.assertEqual(expected_lsp_dhcpv4_options,
                         observed_lsp_dhcpv4_options)
        self.assertEqual(expected_lsp_dhcpv6_options,
                         observed_lsp_dhcpv6_options)
예제 #17
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)
예제 #18
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] = []
             if port['id'] in self.acl_new_values_dict:
                 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
예제 #19
0
    def run_idl(self, txn):
        bridge = idlutils.row_by_value(self.api.idl, 'Bridge', 'name',
                                       'br-int')
        port_name = "df-" + self.chassis.get_name()

        interface = txn.insert(self.api.idl.tables['Interface'])
        interface.name = port_name
        interface.type = self.chassis.get_encap_type()
        options_dict = getattr(interface, 'options', {})
        options_dict['remote_ip'] = self.chassis.get_ip()
        options_dict['key'] = 'flow'
        interface.options = options_dict

        port = txn.insert(self.api.idl.tables['Port'])
        port.name = port_name
        port.verify('interfaces')
        ifaces = getattr(port, 'interfaces', [])
        ifaces.append(interface)
        port.interfaces = ifaces
        external_ids_dict = getattr(interface, 'external_ids', {})
        external_ids_dict['df-chassis-id'] = self.chassis.get_name()
        port.external_ids = external_ids_dict

        bridge.verify('ports')
        ports = getattr(bridge, 'ports', [])
        ports.append(port)
        bridge.ports = ports
예제 #20
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] = []
             if port['id'] in self.acl_new_values_dict:
                 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
예제 #21
0
    def get_local_ports_to_ofport_mapping(self):
        lport_to_ofport = {}
        chassis_to_ofport = {}
        br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')

        for port in br_int.ports:
            if port.name == 'br-int':
                continue
            chassis_id = port.external_ids.get('df-chassis-id')
            for interface in port.interfaces:
                if interface.ofport is None:
                    # TODO(gsagie) log error
                    continue
                ofport = interface.ofport[0]
                if ofport < 1 or ofport > 65533:
                    # TODO(gsagie) log error
                    continue
                if chassis_id is not None:
                    chassis_to_ofport[chassis_id] = ofport
                else:
                    ifaceid = interface.external_ids.get('iface-id')
                    if ifaceid is not None:
                        lport_to_ofport[ifaceid] = ofport

        return chassis_to_ofport, lport_to_ofport
    def _verify_dhcp_option_row_for_port(self, port_id,
                                         expected_lsp_dhcpv4_options,
                                         expected_lsp_dhcpv6_options=None):
        lsp = idlutils.row_by_value(self.monitor_nb_db_idl,
                                    'Logical_Switch_Port', 'name', port_id,
                                    None)

        if lsp.dhcpv4_options:
            observed_lsp_dhcpv4_options = {
                'cidr': lsp.dhcpv4_options[0].cidr,
                'external_ids': lsp.dhcpv4_options[0].external_ids,
                'options': lsp.dhcpv4_options[0].options}
        else:
            observed_lsp_dhcpv4_options = {}

        if lsp.dhcpv6_options:
            observed_lsp_dhcpv6_options = {
                'cidr': lsp.dhcpv6_options[0].cidr,
                'external_ids': lsp.dhcpv6_options[0].external_ids,
                'options': lsp.dhcpv6_options[0].options}
        else:
            observed_lsp_dhcpv6_options = {}

        if expected_lsp_dhcpv6_options is None:
            expected_lsp_dhcpv6_options = {}

        self.assertEqual(expected_lsp_dhcpv4_options,
                         observed_lsp_dhcpv4_options)
        self.assertEqual(expected_lsp_dhcpv6_options,
                         observed_lsp_dhcpv6_options)
예제 #23
0
    def run_idl(self, txn):
        bridge = idlutils.row_by_value(self.api.idl, 'Bridge',
                                       'name', self.integration_bridge)
        port_name = "df-" + self.chassis.get_id()

        interface = txn.insert(self.api.idl.tables['Interface'])
        interface.name = port_name
        interface.type = self.chassis.get_encap_type()
        options_dict = getattr(interface, 'options', {})
        options_dict['remote_ip'] = self.chassis.get_ip()
        options_dict['key'] = 'flow'
        interface.options = options_dict

        port = txn.insert(self.api.idl.tables['Port'])
        port.name = port_name
        port.verify('interfaces')
        ifaces = getattr(port, 'interfaces', [])
        ifaces.append(interface)
        port.interfaces = ifaces
        external_ids_dict = getattr(interface, 'external_ids', {})
        external_ids_dict['df-chassis-id'] = self.chassis.get_id()
        port.external_ids = external_ids_dict

        bridge.verify('ports')
        ports = getattr(bridge, 'ports', [])
        ports.append(port)
        bridge.ports = ports
예제 #24
0
    def get_local_ports_to_ofport_mapping(self):
        lport_to_ofport = {}
        chassis_to_ofport = {}
        br_int = idlutils.row_by_value(self.idl, "Bridge", "name", "br-int")

        for port in br_int.ports:
            if port.name == "br-int":
                continue
            chassis_id = port.external_ids.get("df-chassis-id")
            for interface in port.interfaces:
                if interface.ofport is None:
                    # TODO(gsagie) log error
                    continue
                ofport = interface.ofport[0]
                if ofport < 1 or ofport > 65533:
                    # TODO(gsagie) log error
                    continue
                if chassis_id is not None:
                    chassis_to_ofport[chassis_id] = ofport
                else:
                    ifaceid = interface.external_ids.get("iface-id")
                    if ifaceid is not None:
                        lport_to_ofport[ifaceid] = ofport

        return chassis_to_ofport, lport_to_ofport
예제 #25
0
 def check_controller(self, target):
     is_controller_set = False
     br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')
     # if controller is not set, len(controller) is 0
     if br_int is not None and (len(br_int.controller) > 0
                                and br_int.controller[0].target == target):
         is_controller_set = True
     return is_controller_set
예제 #26
0
 def run_idl(self, txn):
     net = idlutils.row_by_value(self.api.idl, 'Network', 'network_uuid', self.net_uuid, None)
     if net is None:
         net = txn.insert(self.api._tables['Network'])
         
     net.network_uuid = self.net_uuid
     net.tenant = self.tenant
     net.data = self.data
 def get_chassis_datapath_and_iface_types(self, hostname):
     try:
         chassis = idlutils.row_by_value(self.idl, 'Chassis',
                                         'hostname', hostname)
     except idlutils.RowNotFound:
         return (None, None)
     return (chassis.external_ids.get('datapath-type', ''),
             chassis.external_ids.get('iface-types', ''))
예제 #28
0
 def check_controller_fail_mode(self, fail_mode):
     is_fail_mode_set = False
     br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')
     # if fail_mode is not set, len(fail_mode) is 0
     if br_int is not None and (len(br_int.fail_mode) > 0
                                and br_int.fail_mode[0] == fail_mode):
         is_fail_mode_set = True
     return is_fail_mode_set
예제 #29
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)

        ports.remove(lport)
        lswitch.verify('ports')
        setattr(lswitch, 'ports', ports)
        self.api._tables['Logical_Port'].rows[lport.uuid].delete()
예제 #30
0
 def get_chassis(self, name):
     try:
         chassis = idlutils.row_by_value(self.idl,
                                         'Chassis',
                                         'name', name)
         return OvsdbChassis(chassis)
     except idlutils.RowNotFound:
         return None
예제 #31
0
 def check_controller_fail_mode(self, fail_mode):
     is_fail_mode_set = False
     br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')
     if br_int is not None and\
        br_int.fail_mode is not [] and\
        br_int.fail_mode[0] == fail_mode:
         is_fail_mode_set = True
     return is_fail_mode_set
예제 #32
0
 def get_chassis(self, name):
     try:
         chassis = idlutils.row_by_value(self.idl,
                                         'Chassis',
                                         'name', name)
         return OvsdbChassis(chassis)
     except idlutils.RowNotFound:
         return None
예제 #33
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)
예제 #34
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)

        _delvalue_from_list(lrouter, 'ports', lrouter_port)
예제 #35
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.idl.tables['Controller'])
         controller.target = target
         controllers.append(controller)
     br.verify('controller')
     br.controller = controllers
예제 #36
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
예제 #37
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)
        try:
            lrouter_port = idlutils.row_by_value(self.api.idl,
                                                 'Logical_Router_Port',
                                                 'name', self.lport)
        except idlutils.RowNotFound:
            msg = _("Logical Router Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        options = {'router-port': str(lrouter_port.uuid)}
        setattr(port, 'options', options)
        setattr(port, 'type', 'router')
예제 #38
0
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Switch_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_Switch_Port'].rows[lport.uuid].delete()
예제 #39
0
    def get_tunnel_ports(self):
        res = []
        br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')

        for port in br_int.ports:
            if 'df-chassis-id' in port.external_ids:
                chassis_id = port.external_ids['df-chassis-id']
                res.append(OvsdbTunnelPort(port, chassis_id))
        return res
예제 #40
0
    def get_tunnel_ports(self):
        res = []
        br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')

        for port in br_int.ports:
            if 'df-chassis-id' in port.external_ids:
                chassis_id = port.external_ids['df-chassis-id']
                res.append(OvsdbTunnelPort(port, chassis_id))
        return res
예제 #41
0
    def get_tunnel_ports(self):
        res = []
        br_int = idlutils.row_by_value(self.idl, "Bridge", "name", "br-int")

        for port in br_int.ports:
            if "df-chassis-id" in port.external_ids:
                chassis_id = port.external_ids["df-chassis-id"]
                res.append(OvsdbTunnelPort(port, chassis_id))
        return res
예제 #42
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)
예제 #43
0
 def check_controller_fail_mode(self, fail_mode):
     is_fail_mode_set = False
     br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')
     # if fail_mode is not set, len(fail_mode) is 0
     if br_int is not None and (
        len(br_int.fail_mode) > 0 and
        br_int.fail_mode[0] == fail_mode):
         is_fail_mode_set = True
     return is_fail_mode_set
예제 #44
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)
     # Don't need to verify because we unconditionally overwrite
     br.controller = controllers
예제 #45
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
예제 #46
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)

        _delvalue_from_list(lrouter, 'ports', lrouter_port)
예제 #47
0
 def run_idl(self, txn):
     port = idlutils.row_by_value(self.api.idl, 'Port', 'port_uuid', self.port_uuid, None)
     if port is None:
         port = txn.insert(self.api._tables['Port'])
         
     port.port_uuid = self.port_uuid
     port.tenant = self.tenant
     port.data = self.data
     port.fixed_ips = self.fixed_ips
예제 #48
0
파일: commands.py 프로젝트: coreycb/neutron
    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)
예제 #49
0
파일: commands.py 프로젝트: coreycb/neutron
 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)
예제 #50
0
 def check_controller(self, target):
     is_controller_set = False
     br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')
     # if controller is not set, len(controller) is 0
     if br_int is not None and (
        len(br_int.controller) > 0 and
        br_int.controller[0].target == target):
         is_controller_set = True
     return is_controller_set
예제 #51
0
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                          'name', self.lport)
            lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
                                            'name', self.lswitch)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        # Delete DHCP_Options records no longer refered by this port.
        cur_port_dhcp_opts = get_lsp_dhcp_options_uuids(lport, self.lport)
        for uuid in cur_port_dhcp_opts:
            self.api._tables['DHCP_Options'].rows[uuid].delete()

        _delvalue_from_list(lswitch, 'ports', lport)
        self.api._tables['Logical_Switch_Port'].rows[lport.uuid].delete()
예제 #52
0
 def _get_port_pair_uuid(self, port_pair_name):
     lpp_uuid = None
     try:
         lpp = idlutils.row_by_value(self._ovn.idl, 'Logical_Port_Pair',
                                     'name', port_pair_name)
         lpp_uuid = lpp.uuid
     except idlutils.RowNotFound:
         LOG.error("Logical Port Pair %s does not exist", port_pair_name)
         lpp_uuid = None
     return lpp_uuid
예제 #53
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)
예제 #54
0
 def _check_logical_port_exist(self, port_name):
     lport_uuid = None
     try:
         lport = idlutils.row_by_value(self._ovn.idl, 'Logical_Switch_Port',
                                       'name', port_name)
         lport_uuid = lport.uuid
     except idlutils.RowNotFound:
         LOG.error("Logical Port %s does not exist", port_name)
         lport_uuid = None
     return lport_uuid
예제 #55
0
 def _check_logical_port_exist(self, port_name):
     lport_uuid = None
     try:
         lport = idlutils.row_by_value(self._ovn.idl, 'Logical_Switch_Port',
                                       'name', port_name)
         lport_uuid = lport.uuid
     except idlutils.RowNotFound:
         LOG.error("Logical Port %s does not exist", port_name)
         lport_uuid = None
     return lport_uuid
예제 #56
0
 def run_idl(self, txn):
     br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
     for port in br.ports:
         if not any(self.is_deletable_port(iface)
                    for iface in port.interfaces):
             continue
         br.delvalue('ports', port)
         for iface in port.interfaces:
             iface.delete()
         port.delete()
예제 #57
0
    def get_local_port_id_from_name(self, name):
        br_int = idlutils.row_by_value(self.idl, 'Bridge', 'name', 'br-int')
        for port in br_int.ports:
            if port.name != name:
                continue
            for interface in port.interfaces:
                if 'iface-id' in interface.external_ids:
                    return interface.external_ids['iface-id']

        return None
예제 #58
0
 def get_chassis_data_for_ml2_bind_port(self, hostname):
     try:
         chassis = idlutils.row_by_value(self.idl, 'Chassis', 'hostname',
                                         hostname)
     except idlutils.RowNotFound:
         msg = _('Chassis with hostname %s does not exist') % hostname
         raise RuntimeError(msg)
     return (chassis.external_ids.get('datapath-type', ''),
             chassis.external_ids.get('iface-types', ''),
             self._get_chassis_physnets(chassis))
예제 #59
0
 def _get_port_pair_uuid(self, port_pair_name):
     lpp_uuid = None
     try:
         lpp = idlutils.row_by_value(self._ovn.idl, 'Logical_Port_Pair',
                                     'name', port_pair_name)
         lpp_uuid = lpp.uuid
     except idlutils.RowNotFound:
         LOG.error("Logical Port Pair %s does not exist", port_pair_name)
         lpp_uuid = None
     return lpp_uuid
예제 #60
0
 def run_idl(self, txn):
     if self.may_exist:
         addrset = idlutils.row_by_value(self.api.idl, 'Address_Set',
                                         'name', self.name, None)
         if addrset:
             return
     row = txn.insert(self.api._tables['Address_Set'])
     row.name = self.name
     for col, val in self.columns.items():
         setattr(row, col, val)