Class: Lambda::MicroVMs::Client
- Inherits:
-
Object
- Object
- Lambda::MicroVMs::Client
- Defined in:
- lib/lambda/microvms/client.rb
Overview
Ruby wrapper over Aws::Lambda::Client for Lambda MicroVM lifecycle operations.
Constant Summary collapse
- REQUIRED_OPERATIONS =
SDK methods this wrapper expects from Aws::Lambda::Client.
Adapters::MicroVMSdk::REQUIRED_OPERATIONS
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#sdk ⇒ Object
readonly
Returns the value of attribute sdk.
Class Method Summary collapse
-
.sdk_contract_supported?(sdk = nil) ⇒ Boolean
Check whether the given SDK client exposes all MicroVM operations.
-
.unsupported_operations(sdk = nil) ⇒ Array<Symbol>
Return wrapper operations missing from the given SDK client.
Instance Method Summary collapse
-
#call_sdk(operation, **params) ⇒ Object
Dispatch a supported operation to the underlying SDK client.
-
#create_auth_token(**params) ⇒ Object
(also: #create_microvm_auth_token)
Create an auth token for direct MicroVM endpoint access.
-
#create_image(**params) ⇒ Image
Create a MicroVM image through the Lambda SDK.
-
#delete_image(**params) ⇒ Object
Delete a MicroVM image.
-
#get_image(**params) ⇒ Image
Fetch a MicroVM image and wrap the SDK response.
-
#get_microvm(**params) ⇒ MicroVM
Fetch a MicroVM and wrap the SDK response.
-
#image(arn) ⇒ Image
Build an image resource wrapper without fetching it.
-
#initialize(region: nil, profile: nil, sdk: nil, adapter: nil) ⇒ Client
constructor
A new instance of Client.
-
#list_microvms(**params) ⇒ Object
List MicroVMs using the underlying Lambda SDK client.
-
#microvm(id_or_arn) ⇒ MicroVM
Build a MicroVM resource wrapper without fetching it.
-
#resume_microvm(**params) ⇒ Object
Resume a suspended MicroVM.
-
#run(**params) ⇒ MicroVM
(also: #run_microvm)
Run a MicroVM from an image.
-
#suspend_microvm(**params) ⇒ Object
Suspend a MicroVM.
-
#terminate_microvm(**params) ⇒ Object
Terminate a MicroVM.
Constructor Details
#initialize(region: nil, profile: nil, sdk: nil, adapter: nil) ⇒ Client
Returns a new instance of Client.
18 19 20 21 |
# File 'lib/lambda/microvms/client.rb', line 18 def initialize(region: nil, profile: nil, sdk: nil, adapter: nil, **) @sdk = sdk || build_sdk(region: region, profile: profile, **) @adapter = adapter || Adapters::MicroVMSdk.new(@sdk) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
16 17 18 |
# File 'lib/lambda/microvms/client.rb', line 16 def adapter @adapter end |
#sdk ⇒ Object (readonly)
Returns the value of attribute sdk.
16 17 18 |
# File 'lib/lambda/microvms/client.rb', line 16 def sdk @sdk end |
Class Method Details
.sdk_contract_supported?(sdk = nil) ⇒ Boolean
Check whether the given SDK client exposes all MicroVM operations.
38 39 40 |
# File 'lib/lambda/microvms/client.rb', line 38 def self.sdk_contract_supported?(sdk = nil) unsupported_operations(sdk).empty? end |
.unsupported_operations(sdk = nil) ⇒ Array<Symbol>
Return wrapper operations missing from the given SDK client.
27 28 29 30 31 32 |
# File 'lib/lambda/microvms/client.rb', line 27 def self.unsupported_operations(sdk = nil) sdk ||= Aws::Lambda::Client.new(stub_responses: true) if defined?(Aws::Lambda::Client) return REQUIRED_OPERATIONS unless sdk Adapters::MicroVMSdk.new(sdk).unsupported_operations end |
Instance Method Details
#call_sdk(operation, **params) ⇒ Object
Dispatch a supported operation to the underlying SDK client.
150 151 152 |
# File 'lib/lambda/microvms/client.rb', line 150 def call_sdk(operation, **params) adapter.call(operation, **params) end |
#create_auth_token(**params) ⇒ Object Also known as: create_microvm_auth_token
Create an auth token for direct MicroVM endpoint access.
139 140 141 |
# File 'lib/lambda/microvms/client.rb', line 139 def create_auth_token(**params) call_sdk(:create_microvm_auth_token, **params) end |
#create_image(**params) ⇒ Image
Create a MicroVM image through the Lambda SDK.
62 63 64 65 |
# File 'lib/lambda/microvms/client.rb', line 62 def create_image(**params) response = call_sdk(:create_microvm_image, **params) Image.from_response(client: self, response: response) end |
#delete_image(**params) ⇒ Object
Delete a MicroVM image.
80 81 82 |
# File 'lib/lambda/microvms/client.rb', line 80 def delete_image(**params) call_sdk(:delete_microvm_image, **params) end |
#get_image(**params) ⇒ Image
Fetch a MicroVM image and wrap the SDK response.
71 72 73 74 |
# File 'lib/lambda/microvms/client.rb', line 71 def get_image(**params) response = call_sdk(:get_microvm_image, **params) Image.from_response(client: self, response: response) end |
#get_microvm(**params) ⇒ MicroVM
Fetch a MicroVM and wrap the SDK response.
98 99 100 101 |
# File 'lib/lambda/microvms/client.rb', line 98 def get_microvm(**params) response = call_sdk(:get_microvm, **params) MicroVM.from_response(client: self, response: response) end |
#image(arn) ⇒ Image
Build an image resource wrapper without fetching it.
46 47 48 |
# File 'lib/lambda/microvms/client.rb', line 46 def image(arn) Image.new(client: self, arn: arn) end |
#list_microvms(**params) ⇒ Object
List MicroVMs using the underlying Lambda SDK client.
107 108 109 |
# File 'lib/lambda/microvms/client.rb', line 107 def list_microvms(**params) call_sdk(:list_microvms, **params) end |
#microvm(id_or_arn) ⇒ MicroVM
Build a MicroVM resource wrapper without fetching it.
54 55 56 |
# File 'lib/lambda/microvms/client.rb', line 54 def microvm(id_or_arn) MicroVM.new(client: self, id: id_or_arn) end |
#resume_microvm(**params) ⇒ Object
Resume a suspended MicroVM.
123 124 125 |
# File 'lib/lambda/microvms/client.rb', line 123 def resume_microvm(**params) call_sdk(:resume_microvm, **params) end |
#run(**params) ⇒ MicroVM Also known as: run_microvm
Run a MicroVM from an image.
88 89 90 91 |
# File 'lib/lambda/microvms/client.rb', line 88 def run(**params) response = call_sdk(:run_microvm, **params) MicroVM.from_response(client: self, response: response) end |
#suspend_microvm(**params) ⇒ Object
Suspend a MicroVM.
115 116 117 |
# File 'lib/lambda/microvms/client.rb', line 115 def suspend_microvm(**params) call_sdk(:suspend_microvm, **params) end |
#terminate_microvm(**params) ⇒ Object
Terminate a MicroVM.
131 132 133 |
# File 'lib/lambda/microvms/client.rb', line 131 def terminate_microvm(**params) call_sdk(:terminate_microvm, **params) end |