コード例 #1
0
ファイル: lsnmanager.py プロジェクト: pjh03/quantum
 def lsn_port_metadata_setup(self, context, lsn_id, subnet):
     """Connect subnet to specified LSN."""
     data = {
         "mac_address": const.METADATA_MAC,
         "ip_address": subnet['cidr'],
         "subnet_id": subnet['id']
     }
     network_id = subnet['network_id']
     tenant_id = subnet['tenant_id']
     lswitch_port_id = None
     try:
         lswitch_port_id = switch_api.create_lport(self.cluster, network_id,
                                                   tenant_id,
                                                   const.METADATA_PORT_ID,
                                                   const.METADATA_PORT_NAME,
                                                   const.METADATA_DEVICE_ID,
                                                   True)['uuid']
         lsn_port_id = self.lsn_port_create(self.cluster, lsn_id, data)
     except (n_exc.NotFound, p_exc.NsxPluginException,
             api_exc.NsxApiException):
         raise p_exc.PortConfigurationError(net_id=network_id,
                                            lsn_id=lsn_id,
                                            port_id=lswitch_port_id)
     else:
         try:
             lsn_api.lsn_port_plug_network(self.cluster, lsn_id,
                                           lsn_port_id, lswitch_port_id)
         except p_exc.LsnConfigurationConflict:
             self.lsn_port_delete(self.cluster, lsn_id, lsn_port_id)
             switch_api.delete_port(self.cluster, network_id,
                                    lswitch_port_id)
             raise p_exc.PortConfigurationError(net_id=network_id,
                                                lsn_id=lsn_id,
                                                port_id=lsn_port_id)
コード例 #2
0
ファイル: test_switch.py プロジェクト: pjh03/quantum
 def test_delete_port(self):
     lswitch, lport = self._create_switch_and_port()
     switchlib.delete_port(self.fake_cluster,
                           lswitch['uuid'], lport['uuid'])
     self.assertRaises(exceptions.PortNotFoundOnNetwork,
                       switchlib.get_port, self.fake_cluster,
                       lswitch['uuid'], lport['uuid'])
コード例 #3
0
    def _nsx_delete_port(self, context, port_data):
        # FIXME(salvatore-orlando): On the NSX platform we do not really have
        # external networks. So deleting regular ports from external networks
        # does not make sense. However we cannot raise as this would break
        # unit tests.

        # NOTE(rods): reporting mark's comment on havana version of this patch.
        # Akanda does want ports for external networks so this method is
        # basically same with external check removed

        # ---------------------------------------------------------------------
        # Original code:
        # if self._network_is_external(context, port_data['network_id']):
        #     LOG.info(_("NSX plugin does not support regular VIF ports on "
        #                "external networks. Port %s will be down."),
        #              port_data['network_id'])
        #     return
        # ---------------------------------------------------------------------

        nsx_switch_id, nsx_port_id = nsx_utils.get_nsx_switch_and_port_id(
            context.session, self.cluster, port_data['id'])
        if not nsx_port_id:
            LOG.debug(_("Port '%s' was already deleted on NSX platform"), id)
            return
        # TODO(bgh): if this is a bridged network and the lswitch we just got
        # back will have zero ports after the delete we should garbage collect
        # the lswitch.
        try:
            switchlib.delete_port(self.cluster, nsx_switch_id, nsx_port_id)
            LOG.debug(_("_nsx_delete_port completed for port %(port_id)s "
                        "on network %(net_id)s"),
                      {'port_id': port_data['id'],
                       'net_id': port_data['network_id']})
        except n_exc.NotFound:
            LOG.warning(_("Port %s not found in NSX"), port_data['id'])
コード例 #4
0
ファイル: lsnmanager.py プロジェクト: Zemeio/neutron
 def lsn_port_metadata_setup(self, context, lsn_id, subnet):
     """Connect subnet to specified LSN."""
     data = {
         "mac_address": const.METADATA_MAC,
         "ip_address": subnet['cidr'],
         "subnet_id": subnet['id']
     }
     network_id = subnet['network_id']
     tenant_id = subnet['tenant_id']
     lswitch_port_id = None
     try:
         switch_id = nsx_utils.get_nsx_switch_ids(
             context.session, self.cluster, network_id)[0]
         lswitch_port_id = switch_api.create_lport(
             self.cluster, switch_id, tenant_id,
             const.METADATA_PORT_ID, const.METADATA_PORT_NAME,
             const.METADATA_DEVICE_ID, True)['uuid']
         lsn_port_id = self.lsn_port_create(context, lsn_id, data)
     except (n_exc.NotFound, p_exc.NsxPluginException,
             api_exc.NsxApiException):
         raise p_exc.PortConfigurationError(
             net_id=network_id, lsn_id=lsn_id, port_id=lswitch_port_id)
     else:
         try:
             lsn_api.lsn_port_plug_network(
                 self.cluster, lsn_id, lsn_port_id, lswitch_port_id)
         except p_exc.LsnConfigurationConflict:
             self.lsn_port_delete(self.cluster, lsn_id, lsn_port_id)
             switch_api.delete_port(
                 self.cluster, network_id, lswitch_port_id)
             raise p_exc.PortConfigurationError(
                 net_id=network_id, lsn_id=lsn_id, port_id=lsn_port_id)
コード例 #5
0
ファイル: lsnmanager.py プロジェクト: nadlah0216/neutron
 def lsn_port_dispose(self, context, network_id, mac_address):
     """Delete a LSN port given the network and the mac address."""
     lsn_id, lsn_port_id = self.lsn_port_get_by_mac(context, network_id, mac_address, raise_on_err=False)
     if lsn_port_id:
         self.lsn_port_delete(context, lsn_id, lsn_port_id)
         if mac_address == const.METADATA_MAC:
             try:
                 lswitch_port_id = switch_api.get_port_by_neutron_tag(
                     self.cluster, network_id, const.METADATA_PORT_ID
                 )["uuid"]
                 switch_api.delete_port(self.cluster, network_id, lswitch_port_id)
             except (n_exc.PortNotFoundOnNetwork, api_exc.NsxApiException):
                 LOG.warn(_("Metadata port not found while attempting " "to delete it from network %s"), network_id)
     else:
         LOG.warn(_("Unable to find Logical Services Node " "Port with MAC %s"), mac_address)
コード例 #6
0
ファイル: lsnmanager.py プロジェクト: leesurezen/neutron
 def lsn_port_dispose(self, context, network_id, mac_address):
     """Delete a LSN port given the network and the mac address."""
     lsn_id, lsn_port_id = self.lsn_port_get_by_mac(
         context, network_id, mac_address, raise_on_err=False)
     if lsn_port_id:
         self.lsn_port_delete(context, lsn_id, lsn_port_id)
         if mac_address == const.METADATA_MAC:
             try:
                 lswitch_port_id = switch_api.get_port_by_neutron_tag(
                     self.cluster, network_id,
                     const.METADATA_PORT_ID)['uuid']
                 switch_api.delete_port(
                     self.cluster, network_id, lswitch_port_id)
             except (n_exc.PortNotFoundOnNetwork,
                     api_exc.NsxApiException):
                 LOG.warn(_("Metadata port not found while attempting "
                            "to delete it from network %s"), network_id)
     else:
         LOG.warn(_("Unable to find Logical Services Node "
                    "Port with MAC %s"), mac_address)
コード例 #7
0
ファイル: mech_driver.py プロジェクト: ryanpetrello/dhc-nsx
    def delete_port_precommit(self, context):
        port_data = context.current

        if port_data['device_owner'] == n_const.DEVICE_OWNER_FLOATINGIP:
             return  # no need to process further for fip


        nsx_switch_id, nsx_port_id = nsx_utils.get_nsx_switch_and_port_id(
            context._plugin_context.session,
            self.cluster,
            port_data['id']
        )

        try:
            switchlib.delete_port(self.cluster, nsx_switch_id, nsx_port_id)
            LOG.debug(
                "_nsx_delete_port completed for port %(port_id)s on network "
                "%(net_id)s",
                {'port_id': port_data['id'], 'net_id': port_data['network_id']}
            )
        except n_exc.NotFound:
            LOG.warning(_("Port %s not found in NSX"), port_data['id'])
コード例 #8
0
    def _nsx_delete_port(self, context, port_data):
        # FIXME(salvatore-orlando): On the NSX platform we do not really have
        # external networks. So deleting regular ports from external networks
        # does not make sense. However we cannot raise as this would break
        # unit tests.

        # NOTE(rods): reporting mark's comment on havana version of this patch.
        # Akanda does want ports for external networks so this method is
        # basically same with external check removed

        # ---------------------------------------------------------------------
        # Original code:
        # if self._network_is_external(context, port_data['network_id']):
        #     LOG.info(_("NSX plugin does not support regular VIF ports on "
        #                "external networks. Port %s will be down."),
        #              port_data['network_id'])
        #     return
        # ---------------------------------------------------------------------

        nsx_switch_id, nsx_port_id = nsx_utils.get_nsx_switch_and_port_id(
            context.session, self.cluster, port_data['id'])
        if not nsx_port_id:
            LOG.debug(_("Port '%s' was already deleted on NSX platform"), id)
            return
        # TODO(bgh): if this is a bridged network and the lswitch we just got
        # back will have zero ports after the delete we should garbage collect
        # the lswitch.
        try:
            switchlib.delete_port(self.cluster, nsx_switch_id, nsx_port_id)
            LOG.debug(
                _("_nsx_delete_port completed for port %(port_id)s "
                  "on network %(net_id)s"), {
                      'port_id': port_data['id'],
                      'net_id': port_data['network_id']
                  })
        except n_exc.NotFound:
            LOG.warning(_("Port %s not found in NSX"), port_data['id'])
コード例 #9
0
    def _nsx_create_port(self, context, port_data):
        """Driver for creating a logical switch port on NSX platform."""
        # FIXME(salvatore-orlando): On the NSX platform we do not really have
        # external networks. So if as user tries and create a "regular" VIF
        # port on an external network we are unable to actually create.
        # However, in order to not break unit tests, we need to still create
        # the DB object and return success

        # NOTE(rods): Reporting mark's comment on havana version of this patch.
        # Akanda does want ports for external networks so this method is
        # basically same with external check removed and the auto plugging of
        # router ports

        # ---------------------------------------------------------------------
        # Note(rods): Remove the check on the external network
        #
        # Original code:
        # if self._network_is_external(context, port_data['network_id']):
        #     LOG.info(_("NSX plugin does not support regular VIF ports on "
        #                "external networks. Port %s will be down."),
        #              port_data['network_id'])
        #     # No need to actually update the DB state - the default is down
        #     return port_data
        # ---------------------------------------------------------------------
        lport = None
        selected_lswitch = None
        try:
            selected_lswitch = self._nsx_find_lswitch_for_port(context,
                                                               port_data)
            lport = self._nsx_create_port_helper(context.session,
                                                 selected_lswitch['uuid'],
                                                 port_data,
                                                 True)
            nsx_db.add_neutron_nsx_port_mapping(
                context.session, port_data['id'],
                selected_lswitch['uuid'], lport['uuid'])
            # -----------------------------------------------------------------
            # Note(rods): Auto plug router ports
            #
            # Original code:
            # if port_data['device_owner'] not in self.port_special_owners:
            #     switchlib.plug_vif_interface(
            #         self.cluster, selected_lswitch['uuid'],
            #         lport['uuid'], "VifAttachment", port_data['id'])

            switchlib.plug_vif_interface(
                self.cluster, selected_lswitch['uuid'],
                lport['uuid'], "VifAttachment", port_data['id'])
            # -----------------------------------------------------------------

            LOG.debug(_("_nsx_create_port completed for port %(name)s "
                        "on network %(network_id)s. The new port id is "
                        "%(id)s."), port_data)
        except (api_exc.NsxApiException, n_exc.NeutronException):
            self._handle_create_port_exception(
                context, port_data['id'],
                selected_lswitch and selected_lswitch['uuid'],
                lport and lport['uuid'])
        except db_exc.DBError as e:
            if (port_data['device_owner'] == constants.DEVICE_OWNER_DHCP and
                    isinstance(e.inner_exception, sql_exc.IntegrityError)):
                msg = (_("Concurrent network deletion detected; Back-end Port "
                         "%(nsx_id)s creation to be rolled back for Neutron "
                         "port: %(neutron_id)s")
                       % {'nsx_id': lport['uuid'],
                          'neutron_id': port_data['id']})
                LOG.warning(msg)
                if selected_lswitch and lport:
                    try:
                        switchlib.delete_port(self.cluster,
                                              selected_lswitch['uuid'],
                                              lport['uuid'])
                    except n_exc.NotFound:
                        LOG.debug(_("NSX Port %s already gone"), lport['uuid'])
コード例 #10
0
    def _nsx_create_port(self, context, port_data):
        """Driver for creating a logical switch port on NSX platform."""
        # FIXME(salvatore-orlando): On the NSX platform we do not really have
        # external networks. So if as user tries and create a "regular" VIF
        # port on an external network we are unable to actually create.
        # However, in order to not break unit tests, we need to still create
        # the DB object and return success

        # NOTE(rods): Reporting mark's comment on havana version of this patch.
        # Akanda does want ports for external networks so this method is
        # basically same with external check removed and the auto plugging of
        # router ports

        # ---------------------------------------------------------------------
        # Note(rods): Remove the check on the external network
        #
        # Original code:
        # if self._network_is_external(context, port_data['network_id']):
        #     LOG.info(_("NSX plugin does not support regular VIF ports on "
        #                "external networks. Port %s will be down."),
        #              port_data['network_id'])
        #     # No need to actually update the DB state - the default is down
        #     return port_data
        # ---------------------------------------------------------------------
        lport = None
        selected_lswitch = None
        try:
            selected_lswitch = self._nsx_find_lswitch_for_port(
                context, port_data)
            lport = self._nsx_create_port_helper(context.session,
                                                 selected_lswitch['uuid'],
                                                 port_data, True)
            nsx_db.add_neutron_nsx_port_mapping(context.session,
                                                port_data['id'],
                                                selected_lswitch['uuid'],
                                                lport['uuid'])
            # -----------------------------------------------------------------
            # Note(rods): Auto plug router ports
            #
            # Original code:
            # if port_data['device_owner'] not in self.port_special_owners:
            #     switchlib.plug_vif_interface(
            #         self.cluster, selected_lswitch['uuid'],
            #         lport['uuid'], "VifAttachment", port_data['id'])

            switchlib.plug_vif_interface(self.cluster,
                                         selected_lswitch['uuid'],
                                         lport['uuid'], "VifAttachment",
                                         port_data['id'])
            # -----------------------------------------------------------------

            LOG.debug(
                _("_nsx_create_port completed for port %(name)s "
                  "on network %(network_id)s. The new port id is "
                  "%(id)s."), port_data)
        except (api_exc.NsxApiException, n_exc.NeutronException):
            self._handle_create_port_exception(
                context, port_data['id'], selected_lswitch
                and selected_lswitch['uuid'], lport and lport['uuid'])
        except db_exc.DBError as e:
            if (port_data['device_owner'] == constants.DEVICE_OWNER_DHCP
                    and isinstance(e.inner_exception, sql_exc.IntegrityError)):
                msg = (_("Concurrent network deletion detected; Back-end Port "
                         "%(nsx_id)s creation to be rolled back for Neutron "
                         "port: %(neutron_id)s") % {
                             'nsx_id': lport['uuid'],
                             'neutron_id': port_data['id']
                         })
                LOG.warning(msg)
                if selected_lswitch and lport:
                    try:
                        switchlib.delete_port(self.cluster,
                                              selected_lswitch['uuid'],
                                              lport['uuid'])
                    except n_exc.NotFound:
                        LOG.debug(_("NSX Port %s already gone"), lport['uuid'])