1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/ec2/key_pairs.rb
2009-10-22 20:46:15 -07:00

64 lines
1.3 KiB
Ruby

module Fog
module AWS
class EC2
def key_pairs
Fog::AWS::EC2::KeyPairs.new(:connection => self)
end
class KeyPairs < Fog::Collection
attribute :key_name
def initialize(attributes)
@key_name ||= []
super
end
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
def create(attributes = {})
bucket = new(attributes)
bucket.save
bucket
end
def get(key_name)
if key_name
all(key_name).first
end
rescue Fog::Errors::BadRequest
nil
end
def new(attributes = {})
Fog::AWS::EC2::KeyPair.new(
attributes.merge!(
:connection => connection,
:key_pairs => self
)
)
end
def reload
all(key_name)
end
end
end
end
end