Class: Uricp::Strategy::PipedRemoteGet
- Inherits:
-
Object
- Object
- Uricp::Strategy::PipedRemoteGet
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
Instance Attribute Summary
Attributes included from Common
#proposed_options
#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?, #supported_source?, #temp_uri, #unsupported_transfer
#authentication, #curl_command, #curl_download_to_pipe, #curl_manifest, #curl_upload_from, #from, #from=, #http_authentication?, #to, #to=
Instance Method Details
#appropriate? ⇒ Boolean
6
7
8
9
10
11
12
13
14
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 6
def appropriate?
case from.scheme
when 'http', 'https'
return proposal unless sequence_complete?
else
debug "#{self.class.name}: not appropriate"
false
end
end
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 37
def format_peek
return options['target-format'] || 'raw' if dry_run?
options['from_uri'].open() 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
|
74
75
76
77
78
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 74
def
= { 'Range' => 'bytes=0-7' }
['X-Auth-Token'] = options['authenticator'].call if http_authentication?
end
|
#proposal ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 18
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_peek ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 54
def size_peek
return options['max-cache'] if dry_run?
=
['Range'] = 'bytes=0-0'
options['from_uri'].open() 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
|