Class: Lemans::Environments::Base

Inherits:
Object
  • Object
show all
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

Daytona

Defined Under Namespace

Classes: ExecResult

Constant Summary collapse

DEFAULT_TIMEOUT =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

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_secObject (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

#envObject (readonly)

Returns the value of attribute env.



14
15
16
# File 'lib/lemans/environments/base.rb', line 14

def env
  @env
end

#imageObject (readonly)

Returns the value of attribute image.



14
15
16
# File 'lib/lemans/environments/base.rb', line 14

def image
  @image
end

#labelsObject (readonly)

Returns the value of attribute labels.



14
15
16
# File 'lib/lemans/environments/base.rb', line 14

def labels
  @labels
end

#networkObject (readonly)

Returns the value of attribute network.



14
15
16
# File 'lib/lemans/environments/base.rb', line 14

def network
  @network
end

#resourcesObject (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

Raises:

  • (NotImplementedError)


37
# File 'lib/lemans/environments/base.rb', line 37

def download(remote_path, local_path) = raise(NotImplementedError)

#exec(command, timeout: nil, env: {}) ⇒ Object

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/lemans/environments/base.rb', line 41

def network_policy=(policy)
  raise NotImplementedError
end

#startObject

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.

Raises:

  • (NotImplementedError)


29
# File 'lib/lemans/environments/base.rb', line 29

def start = raise(NotImplementedError)

#stopObject

Raises:

  • (NotImplementedError)


45
# File 'lib/lemans/environments/base.rb', line 45

def stop = raise(NotImplementedError)

#upload(local_path, remote_path) ⇒ Object

Raises:

  • (NotImplementedError)


35
# File 'lib/lemans/environments/base.rb', line 35

def upload(local_path, remote_path) = raise(NotImplementedError)