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

aliases, attribute, attributes, #attributes, #inspect, #merge_attributes

Constructor Details

#initialize(attributes) ⇒ KeyPairs

Returns a new instance of KeyPairs.



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

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

Instance Method Details

#all(key_name = []) ⇒ Object



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

def all(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({
      :connection => connection,
      :key_pairs  => self
    }.merge!(key))
  end
  key_pairs
end

#create(attributes = {}) ⇒ Object



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

def create(attributes = {})
  bucket = new(attributes)
  bucket.save
  bucket
end

#get(key_name) ⇒ Object



39
40
41
42
43
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 39

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

#new(attributes = {}) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 45

def new(attributes = {})
  Fog::AWS::EC2::KeyPair.new(
    attributes.merge!(
      :connection => connection,
      :key_pairs  => self
    )
  )
end

#reloadObject



54
55
56
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 54

def reload
  all(key_name)
end