예제 #1
0
    def _get_l3_admin_net(self, create=False):
        network = None
        context = self._get_admin_context()
        filters = self._get_l3_admin_net_query_filter()
        networks = self._plugin.get_networks(context, filters=filters)

        if len(networks) == 0 and create:
            try:
                network = self._create_l3_admin_net(context)
                self._create_l3_admin_subnet(context, network["id"])
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error(_LE("Error in creating L3 admin network."))
        elif len(networks) == 1:
            network = networks[0]
            subnet_ids = network.get("subnets")
            net_id = network["id"]
            if not subnet_ids and create:
                try:
                    self._create_l3_admin_subnet(context, net_id)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        LOG.error(_LE("Error in creating l3 admin subnet."))
            elif len(subnet_ids) == 1:
                self._validate_l3_admin_subnet(context, subnet_ids[0])
            else:
                msg = _("Expected number of subnets in l3 admin network is " "1, found %d.") % len(subnet_ids)
                raise exc.L3AdminNetSubnetError(error_message=msg)
        else:
            msg = _("Expected number of l3 admin networks is 1, found " "%d.") % len(networks)
            raise exc.L3AdminNetError(error_message=msg)
        return network
예제 #2
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)
예제 #3
0
    def validate_and_get_data_from_binding_profile(self, port):
        if (ovn_const.OVN_PORT_BINDING_PROFILE not in port or
                not validators.is_attr_set(
                    port[ovn_const.OVN_PORT_BINDING_PROFILE])):
            return {}
        param_set = {}
        param_dict = {}
        for param_set in ovn_const.OVN_PORT_BINDING_PROFILE_PARAMS:
            param_keys = param_set.keys()
            for param_key in param_keys:
                try:
                    param_dict[param_key] = (port[
                        ovn_const.OVN_PORT_BINDING_PROFILE][param_key])
                except KeyError:
                    pass
            if len(param_dict) == 0:
                continue
            if len(param_dict) != len(param_keys):
                msg = _('Invalid binding:profile. %s are all '
                        'required.') % param_keys
                raise n_exc.InvalidInput(error_message=msg)
            if (len(port[ovn_const.OVN_PORT_BINDING_PROFILE]) != len(
                    param_keys)):
                msg = _('Invalid binding:profile. too many parameters')
                raise n_exc.InvalidInput(error_message=msg)
            break

        if not param_dict:
            return {}

        for param_key, param_type in param_set.items():
            if param_type is None:
                continue
            param_value = param_dict[param_key]
            if not isinstance(param_value, param_type):
                msg = _('Invalid binding:profile. %(key)s %(value)s '
                        'value invalid type') % {'key': param_key,
                                                 'value': param_value}
                raise n_exc.InvalidInput(error_message=msg)

        # Make sure we can successfully look up the port indicated by
        # parent_name.  Just let it raise the right exception if there is a
        # problem.
        if 'parent_name' in param_set:
            self._plugin.get_port(n_context.get_admin_context(),
                                  param_dict['parent_name'])

        if 'tag' in param_set:
            tag = int(param_dict['tag'])
            if tag < 0 or tag > 4095:
                msg = _('Invalid binding:profile. tag "%s" must be '
                        'an integer between 0 and 4095, inclusive') % tag
                raise n_exc.InvalidInput(error_message=msg)

        return param_dict
예제 #4
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)
예제 #5
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()
예제 #6
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)
예제 #7
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)
예제 #8
0
    def run_idl(self, txn):
        if self.row_uuid not in self.api._tables['DHCP_Options'].rows:
            if self.if_exists:
                return
            msg = _("DHCP Options row %s does not exist") % self.row_uuid
            raise RuntimeError(msg)

        self.api._tables['DHCP_Options'].rows[self.row_uuid].delete()
예제 #9
0
 def _delete_acls(self, lswitch_name, acls, acls_delete):
     for acl_delete in acls_delete:
         try:
             acls.remove(acl_delete)
         except ValueError:
             msg = _("Logical Switch %s missing acl") % lswitch_name
             raise RuntimeError(msg)
         acl_delete.delete()
예제 #10
0
 def delete_lswitch_port(self, lport_name=None, lswitch_name=None,
                         ext_id=None, if_exists=True):
     if lport_name is not None:
         return cmd.DelLSwitchPortCommand(self, lport_name,
                                          lswitch_name, if_exists)
     else:
         raise RuntimeError(_("Currently only supports "
                              "delete by lport-name"))
예제 #11
0
 def delete_lport_chain(self, lswitch_name, lport_chain_name=None,
                        if_exists=True):
     if lport_chain_name is not None:
         return cmd.DelLPortChainCommand(self, lswitch_name,
                                         lport_chain_name,
                                         if_exists)
     else:
         raise RuntimeError(_("Currently only supports delete "
                              "by lport-chain-name"))
예제 #12
0
 def delete_lport_pair_group(self, lport_pair_group_name=None,
                             lport_chain=None, ext_id=None,
                             if_exists=True):
     if lport_pair_group_name is not None:
         return cmd.DelLogicalPortPairGroupCommand(
             self, lport_pair_group_name, lport_chain, if_exists)
     else:
         raise RuntimeError(_("Currently only supports "
                              "delete by lport-pair-group-name"))
예제 #13
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)
예제 #14
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))
예제 #15
0
 def delete_lflow_classifier(self, lport_chain_name,
                             lflow_classifier_name=None,
                             if_exists=True):
     if lflow_classifier_name is not None:
         return cmd.DelLogicalFlowClassifierCommand(self, lport_chain_name,
                                                    lflow_classifier_name,
                                                    if_exists)
     else:
         raise RuntimeError(_("Currently only delete "
                              "supports by lflow-classifier-name"))
예제 #16
0
 def delete_lport_pair(self, lport_pair_name=None, lswitch=None,
                       lport_pair_group_name=None, if_exists=True):
     if lport_pair_name is not None:
         return cmd.DelLogicalPortPairCommand(self, lport_pair_name,
                                              lswitch,
                                              lport_pair_group_name,
                                              if_exists)
     else:
         raise RuntimeError(_("Currently only supports "
                              "delete by lport-pair-name"))
예제 #17
0
    def _validate_l3_admin_subnet(self, context, subnet_id):
        subnet = None
        try:
            subnet = self._plugin.get_subnet(context, subnet_id)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.exception(_LE("L3 admin subnet not found"))
        if subnet.get("cidr") != self._cidr:
            msg = _("Subnet CIDR %(a)s does not match configured value " "%(e)s.") % {
                "a": subnet.get("cidr"),
                "e": self._cidr,
            }
            raise exc.L3AdminNetSubnetError(error_message=msg)

        if subnet.get("name") != ovn_const.OVN_L3_ADMIN_NET_SUBNET_NAME:
            msg = _("Subnet name %(a)s does not match expected name " "%(e)s.") % {
                "a": subnet.get("name"),
                "e": ovn_const.OVN_L3_ADMIN_NET_SUBNET_NAME,
            }
            raise exc.L3AdminNetSubnetError(error_message=msg)
예제 #18
0
    def run_idl(self, txn):
        dhcp_options_row = self._get_dhcp_options_row()
        if not dhcp_options_row:
            if self.if_exists:
                return
            msg = _("DHCP Options for subnet_id %(lswitch)s , port_id"
                    " % (port_id)s does not exist") % {
                        'subnet_id': self.subnet_id, 'port_id': self.port_id}
            raise RuntimeError(msg)

        self.api._tables['DHCP_Options'].rows[dhcp_options_row.uuid].delete()
예제 #19
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')
예제 #20
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()
예제 #21
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)

        row = txn.insert(self.api._tables['Logical_Router_Static_Route'])
        for col, val in self.columns.items():
            setattr(row, col, val)
        _addvalue_to_list(lrouter, 'static_routes', row.uuid)
예제 #22
0
    def run_idl(self, txn):
        try:
            addrset = idlutils.row_by_value(self.api.idl, 'Address_Set',
                                            'name', self.name)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Address set %s does not exist. "
                    "Can't delete.") % self.name
            raise RuntimeError(msg)

        self.api._tables['Address_Set'].rows[addrset.uuid].delete()
예제 #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_ports = getattr(lrouter, 'ports', [])
        if (lrouter_port in lrouter_ports):
            lrouter_ports.remove(lrouter_port)
            setattr(lrouter, 'ports', lrouter_ports)
예제 #24
0
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                         'name', self.lport)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        for col, val in self.columns.items():
            setattr(port, col, val)
예제 #25
0
    def _validate_l3_admin_net_ports(self, ports, names):
        network = netaddr.IPNetwork(self._cidr)
        for port in ports:
            fixed_ips = port.get("fixed_ips", [])
            if not fixed_ips or (fixed_ips and len(fixed_ips) > 1):
                msg = _("Unexpected fixed ips %(f) for port %(n)s.") % {"f": fixed_ips, "n": port.get("name")}
                raise exc.L3AdminNetPortsError(error_message=msg)

            ip = netaddr.IPAddress(fixed_ips[0]["ip_address"])
            if ip not in network:
                msg = _("IP %(ip)s of port %(n)s is not in l3 admin subnet " "cidr %(c)s.") % {
                    "ip": ip,
                    "n": port.get("name"),
                    "c": self._cidr,
                }
                raise exc.L3AdminNetPortsError(error_message=msg)

        port_names = [port["name"] for port in ports]
        if sorted(port_names) != sorted(names):
            msg = _("Port names %(a)r does not match expected names " "%(e)r.") % {"a": port_names, "e": names}
            raise exc.L3AdminNetPortsError(error_message=msg)
예제 #26
0
    def run_idl(self, txn):
        try:
            lport_chain = idlutils.row_by_value(self.api.idl,
                                                'Logical_Port_Chain',
                                                'name', self.lport_chain)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Port Chain %s does not exist") % self.lport_chain
            raise RuntimeError(msg)

        for col, val in self.columns.items():
            setattr(lport_chain, col, val)
예제 #27
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}
        _addvalue_to_list(lswitch, 'acls', row.uuid)
예제 #28
0
    def create_network_precommit(self, context):
        """Allocate resources for a new network.

        :param context: NetworkContext instance describing the new
        network.

        Create a new network, allocating resources as necessary in the
        database. Called inside transaction context on session. Call
        cannot block.  Raising an exception will result in a rollback
        of the current transaction.
        """
        network = context.current

        # TODO(rtheis): Add support for multi-provider networks when
        # routed networks are supported.
        if self._get_attribute(network, mpnet.SEGMENTS):
            msg = _("Multi-provider networks are not supported")
            raise n_exc.InvalidInput(error_message=msg)

        network_segments = context.network_segments
        network_type = network_segments[0]["network_type"]
        segmentation_id = network_segments[0]["segmentation_id"]
        physical_network = network_segments[0]["physical_network"]
        LOG.debug(
            "Creating network with type %(network_type)s, "
            "segmentation ID %(segmentation_id)s, "
            "physical network %(physical_network)s"
            % {"network_type": network_type, "segmentation_id": segmentation_id, "physical_network": physical_network}
        )

        if network_type not in [
            plugin_const.TYPE_LOCAL,
            plugin_const.TYPE_FLAT,
            plugin_const.TYPE_GENEVE,
            plugin_const.TYPE_VLAN,
        ]:
            msg = _("Network type %s is not supported") % network_type
            raise n_exc.InvalidInput(error_message=msg)
예제 #29
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()
예제 #30
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
예제 #31
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()
예제 #32
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)

        if lrouter_port:
            for col, val in self.columns.items():
                if col == 'gateway_chassis':
                    col, val = _add_gateway_chassis(self.api, txn, self.name,
                                                    val)
                setattr(lrouter_port, col, val)
            return
예제 #33
0
    def run_idl(self, txn):
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)

        static_routes = getattr(lrouter, 'static_routes', [])
        for route in static_routes:
            ip_prefix = getattr(route, 'ip_prefix', '')
            nexthop = getattr(route, 'nexthop', '')
            if self.ip_prefix == ip_prefix and self.nexthop == nexthop:
                _delvalue_from_list(lrouter, 'static_routes', route)
                route.delete()
                break
예제 #34
0
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                         'name', self.lport)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        # Delete DHCP_Options records no longer referred by this port.
        # The table rows should be consistent for the same transaction.
        # After we get DHCP_Options rows uuids from port dhcpv4_options
        # and dhcpv6_options references, the rows shouldn't disappear for
        # this transaction before we delete it.
        cur_port_dhcp_opts = get_lsp_dhcp_options_uuids(port, self.lport)
        new_port_dhcp_opts = set()
        dhcpv4_options = self.columns.pop('dhcpv4_options', None)
        if dhcpv4_options is None:
            new_port_dhcp_opts.update([
                option.uuid for option in getattr(port, 'dhcpv4_options', [])
            ])
        elif isinstance(dhcpv4_options, list):
            new_port_dhcp_opts.update(dhcpv4_options)
            port.dhcpv4_options = dhcpv4_options
        else:
            new_port_dhcp_opts.add(dhcpv4_options.result)
            port.dhcpv4_options = [dhcpv4_options.result]
        dhcpv6_options = self.columns.pop('dhcpv6_options', None)
        if dhcpv6_options is None:
            new_port_dhcp_opts.update([
                option.uuid for option in getattr(port, 'dhcpv6_options', [])
            ])
        elif isinstance(dhcpv6_options, list):
            new_port_dhcp_opts.update(dhcpv6_options)
            port.dhcpv6_options = dhcpv6_options
        else:
            new_port_dhcp_opts.add(dhcpv6_options.result)
            port.dhcpv6_options = [dhcpv6_options.result]
        for uuid in cur_port_dhcp_opts - new_port_dhcp_opts:
            self.api._tables['DHCP_Options'].rows[uuid].delete()

        for col, val in self.columns.items():
            setattr(port, col, val)
예제 #35
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 referred 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()
예제 #36
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)

        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:
            acl.delete()
        _updatevalues_in_list(lswitch, 'acls', old_values=acls_to_del)
예제 #37
0
파일: commands.py 프로젝트: dingboopt/wqq
    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
        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)
예제 #38
0
    def run_idl(self, txn):
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)

        nats = getattr(lrouter, 'nat', [])
        for nat in nats:
            logical_ip = getattr(nat, 'logical_ip', '')
            external_ip = getattr(nat, 'external_ip', '')
            type = getattr(nat, 'type', '')
            if (not self.logical_ip or self.logical_ip == logical_ip) and \
               (not self.external_ip or self.external_ip == external_ip) and \
               (not self.type or self.type == type):
                _delvalue_from_list(lrouter, 'nat', nat)
                nat.delete()
                break
예제 #39
0
    def get_lrouter_nat_rules(self, lrouter_name):
        try:
            lrouter = idlutils.row_by_value(self.idl, 'Logical_Router',
                                            'name', lrouter_name)
        except idlutils.RowNotFound:
            msg = _("Logical Router %s does not exist") % lrouter_name
            raise RuntimeError(msg)

        nat_rules = []
        for nat_rule in getattr(lrouter, 'nat', []):
            ext_ids = {}
            # TODO(dalvarez): remove this check once the minimum OVS required
            # version contains the column (when OVS 2.8.2 is released).
            if self.is_col_present('NAT', 'external_ids'):
                ext_ids = dict(getattr(nat_rule, 'external_ids', {}))

            nat_rules.append({'external_ip': nat_rule.external_ip,
                              'logical_ip': nat_rule.logical_ip,
                              'type': nat_rule.type,
                              'uuid': nat_rule.uuid,
                              'external_ids': ext_ids})
        return nat_rules
예제 #40
0
    def run_idl(self, txn):
        try:
            port = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                         'name', self.lport)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Switch Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        # Delete DHCP_Options records no longer refered by this port.
        # The table rows should be consistent for the same transaction.
        # After we get a DHCP_Options row uuid from port dhcpv4_options
        # reference, the row shouldn't disappear for this transaction,
        # before we delete it.
        cur_port_dhcp_opts = get_lsp_dhcpv4_options_uuids(port, self.lport)
        new_port_dhcp_opts = set(self.columns.get('dhcpv4_options', []))
        for uuid in cur_port_dhcp_opts - new_port_dhcp_opts:
            self.api._tables['DHCP_Options'].rows[uuid].delete()

        for col, val in self.columns.items():
            setattr(port, col, val)
예제 #41
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)

        # TODO(lucasagomes): Remove this check once we drop the support
        # for OVS versions <= 2.8
        ipv6_ra_configs_supported = self.api.is_col_present(
            'Logical_Router_Port', 'ipv6_ra_configs')
        for col, val in self.columns.items():
            if col == 'ipv6_ra_configs' and not ipv6_ra_configs_supported:
                continue

            if col == 'gateway_chassis':
                col, val = _add_gateway_chassis(self.api, txn, self.name, val)
            setattr(lrouter_port, col, val)
예제 #42
0
    def run_idl(self, txn):
        try:
            addrset = idlutils.row_by_value(self.api.idl, 'Address_Set',
                                            'name', self.name)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Address set %s does not exist. "
                    "Can't update addresses") % self.name
            raise RuntimeError(msg)

        addrset.verify('addresses')
        addresses_col = getattr(addrset, 'addresses', [])
        if self.addrs_add:
            # OVN will ignore duplicate addresses.
            for addr_add in self.addrs_add:
                addresses_col.append(addr_add)
        if self.addrs_remove:
            # OVN will ignore addresses that don't exist.
            for addr_remove in self.addrs_remove:
                if addr_remove in addresses_col:
                    addresses_col.remove(addr_remove)
        setattr(addrset, 'addresses', addresses_col)
예제 #43
0
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                          'name', self.lport)
        except idlutils.RowNotFound:
            msg = _("Logical Switch Port %s does not exist") % self.lport
            raise RuntimeError(msg)

        lport.verify('addresses')
        addresses = getattr(lport, 'addresses', [])
        lport.verify('options')
        options = getattr(lport, 'options', {})

        nat_ip_list = options.get('nat-addresses', '').split()
        if not nat_ip_list:
            nat_ips = addresses[0].split()[0] + ' ' + self.nat_ip
        elif self.nat_ip not in nat_ip_list:
            nat_ip_list.append(self.nat_ip)
            nat_ips = ' '.join(nat_ip_list)
        else:
            return
        options['nat-addresses'] = nat_ips
        lport.options = options
예제 #44
0
    def run_idl(self, txn):
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)

        lrouter.verify('nat')
        # TODO(chandrav): convert this to ovs transaction mutate
        nats = getattr(lrouter, 'nat', [])
        for nat in nats:
            type = getattr(nat, 'type', '')
            external_ip = getattr(nat, 'external_ip', '')
            logical_ip = getattr(nat, 'logical_ip', '')
            if (self.type == type and self.external_ip == external_ip
                    and self.logical_ip == logical_ip):
                nats.remove(nat)
                nat.delete()
                break
        setattr(lrouter, 'nat', nats)
예제 #45
0
파일: commands.py 프로젝트: dingboopt/wqq
    def run_idl(self, txn):
        try:
            lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
                                            'name', self.lrouter)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = _("Logical Router %s does not exist") % self.lrouter
            raise RuntimeError(msg)

        static_routes = getattr(lrouter, 'static_routes', [])
        for route in static_routes:
            ip_prefix = getattr(route, 'ip_prefix', '')
            nexthop = getattr(route, 'nexthop', '')
            if self.ip_prefix == ip_prefix and self.nexthop == nexthop:
                # TODO(rtheis): Use mutate for adding and deleting static
                # routes once bug 1629099 is fixed.
                _delvalue_from_list(lrouter,
                                    'static_routes',
                                    route,
                                    mutate=False)
                route.delete()
                break
예제 #46
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)
예제 #47
0
    def run_idl(self, txn):
        try:
            lport = idlutils.row_by_value(self.api.idl, 'Logical_Switch_Port',
                                          'name', self.lport)

        except idlutils.RowNotFound:
            msg = _("Logical Switch Port %s does not exist") % self.port
            raise RuntimeError(msg)

        lport.verify('options')
        options = getattr(lport, 'options', {})
        nat_ip_list = options.get('nat-addresses', '').split()
        if self.nat_ip not in nat_ip_list:
            return
        nat_ip_list.remove(self.nat_ip)
        if len(nat_ip_list) is 1:
            nat_ips = ''
        else:
            nat_ips = ' '.join(nat_ip_list)
        if not nat_ips:
            del options['nat-addresses']
        else:
            options['nat-addresses'] = nat_ips
        lport.options = options
예제 #48
0
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_config import cfg

from networking_ovn._i18n import _
from neutron.extensions import portbindings

ovn_opts = [
    cfg.StrOpt('ovsdb_connection',
               deprecated_for_removal=True,
               default='tcp:127.0.0.1:6640',
               help=_('The connection string for the native OVSDB backend.'
                      'This option is going to be deprecated and be replaced'
                      'by option ovn_nb_connection.')),
    cfg.StrOpt('ovn_nb_connection',
               deprecated_name='ovsdb_connection',
               default='tcp:127.0.0.1:6641',
               help=_('The connection string for the OVN_Northbound OVSDB')),
    cfg.StrOpt('ovn_sb_connection',
               default='tcp:127.0.0.1:6642',
               help=_('The connection string for the OVN_Southbound OVSDB')),
    cfg.IntOpt('ovsdb_connection_timeout',
               default=60,
               help=_('Timeout in seconds for the OVSDB '
                      'connection transaction')),
    cfg.StrOpt('neutron_sync_mode',
               default='log',
               choices=('off', 'log', 'repair'),
예제 #49
0
class OvsdbConnectionUnavailable(n_exc.ServiceUnavailable):
    message = _("OVS database connection to %(db_schema)s failed with error: "
                "'%(error)s'. Verify that the OVS and OVN services are "
                "available and that the 'ovn_nb_connection' and "
                "'ovn_sb_connection' configuration options are correct.")
예제 #50
0
EXTRA_LOG_LEVEL_DEFAULTS = []

VLOG_LEVELS = {
    'CRITICAL': vlog.CRITICAL,
    'ERROR': vlog.ERROR,
    'WARNING': vlog.WARN,
    'INFO': vlog.INFO,
    'DEBUG': vlog.DEBUG
}

ovn_opts = [
    cfg.StrOpt('ovn_nb_connection',
               default='tcp:127.0.0.1:6641',
               help=_('The connection string for the OVN_Northbound OVSDB.\n'
                      'Use tcp:IP:PORT for TCP connection.\n'
                      'Use ssl:IP:PORT for SSL connection. The '
                      'ovn_nb_private_key, ovn_nb_certificate and '
                      'ovn_nb_ca_cert are mandatory.\n'
                      'Use unix:FILE for unix domain socket connection.')),
    cfg.StrOpt('ovn_nb_private_key',
               default='',
               help=_('The PEM file with private key for SSL connection to '
                      'OVN-NB-DB')),
    cfg.StrOpt('ovn_nb_certificate',
               default='',
               help=_('The PEM file with certificate that certifies the '
                      'private key specified in ovn_nb_private_key')),
    cfg.StrOpt('ovn_nb_ca_cert',
               default='',
               help=_('The PEM file with CA certificate that OVN should use to'
                      ' verify certificates presented to it by SSL peers')),
    cfg.StrOpt('ovn_sb_connection',
예제 #51
0
class UnknownResourceType(n_exc.NeutronException):
    message = _('Uknown resource type: %(resource_type)s')
예제 #52
0
from neutron_lib.utils import host
from oslo_config import cfg

from networking_ovn._i18n import _

DEDUCE_MODE = 'deduce'
USER_MODE = 'user'
GROUP_MODE = 'group'
ALL_MODE = 'all'
SOCKET_MODES = (DEDUCE_MODE, USER_MODE, GROUP_MODE, ALL_MODE)

SHARED_OPTS = [
    cfg.StrOpt('metadata_proxy_socket',
               default='$state_path/metadata_proxy',
               help=_('Location for Metadata Proxy UNIX domain socket.')),
    cfg.StrOpt('metadata_proxy_user',
               default='',
               help=_("User (uid or name) running metadata proxy after "
                      "its initialization (if empty: agent effective "
                      "user).")),
    cfg.StrOpt('metadata_proxy_group',
               default='',
               help=_("Group (gid or name) running metadata proxy after "
                      "its initialization (if empty: agent effective "
                      "group).")),
    cfg.StrOpt('ovs_integration_bridge',
               default='br-int',
               help=_('Name of Open vSwitch bridge to use'))
]
예제 #53
0
class HashRingIsEmpty(n_exc.NeutronException):
    message = _('Hash Ring returned empty when hashing "%(key)s". '
                'This should never happen in a normal situation, please '
                'check the status of your cluster')
예제 #54
0
EXTRA_LOG_LEVEL_DEFAULTS = []

VLOG_LEVELS = {
    'CRITICAL': vlog.CRITICAL,
    'ERROR': vlog.ERROR,
    'WARNING': vlog.WARN,
    'INFO': vlog.INFO,
    'DEBUG': vlog.DEBUG
}

ovn_opts = [
    cfg.StrOpt('ovn_nb_connection',
               default='tcp:127.0.0.1:6641',
               help=_('The connection string for the OVN_Northbound OVSDB.\n'
                      'Use tcp:IP:PORT for TCP connection.\n'
                      'Use ssl:IP:PORT for SSL connection. The '
                      'ovn_nb_private_key, ovn_nb_certificate and '
                      'ovn_nb_ca_cert are mandatory.\n'
                      'Use unix:FILE for unix domain socket connection.')),
    cfg.StrOpt('ovn_nb_private_key',
               default='',
               help=_('The PEM file with private key for SSL connection to '
                      'OVN-NB-DB')),
    cfg.StrOpt('ovn_nb_certificate',
               default='',
               help=_('The PEM file with certificate that certifies the '
                      'private key specified in ovn_nb_private_key')),
    cfg.StrOpt('ovn_nb_ca_cert',
               default='',
               help=_('The PEM file with CA certificate that OVN should use to'
                      ' verify certificates presented to it by SSL peers')),
    cfg.StrOpt('ovn_sb_connection',
예제 #55
0
class RevisionConflict(n_exc.NeutronException):
    message = _('OVN revision number for %(resource_id)s (type: '
                '%(resource_type)s) is equal or higher than the given '
                'resource. Skipping update')
예제 #56
0
class JournalAlreadyStarted(n_exc.NeutronException):
    message = _('Journal thread already started')
예제 #57
0
class StandardAttributeIDNotFound(n_exc.NeutronException):
    message = _('Standard attribute ID not found for %(resource_uuid)s')
예제 #58
0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_config import cfg

from networking_ovn._i18n import _
from neutron.extensions import portbindings

ovn_opts = [
    cfg.StrOpt('ovsdb_connection',
               default='tcp:127.0.0.1:6640',
               help=_('The connection string for the native OVSDB backend')),
    cfg.IntOpt('ovsdb_connection_timeout',
               default=60,
               help=_('Timeout in seconds for the OVSDB '
                      'connection transaction')),
    cfg.StrOpt('neutron_sync_mode',
               default='log',
               choices=('off', 'log', 'repair'),
               help=_('The synchronization mode of OVN with Neutron DB. \n'
                      'off - synchronization is off \n'
                      'log - during neutron-server startup, '
                      'check to see if OVN is in sync with '
                      'the Neutron database. '
                      ' Log warnings for any inconsistencies found so'
                      ' that an admin can investigate \n'
                      'repair - during neutron-server startup, automatically'
예제 #59
0
class ProtocolNotSupported(n_exceptions.NeutronException):
    message = _('The protocol "%(protocol)s" is not supported. Valid '
                'protocols are: %(valid_protocols)s; or protocol '
                'numbers ranging from 0 to 255.')
예제 #60
0
class AgentStatsNotFound(n_exc.NeutronException):
    _message = _('The stats for agent %(agent_id)s could not be found')