Sha256: 9150d45a2e04aaac283a8123ebd17ac22278f91ca283c4cd93f7c1ff6714c1c8

Contents?: true

Size: 1.8 KB

Versions: 45

Compression:

Stored size: 1.8 KB

Contents

require 'fog/core/model'

module Fog
  module Compute
    class Linode
      class Disk < Fog::Model
        identity :id
        attribute :name
        attribute :type

        def save
          requires :server
          raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
          @type, @image, @stack_script, @name, @password, @size =
            attributes.values_at :type, :image, :stack_script, :name, :password, :size
          create_disk
        end        

        def destroy
          requires :identity, :server
          connection.linode_disk_delete server.id, id
        end

        def server
          @server
        end

        private
        def server=(server)
          @server = server
        end

        def create_disk
          case
          when @image && @stack_script then create_disk_from_stack_script
          when @image then create_disk_from_image
          when @type then create_disk_type
          else raise 'disk cannot be created'
          end
        end

        def create_disk_type
          self.id = connection.linode_disk_create(server.id, "#{@name}_#{@type}", @type, @size).body['DATA']['DiskID']
          reload
        end

        def create_disk_from_image
          disk = connection.linode_disk_createfromdistribution server.id, @image.id, "#{@name}_main", @size, @password
          self.id = disk.body['DATA']['DiskID']
          reload
        end        

        def create_disk_from_stack_script
          disk = connection.linode_disk_createfromstackscript(server.id, @stack_script.id, @image.id,
                                                              "#{@name}_main", @size, @password, @stack_script.options)
          self.id = disk.body['DATA']['DiskID']
          reload
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 14 rubygems

Version Path
fog-nirvanix-1.8.2 lib/fog/linode/models/compute/disk.rb
fog-nirvanix-1.8.1 lib/fog/linode/models/compute/disk.rb
fog-parser-fix-1.6.1 lib/fog/linode/models/compute/disk.rb
fog-test-again-1.6.0 lib/fog/linode/models/compute/disk.rb
fog-parser-fix-1.6.0 lib/fog/linode/models/compute/disk.rb
ey-vendored-backup-3.0.27 vendor/gems/fog/lib/fog/linode/models/compute/disk.rb
fog-sgonyea-1.8.1 lib/fog/linode/models/compute/disk.rb
fog-1.8.0 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/linode/models/compute/disk.rb
fog-1.7.0 lib/fog/linode/models/compute/disk.rb
fog-1.6.0 lib/fog/linode/models/compute/disk.rb
fog-1.5.0 lib/fog/linode/models/compute/disk.rb
fog-1.4.0 lib/fog/linode/models/compute/disk.rb
brightbox-cli-0.18.1 lib/brightbox-cli/vendor/fog/lib/fog/linode/models/compute/disk.rb
michiels-fog-1.3.1 lib/fog/linode/models/compute/disk.rb
ftl-0.2.0 vendor/bundle/gems/fog-1.3.1/lib/fog/linode/models/compute/disk.rb
brightbox-cli-0.18.0 lib/brightbox-cli/vendor/fog/lib/fog/linode/models/compute/disk.rb
fog-1.3.1 lib/fog/linode/models/compute/disk.rb
fog-1.3.0 lib/fog/linode/models/compute/disk.rb
brightbox-cli-0.17.5 lib/brightbox-cli/vendor/fog/lib/fog/linode/models/compute/disk.rb