Class: Rexec::SandboxService
- Inherits:
-
Object
- Object
- Rexec::SandboxService
- Defined in:
- lib/rexec/container.rb
Overview
Service for managing sandboxes. HTTP paths remain /api/containers.
Instance Method Summary collapse
-
#create(image:, name: nil, environment: {}, labels: {}) ⇒ Sandbox
Create a new sandbox.
-
#delete(id) ⇒ Object
Delete a sandbox.
-
#get(id) ⇒ Sandbox
Get a sandbox by ID.
-
#initialize(client) ⇒ SandboxService
constructor
A new instance of SandboxService.
-
#list ⇒ Array<Sandbox>
List all sandboxes.
-
#start(id) ⇒ Object
Start a sandbox.
-
#stop(id) ⇒ Object
Stop a sandbox.
Constructor Details
#initialize(client) ⇒ SandboxService
Returns a new instance of SandboxService.
33 34 35 |
# File 'lib/rexec/container.rb', line 33 def initialize(client) @client = client end |
Instance Method Details
#create(image:, name: nil, environment: {}, labels: {}) ⇒ Sandbox
Create a new sandbox.
70 71 72 73 74 75 76 77 78 |
# File 'lib/rexec/container.rb', line 70 def create(image:, name: nil, environment: {}, labels: {}) body = { image: image } body[:name] = name if name body[:environment] = environment unless environment.empty? body[:labels] = labels unless labels.empty? data = @client.request(:post, "/api/containers", body: body) Sandbox.new(data) end |
#delete(id) ⇒ Object
Delete a sandbox.
83 84 85 86 |
# File 'lib/rexec/container.rb', line 83 def delete(id) @client.request(:delete, "/api/containers/#{id}") nil end |
#get(id) ⇒ Sandbox
Get a sandbox by ID.
51 52 53 54 |
# File 'lib/rexec/container.rb', line 51 def get(id) data = @client.request(:get, "/api/containers/#{id}") Sandbox.new(data) end |
#list ⇒ Array<Sandbox>
List all sandboxes.
40 41 42 43 44 45 |
# File 'lib/rexec/container.rb', line 40 def list data = @client.request(:get, "/api/containers") # API returns { "containers" => [...], "count" => N, "limit" => M } items = data.is_a?(Array) ? data : (data && data["containers"]) || [] items.map { |c| Sandbox.new(c) } end |
#start(id) ⇒ Object
Start a sandbox.
91 92 93 94 |
# File 'lib/rexec/container.rb', line 91 def start(id) @client.request(:post, "/api/containers/#{id}/start") nil end |
#stop(id) ⇒ Object
Stop a sandbox.
99 100 101 102 |
# File 'lib/rexec/container.rb', line 99 def stop(id) @client.request(:post, "/api/containers/#{id}/stop") nil end |