Class: Daytona::Daytona
- Inherits:
-
Object
- Object
- Daytona::Daytona
- Defined in:
- lib/daytona/daytona.rb
Overview
rubocop:disable Metrics/ClassLength
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
-
#create(params = nil, on_snapshot_create_logs: nil) ⇒ Daytona::Sandbox
Creates a sandbox with the specified parameters.
-
#delete(sandbox) ⇒ void
Deletes a Sandbox.
-
#find_one(id: nil, labels: nil) ⇒ Daytona::Sandbox
Finds a Sandbox by its ID or labels.
-
#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.
Constructor Details
#initialize(config = Config.new) ⇒ Daytona
Returns a new instance of Daytona.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/daytona/daytona.rb', line 30 def initialize(config = Config.new) # rubocop:disable Metrics/AbcSize @config = config ensure_access_token_defined @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)) @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) @proxy_toolbox_url_cache = {} @proxy_toolbox_url_mutex = Mutex.new end |
Instance Attribute Details
#api_client ⇒ DaytonaApiClient (readonly)
12 13 14 |
# File 'lib/daytona/daytona.rb', line 12 def api_client @api_client end |
#config ⇒ Daytona::Config (readonly)
9 10 11 |
# File 'lib/daytona/daytona.rb', line 9 def config @config end |
#object_storage_api ⇒ DaytonaApiClient::ObjectStorageApi (readonly)
21 22 23 |
# File 'lib/daytona/daytona.rb', line 21 def object_storage_api @object_storage_api end |
#sandbox_api ⇒ DaytonaApiClient::SandboxApi (readonly)
15 16 17 |
# File 'lib/daytona/daytona.rb', line 15 def sandbox_api @sandbox_api end |
#snapshot ⇒ Daytona::SnapshotService (readonly)
27 28 29 |
# File 'lib/daytona/daytona.rb', line 27 def snapshot @snapshot end |
#snapshots_api ⇒ DaytonaApiClient::SnapshotsApi (readonly)
24 25 26 |
# File 'lib/daytona/daytona.rb', line 24 def snapshots_api @snapshots_api end |
#volume ⇒ Daytona::VolumeService (readonly)
18 19 20 |
# File 'lib/daytona/daytona.rb', line 18 def volume @volume end |
Instance Method Details
#create(params = nil, on_snapshot_create_logs: nil) ⇒ Daytona::Sandbox
Creates a sandbox with the specified parameters
49 50 51 52 53 54 55 56 57 |
# File 'lib/daytona/daytona.rb', line 49 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.
63 |
# File 'lib/daytona/daytona.rb', line 63 def delete(sandbox) = sandbox.delete |
#find_one(id: nil, labels: nil) ⇒ Daytona::Sandbox
Finds a Sandbox by its ID or labels.
80 81 82 83 84 85 86 87 |
# File 'lib/daytona/daytona.rb', line 80 def find_one(id: nil, labels: nil) return get(id) if id response = list(labels) raise Sdk::Error, "No sandbox found with labels #{labels}" if response.items.empty? response.items.first end |
#get(id) ⇒ Daytona::Sandbox
Gets a Sandbox by its ID.
69 70 71 72 |
# File 'lib/daytona/daytona.rb', line 69 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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/daytona/daytona.rb', line 96 def list(labels = {}, page: nil, limit: nil) # rubocop:disable Metrics/MethodLength 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 { |sandbox_dto| to_sandbox(sandbox_dto:, code_toolbox: code_toolbox_from_labels(sandbox_dto.labels)) } ) 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) |