Sha256: f9ed290d4aacdd747118a72349085b605a9112017d4e9ee25712eb95a73cec62

Contents?: true

Size: 1.77 KB

Versions: 108

Compression:

Stored size: 1.77 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 persisted?
          @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
          service.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 = service.linode_disk_create(server.id, "#{@name}_#{@type}", @type, @size).body['DATA']['DiskID']
          reload
        end

        def create_disk_from_image
          disk = service.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 = service.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

108 entries across 106 versions & 11 rubygems

Version Path
ns-fog-1.22.3 lib/fog/linode/models/compute/disk.rb
ns-fog-1.22.2 lib/fog/linode/models/compute/disk.rb
fog-1.22.1 lib/fog/linode/models/compute/disk.rb
fog-1.22.0 lib/fog/linode/models/compute/disk.rb
fog-1.21.0 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/linode/models/compute/disk.rb
fog-1.20.0 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/linode/models/compute/disk.rb
fog-1.19.0 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/linode/models/compute/disk.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/linode/models/compute/disk.rb