Sha256: f92d3b56e78e1e6b62c1302c3f20b75c985ea5d186dfebdc6e4ef60806970c6c

Contents?: true

Size: 1.85 KB

Versions: 37

Compression:

Stored size: 1.85 KB

Contents

require 'fog/core/model'

module Fog
  module HP
    class BlockStorageV2

      class Snapshot < Fog::Model

        identity  :id

        attribute :name,                 :aliases => 'display_name'
        attribute :description,          :aliases => 'display_description'
        attribute :size
        attribute :status
        attribute :created_at
        attribute :volume_id
        attribute :metadata

        def initialize(attributes = {})
          # assign these attributes first to prevent race condition with persisted?
          self.force = attributes.delete(:force)   # force snapshotting of attached volumes
          super
        end

        def destroy
          requires :id
          service.delete_snapshot(id)
          true
        end

        def force=(new_force)
          @force = new_force
        end

        def ready?
          self.status == 'available'
        end

        def save
          identity ? update : create
        end

        private

        def create
          requires :volume_id
          options = {
            'display_name'        => name,
            'display_description' => description,
            'force'               => @force,
            'metadata'            => metadata
          }
          options = options.reject {|_, value| value.nil?}
          data = service.create_snapshot(volume_id, options)
          merge_attributes(data.body['snapshot'])
          true
        end

        def update
          requires :id
          options = {
            'display_name'        => name,
            'display_description' => description,
            'metadata'            => metadata
          }
          options = options.reject {|_, value| value.nil?}
          data = service.update_snapshot(id, options)
          merge_attributes(data.body['snapshot'])
          true
        end

      end

    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.21.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.20.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.19.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/hp/models/block_storage_v2/snapshot.rb