Esempio n. 1
0
 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)
Esempio n. 2
0
 def lsn_port_dhcp_setup(self,
                         context,
                         network_id,
                         port_id,
                         port_data,
                         subnet_config=None):
     """Connect network to LSN via specified port and port_data."""
     try:
         lsn_id = None
         switch_id = nsx_utils.get_nsx_switch_ids(context.session,
                                                  self.cluster,
                                                  network_id)[0]
         lswitch_port_id = switch_api.get_port_by_neutron_tag(
             self.cluster, switch_id, port_id)['uuid']
         lsn_id = self.lsn_get(context, network_id)
         lsn_port_id = self.lsn_port_create(context, lsn_id, port_data)
     except (n_exc.NotFound, p_exc.NsxPluginException):
         raise p_exc.PortConfigurationError(net_id=network_id,
                                            lsn_id=lsn_id,
                                            port_id=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(context, lsn_id, lsn_port_id)
             raise p_exc.PortConfigurationError(net_id=network_id,
                                                lsn_id=lsn_id,
                                                port_id=port_id)
         if subnet_config:
             self.lsn_port_dhcp_configure(context, lsn_id, lsn_port_id,
                                          subnet_config)
         else:
             return (lsn_id, lsn_port_id)
Esempio n. 3
0
 def lsn_port_dhcp_setup(
     self, context, network_id, port_id, port_data, subnet_config=None):
     """Connect network to LSN via specified port and port_data."""
     try:
         lsn_id = None
         switch_id = nsx_utils.get_nsx_switch_ids(
             context.session, self.cluster, network_id)[0]
         lswitch_port_id = switch_api.get_port_by_neutron_tag(
             self.cluster, switch_id, port_id)['uuid']
         lsn_id = self.lsn_get(context, network_id)
         lsn_port_id = self.lsn_port_create(context, lsn_id, port_data)
     except (n_exc.NotFound, p_exc.NsxPluginException):
         raise p_exc.PortConfigurationError(
             net_id=network_id, lsn_id=lsn_id, port_id=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(context, lsn_id, lsn_port_id)
             raise p_exc.PortConfigurationError(
                 net_id=network_id, lsn_id=lsn_id, port_id=port_id)
         if subnet_config:
             self.lsn_port_dhcp_configure(
                 context, lsn_id, lsn_port_id, subnet_config)
         else:
             return (lsn_id, lsn_port_id)
Esempio n. 4
0
    def update_network_precommit(self, context):
        if context.original['name'] != context.current['name']:
            nsx_switch_ids = nsx_utils.get_nsx_switch_ids(
               context._plugin_context.session,
               self.cluster,
               context.current['id']
            )

            if not nsx_switch_ids or len(nsx_switch_ids) < 1:
                 LOG.warn(_("Unable to find NSX mappings for neutron "
                             "network:%s"), context.original['id'])

            try:
                switchlib.update_lswitch(
                    self.cluster,
                    lswitch_ids[0],
                    context.current['name']
                )
            except api_exc.NsxApiException as e:
                 LOG.warn(_("Logical switch update on NSX backend failed. "
                            "Neutron network id:%(net_id)s; "
                            "NSX lswitch id:%(lswitch_id)s;"
                            "Error:%(error)s"),
                            {'net_id': context.current['id'],
                             'lswitch_id': lswitch_ids[0],
                             'error': e})
Esempio n. 5
0
 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)
Esempio n. 6
0
 def _verify_get_nsx_switch_ids(self, exp_ls_uuids):
     # The nsxlib and db calls are mocked, therefore the cluster
     # and the neutron_router_id parameters can be set to None
     ls_uuids = nsx_utils.get_nsx_switch_ids(db_api.get_session(), None, None)
     for ls_uuid in ls_uuids or []:
         self.assertIn(ls_uuid, exp_ls_uuids)
         exp_ls_uuids.remove(ls_uuid)
     self.assertFalse(exp_ls_uuids)
Esempio n. 7
0
 def _verify_get_nsx_switch_ids(self, exp_ls_uuids):
     # The nsxlib and db calls are mocked, therefore the cluster
     # and the neutron_router_id parameters can be set to None
     ls_uuids = nsx_utils.get_nsx_switch_ids(db_api.get_session(), None,
                                             None)
     for ls_uuid in ls_uuids or []:
         self.assertIn(ls_uuid, exp_ls_uuids)
         exp_ls_uuids.remove(ls_uuid)
     self.assertFalse(exp_ls_uuids)
Esempio n. 8
0
    def delete_network_precommit(self, context):
        nsx_switch_ids = nsx_utils.get_nsx_switch_ids(
           context._plugin_context.session,
           self.cluster,
           context.current['id']
        )

        try:
            switchlib.delete_networks(
                self.cluster,
                context.current['id'],
                nsx_switch_ids
            )
        except n_exc.NotFound:
             LOG.warning(_("The following logical switches were not found "
                           "on the NSX backend:%s"), nsx_switch_ids)