Revision 0c715f3a

View differences:

src/onedb/vcenter_one54.rb
54 54
        Dir["#{TMP_DIR}/one_migrate_vm_*"].each do |vm_filename|
55 55
            vm_id = vm_filename.split("_")[-1]
56 56
            vm_xml = File.read(vm_filename)
57

  
58
            vm_xml_doc = REXML::Document.new(vm_xml).root
59

  
60
            seq_node  = vm_xml_doc.elements["HISTORY_RECORDS/HISTORY/SEQ"]
61
            dsid_node = vm_xml_doc.elements["HISTORY_RECORDS/HISTORY/DS_ID"]
62

  
63
            if seq_node && seq_node.has_text? && dsid_node && dsid_node.has_text?
64
                seq = seq_node.text
65
                dsid= dsid_node.text
66
                begin
67

  
68
                h_dataset = @db["SELECT body from history where vid=#{vm_id} and seq=#{seq}"]
69
                h_body    = h_dataset.map(:body)
70

  
71
                h_xml = REXML::Document.new(h_body[0]).root
72

  
73
                h_ds_node = h_xml.elements["DS_ID"]
74

  
75
                if h_ds_node && h_ds_node.has_text?
76
                    h_ds_node.text = dsid
77

  
78
                    h_xml.delete_element "TM_MAD"
79

  
80
                    tmmad_elem = REXML::Element.new("TM_MAD")
81
                    tmmad_elem.text = "vcenter"
82
                    h_xml.add_element(tmmad_elem)
83

  
84
                    @db.run("UPDATE history SET body='#{h_xml.to_s}' WHERE vid=#{vm_id} and seq=#{seq}")
85
                end
86

  
87
                rescue
88
                    puts "VM #{vm_id} cannot set datastore. Manual update needed"
89
                end
90
            end
91

  
57 92
            @db.run("UPDATE vm_pool SET body='#{vm_xml}' WHERE oid='#{vm_id}'")
58 93
            puts "    VM #{vm_id} migrated!" if verbose
59 94
        end

Also available in: Unified diff