def delete_port(self, port_id):
     """delete_port ."""
     db_context = neutron_context.get_admin_context()
     try:
         port_map = db.get_bnp_neutron_port(db_context, port_id)
     except Exception:
         LOG.error(_LE("No neutron port is associated with the phys port"))
         return
     is_last_port_in_vlan = False
     seg_id = port_map.segmentation_id
     bnp_sw_map = db.get_bnp_switch_port_mappings(db_context, port_id)
     switch_port_id = bnp_sw_map[0].switch_port_id
     bnp_switch = db.get_bnp_phys_switch(db_context,
                                         bnp_sw_map[0].switch_id)
     cred_dict = self._get_credentials_dict(bnp_switch, 'delete_port')
     phys_port = db.get_bnp_phys_switch_port_by_id(db_context,
                                                   switch_port_id)
     result = db.get_bnp_neutron_port_by_seg_id(db_context, seg_id)
     if not result:
         LOG.error(_LE("No neutron port is associated with the phys port"))
         self._raise_ml2_error(wexc.HTTPNotFound, 'delete_port')
     if len(result) == 1:
         # to prevent snmp set from the same VLAN
         is_last_port_in_vlan = True
     port_dict = {'port':
                  {'id': port_id,
                   'segmentation_id': seg_id,
                   'ifindex': phys_port.ifindex,
                   'is_last_port_vlan': is_last_port_in_vlan
                   }
                  }
     credentials_dict = port_dict.get('port')
     credentials_dict['credentials'] = cred_dict
     try:
         prov_protocol = bnp_switch.prov_proto
         vendor = bnp_switch.vendor
         family = bnp_switch.family
         prov_driver = self._provisioning_driver(prov_protocol, vendor,
                                                 family)
         if not prov_driver:
             LOG.error(_LE("No suitable provisioning driver found"
                           ))
             self._raise_ml2_error(wexc.HTTPNotFound, 'create_port')
         prov_driver.obj.delete_isolation(port_dict)
         db.delete_bnp_neutron_port(db_context, port_id)
         db.delete_bnp_switch_port_mappings(db_context, port_id)
     except Exception as e:
         LOG.error(_LE("Error in deleting the port '%s' "), e)
         self._raise_ml2_error(wexc.HTTPNotFound, 'delete_port')
 def delete_port(self, port_id):
     """delete_port ."""
     db_context = neutron_context.get_admin_context()
     try:
         port_map = db.get_bnp_neutron_port(db_context, port_id)
     except Exception:
         LOG.error(_LE("No neutron port is associated with the phys port"))
         return
     is_last_port_in_vlan = False
     seg_id = port_map.segmentation_id
     bnp_sw_map = db.get_bnp_switch_port_mappings(db_context, port_id)
     bnp_switch = db.get_bnp_phys_switch(db_context,
                                         bnp_sw_map[0].switch_id)
     cred_dict = self._get_credentials_dict(bnp_switch, 'delete_port')
     result = db.get_bnp_neutron_port_by_seg_id(db_context, seg_id)
     if not result:
         LOG.error(_LE("No neutron port is associated with the phys port"))
         self._raise_ml2_error(wexc.HTTPNotFound, 'delete_port')
     if len(result) == 1:
         # to prevent snmp set from the same VLAN
         is_last_port_in_vlan = True
     port_dict = {'port':
                  {'id': port_id,
                   'segmentation_id': seg_id,
                   'ifindex': bnp_sw_map[0].ifindex,
                   'is_last_port_vlan': is_last_port_in_vlan
                   }
                  }
     credentials_dict = port_dict.get('port')
     credentials_dict['credentials'] = cred_dict
     try:
         prov_protocol = bnp_switch.management_protocol
         vendor = bnp_switch.vendor
         family = bnp_switch.family
         prov_driver = self._provisioning_driver(prov_protocol, vendor,
                                                 family)
         if not prov_driver:
             LOG.error(_LE("No suitable provisioning driver found"
                           ))
             self._raise_ml2_error(wexc.HTTPNotFound, 'create_port')
         prov_driver.obj.delete_isolation(port_dict)
         db.delete_bnp_neutron_port(db_context, port_id)
         db.delete_bnp_switch_port_mappings(db_context, port_id)
     except Exception as e:
         LOG.error(_LE("Error in deleting the port '%s' "), e)
         self._raise_ml2_error(wexc.HTTPNotFound, 'delete_port')
 def delete_port(self, port_id):
     """delete_port ."""
     try:
         port_map = db.get_bnp_neutron_port(self.context, port_id)
     except Exception:
         LOG.error(_LE("No neutron port is associated with the phys port"))
         return
     is_last_port_in_vlan = False
     seg_id = port_map.segmentation_id
     bnp_sw_map = db.get_bnp_switch_port_mappings(self.context, port_id)
     switch_port_id = bnp_sw_map[0].switch_port_id
     bnp_switch = db.get_bnp_phys_switch(self.context,
                                         bnp_sw_map[0].switch_id)
     cred_dict = self._get_credentials_dict(bnp_switch, 'delete_port')
     phys_port = db.get_bnp_phys_switch_port_by_id(self.context,
                                                   switch_port_id)
     result = db.get_bnp_neutron_port_by_seg_id(self.context, seg_id)
     if not result:
         LOG.error(_LE("No neutron port is associated with the phys port"))
         self._raise_ml2_error(wexc.HTTPNotFound, 'delete_port')
     if len(result) == 1:
         # to prevent snmp set from the same VLAN
         is_last_port_in_vlan = True
     port_dict = {'port':
                  {'id': port_id,
                   'segmentation_id': seg_id,
                   'ifindex': phys_port.ifindex,
                   'is_last_port_vlan': is_last_port_in_vlan
                   }
                  }
     credentials_dict = port_dict.get('port')
     credentials_dict['credentials'] = cred_dict
     try:
         self.protocol_driver.delete_isolation(port_dict)
         db.delete_bnp_neutron_port(self.context, port_id)
         db.delete_bnp_switch_port_mappings(self.context, port_id)
     except Exception as e:
         LOG.error(_LE("Error in deleting the port '%s' "), e)
         self._raise_ml2_error(wexc.HTTPNotFound, 'delete_port')