1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #5305: fsck should locate the image based on just the name

This commit is contained in:
Jaime Melis 2017-08-04 17:08:07 +02:00
parent 219b0545ab
commit 25df1f1607
2 changed files with 25 additions and 16 deletions

View File

@ -568,15 +568,16 @@ EOT
# Params:
# +type+:: type name of the disk, can be “hd” or “cdrom”
# +doc+:: Nokogiri::XML::Node describing the VM template
def get_disk_id(type, index, doc)
def get_disk_id(type, index, doc, uid)
found_i = -1
doc.root.xpath("TEMPLATE/DISK").each_with_index do |disk, disk_i|
id = disk.at_xpath("IMAGE_ID")
if ! id.nil?
if id
image = get_image_from_id(id.content)
else
image = get_image_from_name(disk)
image = get_image_from_name(disk, uid)
end
next if image.nil?
@ -608,29 +609,34 @@ EOT
# Returns a Nokogiri::XML::Node describing an image
# Params:
# +disk+:: Nokogiri::XML::Node describing a disk used by a template
def get_image_from_name(disk)
name = disk.at_xpath("IMAGE") && disk.at_xpath("IMAGE").content
uid = disk.at_xpath("IMAGE_UID")
uname = disk.at_xpath("IMAGE_UNAME")
def get_image_from_name(disk, template_uid)
name = disk.at_xpath("IMAGE") && disk.at_xpath("IMAGE").content
if ! name.nil? and (! uid.nil? or ! uname.nil?)
if uid.nil?
uid = get_user_id(uname.content)
return nil if name.nil?
uid = disk.at_xpath("IMAGE_UID")
uname = disk.at_xpath("IMAGE_UNAME")
if uid
uid = uid.content
else
uid = uid.content
if uname
uid = get_user_id(uname.content)
else
uid = template_uid
end
end
return nil if uid.nil?
row = @db.fetch("SELECT body from image_pool where name=\"#{name}\" and uid=#{uid}").first
row = @db.fetch("SELECT body FROM image_pool WHERE name=\"#{name}\" AND uid=#{uid}").first
# No image found, so unable to get image TYPE
return nil if row.nil?
image = Nokogiri::XML(row[:body], nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
return image
end
return nil
return image
end
# Returns the ID of a user name

View File

@ -8,6 +8,8 @@ module OneDBFsck
boot = doc.root.at_xpath("TEMPLATE/OS/BOOT")
uid = doc.root.at_xpath('UID').content
if boot.nil? || boot.text.downcase.match(/fd|hd|cdrom|network/).nil?
next
end
@ -40,7 +42,8 @@ module OneDBFsck
cdrom_i += 1
end
id = get_disk_id(dev, index, doc)
id = get_disk_id(dev, index, doc, uid)
if id.nil?
log_error("VM Template #{row[:oid]} OS/BOOT contains deprecated format \"#{boot.content}\", but DISK ##{index} of type #{dev} could not be found to fix it automatically", false)
error = true