Class: Kitchen::Driver::Aws::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/driver/aws/client.rb

Overview

A class for creating and managing the EC2 client connection

Author:

Instance Method Summary collapse

Constructor Details

#initialize(region, profile_name = "default", http_proxy = nil, retry_limit = nil, ssl_verify_peer = true) ⇒ Client

Returns a new instance of Client.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kitchen/driver/aws/client.rb', line 35

def initialize(
  region,
  profile_name = "default",
  http_proxy = nil,
  retry_limit = nil,
  ssl_verify_peer = true
)
  ::Aws.config.update(
    region: region,
    profile: profile_name,
    http_proxy: http_proxy,
    ssl_verify_peer: ssl_verify_peer
  )
  ::Aws.config.update(retry_limit: retry_limit) unless retry_limit.nil?
end

Instance Method Details

#clientObject



78
79
80
# File 'lib/kitchen/driver/aws/client.rb', line 78

def client
  @client ||= ::Aws::EC2::Client.new
end

#create_instance(options) ⇒ Aws::EC2::Instance

create a new AWS EC2 instance

Parameters:

  • options (Hash)

    has of instance options

Returns:

  • (Aws::EC2::Instance)

See Also:



55
56
57
# File 'lib/kitchen/driver/aws/client.rb', line 55

def create_instance(options)
  resource.create_instances(options).first
end

#get_instance(id) ⇒ Aws::EC2::Instance

get an instance object given an id

Parameters:

  • id (String)

    aws instance id

Returns:

  • (Aws::EC2::Instance)


62
63
64
# File 'lib/kitchen/driver/aws/client.rb', line 62

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

Parameters:

  • request_id (String)

    aws spot instance id

Returns:

  • (Aws::EC2::Instance)


69
70
71
72
73
74
75
76
# File 'lib/kitchen/driver/aws/client.rb', line 69

def get_instance_from_spot_request(request_id)
  resource.instances(
    filters: [{
      name: "spot-instance-request-id",
      values: [request_id],
    }]
  ).to_a[0]
end

#resourceObject



82
83
84
# File 'lib/kitchen/driver/aws/client.rb', line 82

def resource
  @resource ||= ::Aws::EC2::Resource.new
end