Class: Lemans::Environments::Base
- Inherits:
-
Object
- Object
- Lemans::Environments::Base
- Defined in:
- lib/lemans/environments/base.rb
Overview
What every backend must do, and nothing more: a narrow contract is what makes a second backend a day of work instead of a subsystem.
Direct Known Subclasses
Defined Under Namespace
Classes: ExecResult
Constant Summary collapse
- DEFAULT_TIMEOUT =
60
Instance Attribute Summary collapse
-
#build_timeout_sec ⇒ Object
readonly
Returns the value of attribute build_timeout_sec.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #download(remote_path, local_path) ⇒ Object
- #exec(command, timeout: nil, env: {}) ⇒ Object
- #exec!(command) ⇒ Object
-
#initialize(image:, resources:, network:, env: {}, labels: {}, build_timeout_sec: nil) ⇒ Base
constructor
labelsis backend-agnostic trial metadata (task, trial id, phase); every backend receives it even if it has nowhere to put it. -
#network_policy=(policy) ⇒ Object
Phases change what the sandbox may reach: setup pulls packages, the agent reaches the model API and nothing else, the verifier reaches nothing.
-
#start ⇒ Object
Build the image and bring the sandbox up under the network policy it was constructed with; a backend that cannot honour the policy must raise.
- #stop ⇒ Object
- #upload(local_path, remote_path) ⇒ Object
Constructor Details
#initialize(image:, resources:, network:, env: {}, labels: {}, build_timeout_sec: nil) ⇒ Base
labels is backend-agnostic trial metadata (task, trial id, phase);
every backend receives it even if it has nowhere to put it.
18 19 20 21 22 23 24 25 |
# File 'lib/lemans/environments/base.rb', line 18 def initialize(image:, resources:, network:, env: {}, labels: {}, build_timeout_sec: nil) @image = image @resources = resources @network = network @env = env @labels = labels @build_timeout_sec = build_timeout_sec end |
Instance Attribute Details
#build_timeout_sec ⇒ Object (readonly)
Returns the value of attribute build_timeout_sec.
14 15 16 |
# File 'lib/lemans/environments/base.rb', line 14 def build_timeout_sec @build_timeout_sec end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
14 15 16 |
# File 'lib/lemans/environments/base.rb', line 14 def env @env end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
14 15 16 |
# File 'lib/lemans/environments/base.rb', line 14 def image @image end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
14 15 16 |
# File 'lib/lemans/environments/base.rb', line 14 def labels @labels end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
14 15 16 |
# File 'lib/lemans/environments/base.rb', line 14 def network @network end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
14 15 16 |
# File 'lib/lemans/environments/base.rb', line 14 def resources @resources end |
Instance Method Details
#download(remote_path, local_path) ⇒ Object
37 |
# File 'lib/lemans/environments/base.rb', line 37 def download(remote_path, local_path) = raise(NotImplementedError) |
#exec(command, timeout: nil, env: {}) ⇒ Object
33 |
# File 'lib/lemans/environments/base.rb', line 33 def exec(command, timeout: nil, env: {}) = raise(NotImplementedError) |
#exec!(command) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/lemans/environments/base.rb', line 47 def exec!(command, **) result = exec(command, **) return result if result.success? raise InfrastructureError, "#{command} exited #{result.exit_code}: #{result.output.to_s[0, 2000]}" end |
#network_policy=(policy) ⇒ Object
Phases change what the sandbox may reach: setup pulls packages, the agent reaches the model API and nothing else, the verifier reaches nothing.
41 42 43 |
# File 'lib/lemans/environments/base.rb', line 41 def network_policy=(policy) raise NotImplementedError end |
#start ⇒ Object
Build the image and bring the sandbox up under the network policy it was constructed with; a backend that cannot honour the policy must raise.
29 |
# File 'lib/lemans/environments/base.rb', line 29 def start = raise(NotImplementedError) |
#stop ⇒ Object
45 |
# File 'lib/lemans/environments/base.rb', line 45 def stop = raise(NotImplementedError) |
#upload(local_path, remote_path) ⇒ Object
35 |
# File 'lib/lemans/environments/base.rb', line 35 def upload(local_path, remote_path) = raise(NotImplementedError) |