Sha256: f334e5a0784037617484530e8feca7e780695a2da70c1505cf949928b54dafb3

Contents?: true

Size: 1.72 KB

Versions: 7

Compression:

Stored size: 1.72 KB

Contents

require 'fog/model'

module Fog
  module Bluebox
    class Compute

      class BlockInstantiationError < StandardError; end

      class Server < Fog::Model

        identity :id

        attribute :memory
        attribute :storage
        attribute :hostname
        attribute :cpu
        attribute :ips
        attribute :status
        attribute :flavor_id
        # attribute :image_id

        attr_accessor :image_id
        attribute :template

        # Not reported by the API, but used at create time
        attr_accessor :password, :ssh_key, :user

        def destroy
          requires :id
          connection.destroy_block(@id)
          true
        end

        def flavor
          requires :flavor_id
          connection.flavors.get(@flavor_id)
        end

        def image
          requires :image_id
          connection.images.get(@image_id)
        end

        def ready?
          @status == 'running'
        end

        def reboot(type = 'SOFT')
          requires :id
          connection.reboot_block(@id, type)
          true
        end

        def save
          requires :flavor_id, :image_id
          options = if !@password && !@ssh_key
            raise(ArgumentError, "password or ssh_key is required for this operation")
          elsif @ssh_key
            {'ssh_public_key' => @ssh_key}
          elsif @password
            {'password' => @password}
          end
          if @user
            options['user'] = @user
          end
          data = connection.create_block(@flavor_id, @image_id, options)
          merge_attributes(data.body)
          true
        end

        private

        def product=(new_product)
          @flavor_id = new_product['id']
        end

      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fog-0.3.6 lib/fog/bluebox/models/compute/server.rb
fog-0.3.5 lib/fog/bluebox/models/compute/server.rb
fog-0.3.4 lib/fog/bluebox/models/compute/server.rb
fog-0.3.3 lib/fog/bluebox/models/compute/server.rb
fog-0.3.2 lib/fog/bluebox/models/compute/server.rb
fog-0.3.1 lib/fog/bluebox/models/compute/server.rb
fog-0.3.0 lib/fog/bluebox/models/compute/server.rb