Sha256: 92eae1238e5df38fc059a308244a81fbe6935386bcda469d8e89145dd030ce61

Contents?: true

Size: 1.92 KB

Versions: 17

Compression:

Stored size: 1.92 KB

Contents

require 'fog/openstack/models/collection'
require 'fog/openstack/models/compute/server'

module Fog
  module Compute
    class OpenStack
      class Servers < Fog::OpenStack::Collection
        attribute :filters

        model Fog::Compute::OpenStack::Server

        def initialize(attributes)
          self.filters ||= {}
          super
        end

        def all(filters_arg = filters)
          filters = filters_arg
          data = service.list_servers_detail(filters)
          load_response(data, 'servers')
        end

        def summary(filters_arg = filters)
          filters = filters_arg
          data = service.list_servers(filters)
          load_response(data, 'servers')
        end

        # Creates a new server and populates ssh keys
        # @return [Fog::Compute::OpenStack::Server]
        # @raise [Fog::Compute::OpenStack::NotFound] - HTTP 404
        # @raise [Fog::Compute::OpenStack::BadRequest] - HTTP 400
        # @raise [Fog::Compute::OpenStack::InternalServerError] - HTTP 500
        # @raise [Fog::Compute::OpenStack::ServiceError]
        # @example
        #   service.servers.bootstrap :name => 'bootstrap-server',
        #                             :flavor_ref => service.flavors.first.id,
        #                             :image_ref => service.images.find {|img| img.name =~ /Ubuntu/}.id,
        #                             :public_key_path => '~/.ssh/fog_rsa.pub',
        #                             :private_key_path => '~/.ssh/fog_rsa'
        #
        def bootstrap(new_attributes = {})
          server = create(new_attributes)
          server.wait_for { ready? }
          server.setup(:password => server.password)
          server
        end

        def get(server_id)
          if server = service.get_server_details(server_id).body['server']
            new(server)
          end
        rescue Fog::Compute::OpenStack::NotFound
          nil
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
fog-openstack-0.1.10 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.9 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.8 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.7 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.6 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.5 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.4 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.3 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.2 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.1 lib/fog/openstack/models/compute/servers.rb
fog-openstack-0.1.0 lib/fog/openstack/models/compute/servers.rb
fog-1.37.0 lib/fog/openstack/models/compute/servers.rb
fog-1.36.0 lib/fog/openstack/models/compute/servers.rb
fog-1.35.0 lib/fog/openstack/models/compute/servers.rb
fog-2.0.0.pre.0 lib/fog/openstack/models/compute/servers.rb
fog-1.34.0 lib/fog/openstack/models/compute/servers.rb
fog-1.33.0 lib/fog/openstack/models/compute/servers.rb