diskid 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/diskid +32 -23
- data/bin/diskid-ws +1 -1
- data/lib/diskid.rb +37 -5
- metadata +19 -19
data/bin/diskid
CHANGED
@@ -7,6 +7,7 @@ require 'diskid'
|
|
7
7
|
|
8
8
|
class DiskIDCommand < Clamp::Command
|
9
9
|
parameter 'FILE', "Disk file", :attribute_name => 'file'
|
10
|
+
option '--local', :flag, "Try to identify the disk using a local qemu-img binary"
|
10
11
|
option '--server-port', "PORT", "DiskID service port", :default => '80'
|
11
12
|
option '--server-host', "HOST", "DiskID service host", :default => 'diskid.frameos.org'
|
12
13
|
option '--format', "FORMAT", "Disk info output format (text, json, xml)", :default => 'text'
|
@@ -21,33 +22,41 @@ class DiskIDCommand < Clamp::Command
|
|
21
22
|
puts "Supported formats: vvfat vpc vmdk vdi sheepdog raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd dmg tftp ftps ftp https http cow cloop bochs blkverify blkdebug"
|
22
23
|
exit 1
|
23
24
|
end
|
25
|
+
|
26
|
+
# Use local qemu-img to identify the disk
|
27
|
+
if local?
|
28
|
+
di = DiskID::Inspector.new(file, 'qemu-img').identify
|
29
|
+
begin
|
30
|
+
puts di.send "to_#{format}"
|
31
|
+
rescue NoMethodError
|
32
|
+
$stderr.puts "Invalid format."
|
33
|
+
end
|
34
|
+
else
|
35
|
+
begin
|
36
|
+
RestClient.get "http://#{server_host}:#{server_port}/service-check"
|
37
|
+
rescue => e
|
38
|
+
$stderr.puts "Couldn't reach http://#{server_host}."
|
39
|
+
exit 1
|
40
|
+
end
|
24
41
|
|
25
|
-
|
42
|
+
fsize = File.size(file).bytes.to.megabytes.to_f.round
|
43
|
+
unit = 'M'
|
44
|
+
if fsize > 1024
|
45
|
+
fsize = fsize.megabytes.to.gigabytes.to_f.round
|
46
|
+
unit = 'G'
|
47
|
+
end
|
26
48
|
|
27
|
-
|
28
|
-
RestClient.get "http://#{server_host}:#{server_port}/service-check"
|
29
|
-
rescue => e
|
30
|
-
$stderr.puts "Couldn't reach http://#{server_host}."
|
31
|
-
exit 1
|
32
|
-
end
|
49
|
+
fsize = "#{fsize}#{unit}"
|
33
50
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
51
|
+
#out = `head -n 20 #{file}|curl -s -X POST -F client_version=#{DiskID::VERSION} -F chunk=@- -F file_size=#{fsize} -F file_name=#{File.basename(file)} http://#{server_host}:#{server_port}/?format=#{format} 2>&1`
|
52
|
+
out = RestClient.post "http://#{server_host}:#{server_port}/",
|
53
|
+
:chunk => File.read(file, 20000),
|
54
|
+
:client_version => DiskID::VERSION,
|
55
|
+
:file_size => fsize,
|
56
|
+
:file_name => File.basename(file),
|
57
|
+
:format => format
|
58
|
+
puts out
|
39
59
|
end
|
40
|
-
|
41
|
-
fsize = "#{fsize}#{unit}"
|
42
|
-
|
43
|
-
#out = `head -n 20 #{file}|curl -s -X POST -F client_version=#{DiskID::VERSION} -F chunk=@- -F file_size=#{fsize} -F file_name=#{File.basename(file)} http://#{server_host}:#{server_port}/?format=#{format} 2>&1`
|
44
|
-
out = RestClient.post "http://#{server_host}:#{server_port}/",
|
45
|
-
:chunk => File.read(file, 20000),
|
46
|
-
:client_version => DiskID::VERSION,
|
47
|
-
:file_size => fsize,
|
48
|
-
:file_name => File.basename(file),
|
49
|
-
:format => format
|
50
|
-
puts out
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
data/bin/diskid-ws
CHANGED
@@ -49,7 +49,7 @@ class DiskIDWS < Sinatra::Base
|
|
49
49
|
file_size = params[:file_size] || ''
|
50
50
|
begin
|
51
51
|
inspector = DiskID::Inspector.new(tmpfile.path)
|
52
|
-
di = inspector.
|
52
|
+
di = inspector.identify
|
53
53
|
di.file_name = file_name
|
54
54
|
di.disk_size = file_size
|
55
55
|
if params[:format] == 'json'
|
data/lib/diskid.rb
CHANGED
@@ -2,11 +2,12 @@ module DiskID
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
VERSION = "0.2.
|
5
|
+
VERSION = "0.2.2"
|
6
6
|
|
7
7
|
class DiskInfo
|
8
8
|
|
9
9
|
attr_accessor :file_name, :format, :virtual_size, :disk_size
|
10
|
+
attr_accessor :variant
|
10
11
|
|
11
12
|
def initialize(params)
|
12
13
|
@hash = params
|
@@ -14,6 +15,7 @@ module DiskID
|
|
14
15
|
@format = @hash['format']
|
15
16
|
@virtual_size = @hash['virtual_size']
|
16
17
|
@disk_size = @hash['disk_size']
|
18
|
+
@variant = @hash['variant']
|
17
19
|
end
|
18
20
|
|
19
21
|
def to_json
|
@@ -25,19 +27,31 @@ module DiskID
|
|
25
27
|
buf << "<disk_info>"
|
26
28
|
buf << "<file_name>#{@file_name}</file_name>"
|
27
29
|
buf << "<format>#{@format}</format>"
|
30
|
+
buf << "<variant>#{@variant}</variant>" if not @variant.empty?
|
28
31
|
buf << "<virtual_size>#{@virtual_size}</virtual_size>"
|
29
32
|
buf << "<disk_size>#{@disk_size}</disk_size>"
|
30
33
|
buf << "</disk_info>"
|
31
34
|
buf
|
32
35
|
end
|
33
36
|
|
37
|
+
def to_text
|
38
|
+
t = ""
|
39
|
+
t << "file_name: #{@file_name}\n"
|
40
|
+
t << "format: #{@format}\n"
|
41
|
+
t << "variant: #{@variant}\n" if not @variant.empty?
|
42
|
+
t << "virtual_size: #{@virtual_size}\n"
|
43
|
+
t << "disk_size: #{@disk_size}\n"
|
44
|
+
end
|
45
|
+
|
34
46
|
def to_hash
|
35
|
-
{
|
47
|
+
h = {
|
36
48
|
'file_name' => @file_name,
|
37
49
|
'format' => @format,
|
38
50
|
'virtual_size' => @virtual_size,
|
39
51
|
'disk_size' => @disk_size
|
40
52
|
}
|
53
|
+
h['variant'] = @variant if not @variant.empty?
|
54
|
+
h
|
41
55
|
end
|
42
56
|
|
43
57
|
end
|
@@ -46,25 +60,43 @@ module DiskID
|
|
46
60
|
|
47
61
|
|
48
62
|
def initialize(file, qemu_img_bin='qemu-img-bleeding')
|
49
|
-
@qemu_img_bin = qemu_img_bin
|
63
|
+
@qemu_img_bin = (qemu_img_bin || '').strip.chomp
|
64
|
+
if not @qemu_img_bin =~ /^\//
|
65
|
+
@qemu_img_bin = `sh -c 'command -v #{@qemu_img_bin}'`.strip.chomp
|
66
|
+
end
|
67
|
+
raise ArgumentError.new("qemu-img command not found: #{@qemu_img_bin}") if @qemu_img_bin.empty?
|
68
|
+
|
50
69
|
@file = file
|
51
70
|
end
|
52
71
|
|
53
|
-
def
|
72
|
+
def identify
|
54
73
|
out = `#{@qemu_img_bin} info #{@file}`
|
55
74
|
raise Exception.new("Error getting info from #{@file}") if $? != 0
|
56
75
|
|
57
76
|
md = /image:(.*)$\nfile format:(.*)$\nvirtual size:(.*)$\ndisk size:(.*)\n/.match out
|
58
77
|
@file_name,@format,@virtual_size,@disk_size = [md[1], md[2], md[3], md[4]].map { |e| e.strip.chomp }
|
59
78
|
@virtual_size = @virtual_size.split()[0]
|
79
|
+
variant = ''
|
80
|
+
if @format == 'vmdk'
|
81
|
+
variant = read_variant @file
|
82
|
+
end
|
60
83
|
DiskInfo.new({
|
61
84
|
'file_name' => @file_name,
|
62
85
|
'format' => @format,
|
63
86
|
'virtual_size' => @virtual_size,
|
64
|
-
'disk_size' => @disk_size
|
87
|
+
'disk_size' => @disk_size,
|
88
|
+
'variant' => variant
|
65
89
|
})
|
66
90
|
end
|
67
91
|
|
92
|
+
private
|
93
|
+
def read_variant(file)
|
94
|
+
IO.read(file, 20000).each_line do |l|
|
95
|
+
return $1 if l =~ /createType="(.*?)"/
|
96
|
+
end
|
97
|
+
''
|
98
|
+
end
|
68
99
|
|
69
100
|
end
|
101
|
+
|
70
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diskid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &24178460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *24178460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &24177980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *24177980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &24177440 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *24177440
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &24176940 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *24176940
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sinatra
|
60
|
-
requirement: &
|
60
|
+
requirement: &24176380 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *24176380
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: clamp
|
71
|
-
requirement: &
|
71
|
+
requirement: &23667400 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *23667400
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: alchemist
|
82
|
-
requirement: &
|
82
|
+
requirement: &23666820 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *23666820
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rest-client
|
93
|
-
requirement: &
|
93
|
+
requirement: &23666320 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *23666320
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: json
|
104
|
-
requirement: &
|
104
|
+
requirement: &23665840 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *23665840
|
113
113
|
description: Virtual Disk Identification Service
|
114
114
|
email: rubiojr@frameos.org
|
115
115
|
executables:
|