nimblebox logo
Docs
v2.1.0

nbox.instance

NBX-Build Instances are APIs to your machines. These APIs can be used to change state of the machine (start, stop, etc.), can be used to transfer files to and from the machine (using Instance.mv commands), calling any shell command using Instance.remote.

CLI Commands

Build comes built in with several functions to move and list files from the instance. All you need to know is that cloud files have prefix nbx:// which is where your projects are. Here's a quick list:


# move files
nbx build -i 'instance_name' --workspace_id 'workspace_id'   mv ./local_file nbx://cloud_file

# or move folders
nbx build -i 'instance_name' --workspace_id 'workspace_id'   mv ./local_folder nbx://in_this/folder/

You might be required to agree to the SSH connection being setup. If you want to avoid that set NBOX_SSH_NO_HOST_CHECKING=1. All these APIs are also available in python.

Functions

iconfunctionprint_status
[source]
(fields:List[str])
Parameters
  • fields -

    fields to print. Defaults to []. If not provided all fields will be printed.

Print complete status of NBX-Build instances. If workspace_id is not provided personal workspace will be used. Used in CLI

Classes

iconclassInstance
[source]
iconfunction__init__
[source]
(i:str)
Parameters
  • i -

    name or project_id of the instance

NBX-Build Instance class manages the both individual instance, but provides webserver functionality using nbox_ws_v1, such as starting and stopping, deletion and more.

iconfunction__repr__
[source]
iconfunctionnew
[source]
(project_name:str,storage_limit:int,project_type:str,github_branch:str,github_link:str,template_id:int,clone_id:int)
Parameters
  • project_name -

    Name of the instance

  • storage_limit -

    Storage limit in GB. Defaults to 25.

  • project_type -

    Type of the instance. Defaults to "blank".

  • github_branch -

    Branch of the github repo. Defaults to "".

  • github_link -

    Link to the github repo. Defaults to "".

  • template_id -

    ID of the template to use. Defaults to 0.

  • clone_id -

    ID of the instance to clone. Defaults to 0.

Create a new NBX-Build instance.

Returns:

  • Instance: The newly created instance.
iconfunctionget_subway
[source]
(subdomain:str)
Parameters
  • subdomain -

    The subdomain to connect to

Get a Subway object for the instance.

Returns:

  • Subway: The Subway object.
iconfunctionis_running
[source]

Check if the instance is running.

Returns:

  • bool: True if the instance is running, False otherwise.
iconfunctionrefresh
[source]

Update the data, get latest state

iconfunction_start
[source]

Turn on the the unserlying compute

iconfunction_open
[source]
iconfunctionstart
[source]
(cpu:int,gpu:str,gpu_count:int,auto_shutdown:int,dedicated_hw:bool,zone:str)
Parameters
  • cpu -

    CPU count should be one of [2, 4, 8]

  • gpu -

    GPU name should be one of ["t5", "p100", "v100", "k80"]

  • gpu_count -

    When zero, cpu-only instance is started

  • auto_shutdown -

    No autoshutdown if zero, defaults to 6.

  • dedicated_hw -

    If not spot/pre-emptible like machines used

  • zone -

    GCP cloud regions, defaults to "asia-south-1".

Start instance if not already running and loads APIs from the compute server. Actual start is implemented in _start method, this combines other things

iconfunctionstop
[source]

Stop the Instance

iconfunctiondelete
[source]

With great power comes great responsibility.

iconfunction_unopened_error
[source]
iconfunction__create_connection
[source]

This function is used to create a the Connection Manager object and not depend on __create_threads from ssh

iconfunction__run_command
[source]
iconfunctionls
[source]
(path:str)
Parameters
  • path -

    Path to list files in all paths will be built relative to "/home/ubuntu/project/" folder.

List files in a directory relative to '/home/ubuntu/project'

[nbox API] - nbox.Instance(...).ls("/")
[nbox CLI] - nbx build ... ls ./
iconfunctionmv
[source]
(src:str,dst:str,force:bool)
Parameters
  • src -

    Source file or folder to move

  • dst -

    Destination file or folder to move to

  • force -

    If True, will override the destination file if it already exists

Move files to and fro NBX-Build. Use 'nbx://' as prefix for Instance, all files will be placed relative to '/home/ubuntu/project/' folder.

iconfunctionrm
[source]
(file:str)
Parameters
  • file -

    File to remove

Remove file from NBX-Build.

iconfunctionremote
[source]
(x:str)
Parameters
  • x -

    Command to run

Run any command using SSH, in the underlying system it will setup a SSH connection and execute any command.

iconfunction__call__
[source]

EXPERIMENTAL: FEATURES MIGHT BREAK Caller is the most important UI/UX. The letter x in programming is reserved the most arbitrary thing, and this nbox.Instance is the gateway to a cloud instance. You can:

  1. run a script on the cloud
  2. run a local script on the cloud
  3. get the status of a script
  4. [TBD] run a special kind of functions known as pure functions <https://en.wikipedia.org/wiki/Pure_function>_

Pure functions in programming are functions that are self sufficient in terms of execution, eg. all the packages are imported inside the function and there are no side effects in an execution (seeds included for probabilistic functions). Writing such functions in python with any IDE with checker is dead easy, however the performace guarantee is premium given high costs. Thus the logic to parsing these will have to be written as a seperate module.

nbox SDKnbox provides built in access to all the APIs and packages them in the most user friendly manner.Star 0