Revision b1273bae

View differences:

install.sh
1026 1026
                      src/onedb/3.8.2_to_3.8.3.rb \
1027 1027
                      src/onedb/3.8.3_to_3.8.4.rb \
1028 1028
                      src/onedb/3.8.4_to_3.9.80.rb \
1029
                      src/onedb/3.9.80_to_4.0.0.rb \
1029 1030
                      src/onedb/fsck.rb \
1030 1031
                      src/onedb/onedb.rb \
1031 1032
                      src/onedb/onedb_backend.rb"
src/onedb/3.9.80_to_4.0.0.rb
1
# -------------------------------------------------------------------------- #
2
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs        #
3
#                                                                            #
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
5
# not use this file except in compliance with the License. You may obtain    #
6
# a copy of the License at                                                   #
7
#                                                                            #
8
# http://www.apache.org/licenses/LICENSE-2.0                                 #
9
#                                                                            #
10
# Unless required by applicable law or agreed to in writing, software        #
11
# distributed under the License is distributed on an "AS IS" BASIS,          #
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13
# See the License for the specific language governing permissions and        #
14
# limitations under the License.                                             #
15
#--------------------------------------------------------------------------- #
16

  
17
require "rexml/document"
18
include REXML
19

  
20
module Migrator
21
    def db_version
22
        "4.0.0"
23
    end
24

  
25
    def one_version
26
        "OpenNebula 4.0.0"
27
    end
28

  
29
    def up
30

  
31
        ########################################################################
32
        # Feature #1631: Add ACTION to history entries
33
        ########################################################################
34

  
35
        @db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;"
36
        @db.run "CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);"
37

  
38
        @db.fetch("SELECT * FROM old_vm_pool") do |row|
39
            doc = Document.new(row[:body])
40

  
41
            doc.root.each_element("HISTORY_RECORDS/HISTORY") do |e|
42
                update_history(e)
43
            end
44

  
45
            @db[:vm_pool].insert(
46
                :oid        => row[:oid],
47
                :name       => row[:name],
48
                :body       => doc.root.to_s,
49
                :uid        => row[:uid],
50
                :gid        => row[:gid],
51
                :last_poll  => row[:last_poll],
52
                :state      => row[:state],
53
                :lcm_state  => row[:lcm_state],
54
                :owner_u    => row[:owner_u],
55
                :group_u    => row[:group_u],
56
                :other_u    => row[:other_u])
57
        end
58

  
59
        @db.run "DROP TABLE old_vm_pool;"
60

  
61
        @db.run "ALTER TABLE history RENAME TO old_history;"
62
        @db.run "CREATE TABLE history (vid INTEGER, seq INTEGER, body MEDIUMTEXT, stime INTEGER, etime INTEGER,PRIMARY KEY(vid,seq));"
63

  
64
        @db.fetch("SELECT * FROM old_history") do |row|
65
            doc = Document.new(row[:body])
66

  
67
            doc.root.each_element("/HISTORY") do |e|
68
                update_history(e)
69
            end
70

  
71
            @db[:history].insert(
72
                :vid    => row[:vid],
73
                :seq    => row[:seq],
74
                :body   => doc.root.to_s,
75
                :stime  => row[:stime],
76
                :etime  => row[:etime])
77
        end
78

  
79
        @db.run "DROP TABLE old_history;"
80

  
81

  
82
        return true
83
    end
84

  
85
    def update_history(history_elem)
86
        history_elem.add_element("ACTION").text = "20" # NONE_ACTION
87

  
88
        # History reason enum has changed from
89
        # NONE, ERROR, STOP_RESUME, USER, CANCEL   to
90
        # NONE, ERROR, USER
91
        history_elem.each_element("REASON") do |reason_e|
92
            reason = reason_e.text.to_i
93

  
94
            if reason > 1           # STOP_RESUME, USER, CANCEL
95
                reason_e.text = "2" # USER
96
            end
97
        end
98
    end
99
end

Also available in: Unified diff