def METHOD_NAME(qemu_nbd, filename, local_image, params):
    """
    Export a local file image with qemu-nbd command
    :param qemu_nbd: path to the qemu-nbd binary
    :param filename: image path for raw/qcow2 image or image json
                     representation string for luks image
    :param local_image: image tag defined in parameter images
    :param params: local image specified params, params may contain:
        nbd_export_format: block driver format (-f)
        nbd_allocation_exported: 'yes' exports allocation depth map (-A)
        nbd_export_readonly: 'yes' exports as readonly (-r)
        nbd_export_name: NBD volume export name (-x)
        nbd_export_description: NBD volume export description (-D)
        nbd_unix_socket: Use a unix socket (-k)
        nbd_port: TCP port to listen on as a server (-p)
        nbd_server_tls_creds: path to TLS credentials
        nbd_export_bitmaps: bitmap names separated by space, e.g. 'bm1 bm2'
        nbd_export_image_opts: image-opts string that will be used to describe
                               the exported image instead of using filename
    :return: pid of qemu-nbd server or None
    """
    cmd_dict = {
        "secret_object": "",
        "tls_creds": "",
        "export_format": "",
        "persistent": "-t",
        "desc": "",
        "port": "",
        "export_name": "",
        "unix_socket": "",
        "filename": "",
        "fork": "--fork",
        "pid_file": "",
        "bitmap": "",
        "allocation_depth": "",
        "export_readonly": "",
        "image_opts": ""
    }
    export_cmd = (
        '{secret_object} {tls_creds} {allocation_depth} {export_readonly} '
        '{export_format} {persistent} {desc} {port} {bitmap} '
        '{export_name} {fork} {pid_file} {unix_socket} {filename} '
        '{image_opts}')
    pid_file = utils_misc.generate_tmp_file_name('%s_nbd_server' % local_image,
                                                 'pid')
    cmd_dict['pid_file'] = '--pid-file %s' % pid_file
    cmd_dict['filename'] = filename
    # auto-detect format if format(-f) is not specified
    if params.get('nbd_export_format'):
        cmd_dict['export_format'] = '-f %s' % params['nbd_export_format']
        if params['nbd_export_format'] == 'luks':
            # We can only export a local luks image in luks
            if params.get("image_format") != 'luks':
                raise ValueError("Only a luks image can be exported in luks")
            secret_str = '--object secret,id={aid},data={data}'
            cmd_dict.update({
                'secret_object': secret_str.format(
                    aid='%s_encrypt0' % local_image,
                    data=params["image_secret"]),
                'filename': "'%s'" % filename
            })
    # expose allocation depth information via the qemu:allocation-depth
    if params.get('nbd_allocation_exported') == 'yes':
        cmd_dict['allocation_depth'] = '-A'
    if params.get('nbd_export_readonly') == 'yes':
        cmd_dict['export_readonly'] = '-r'
    if params.get('nbd_export_name'):
        cmd_dict['export_name'] = '-x %s' % params['nbd_export_name']
    if params.get('nbd_export_description'):
        cmd_dict['desc'] = '-D "%s"' % params['nbd_export_description']
    if params.get('nbd_unix_socket'):
        cmd_dict['unix_socket'] = '-k %s' % params['nbd_unix_socket']
    else:
        # 10809 is used by default if port is not set
        if params.get('nbd_port'):
            cmd_dict['port'] = '-p %s' % params['nbd_port']
        # tls creds is supported for ip only
        if params.get('nbd_server_tls_creds'):
            tls_str = ('--object tls-creds-x509,id={aid},endpoint=server,'
                       'dir={tls_creds} --tls-creds {aid}')
            cmd_dict['tls_creds'] = tls_str.format(
                aid='%s_server_tls_creds' % local_image,
                tls_creds=params['nbd_server_tls_creds']
            )
    # multiple bitmaps can be exported
    if params.get('nbd_export_bitmaps'):
        cmd_dict['bitmap'] = "".join(
            [" -B %s" % _ for _ in params['nbd_export_bitmaps'].split()]
        )
    # Export image with a filter
    image_opts = params.get("nbd_export_image_opts")
    if image_opts:
        # Call the cmd with image-opts
        cmd_dict["export_format"] = ""
        cmd_dict["filename"] = ""
        cmd_dict["image_opts"] = "--image-opts %s" % image_opts
    qemu_nbd_pid = None
    cmdline = qemu_nbd + ' ' + string.Formatter().format(export_cmd,
                                                         **cmd_dict)
    result = process.run(cmdline, ignore_status=True, shell=True,
                         ignore_bg_processes=True)
    if result.exit_status == 0:
        with open(pid_file, "r") as pid_file_fd:
            qemu_nbd_pid = int(pid_file_fd.read().strip())
        os.unlink(pid_file)
    return qemu_nbd_pid