Class: Lemans::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/lemans/environment.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. The name-to-class registry lives on the Environments module.

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: nil) ⇒ Environment

labels is backend-agnostic trial metadata (task, trial id, phase); every backend receives it even if it has nowhere to put it.



20
21
22
23
24
25
26
27
# File 'lib/lemans/environment.rb', line 20

def initialize(image:, resources:, network:, env: {}, labels: {}, build_timeout: nil)
  @image = image
  @resources = resources
  @network = network
  @env = env
  @labels = labels
  @build_timeout = build_timeout
end

Instance Attribute Details

#build_timeoutObject (readonly)

Returns the value of attribute build_timeout.



16
17
18
# File 'lib/lemans/environment.rb', line 16

def build_timeout
  @build_timeout
end

#envObject (readonly)

Returns the value of attribute env.



16
17
18
# File 'lib/lemans/environment.rb', line 16

def env
  @env
end

#imageObject (readonly)

Returns the value of attribute image.



16
17
18
# File 'lib/lemans/environment.rb', line 16

def image
  @image
end

#labelsObject (readonly)

Returns the value of attribute labels.



16
17
18
# File 'lib/lemans/environment.rb', line 16

def labels
  @labels
end

#networkObject (readonly)

Returns the value of attribute network.



16
17
18
# File 'lib/lemans/environment.rb', line 16

def network
  @network
end

#resourcesObject (readonly)

Returns the value of attribute resources.



16
17
18
# File 'lib/lemans/environment.rb', line 16

def resources
  @resources
end

Instance Method Details

#download(remote_path, local_path) ⇒ Object

Raises:

  • (NotImplementedError)


37
# File 'lib/lemans/environment.rb', line 37

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

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

Raises:

  • (NotImplementedError)


33
# File 'lib/lemans/environment.rb', line 33

def exec(command, timeout: nil, env: {}) = raise(NotImplementedError)

#exec!(command) ⇒ Object



47
48
49
50
51
52
# File 'lib/lemans/environment.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

#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)


31
# File 'lib/lemans/environment.rb', line 31

def start = raise(NotImplementedError)

#stopObject

Raises:

  • (NotImplementedError)


45
# File 'lib/lemans/environment.rb', line 45

def stop = raise(NotImplementedError)

#switch_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/environment.rb', line 41

def switch_network_policy!(policy)
  raise NotImplementedError
end

#upload(local_path, remote_path) ⇒ Object

Raises:

  • (NotImplementedError)


35
# File 'lib/lemans/environment.rb', line 35

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