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 ⇒ Object
-
#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
A new instance of Client.
-
#instance_exists?(id) ⇒ Boolean
check if instance exists, given an id.
- #resource ⇒ Object
Constructor Details
#initialize(region, profile_name = "default", http_proxy = nil, retry_limit = nil, ssl_verify_peer = true) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kitchen/driver/aws/client.rb', line 31 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 ⇒ Object
81 82 83 |
# File 'lib/kitchen/driver/aws/client.rb', line 81 def client @client ||= ::Aws::EC2::Client.new end |
#create_instance(options) ⇒ Aws::EC2::Instance
create a new AWS EC2 instance
51 52 53 |
# File 'lib/kitchen/driver/aws/client.rb', line 51 def create_instance() resource.create_instances().first end |
#get_instance(id) ⇒ Aws::EC2::Instance
get an instance object given an id
58 59 60 |
# File 'lib/kitchen/driver/aws/client.rb', line 58 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
65 66 67 68 69 70 71 72 |
# File 'lib/kitchen/driver/aws/client.rb', line 65 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
77 78 79 |
# File 'lib/kitchen/driver/aws/client.rb', line 77 def instance_exists?(id) resource.instance(id).exists? end |
#resource ⇒ Object
85 86 87 |
# File 'lib/kitchen/driver/aws/client.rb', line 85 def resource @resource ||= ::Aws::EC2::Resource.new end |