diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index 2652892f18..06aba4298e 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -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 diff --git a/src/onedb/fsck/template.rb b/src/onedb/fsck/template.rb index b8e873854b..8aebb24b10 100644 --- a/src/onedb/fsck/template.rb +++ b/src/onedb/fsck/template.rb @@ -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