'Perform port operations taking care of concurrency issues.'

def _port_action(self, plugin, context, port, action):

    try:
        if (action == 'create_port'):
            return p_utils.create_port(plugin, context, port)
        elif (action == 'update_port'):
            return plugin.update_port(context, port['id'], port)
        else:
            msg = _('Unrecognized    action')
            raise exceptions.Invalid(message=msg)
    except (db_exc.DBReferenceError, exceptions.NetworkNotFound, exceptions.SubnetNotFound, exceptions.InvalidInput, exceptions.IpAddressGenerationFailure) as e:
        with excutils.save_and_reraise_exception(reraise=False) as ctxt:
            if isinstance(e, exceptions.IpAddressGenerationFailure):
                try:
                    subnet_id = port['port']['fixed_ips'][0]['subnet_id']
                    plugin.get_subnet(context, subnet_id)
                except exceptions.SubnetNotFound:
                    pass
                else:
                    ctxt.reraise = True
            if ctxt.reraise:
                net_id = port['port']['network_id']
                LOG.warning(_LW('Action    %(action)s    for    network    %(net_id)s    could    not    complete    successfully:    %(reason)s'), {'action': action, 'net_id': net_id, 'reason': e})
