Sha256: 63b37811c0dd9505b8748d83199b3403eafe2bd191dbbfd7cb8e0815aa4dbacf

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'json'
module Uricp::Strategy
  class PipedRbdGet
    include Uricp::Strategy::Common
    include Methadone::SH

    def appropriate?
      case from.scheme
      when 'rbd'
        return proposal unless sequence_complete? || snap_in_progress?
      end
      debug "#{self.class.name}: not appropriate"
      false
    end

    def command
      "rbd snap create --id #{rbd_id} '#{rbd_snap_target(from)}' && " \
      "rbd export --no-progress --id #{rbd_id} '#{rbd_snap_target(from)}' - |"
    end

    def proposal
      @proposed_options = options.dup
      @proposed_options['rbd_snapshot'] = rbd_snap_target(from)
      @proposed_options['from_uri'] = PIPE_URI
      @proposed_options.delete('cache')
      @proposed_options.delete('cache_name')
      self
    end

    RBD_SNAPSHOT = 'uricp_snap'.freeze

    def rbd_snap_target(uri)
      "#{rbd_target(uri)}@#{RBD_SNAPSHOT}"
    end

    def snap_in_progress?
      return false if dry_run?

      result = false
      sh "rbd snap ls --id #{rbd_id} --format json #{rbd_target(from)}" do |stdout|
        result = JSON.parse(stdout).any? { |x| x['name'] == RBD_SNAPSHOT }
      end
      result
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uricp-0.0.18 lib/uricp/strategy/piped_rbd_get.rb
uricp-0.0.17 lib/uricp/strategy/piped_rbd_get.rb