docstr: Args:
      instance_name: instance label
      bundle_id: desired host
      image_name: docker image name
      onstart: commands to run on start
      registry_auth: registry auth credentials for private images
  
  Raises:
      NoCapacityError: if instance cannot be created
  
  Returns:
      create instance response
docstr_tok: ["Args",":","instance_name",":","instance","label","bundle_id",":","desired","host","image_name",":","docker","image","name","onstart",":","commands","to","run","on","start","registry_auth",":","registry","auth","credentials","for","private","images","Raises",":","NoCapacityError",":","if","instance","can","not","be","created","Returns",":","create","instance","response"]
code: def create_instance(
      self,
      instance_name: str,
      bundle_id: Union[str, int],
      image_name: str,
      onstart: str,
      registry_auth: Optional[RegistryAuth] = None,
  ) -> dict:
      """
      Args:
          instance_name: instance label
          bundle_id: desired host
          image_name: docker image name
          onstart: commands to run on start
          registry_auth: registry auth credentials for private images
  
      Raises:
          NoCapacityError: if instance cannot be created
  
      Returns:
          create instance response
      """
      image_login = None
      if registry_auth:
          registry = (
              docker.parse_image_name(image_name).registry
              or "docker.io"
          )
          image_login = f"-u {registry_auth.username} -p {registry_auth.password} {registry}"
      payload = {
          "client_id": "me",
          "image": image_name,
          "disk": DISK_SIZE,
          "label": instance_name,
          "env": {
              "-p 10022:10022": "1",
          },
          "onstart": "/bin/sh",
          "args": ["-c", onstart],
          "runtype": "args",
          "image_login": image_login,
          "python_utf8": False,
          "lang_utf8": False,
          "use_jupyter_lab": False,
          "jupyter_dir": None,
          "create_from": None,
          "force": False,
      }
      resp = self.s.put(self._url(f"/asks/{bundle_id}/"), json=payload)
      if (
          resp.status_code != 200
          or not (data := resp.json())["success"]
      ):
          raise NoCapacityError(resp.text)
      self._invalidate_cache()
      return data
  
file_path: dstack/src/dstack/_internal/core/backends/vastai/api_client.py
imports: import shlex
  import threading
  import time
  from typing import List, Optional, Union
  import requests
  from requests.adapters import HTTPAdapter, Retry
  import dstack._internal.server.services.docker
  from dstack._internal.core.errors import NoCapacityError
  from dstack._internal.core.models.configurations import RegistryAuth
label_desc: Use image node_id 3 for calling the VastAIAPIClient obj's underlying member method code with example usage: obj.create_instance(instance_name, bundle_id, image_name, onstart, registry_auth) and returns: data