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
32
33
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 20

def all(key_name = @key_name)
  data = connection.describe_key_pairs(key_name).body
  key_pairs = Fog::AWS::EC2::KeyPairs.new({
    :connection => connection,
    :key_name   => key_name
  }.merge!(attributes))
  data['keySet'].each do |key|
    key_pairs << Fog::AWS::EC2::KeyPair.new({
      :collection => key_pairs,
      :connection => connection
    }.merge!(key))
  end
  key_pairs
end

#get(key_name) ⇒ Object



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

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