Class: Daytona::Daytona
- Inherits:
-
Object
- Object
- Daytona::Daytona
- Includes:
- Instrumentation
- Defined in:
- lib/daytona/daytona.rb
Instance Attribute Summary collapse
- #api_client ⇒ DaytonaApiClient readonly
- #config ⇒ Daytona::Config readonly
- #object_storage_api ⇒ DaytonaApiClient::ObjectStorageApi readonly
- #sandbox_api ⇒ DaytonaApiClient::SandboxApi readonly
- #snapshot ⇒ Daytona::SnapshotService readonly
- #snapshots_api ⇒ DaytonaApiClient::SnapshotsApi readonly
- #volume ⇒ Daytona::VolumeService readonly
Instance Method Summary collapse
-
#close ⇒ void
Shuts down OTel providers, flushing any pending telemetry data.
-
#create(params = nil, on_snapshot_create_logs: nil) ⇒ Daytona::Sandbox
Creates a sandbox with the specified parameters.
-
#delete(sandbox) ⇒ void
Deletes a Sandbox.
-
#get(id) ⇒ Daytona::Sandbox
Gets a Sandbox by its ID.
-
#initialize(config = Config.new) ⇒ Daytona
constructor
A new instance of Daytona.
-
#list(labels = {}, page: nil, limit: nil) ⇒ Daytona::PaginatedResource
Lists Sandboxes filtered by labels.
-
#start(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
Starts a Sandbox and waits for it to be ready.
-
#stop(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
Stops a Sandbox and waits for it to be stopped.
Methods included from Instrumentation
Constructor Details
#initialize(config = Config.new) ⇒ Daytona
Returns a new instance of Daytona.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/daytona/daytona.rb', line 32 def initialize(config = Config.new) @config = config ensure_access_token_defined otel_enabled = config._experimental&.dig('otel_enabled') || config.read_env('DAYTONA_EXPERIMENTAL_OTEL_ENABLED') == 'true' @otel_state = (::Daytona.init_otel(Sdk::VERSION) if otel_enabled) @api_client = build_api_client @sandbox_api = DaytonaApiClient::SandboxApi.new(api_client) @config_api = DaytonaApiClient::ConfigApi.new(api_client) @volume = VolumeService.new(DaytonaApiClient::VolumesApi.new(api_client), otel_state:) @object_storage_api = DaytonaApiClient::ObjectStorageApi.new(api_client) @snapshots_api = DaytonaApiClient::SnapshotsApi.new(api_client) @snapshot = SnapshotService.new(snapshots_api:, object_storage_api:, default_region_id: config.target, otel_state:) end |
Instance Attribute Details
#api_client ⇒ DaytonaApiClient (readonly)
14 15 16 |
# File 'lib/daytona/daytona.rb', line 14 def api_client @api_client end |
#config ⇒ Daytona::Config (readonly)
11 12 13 |
# File 'lib/daytona/daytona.rb', line 11 def config @config end |
#object_storage_api ⇒ DaytonaApiClient::ObjectStorageApi (readonly)
23 24 25 |
# File 'lib/daytona/daytona.rb', line 23 def object_storage_api @object_storage_api end |
#sandbox_api ⇒ DaytonaApiClient::SandboxApi (readonly)
17 18 19 |
# File 'lib/daytona/daytona.rb', line 17 def sandbox_api @sandbox_api end |
#snapshot ⇒ Daytona::SnapshotService (readonly)
29 30 31 |
# File 'lib/daytona/daytona.rb', line 29 def snapshot @snapshot end |
#snapshots_api ⇒ DaytonaApiClient::SnapshotsApi (readonly)
26 27 28 |
# File 'lib/daytona/daytona.rb', line 26 def snapshots_api @snapshots_api end |
#volume ⇒ Daytona::VolumeService (readonly)
20 21 22 |
# File 'lib/daytona/daytona.rb', line 20 def volume @volume end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Shuts down OTel providers, flushing any pending telemetry data.
52 53 54 55 |
# File 'lib/daytona/daytona.rb', line 52 def close ::Daytona.shutdown_otel(@otel_state) @otel_state = nil end |
#create(params = nil, on_snapshot_create_logs: nil) ⇒ Daytona::Sandbox
Creates a sandbox with the specified parameters
62 63 64 65 66 67 68 69 70 |
# File 'lib/daytona/daytona.rb', line 62 def create(params = nil, on_snapshot_create_logs: nil) if params.nil? params = CreateSandboxFromSnapshotParams.new(language: CodeLanguage::PYTHON) elsif params.language.nil? params.language = CodeLanguage::PYTHON end _create(params, on_snapshot_create_logs:) end |
#delete(sandbox) ⇒ void
This method returns an undefined value.
Deletes a Sandbox.
76 |
# File 'lib/daytona/daytona.rb', line 76 def delete(sandbox) = sandbox.delete |
#get(id) ⇒ Daytona::Sandbox
Gets a Sandbox by its ID.
82 83 84 85 |
# File 'lib/daytona/daytona.rb', line 82 def get(id) sandbox_dto = sandbox_api.get_sandbox(id) to_sandbox(sandbox_dto:, code_toolbox: code_toolbox_from_labels(sandbox_dto.labels)) end |
#list(labels = {}, page: nil, limit: nil) ⇒ Daytona::PaginatedResource
Lists Sandboxes filtered by labels.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/daytona/daytona.rb', line 94 def list(labels = {}, page: nil, limit: nil) raise Sdk::Error, 'page must be positive integer' if page && page < 1 raise Sdk::Error, 'limit must be positive integer' if limit && limit < 1 response = sandbox_api.list_sandboxes_paginated(labels: JSON.dump(labels), page:, limit:) PaginatedResource.new( total: response.total, page: response.page, total_pages: response.total_pages, items: response .items .map do |sandbox_dto| to_sandbox(sandbox_dto:, code_toolbox: code_toolbox_from_labels(sandbox_dto.labels)) end ) end |
#start(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Starts a Sandbox and waits for it to be ready.
118 |
# File 'lib/daytona/daytona.rb', line 118 def start(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) = sandbox.start(timeout) |
#stop(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Stops a Sandbox and waits for it to be stopped.
125 |
# File 'lib/daytona/daytona.rb', line 125 def stop(sandbox, timeout = Sandbox::DEFAULT_TIMEOUT) = sandbox.stop(timeout) |