Class: Uricp::Strategy::PipedRemoteGet

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/uricp/strategy/piped_remote_get.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)


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

def appropriate?
  case from.scheme
  when 'http', 'https'
    return proposal unless sequence_complete?
  else
    debug "#{self.class.name}: not appropriate"
    false
  end
end

#format_peekObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/uricp/strategy/piped_remote_get.rb', line 39

def format_peek
  return options['target-format'] || 'raw' if dry_run?

  options['from_uri'].open(headers) do |u|
    encoding(u)
  end
rescue OpenURI::HTTPError => e
  case e.io.status[0]
  when '416'
    'raw'
  else
    raise
  end
rescue SocketError => e
  raise SocketError, options['from_uri'].to_s + ' inaccessible: ' + e.message
end

#headersObject



76
77
78
79
80
# File 'lib/uricp/strategy/piped_remote_get.rb', line 76

def headers
  headers = { 'Range' => 'bytes=0-7' }
  headers['X-Auth-Token'] = options['authenticator'].call if http_authentication?
  headers
end

#proposalObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/uricp/strategy/piped_remote_get.rb', line 20

def proposal
  @proposed_options = options.dup
  @proposed_options['from_uri'] = PIPE_URI
  if conversion_required?
    @proposed_options['source-format'] = format_peek
    if @proposed_options['source-format'] == @proposed_options['target-format']
      @proposed_options.delete('source-format')
      @proposed_options.delete('target-format')
    end
  end
  if options['max-cache'] &&
     size_peek.to_i > options['max-cache'].to_i
    @proposed_options.delete('cache')
    @proposed_options.delete('cache_name')
    @proposed_options.delete('max-cache')
  end
  self
end

#size_peekObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/uricp/strategy/piped_remote_get.rb', line 56

def size_peek
  return options['max-cache'] if dry_run?

  size_headers = headers
  size_headers['Range'] = 'bytes=0-0'
  options['from_uri'].open(headers) do |u|
    match = %r{bytes\s+(\d+)-(\d+)/(\d+|\*)}i.match(u.meta['content-range'])
    match && match[3].to_i
  end
rescue OpenURI::HTTPError => e
  case e.io.status[0]
  when '416'
    0
  else
    raise
  end
rescue SocketError => e
  raise SocketError, options['from_uri'].to_s + ' inaccessible: ' + e.message
end