Sha256: 02b0d0c4f697b68f7e6bec3d0cb999dfb2255f3b3d25a29d86a18f1a35504b13

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 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={})
          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?
          status == '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 status
          @status ||= 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

4 entries across 4 versions & 1 rubygems

Version Path
fog-0.7.2 lib/fog/compute/models/voxel/server.rb
fog-0.7.1 lib/fog/compute/models/voxel/server.rb
fog-0.7.0 lib/fog/compute/models/voxel/server.rb
fog-0.6.0 lib/fog/compute/models/voxel/server.rb