27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/vagrant-zones/action/import.rb', line 27
def call(env)
@machine = env[:machine]
@executor = Executor::Exec.new
image = @machine.config.vm.box
curdir = Dir.pwd
datadir = @machine.data_dir
@driver = @machine.provider.driver
ui = env[:ui]
ui.info(I18n.t('vagrant_zones.meeting'))
ui.info(I18n.t('vagrant_zones.datadir'))
ui.info(" #{datadir}")
ui.info(I18n.t('vagrant_zones.detecting_box'))
if image[-4, 4] == '.zss'
if File.exist?("#{curdir}/#{image}")
FileUtils.cp("#{curdir}/#{image}", "#{datadir}/#{image}")
ui.info(I18n.t('vagrant_zones.zfs_snapshot_stream_detected'))
elsif !File.exist?("#{datadir}/#{image}")
raise Vagrant::Errors::BoxNotFound
end
elsif validate_uuid_format(image)
raise Vagrant::Errors::BoxNotFound unless check(image, ui)
uri = URI("#{@joyent_images_url}#{image}/file")
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new uri
http.request request do |response|
file_size = response['content-length'].to_i
amount_downloaded = 0
ratelimit = 0
rate = 500
large_file = "#{datadir}/#{image}"
File.open(large_file, 'wb') do |io|
response.read_body do |chunk|
io.write chunk
amount_downloaded += chunk.size
ui.rewriting do |uiprogress|
ratelimit += 1
if ratelimit >= rate
uiprogress.clear_line
status = format('%.2f%%', (amount_downloaded.to_f / file_size * 100))
uiprogress.info(I18n.t('vagrant_zones.importing_joyent_image') + "#{image} ==> ", new_line: false)
uiprogress.report_progress(status, 100, false)
ratelimit = 0
end
end
end
ui.clear_line
end
end
end
ui.info(I18n.t('vagrant_zones.joyent_image_uuid_detected') + image)
else
box_format = env[:machine].box.metadata['format'] unless env[:machine].box.nil?
if box_format == 'ovf'
ui.info(I18n.t('vagrant_zones.detected_ovf_format'))
end
ui.info(I18n.t('vagrant_zones.vagrant_cloud_box_detected'))
ui.info(" #{image}")
ui.clear_line
end
@app.call(env)
end
|