Sha256: f64a4e78fa01fe2b09c1100cd597202acb727d44fd2808e3b3c80c6fcd24ef49

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require 'fog/core/model'

module Fog
  module Voxel
    class Compute

      class Server < Fog::Model

        identity :id

        attribute :name
        attribute :processing_cores
        attribute :image_id
        attribute :facility
        attribute :disk_size
        attribute :ip_assignments, :aliases => 'ipassignments'

        def initialize(attributes={})
          self.image_id ||= '55' # Ubuntu 10.04 LTS 64bit
          super
        end

        def destroy
          requires :id
          connection.voxcloud_delete(id)
          true
        end

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

        def ready?
          self.state == 'SUCCEEDED'
        end

        def private_ip_address
          ip_assignments.select {|ip_assignment| ip_assignment['type'] == 'internal'}.first
        end

        def public_ip_address
          ip_assignments.select {|ip_assignment| ip_assignment['type'] == 'external'}.first
        end

        def reboot
          requires :id
          connection.devices_power(id, :reboot)
          true
        end

        def state
          @state ||= connection.voxcloud_status(id).body['devices'].first['status']
        end

        def save
          raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
          requires :name, :image_id, :processing_cores, :facility, :disk_size

          data = connection.voxcloud_create({
            :disk_size => disk_size,
            :facility => facility,
            :hostname => name,
            :image_id => image_id,
            :processing_cores => processing_cores
          }).body

          merge_attributes(data['device'])

          true
        end

      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-0.8.2 lib/fog/compute/models/voxel/server.rb