Class: Uricp::Strategy::LocalConvert

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/uricp/strategy/local_convert.rb

Constant Summary

Constants included from Common

Common::DRY_SNAP, Common::PIPE_URI, Common::VOL_REGEX

Instance Attribute Summary

Attributes included from Common

#proposed_options

Attributes included from CurlPrimitives

#options

Instance Method Summary collapse

Methods included from Common

#all_local_files?, #always_write_sparse?, #compression_required?, #conversion_required?, #dry_run?, #encoding, #file_source?, #format_change?, #get_temp_filename, #in_rbd_cache, #in_rbd_cache?, #initialize, #lz4?, #lz4_source?, #not_in_rbd_cache?, #proposed_path, #qcow2?, #raw_target?, #rbd_base_name, #rbd_cache_image_exists?, #rbd_cache_image_spec, #rbd_cache_name, #rbd_cache_upload_available?, #rbd_clone_snapshot, #rbd_id, #rbd_image_spec, #rbd_sequence_complete?, #rbd_snapshot_name, #rbd_snapshot_spec?, #rbd_uri, #segmented?, #sequence_complete?, #snap_check, #supported_source?, #temp_uri, #unsupported_transfer

Methods included from CurlPrimitives

#authentication, #curl_command, #curl_download_to_pipe, #curl_manifest, #curl_upload_from, #from, #from=, #http_authentication?, #to, #to=

Instance Method Details

#appropriate?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
# File 'lib/uricp/strategy/local_convert.rb', line 7

def appropriate?
  if conversion_required? && file_source? && supported_source?
    return proposal if new_qemu? || supported_conversion?

    raise Uricp::UnsupportedConversion,
          'qemu-img does not support required conversion'
  end
  debug "#{self.class.name}: not appropriate"
  false
end

#commandObject



18
19
20
# File 'lib/uricp/strategy/local_convert.rb', line 18

def command
  qemu_img_command(proposed_path)
end

#compat_optionObject



59
60
61
# File 'lib/uricp/strategy/local_convert.rb', line 59

def compat_option
  '-o compat=0.10' if new_qemu?
end

#compress_optionObject



63
64
65
# File 'lib/uricp/strategy/local_convert.rb', line 63

def compress_option
  options['compress'] && '-c'
end

#conversion_optionsObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/uricp/strategy/local_convert.rb', line 48

def conversion_options
  case options['target-format']
  when :raw
    '-O raw'
  when :qcow2
    "#{compress_option} -O qcow2 #{compat_option}"
  when :qcow3, :qcow2v3
    "#{compress_option} -O qcow2 -o compat=1.1"
  end
end

#new_qemu?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/uricp/strategy/local_convert.rb', line 36

def new_qemu?
  @new_qemu ||= !!(`qemu-img convert -O qcow2 -o ? a b` =~ /\bcompat\b/m)
end

#proposalObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/uricp/strategy/local_convert.rb', line 22

def proposal
  @proposed_options = options.dup
  if to.scheme == 'file'
    @proposed_options['from_uri'] = @proposed_options['to_uri']
  else
    @proposed_options['from_uri'] = temp_uri
    @proposed_options['clean'] ||= []
    @proposed_options['clean'] << proposed_path
  end
  @proposed_options.delete('source-format')
  @proposed_options.delete('target-format')
  self
end

#qemu_img_command(target) ⇒ Object



44
45
46
# File 'lib/uricp/strategy/local_convert.rb', line 44

def qemu_img_command(target)
  "qemu-img convert #{conversion_options} #{from.path} #{target};"
end

#supported_conversion?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/uricp/strategy/local_convert.rb', line 40

def supported_conversion?
  ([:qcow3, :qcow2v3] & [options['source-format'], options['target-format']]).empty? # rubocop:disable Style/SymbolArray
end