Class: Kitchen::Driver::Aws::Client
- Inherits:
-
Object
- Object
- Kitchen::Driver::Aws::Client
- Defined in:
- lib/kitchen/driver/aws/client.rb
Overview
A class for creating and managing the EC2 client connection
Instance Method Summary collapse
-
#client ⇒ Aws::EC2::Client
The low-level EC2 client, for API calls with no resource equivalent.
-
#create_instance(options) ⇒ Aws::EC2::Instance
create a new AWS EC2 instance.
-
#get_instance(id) ⇒ Aws::EC2::Instance
get an instance object given an id.
-
#get_instance_from_spot_request(request_id) ⇒ Aws::EC2::Instance
get an instance object given a spot request ID.
-
#initialize(region, profile_name = "default", http_proxy = nil, retry_limit = nil, ssl_verify_peer = true) ⇒ Client
constructor
Configure the AWS SDK for this driver's connection settings.
-
#instance_exists?(id) ⇒ Boolean
check if instance exists, given an id.
-
#resource ⇒ Aws::EC2::Resource
The EC2 resource interface, for working with instances and images as objects rather than raw API responses.
Constructor Details
#initialize(region, profile_name = "default", http_proxy = nil, retry_limit = nil, ssl_verify_peer = true) ⇒ Client
Configure the AWS SDK for this driver's connection settings.
These settings are applied to the SDK's process-wide configuration rather than held on this object, so clients built later pick them up. A nil retry limit is omitted rather than written, so that the SDK's own default survives.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kitchen/driver/aws/client.rb', line 46 def initialize( region, profile_name = "default", http_proxy = nil, retry_limit = nil, ssl_verify_peer = true ) ::Aws.config.update( region:, profile: profile_name, http_proxy:, ssl_verify_peer: ) ::Aws.config.update(retry_limit:) unless retry_limit.nil? end |
Instance Method Details
#client ⇒ Aws::EC2::Client
The low-level EC2 client, for API calls with no resource equivalent.
99 100 101 |
# File 'lib/kitchen/driver/aws/client.rb', line 99 def client @client ||= ::Aws::EC2::Client.new end |
#create_instance(options) ⇒ Aws::EC2::Instance
create a new AWS EC2 instance
66 67 68 |
# File 'lib/kitchen/driver/aws/client.rb', line 66 def create_instance() resource.create_instances().first end |
#get_instance(id) ⇒ Aws::EC2::Instance
get an instance object given an id
73 74 75 |
# File 'lib/kitchen/driver/aws/client.rb', line 73 def get_instance(id) resource.instance(id) end |
#get_instance_from_spot_request(request_id) ⇒ Aws::EC2::Instance
get an instance object given a spot request ID
80 81 82 83 84 85 86 87 |
# File 'lib/kitchen/driver/aws/client.rb', line 80 def get_instance_from_spot_request(request_id) resource.instances( filters: [{ name: "spot-instance-request-id", values: [request_id], }] ).to_a[0] end |
#instance_exists?(id) ⇒ Boolean
check if instance exists, given an id
92 93 94 |
# File 'lib/kitchen/driver/aws/client.rb', line 92 def instance_exists?(id) resource.instance(id).exists? end |
#resource ⇒ Aws::EC2::Resource
The EC2 resource interface, for working with instances and images as objects rather than raw API responses.
107 108 109 |
# File 'lib/kitchen/driver/aws/client.rb', line 107 def resource @resource ||= ::Aws::EC2::Resource.new end |