2013-07-17 03:18:27 -04:00
|
|
|
require 'fog/core/collection'
|
2013-07-31 15:12:43 -04:00
|
|
|
require 'fog/rackspace/models/compute_v2/key_pair'
|
2013-07-17 03:18:27 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
|
2013-07-31 15:12:43 -04:00
|
|
|
class KeyPairs < Fog::Collection
|
2013-07-17 03:18:27 -04:00
|
|
|
|
2013-07-31 15:12:43 -04:00
|
|
|
model Fog::Compute::RackspaceV2::KeyPair
|
2013-07-17 03:18:27 -04:00
|
|
|
|
2013-07-26 10:04:29 -04:00
|
|
|
# Fetch the list of known keypairs
|
|
|
|
# @return [Fog::Compute::RackspaceV2::Keypairs] the retreived keypairs
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
2013-07-17 03:18:27 -04:00
|
|
|
def all
|
|
|
|
data = []
|
|
|
|
service.list_keypairs.body['keypairs'].each do |kp|
|
|
|
|
data << kp['keypair'] if kp['keypair']
|
|
|
|
end
|
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2013-07-26 10:04:29 -04:00
|
|
|
# Fetch keypair details
|
2013-11-22 11:42:43 -05:00
|
|
|
# @param [String] key_name name of the key to request
|
2013-07-26 10:04:29 -04:00
|
|
|
# @return [Fog::Compute::RackspaceV2::Keypair] the requested keypair or 'nil' when not found
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
|
|
|
def get(key_name)
|
2013-07-26 09:00:45 -04:00
|
|
|
begin
|
2013-07-26 10:04:29 -04:00
|
|
|
new(service.get_keypair(key_name).body['keypair'])
|
2013-07-26 09:00:45 -04:00
|
|
|
rescue Fog::Compute::RackspaceV2::NotFound
|
|
|
|
nil
|
|
|
|
end
|
2013-07-17 03:18:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|