Creates a new instance.

    More details for parameters can be found in the RAPI documentation.

    @type mode: string
    @param mode: Instance creation mode
    @type name: string
    @param name: Hostname of the instance to create
    @type disk_template: string
    @param disk_template: Disk template for instance (e.g. plain, diskless,
                                                file, or drbd)
    @type disks: list of dicts
    @param disks: List of disk definitions
    @type nics: list of dicts
    @param nics: List of NIC definitions
    @type dry_run: bool
    @keyword dry_run: whether to perform a dry run
    @type no_install: bool
    @keyword no_install: whether to create without installing OS(true=don't install)

    @rtype: int
    @return: job id

def CreateInstance(r, mode, name, disk_template, disks, nics,
                   **kwargs):
    """
    Creates a new instance.

    More details for parameters can be found in the RAPI documentation.

    @type mode: string
    @param mode: Instance creation mode
    @type name: string
    @param name: Hostname of the instance to create
    @type disk_template: string
    @param disk_template: Disk template for instance (e.g. plain, diskless,
                                                file, or drbd)
    @type disks: list of dicts
    @param disks: List of disk definitions
    @type nics: list of dicts
    @param nics: List of NIC definitions
    @type dry_run: bool
    @keyword dry_run: whether to perform a dry run
    @type no_install: bool
    @keyword no_install: whether to create without installing OS(true=don't install)

    @rtype: int
    @return: job id
    """

    if INST_CREATE_REQV1 not in r.features:
        raise GanetiApiError("Cannot create Ganeti 2.1-style instances")

    query = {}

    if kwargs.get("dry_run"):
        query["dry-run"] = 1
    if kwargs.get("no_install"):
        query["no-install"] = 1

    # Make a version 1 request.
    body = {
        _REQ_DATA_VERSION_FIELD: 1,
        "mode": mode,
        "name": name,
        "disk_template": disk_template,
        "disks": disks,
        "nics": nics,
    }

    conflicts = set(kwargs.iterkeys()) & set(body.iterkeys())
    if conflicts:
        raise GanetiApiError("Required fields can not be specified as"
                             " keywords: %s" % ", ".join(conflicts))

    kwargs.pop("dry_run", None)
    body.update(kwargs)

    return r.request("post", "/2/instances", query=query, content=body)