Class: E2B::Models::SandboxInfo
- Inherits:
-
Object
- Object
- E2B::Models::SandboxInfo
- Defined in:
- lib/e2b/models/sandbox_info.rb
Overview
Information about a sandbox
Instance Attribute Summary collapse
-
#alias_name ⇒ String?
readonly
Alias/name of the sandbox.
-
#client_id ⇒ String
readonly
Client ID.
-
#cpu_count ⇒ Integer
readonly
CPU count.
-
#end_at ⇒ Time
readonly
When the sandbox will end (timeout).
-
#envd_version ⇒ String?
readonly
Envd version reported by the control plane.
-
#memory_mb ⇒ Integer
readonly
Memory in MB.
-
#metadata ⇒ Hash
readonly
Metadata.
-
#sandbox_domain ⇒ String?
readonly
Domain where the sandbox is hosted.
-
#sandbox_id ⇒ String
readonly
Sandbox ID.
-
#started_at ⇒ Time
readonly
When the sandbox was started.
-
#state ⇒ String?
readonly
Current sandbox state.
-
#template_id ⇒ String
readonly
Template ID used to create the sandbox.
Class Method Summary collapse
-
.from_hash(data) ⇒ SandboxInfo
Create from API response hash.
- .parse_time(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(sandbox_id:, template_id:, alias_name: nil, client_id: nil, started_at: nil, end_at: nil, cpu_count: nil, memory_mb: nil, metadata: {}, state: nil, sandbox_domain: nil, envd_version: nil) ⇒ SandboxInfo
constructor
A new instance of SandboxInfo.
-
#running? ⇒ Boolean
Check if sandbox is still running (not past end_at).
-
#time_remaining ⇒ Integer
Time remaining until timeout.
Constructor Details
#initialize(sandbox_id:, template_id:, alias_name: nil, client_id: nil, started_at: nil, end_at: nil, cpu_count: nil, memory_mb: nil, metadata: {}, state: nil, sandbox_domain: nil, envd_version: nil) ⇒ SandboxInfo
Returns a new instance of SandboxInfo.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/e2b/models/sandbox_info.rb', line 64 def initialize(sandbox_id:, template_id:, alias_name: nil, client_id: nil, started_at: nil, end_at: nil, cpu_count: nil, memory_mb: nil, metadata: {}, state: nil, sandbox_domain: nil, envd_version: nil) @sandbox_id = sandbox_id @template_id = template_id @alias_name = alias_name @client_id = client_id @started_at = started_at @end_at = end_at @cpu_count = cpu_count @memory_mb = memory_mb @metadata = || {} @state = state @sandbox_domain = sandbox_domain @envd_version = envd_version end |
Instance Attribute Details
#alias_name ⇒ String? (readonly)
Returns Alias/name of the sandbox.
14 15 16 |
# File 'lib/e2b/models/sandbox_info.rb', line 14 def alias_name @alias_name end |
#client_id ⇒ String (readonly)
Returns Client ID.
17 18 19 |
# File 'lib/e2b/models/sandbox_info.rb', line 17 def client_id @client_id end |
#cpu_count ⇒ Integer (readonly)
Returns CPU count.
26 27 28 |
# File 'lib/e2b/models/sandbox_info.rb', line 26 def cpu_count @cpu_count end |
#end_at ⇒ Time (readonly)
Returns When the sandbox will end (timeout).
23 24 25 |
# File 'lib/e2b/models/sandbox_info.rb', line 23 def end_at @end_at end |
#envd_version ⇒ String? (readonly)
Returns Envd version reported by the control plane.
41 42 43 |
# File 'lib/e2b/models/sandbox_info.rb', line 41 def envd_version @envd_version end |
#memory_mb ⇒ Integer (readonly)
Returns Memory in MB.
29 30 31 |
# File 'lib/e2b/models/sandbox_info.rb', line 29 def memory_mb @memory_mb end |
#metadata ⇒ Hash (readonly)
Returns Metadata.
32 33 34 |
# File 'lib/e2b/models/sandbox_info.rb', line 32 def @metadata end |
#sandbox_domain ⇒ String? (readonly)
Returns Domain where the sandbox is hosted.
38 39 40 |
# File 'lib/e2b/models/sandbox_info.rb', line 38 def sandbox_domain @sandbox_domain end |
#sandbox_id ⇒ String (readonly)
Returns Sandbox ID.
8 9 10 |
# File 'lib/e2b/models/sandbox_info.rb', line 8 def sandbox_id @sandbox_id end |
#started_at ⇒ Time (readonly)
Returns When the sandbox was started.
20 21 22 |
# File 'lib/e2b/models/sandbox_info.rb', line 20 def started_at @started_at end |
#state ⇒ String? (readonly)
Returns Current sandbox state.
35 36 37 |
# File 'lib/e2b/models/sandbox_info.rb', line 35 def state @state end |
#template_id ⇒ String (readonly)
Returns Template ID used to create the sandbox.
11 12 13 |
# File 'lib/e2b/models/sandbox_info.rb', line 11 def template_id @template_id end |
Class Method Details
.from_hash(data) ⇒ SandboxInfo
Create from API response hash
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/e2b/models/sandbox_info.rb', line 47 def self.from_hash(data) new( sandbox_id: data["sandboxID"] || data["sandbox_id"] || data[:sandboxID], template_id: data["templateID"] || data["template_id"] || data[:templateID], alias_name: data["alias"] || data[:alias], client_id: data["clientID"] || data["client_id"] || data[:clientID], started_at: parse_time(data["startedAt"] || data["started_at"] || data[:startedAt]), end_at: parse_time(data["endAt"] || data["end_at"] || data[:endAt]), cpu_count: data["cpuCount"] || data["cpu_count"] || data[:cpuCount], memory_mb: data["memoryMB"] || data["memory_mb"] || data[:memoryMB], metadata: data["metadata"] || data[:metadata] || {}, state: data["state"] || data[:state], sandbox_domain: data["domain"] || data[:domain], envd_version: data["envdVersion"] || data["envd_version"] || data[:envdVersion] ) end |
.parse_time(value) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/e2b/models/sandbox_info.rb', line 101 def self.parse_time(value) return nil if value.nil? return value if value.is_a?(Time) Time.parse(value.to_s) rescue ArgumentError, TypeError nil end |
Instance Method Details
#running? ⇒ Boolean
Check if sandbox is still running (not past end_at)
84 85 86 87 88 89 |
# File 'lib/e2b/models/sandbox_info.rb', line 84 def running? return false if @state == "paused" return true if @end_at.nil? Time.now < @end_at end |
#time_remaining ⇒ Integer
Time remaining until timeout
94 95 96 97 98 99 |
# File 'lib/e2b/models/sandbox_info.rb', line 94 def time_remaining return 0 if @end_at.nil? remaining = (@end_at - Time.now).to_i remaining.positive? ? remaining : 0 end |