<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def MigrateNode(r, node, mode=None, dry_run=False, iallocator=None, target_node=None):
 """ Migrates all primary instances from a node. @type node: str @param node: node to migrate @type mode: string @param mode: if passed, it will overwrite the live migration type, otherwise the hypervisor default will be used @type dry_run: bool @param dry_run: whether to perform a dry run @type iallocator: string @param iallocator: instance allocator to use @type target_node: string @param target_node: Target node for shared-storage instances @rtype: int @return: job id """


    query = {
        "dry-run": dry_run,
    }

    if NODE_MIGRATE_REQV1 in r.features:
        body = {}

        if mode is not None:
            body["mode"] = mode
        if iallocator is not None:
            body["iallocator"] = iallocator
        if target_node is not None:
            body["target_node"] = target_node

    else:
        # Use old request format
        if target_node is not None:
            raise GanetiApiError("Server does not support specifying"
                                 " target node for node migration")

        body = None

        if mode is not None:
            query["mode"] = mode

    return r.request("post", "/2/nodes/%s/migrate" % node, query=query,
                     content=body)