Class: Fog::AWS::EC2::KeyPairs

Inherits:
Collection show all
Defined in:
lib/fog/aws/models/ec2/key_pairs.rb

Instance Method Summary collapse

Methods inherited from Collection

#_dump, _load, aliases, attribute, attributes, #attributes, #connection, #connection=, #create, #inspect, #merge_attributes, model, #model, #new, #reload

Constructor Details

#initialize(attributes) ⇒ KeyPairs

Returns a new instance of KeyPairs.



15
16
17
18
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 15

def initialize(attributes)
  @key_name ||= []
  super
end

Instance Method Details

#all(key_name = @key_name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 20

def all(key_name = @key_name)
  @key_name = key_name
  if @loaded
    clear
  end
  @loaded = true
  data = connection.describe_key_pairs(key_name).body
  data['keySet'].each do |key|
    self << new(key)
  end
  self
end

#get(key_name) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 33

def get(key_name)
  if key_name
    all(key_name).first
  end
rescue Excon::Errors::BadRequest
  nil
end