module Uricp::Strategy::Common
Constants
- PIPE_URI
Attributes
proposed_options[R]
Public Class Methods
new(options)
click to toggle source
# File lib/uricp/strategy/common.rb, line 6 def initialize(options) @options = options debug "#{self.class.name}: options are #{options.inspect}" end
Public Instance Methods
all_local_files?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 20 def all_local_files? !sequence_complete? && file_source? && to.scheme == 'file' end
always_write_sparse?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 36 def always_write_sparse? options['force'] end
compression_required?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 24 def compression_required? options['compress'] end
conversion_required?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 32 def conversion_required? options['target-format'] end
dry_run?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 73 def dry_run? options['dry-run'] end
encoding(io)
click to toggle source
# File lib/uricp/strategy/common.rb, line 48 def encoding(io) magic = io.read(4).to_s if lz4?(magic) :lz4 elsif qcow2?(magic) version = io.read(4) case version.unpack('N') when [2] :qcow2 when [3] :qcow3 else :qcow2un end else :raw end end
file_source?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 85 def file_source? from.scheme == 'file' end
format_change?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 67 def format_change? conversion_required? && ( options['source-format'] != options['target-format'] ) end
get_temp_filename(base_dir)
click to toggle source
# File lib/uricp/strategy/common.rb, line 95 def get_temp_filename(base_dir) t = Time.now.strftime('%Y%m%d') File.join(base_dir, "uricp-#{t}-#{$$}-#{rand(0x100000000).to_s(36)}") end
lz4?(magic)
click to toggle source
# File lib/uricp/strategy/common.rb, line 40 def lz4?(magic) magic.unpack('V') == [0x184D2204] end
lz4_source?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 77 def lz4_source? options['source-format'] == :lz4 end
proposed_path()
click to toggle source
# File lib/uricp/strategy/common.rb, line 100 def proposed_path proposed_options['from_uri'].path end
qcow2?(magic)
click to toggle source
# File lib/uricp/strategy/common.rb, line 44 def qcow2?(magic) magic.unpack('a3C') == ['QFI', 0xfb] end
raw_target?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 81 def raw_target? options['target-format'] == :raw end
rbd_id()
click to toggle source
# File lib/uricp/strategy/common.rb, line 116 def rbd_id 'libvirt' end
rbd_target(uri)
click to toggle source
# File lib/uricp/strategy/common.rb, line 112 def rbd_target(uri) uri.path[1..-1] end
segmented?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 28 def segmented? options['segment-size'] end
sequence_complete?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 89 def sequence_complete? from == to end
supported_source?()
click to toggle source
# File lib/uricp/strategy/common.rb, line 108 def supported_source? options['source-format'] && !lz4_source? end
temp_uri()
click to toggle source
# File lib/uricp/strategy/common.rb, line 104 def temp_uri URI.join('file:///', get_temp_filename(options['temp'])) end
unsupported_transfer()
click to toggle source
# File lib/uricp/strategy/common.rb, line 13 def unsupported_transfer raise Uricp::UnsupportedURLtype, "Unsupported transfer from #{from} to #{to}" end
Also aliased as: command