Sha256: 5ea7f8bc5a52622ee7e1175510b38ba7e7837c1b1ad40f90633d9a505ff788b3

Contents?: true

Size: 1019 Bytes

Versions: 7

Compression:

Stored size: 1019 Bytes

Contents

require 'fog/core/collection'
require 'fog/compute/models/linode/disk'

module Fog
  module Compute
    class Linode
      class Disks < Fog::Collection
        model Fog::Compute::Linode::Disk
        attribute :server

        def all
          requires :server
          load disks(server.id)
        end

        def get(id)
          requires :server
          new disks(server.id, id).first
        rescue Fog::Linode::Compute::NotFound
          nil
        end

        def new(attributes = {})
          requires :server
          super({ :server => server }.merge!(attributes))
        end

        private
        def disks(linode_id, id=nil)
          connection.linode_disk_list(linode_id, id).body['DATA'].map { |disk| map_disk disk }
        end
        
        def map_disk(disk)
          disk = disk.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v  }
          disk.merge! :id => disk[:diskid], :name => disk[:label], :server_id => disk[:linodeid]
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
brightbox-cli-0.13.1 lib/brightbox-cli/vendor/fog/lib/fog/compute/models/linode/disks.rb
brightbox-cli-0.13.0 lib/brightbox-cli/vendor/fog/lib/fog/compute/models/linode/disks.rb
fog-0.11.0 lib/fog/compute/models/linode/disks.rb
fog-0.10.0 lib/fog/compute/models/linode/disks.rb
fog4encbs-0.9.0.1 lib/fog/compute/models/linode/disks.rb
fog4encbs-0.9.0 lib/fog/compute/models/linode/disks.rb
fog-0.9.0 lib/fog/compute/models/linode/disks.rb