Sha256: 4af4486fe1cd3c4c204e5e6a56291e9fec95b4d2711e117fa23c99f75f298503

Contents?: true

Size: 1.38 KB

Versions: 18

Compression:

Stored size: 1.38 KB

Contents

require 'fog/core/collection'
require 'fog/rackspace/models/compute_v2/key_pair'

module Fog
  module Compute
    class RackspaceV2

      class KeyPairs < Fog::Collection

        model Fog::Compute::RackspaceV2::KeyPair

        # 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]
        def all
          data = []
          service.list_keypairs.body['keypairs'].each do |kp|
            data << kp['keypair'] if kp['keypair']
          end
          load(data)
        end

        # Fetch keypair details
        # @param  [String] key_name: name of the key to request
        # @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)
            begin
                new(service.get_keypair(key_name).body['keypair'])
            rescue Fog::Compute::RackspaceV2::NotFound
                nil
            end
        end

      end
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
fog-maestrodev-1.18.0.20131125111730 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131125083406 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131123105121 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131122203507 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131121075022 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131118164830 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131115184302 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131114200144 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131112185232 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131111203459 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-1.18.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-1.17.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-1.16.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.15.0.20130927082724 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.15.0.20130829165835 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-1.15.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
gapinc-fog-1.14.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.14.0.20130806165225 lib/fog/rackspace/models/compute_v2/key_pairs.rb