1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-26 10:03:37 +03:00

Merge branch 'master' of git.opennebula.org:one

This commit is contained in:
Daniel Molina 2011-12-08 00:08:31 +01:00
commit ce182b20e4

View File

@ -28,13 +28,42 @@ module Migrator
end
def up
puts " > Networking isolation hooks have been moved to Host drivers.\n"<<
" If you were using a networking hook, enter its name, or press enter\n"<<
" to use the default dummy vn_mad driver.\n\n"
print " Driver name (802.1Q, dummy, ebtables, ovswitch): "
vn_mad = gets.chomp
puts " > Networking isolation hooks have been moved to Host drivers.\n"<<
" If you were using a networking hook, enter its name, or press enter\n"<<
" to use the default dummy vn_mad driver.\n\n"
vn_mad = "dummy" if vn_mad.empty?
vn_mad = ""
while !( ["802.1Q", "dummy", "ebtables", "ovswitch"].include?(vn_mad) ) do
print " Driver name (802.1Q, dummy, ebtables, ovswitch): "
vn_mad = gets.chomp
vn_mad = "dummy" if vn_mad.empty?
end
# 0 = all, 1 = none, 2 = interactive
vlan_option = 1
if ( vn_mad == "ebtables" || vn_mad == "ovswitch" )
puts
puts " > A new attribute, VLAN = YES/NO will be added to each VNET.\n"<<
" For driver '#{vn_mad}', please choose if you want to isolate all networks (all),\n"<<
" none (none), or be asked individually for each VNET (interactive)\n"
vlan = ""
while !( ["all", "none", "interactive"].include?(vlan) ) do
print " Isolate VNETs (all, none, interactive): "
vlan = gets.chomp
end
case vlan
when "all"
vlan_option = 0
when "none"
vlan_option = 1
when "interactive"
vlan_option = 2
end
end
# New VN_MAD element for hosts
@ -80,7 +109,19 @@ module Migrator
net_address = e.text
}
net_address = IPAddr.new(net_address, Socket::AF_INET)
net_valid = false
while !net_valid do
begin
net_address = IPAddr.new(net_address, Socket::AF_INET)
net_valid = true
rescue ArgumentError
puts
puts " > Error processing VNET ##{row[:oid]} '#{row[:name]}'\n"<<
" This network address is invalid: '#{net_address}'\n"
print " Please enter a valid network address: "
net_address = gets.chomp
end
end
st_size = ""
@ -98,18 +139,44 @@ module Migrator
size = st_size.to_i
host_bits = (Math.log(size+2)/Math.log(2)).ceil
end
net_mask = 0xFFFFFFFF << host_bits
net_address = net_address.to_i & net_mask
ip_start_elem.text = IPAddr.new((ip_start = net_address + 1), Socket::AF_INET).to_s
ip_start_elem.text = IPAddr.new((net_address + 1), Socket::AF_INET).to_s
ip_end_elem.text = IPAddr.new((net_address + (1 << host_bits) - 2), Socket::AF_INET).to_s
end
# TODO: Set vlan = 1 if PHYDEV is set
phydev_present = false
doc.root.each_element("PHYDEV") { |e|
phydev_present = true
}
vlan_elem = doc.root.add_element("VLAN")
vlan_elem.text = "0"
if phydev_present
vlan_elem.text = "1"
else
case vlan_option
when 0
vlan_elem.text = "1"
when 1
vlan_elem.text = "0"
when 2
vlan = ""
while !( ["y", "n"].include?(vlan) ) do
print " > Isolate VNET ##{row[:oid]} '#{row[:name]}'? (y/n) : "
vlan = gets.chomp
end
if ( vlan == "y" )
vlan_elem.text = "1"
else
vlan_elem.text = "0"
end
end
end
@db[:network_pool].insert(
:oid => row[:oid],
@ -122,6 +189,27 @@ module Migrator
@db.run "DROP TABLE old_network_pool;"
# Add empty HISTORY_RECORDS element to VMs without any records
@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 TEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER);"
@db.run "INSERT INTO vm_pool SELECT * FROM old_vm_pool;"
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Document.new(row[:body])
found = false
doc.root.each_element("HISTORY_RECORDS") { |e|
found = true
}
if !found
doc.root.add_element("HISTORY_RECORDS")
end
end
@db.run "DROP TABLE old_vm_pool;"
return true
end
end