Sha256: b5edc62f46673a4c41e1165a291b7e0b9bd29e9227338cfc135a7cfc10ef28bc

Contents?: true

Size: 1.37 KB

Versions: 26

Compression:

Stored size: 1.37 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

26 entries across 26 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-1.21.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-1.20.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-1.19.0 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/rackspace/models/compute_v2/key_pairs.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/rackspace/models/compute_v2/key_pairs.rb