2012-02-16 04:01:47 -05:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/openstack/models/compute/key_pair'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
2012-02-21 11:09:26 -05:00
|
|
|
class OpenStack
|
2012-02-16 04:01:47 -05:00
|
|
|
|
|
|
|
class KeyPairs < Fog::Collection
|
|
|
|
|
2012-02-21 11:09:26 -05:00
|
|
|
model Fog::Compute::OpenStack::KeyPair
|
2012-02-16 04:01:47 -05:00
|
|
|
|
|
|
|
def all
|
2012-02-21 11:09:26 -05:00
|
|
|
items = Array.new
|
2012-02-16 04:01:47 -05:00
|
|
|
connection.list_key_pairs.body['keypairs'].each do |kp|
|
2012-02-21 11:09:26 -05:00
|
|
|
items = items + kp.values
|
2012-02-16 04:01:47 -05:00
|
|
|
end
|
|
|
|
load(items)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(key_pair_name)
|
|
|
|
if key_pair_name
|
|
|
|
self.all.select {|kp| kp.name == key_pair_name}.first
|
|
|
|
end
|
2012-02-21 11:09:26 -05:00
|
|
|
rescue Fog::Compute::OpenStack::NotFound
|
2012-02-16 04:01:47 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-21 11:09:26 -05:00
|
|
|
end
|