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
|
# File 'lib/ovfcatalog-plugin.rb', line 33
def upload_files(disk_file)
server_host = @plugin_config['host']
server_port = @plugin_config['port']
name = @plugin_config['name']
ram = @plugin_config['ram']
cpu = @plugin_config['cpu']
category = @plugin_config['category']
icon_path = @plugin_config['icon_path']
description = "#{@appliance_config.name}-#{@appliance_config.version}.#{@appliance_config.release}-#{@appliance_config.os.name}-#{@appliance_config.os.version}-#{@appliance_config.hardware.arch}"
disk_info = DiskID::Client.identify(disk_file)
units = disk_info['virtual_size'].gsub(/[0-9]|\./,'')
virtual_size = disk_info['virtual_size'].gsub(/G|M/,'')
if units == 'G'
vsbytes = virtual_size.to_f * 1024 * 1024 * 1024
else
vsbytes = virtual_size.to_f * 1024 * 1024
end
puts "Name:".ljust(40) + name
puts "Description:".ljust(40) + description
puts "Category:".ljust(40) + category
puts "RAM:".ljust(40) + "#{ram} MB"
puts "CPU:".ljust(40) + cpu
puts "HD:".ljust(40) + "#{virtual_size} #{units} (#{vsbytes} bytes)"
puts "Filesize:".ljust(40) + "#{FileTest.size(disk_file)} bytes"
c = Curl::Easy.new "http://#{server_host}:#{server_port}/createOvf"
c.multipart_form_post = true
c.on_progress { |dt, dn, ut, un| print "\r\e[0KUploading disk: %.0f%" % ((un*100)/ut); true }
c.http_post Curl::PostField.content('object.diskFilePath', disk_file),
Curl::PostField.content('object.diskFileSize', FileTest.size(disk_file).to_s),
Curl::PostField.content('object.diskFileFormat', guess_format(disk_file)),
Curl::PostField.content('object.name', name),
Curl::PostField.content('object.description', description),
Curl::PostField.content('object.categoryName', category),
Curl::PostField.content('object.iconPath', icon_path),
Curl::PostField.content('object.cpu', cpu),
Curl::PostField.content('object.ram', ram),
Curl::PostField.content('object.ramSizeUnit', "MB"),
Curl::PostField.content('object.hd', virtual_size),
Curl::PostField.content('object.hdSizeUnit', "#{units}B"),
Curl::PostField.content('object.hdInBytes', vsbytes.to_s ),
Curl::PostField.file('diskFile', disk_file)
puts
end
|