Sha256: 92ea6292df8ddc3648a9b991920c13d978d90ba0ef81e8a50deff98a6e3ee87b

Contents?: true

Size: 1.84 KB

Versions: 29

Compression:

Stored size: 1.84 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

29 entries across 29 versions & 4 rubygems

Version Path
fog-1.37.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.36.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.35.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-2.0.0.pre.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.34.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.33.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.32.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.31.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.30.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.29.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.28.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.27.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.26.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.25.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
nsidc-fog-1.24.1 lib/fog/hp/models/block_storage_v2/snapshot.rb
fog-1.24.0 lib/fog/hp/models/block_storage_v2/snapshot.rb
ns-fog-1.22.11 lib/fog/hp/models/block_storage_v2/snapshot.rb
ns-fog-1.22.10 lib/fog/hp/models/block_storage_v2/snapshot.rb