def delete_port_postcommit(self, context):
        """Call ISM API to reset VLAN configuration."""

        port = context.current
        if not fj_util.is_baremetal(port):
            LOG.warning("This plugin is under developing and "
                        "not doing at all.")
            return
def validate_baremetal_deploy(mech_context):
    """Validate baremetal deploy.

    @param mech_context a context object
    @return True if enable to baremetal deploy otherwise False
    """

    port = mech_context.current
    network = mech_context.network
    if (fj_util.is_baremetal(port) and
       is_supported(network) and fj_util.get_physical_connectivity(port)):
        return True
    return False
    def delete_port_postcommit(self, mech_context):
        """Calls cleanup process for C-Fabric.

        Case1: Baremetal deploy
                   Clear VLAN/LAG for specified physical port.
        Case2: Otherwise
                   Dissociate MAC address from the portprofile.
        """

        method = 'delete_port_postcommit'
        port = mech_context.current
        port_id = port['id']
        network_id = port['network_id']
        tenant_id = port['tenant_id']
        if fj_util.is_baremetal(port):
            if validate_baremetal_deploy(mech_context):
                params = self.get_physical_net_params(mech_context)
                try:
                    self.clear_vlan(params)
                except Exception:
                    LOG.exception(_LE("Failed to clear vlan%s."),
                        params['vlanid'])
                    raise ml2_exc.MechanismDriverError(method=method)
        elif not is_supported(mech_context.network):
            pass
        else:
            segments = mech_context.network.network_segments
            # currently supports only one segment per network
            segment = segments[0]
            vfab_id = self._get_vfab_id(segment[driver_api.PHYSICAL_NETWORK])
            vlanid = segment[driver_api.SEGMENTATION_ID]
            interface_mac = port['mac_address']

            try:
                self._driver.dissociate_mac_from_network(
                    self._switch['address'],
                    self._switch['username'],
                    self._switch['password'],
                    vfab_id,
                    vlanid,
                    interface_mac)
            except Exception:
                LOG.exception(
                    _LE("Fujitsu Mechanism: failed to dissociate MAC %s") %
                    interface_mac)
                raise ml2_exc.MechanismDriverError(method=method)
        LOG.info(
            _LI("delete port (postcommit): port_id=%(port_id)s "
                "network_id=%(network_id)s tenant_id=%(tenant_id)s"),
            {'port_id': port_id,
             'network_id': network_id, 'tenant_id': tenant_id})
    def create_port_postcommit(self, mech_context):
        """Calls setup process for C-Fabric.

        Case1: Baremetal deploy
                   Setup VLAN for specified physical port.
        Case2: Otherwise
                   Associate the assigned MAC address to the portprofile.
        """

        if fj_util.is_baremetal(mech_context.current):
            return

        if not is_supported(mech_context.network):
            return

        method = 'create_port_postcommit'
        port = mech_context.current
        port_id = port['id']
        network_id = port['network_id']
        tenant_id = port['tenant_id']
        segments = mech_context.network.network_segments
        # currently supports only one segment per network
        segment = segments[0]

        vfab_id = self._get_vfab_id(segment[driver_api.PHYSICAL_NETWORK])
        vlanid = segment[driver_api.SEGMENTATION_ID]

        interface_mac = port['mac_address']

        try:
            self._driver.associate_mac_to_network(self._switch['address'],
                                                  self._switch['username'],
                                                  self._switch['password'],
                                                  vfab_id,
                                                  vlanid,
                                                  interface_mac)
        except Exception:
            LOG.exception(
                _LE("Fujitsu Mechanism: failed to associate mac %s")
                % interface_mac)
            raise ml2_exc.MechanismDriverError(method=method)

        LOG.info(
            _LI("created port (postcommit): port_id=%(port_id)s "
                "network_id=%(network_id)s tenant_id=%(tenant_id)s"),
            {'port_id': port_id,
             'network_id': network_id, 'tenant_id': tenant_id})