1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

B #2189: Changed migrator (#2224)

This commit is contained in:
juanmont 2018-06-27 09:22:28 +02:00 committed by Ruben S. Montero
parent 484e412b0a
commit 777f435313
3 changed files with 76 additions and 3 deletions

View File

@ -1506,10 +1506,17 @@ int DispatchManager::snapshot_delete(int vid, int snap_id,
return -1;
}
bool is_keep_snapshots = false;
if ( vm->hasHistory() )
{
is_keep_snapshots = vmm->is_keep_snapshots(vm->get_vmm_mad());
}
if ( (vm->get_state() != VirtualMachine::ACTIVE ||
vm->get_lcm_state() != VirtualMachine::RUNNING) &&
(!vmm->is_keep_snapshots(vm->get_vmm_mad()) ||
(!is_keep_snapshots ||
vm->get_state() != VirtualMachine::POWEROFF) )
{
oss << "Could not delete snapshot " << snap_id << " for VM " << vid

View File

@ -37,6 +37,8 @@ module Migrator
feature_1377()
bug_2189()
log_time()
return true
@ -163,4 +165,68 @@ module Migrator
STDERR.puts " > You can now delete #{az_driver_conf} file"
end
def bug_2189()
@db.run "ALTER TABLE image_pool RENAME TO old_image_pool;"
@db.run "CREATE TABLE image_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name,uid) );"
@db.transaction do
@db.fetch("SELECT * FROM old_image_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
if ( !doc.xpath("//SNAPSHOTS/SNAPSHOT/ID").max.nil? )
next_snapshot = doc.xpath("//SNAPSHOTS/SNAPSHOT/ID").max.text.to_i + 1
else
next_snapshot = 0
end
doc.xpath("//SNAPSHOTS").first.add_child(doc.create_element("NEXT_SNAPSHOT")).content = next_snapshot
@db[:image_pool].insert(
:oid => row[:oid],
:name => row[:name],
:body => doc.root.to_s,
:uid => row[:uid],
:gid => row[:gid],
:owner_u => row[:owner_u],
:group_u => row[:group_u],
:other_u => row[:other_u])
end
end
@db.run "DROP TABLE old_image_pool;"
@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],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
if ( !doc.xpath("//SNAPSHOTS/SNAPSHOT/ID").max.nil? )
next_snapshot = doc.xpath("//SNAPSHOTS/SNAPSHOT/ID").max.text.to_i + 1
else
next_snapshot = 0
end
doc.xpath("//SNAPSHOTS").first.add_child(doc.create_element("NEXT_SNAPSHOT")).content = next_snapshot
@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;"
end
end

View File

@ -176,7 +176,7 @@ int Snapshots::create_snapshot(const string& name, long long size_mb)
snapshot->replace("PARENT", "-1");
}
snapshot_template.replace("NEXT_SNAPSHOST", next_snapshot + 1);
snapshot_template.replace("NEXT_SNAPSHOT", next_snapshot + 1);
snapshot_template.set(snapshot);