/
3.9.80_to_3.9.90.rb
161 lines (128 loc) 路 5.55 KB
/
3.9.80_to_3.9.90.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require "nokogiri"
class String
def red
colorize(31)
end
private
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
end
module Migrator
def db_version
"3.9.90"
end
def one_version
"OpenNebula 3.9.90"
end
def up
init_log_time()
########################################################################
# Feature #1631: Add ACTION to history entries
########################################################################
@db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;"
@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);"
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body])
doc.root.xpath("HISTORY_RECORDS/HISTORY").each do |e|
update_history(e)
end
@db[:vm_pool].insert(
:oid => row[:oid],
:name => row[:name],
:body => doc.root.to_s,
:uid => row[:uid],
:gid => row[:gid],
:last_poll => row[:last_poll],
:state => row[:state],
:lcm_state => row[:lcm_state],
:owner_u => row[:owner_u],
:group_u => row[:group_u],
:other_u => row[:other_u])
end
end
@db.run "DROP TABLE old_vm_pool;"
log_time()
@db.run "ALTER TABLE history RENAME TO old_history;"
@db.run "CREATE TABLE history (vid INTEGER, seq INTEGER, body MEDIUMTEXT, stime INTEGER, etime INTEGER,PRIMARY KEY(vid,seq));"
@db.transaction do
@db.fetch("SELECT * FROM old_history") do |row|
doc = Nokogiri::XML(row[:body])
doc.root.xpath("/HISTORY").each do |e|
update_history(e)
end
@db[:history].insert(
:vid => row[:vid],
:seq => row[:seq],
:body => doc.root.to_s,
:stime => row[:stime],
:etime => row[:etime])
end
end
@db.run "DROP TABLE old_history;"
log_time()
########################################################################
# Banner for drivers renamed
########################################################################
puts
puts "ATTENTION: manual intervention required".red
puts <<-END.gsub(/^ {8}/, '')
IM and VM MADS have been renamed in oned.conf. To keep your
existing hosts working, you need to duplicate the drivers with the
old names.
For example, for kvm you will have IM_MAD "kvm" and VM_MAD "kvm", so you
need to add IM_MAD "im_kvm" and VM_MAD "vmm_kvm"
IM_MAD = [
name = "kvm",
executable = "one_im_ssh",
arguments = "-r 0 -t 15 kvm" ]
IM_MAD = [
name = "im_kvm",
executable = "one_im_ssh",
arguments = "-r 0 -t 15 kvm" ]
VM_MAD = [
name = "kvm",
executable = "one_vmm_exec",
arguments = "-t 15 -r 0 kvm",
default = "vmm_exec/vmm_exec_kvm.conf",
type = "kvm" ]
VM_MAD = [
name = "vmm_kvm",
executable = "one_vmm_exec",
arguments = "-t 15 -r 0 kvm",
default = "vmm_exec/vmm_exec_kvm.conf",
type = "kvm" ]
END
return true
end
def update_history(history_elem)
# NONE_ACTION
history_elem.add_child(
history_elem.document.create_element("ACTION")).content = "0"
# History reason enum has changed from
# NONE, ERROR, STOP_RESUME, USER, CANCEL to
# NONE, ERROR, USER
history_elem.xpath("REASON").each do |reason_e|
reason = reason_e.text.to_i
if reason > 1 # STOP_RESUME, USER, CANCEL
reason_e.content = "2" # USER
end
end
end
end