Class: Lambda::MicroVMs::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda/microvms/image.rb

Overview

Represents a Lambda MicroVM image/snapshot artifact.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, arn:, data: nil) ⇒ Image

Returns a new instance of Image.



14
15
16
17
18
# File 'lib/lambda/microvms/image.rb', line 14

def initialize(client:, arn:, data: nil)
  @client = client
  @arn = arn
  @data = data
end

Instance Attribute Details

#arnObject (readonly)

Returns the value of attribute arn.



7
8
9
# File 'lib/lambda/microvms/image.rb', line 7

def arn
  @arn
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/lambda/microvms/image.rb', line 7

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/lambda/microvms/image.rb', line 7

def data
  @data
end

Class Method Details

.from_response(client:, response:) ⇒ Object



9
10
11
12
# File 'lib/lambda/microvms/image.rb', line 9

def self.from_response(client:, response:)
  arn = Util.extract(response, :image_arn, :microvm_image_arn, :arn)
  new(client: client, arn: arn, data: response)
end

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/lambda/microvms/image.rb', line 30

def ready?
  %i[ready available active].include?(state)
end

#refreshObject



20
21
22
23
24
# File 'lib/lambda/microvms/image.rb', line 20

def refresh
  fresh = client.get_image(image_arn: arn)
  @data = fresh.data
  self
end

#run(role_arn:, payload: nil, **params) ⇒ Object



41
42
43
44
45
# File 'lib/lambda/microvms/image.rb', line 41

def run(role_arn:, payload: nil, **params)
  request = params.merge(image_arn: arn, role_arn: role_arn)
  request[:payload] = payload if payload
  client.run(**request)
end

#stateObject



26
27
28
# File 'lib/lambda/microvms/image.rb', line 26

def state
  Util.normalize_state(Util.extract(@data, :state, :status, :image_state))
end

#wait_until_ready(delay: Waiter::DEFAULT_DELAY, timeout: Waiter::DEFAULT_TIMEOUT) ⇒ Object



34
35
36
37
38
39
# File 'lib/lambda/microvms/image.rb', line 34

def wait_until_ready(delay: Waiter::DEFAULT_DELAY, timeout: Waiter::DEFAULT_TIMEOUT)
  Waiter.new(delay: delay, timeout: timeout).wait(message: "image #{arn} to be ready") do
    refresh.ready?
  end
  self
end