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
Instance Method Summary collapse
-
#initialize(client:, arn:, data: nil) ⇒ Image
constructor
A new instance of Image.
- #ready? ⇒ Boolean
- #refresh ⇒ Object
- #run(role_arn:, payload: nil, **params) ⇒ Object
- #state ⇒ Object
- #wait_until_ready(delay: Waiter::DEFAULT_DELAY, timeout: Waiter::DEFAULT_TIMEOUT) ⇒ Object
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
#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
Instance Method Details
#ready? ⇒ Boolean
30 31 32 |
# File 'lib/lambda/microvms/image.rb', line 30 def ready? %i[ready available active].include?(state) end |
#refresh ⇒ Object
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 |
#state ⇒ Object
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 |