Class: Lambda::MicroVMs::Image
- Inherits:
-
Object
- Object
- Lambda::MicroVMs::Image
- Defined in:
- lib/lambda/microvms/image.rb
Overview
Represents a Lambda MicroVM image/snapshot artifact.
Instance Attribute Summary collapse
-
#arn ⇒ Object
readonly
Returns the value of attribute arn.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.from_response(client:, response:) ⇒ Image
Build an image resource from an SDK response.
Instance Method Summary collapse
-
#initialize(client:, arn:, data: nil) ⇒ Image
constructor
A new instance of Image.
- #ready? ⇒ Boolean
-
#refresh ⇒ self
Refresh image data from the service.
-
#run(role_arn:, payload: nil, **params) ⇒ MicroVM
Run a MicroVM from this image.
-
#state ⇒ Symbol
Current normalized image state.
-
#wait_until_ready(delay: Waiter::DEFAULT_DELAY, timeout: Waiter::DEFAULT_TIMEOUT) ⇒ self
Wait until the image reaches a ready-like state.
Constructor Details
#initialize(client:, arn:, data: nil) ⇒ Image
Returns a new instance of Image.
19 20 21 22 23 |
# File 'lib/lambda/microvms/image.rb', line 19 def initialize(client:, arn:, data: nil) @client = client @arn = arn @data = data end |
Instance Attribute Details
#arn ⇒ Object (readonly)
Returns the value of attribute arn.
7 8 9 |
# File 'lib/lambda/microvms/image.rb', line 7 def arn @arn end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/lambda/microvms/image.rb', line 7 def client @client end |
#data ⇒ Object (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:) ⇒ Image
Build an image resource from an SDK response.
14 15 16 17 |
# File 'lib/lambda/microvms/image.rb', line 14 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
41 42 43 |
# File 'lib/lambda/microvms/image.rb', line 41 def ready? %i[ready available active].include?(state) end |
#refresh ⇒ self
Refresh image data from the service.
28 29 30 31 32 |
# File 'lib/lambda/microvms/image.rb', line 28 def refresh fresh = client.get_image(image_arn: arn) @data = fresh.data self end |
#run(role_arn:, payload: nil, **params) ⇒ MicroVM
Run a MicroVM from this image.
63 64 65 66 67 |
# File 'lib/lambda/microvms/image.rb', line 63 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 |
#state ⇒ Symbol
Current normalized image state.
37 38 39 |
# File 'lib/lambda/microvms/image.rb', line 37 def state Util.normalize_state(Util.extract(@data, :state, :status, :image_state)) end |
#wait_until_ready(delay: Waiter::DEFAULT_DELAY, timeout: Waiter::DEFAULT_TIMEOUT) ⇒ self
Wait until the image reaches a ready-like state.
50 51 52 53 54 55 |
# File 'lib/lambda/microvms/image.rb', line 50 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 |