1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-27 14:03:40 +03:00

Remove Xen from the VNM drivers and rework the signature of the

constructors (hypervisor is not sent, it's calculated on the spot)
This commit is contained in:
Jaime Melis 2016-04-06 12:12:42 +02:00
parent 89ae322d4a
commit 6c1795857a
27 changed files with 104 additions and 187 deletions

View File

@ -23,16 +23,15 @@ require 'vlan_tag_driver'
template64 = ARGV[0]
deploy_id = nil
hypervisor = nil
xpath_filter = VLANTagDriver::XPATH_FILTER
begin
hm = VLANTagDriver.from_base64(template64)
hm = VLANTagDriver.from_base64(template64, xpath_filter, deploy_id)
hm.deactivate
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.deactivate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -23,14 +23,12 @@ require 'vlan_tag_driver'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = VLANTagDriver::XPATH_FILTER
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -21,5 +21,5 @@ $: << File.join(File.dirname(__FILE__), "..")
require 'vlan_tag_driver'
hm = VLANTagDriver.from_base64(ARGV[0])
hm = VLANTagDriver.from_base64(ARGV[0], xpath_filter, deploy_id)
exit hm.activate

View File

@ -24,14 +24,12 @@ require 'vlan_tag_driver'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = VLANTagDriver::XPATH_FILTER
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate(true)
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -32,10 +32,11 @@ class VLANTagDriver < VNMMAD::VLANDriver
############################################################################
# Create driver device operations are locked
############################################################################
def initialize(vm, deploy_id = nil, hypervisor = nil)
def initialize(vm, xpath_filter = nil, deploy_id = nil)
@locking = true
super(vm, XPATH_FILTER, deploy_id, hypervisor)
xpath_filter ||= XPATH_FILTER
super(vm, xpath_filter, deploy_id)
end
############################################################################

View File

@ -21,9 +21,11 @@ class EbtablesVLAN < VNMMAD::VNMDriver
DRIVER = "ebtables"
XPATH_FILTER = "TEMPLATE/NIC[VN_MAD='ebtables']"
def initialize(vm, deploy_id = nil, hypervisor = nil)
super(vm,XPATH_FILTER,deploy_id,hypervisor)
def initialize(vm, xpath_filter = nil, deploy_id = nil)
@locking = true
xpath_filter ||= XPATH_FILTER
super(vm, xpath_filter, deploy_id)
end
def ebtables(rule)

View File

@ -23,17 +23,15 @@ require 'Ebtables'
template64 = ARGV[0]
deploy_id = nil
hypervisor = nil
xpath_filter = EbtablesVLAN::XPATH_FILTER
onevlan = EbtablesVLAN.from_base64(template64)
onevlan = EbtablesVLAN.from_base64(template64, xpath_filter, deploy_id)
onevlan.deactivate
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.deactivate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -23,17 +23,15 @@ require 'Ebtables'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = EbtablesVLAN::XPATH_FILTER
onevlan = EbtablesVLAN.from_base64(template64, deploy_id)
onevlan = EbtablesVLAN.from_base64(template64, xpath_filter, deploy_id)
onevlan.activate
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -24,14 +24,12 @@ require 'Ebtables'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = EbtablesVLAN::XPATH_FILTER
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate(true)
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -23,14 +23,12 @@ require 'vnmmad'
template64 = ARGV[0]
deploy_id = nil
hypervisor = nil
xpath_filter = nil
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.deactivate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -23,14 +23,12 @@ require 'vnmmad'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = nil
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -23,14 +23,12 @@ require 'vnmmad'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = nil
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate(true)
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -18,20 +18,6 @@ module VNMMAD
module VNMNetwork
# This module include implementation specific functions. It MUST not be
# be used in other VNMAD classes.
module Configuration
# Return the command to talk to the Xen hypervisor xm or xl for
# Xen 3 and 4
def self.get_xen_command
if system("ps axuww | grep -v grep | grep '\\bxend\\b'")
"sudo xm"
else
"sudo xl"
end
end
end
# Command configuration for common network commands. This CAN be adjust
# to local installations. Any modification requires to sync the hosts with
# onehost sync command.
@ -41,7 +27,6 @@ module VNMNetwork
:brctl => "sudo brctl",
:ip => "sudo ip",
:virsh => "virsh -c qemu:///system",
:xm => Configuration::get_xen_command,
:ovs_vsctl=> "sudo ovs-vsctl",
:ovs_ofctl=> "sudo ovs-ofctl",
:lsmod => "lsmod",

View File

@ -18,18 +18,15 @@ module VNMMAD
module VNMNetwork
# This Hash will be pppulated by the NicKVM and other hypervisor-nic
# specific classes.
HYPERVISORS = {}
# This class represents the NICS of a VM, it provides a factory method
# to create VMs of the given hyprtvisor
class Nics < Array
def initialize(hypervisor)
case hypervisor
when "kvm"
@nicClass = NicKVM
when "xen"
@nicClass = NicXen
when "vmware"
@nicClass = NicVMware
end
@nicClass = HYPERVISORS[hypervisor]
end
def new_nic
@ -47,6 +44,8 @@ module VNMNetwork
# A NIC using KVM. This class implements functions to get the physical
# interface that the NIC is using, based on the MAC address
class NicKVM < Hash
VNMNetwork::HYPERVISORS["kvm"] = self
def initialize
super(nil)
end
@ -88,55 +87,11 @@ module VNMNetwork
end
end
# A NIC using Xen. This class implements functions to get the physical interface
# that the NIC is using
class NicXen < Hash
def initialize
super(nil)
end
def get_info(vm)
if vm.deploy_id
deploy_id = vm.deploy_id
else
deploy_id = vm['DEPLOY_ID']
end
if deploy_id and (vm.vm_info[:domid].nil? or vm.vm_info[:networks].nil?)
vm.vm_info[:domid] =`#{VNMNetwork::COMMANDS[:xm]} domid #{deploy_id}`.strip
vm.vm_info[:networks] =`#{VNMNetwork::COMMANDS[:xm]} network-list #{deploy_id}`
vm.vm_info.each_key do |k|
vm.vm_info[k] = nil if vm.vm_info[k].to_s.strip.empty?
end
end
end
def get_tap(vm)
domid = vm.vm_info[:domid]
if domid
networks = vm.vm_info[:networks].split("\n")[1..-1]
networks.each do |net|
n = net.split
iface_id = n[0]
iface_mac = n[2]
if iface_mac == self[:mac]
self[:tap] = "vif#{domid}.#{iface_id}"
break
end
end
end
self
end
end
# A NIC using VMware. This class implements functions to get the physical interface
# that the NIC is using
class NicVMware < Hash
VNMNetwork::HYPERVISORS["vmware"] = self
def initialize
super(nil)
end
@ -151,4 +106,4 @@ module VNMNetwork
end
end
end

View File

@ -17,7 +17,7 @@
module VNMMAD
############################################################################
# OpenNebula Firewall with Security Groups Based on IPTables (KVM and Xen)
# OpenNebula Firewall with Security Groups Based on IPTables (KVM)
############################################################################
class SGDriver < VNMDriver
DRIVER = "sg"
@ -39,16 +39,16 @@ module VNMMAD
# Creates a new SG driver and scans SG Rules
# @param [String] VM XML base64 encoded
# @param [String] hypervisor ID for the VM
# @param [String] hypervisor (e.g. 'kvm','xen'...)
# @param [String] hypervisor (e.g. 'kvm' ...)
# @param [String] Xpath for the NICs using the SG driver
def initialize(vm_64, deploy_id = nil, hypervisor = nil, xpath = nil)
vm = Base64::decode64(vm_64)
def initialize(vm_64, xpath_filter = nil, deploy_id = nil)
@locking = true
xpath_filter = xpath || XPATH_FILTER
vm = Base64::decode64(vm_64)
super(vm, xpath_filter, deploy_id, hypervisor)
xpath_filter ||= XPATH_FILTER
super(vm, xpath_filter, deploy_id)
@locking = true
@commands = VNMNetwork::Commands.new
rules = {}

View File

@ -23,10 +23,10 @@ module VNMMAD
############################################################################
class VLANDriver < VNMMAD::VNMDriver
def initialize(vm_tpl, xpath_filter, deploy_id = nil, hypervisor = nil)
def initialize(vm_tpl, xpath_filter, deploy_id = nil)
@locking = true
super(vm_tpl, xpath_filter, deploy_id, hypervisor)
super(vm_tpl, xpath_filter, deploy_id)
end
# Activate the driver and creates bridges and tags devices as needed.

View File

@ -30,19 +30,17 @@ module VNMNetwork
# @param vm_root [REXML] XML document representing the VM
# @param xpath_filer [String] to get the VM NICs
# @param deploy_id [String] refers to the VM in the hypervisor
# @param hypervisor [String]
def initialize(vm_root, xpath_filter, deploy_id, hypervisor)
def initialize(vm_root, xpath_filter, deploy_id)
@vm_root = vm_root
@xpath_filter = xpath_filter
@deploy_id = deploy_id
@hypervisor = hypervisor
@vm_info = Hash.new
@deploy_id = nil if deploy_id == "-"
nics = VNMNetwork::Nics.new(@hypervisor)
nics = VNMNetwork::Nics.new(hypervisor)
@vm_root.elements.each(@xpath_filter) do |nic_element|
@vm_root.elements.each(xpath_filter) do |nic_element|
nic = nics.new_nic
nic_build_hash(nic_element,nic)
@ -67,7 +65,7 @@ module VNMNetwork
# Access an XML Element of the VM
# @param element [String] element name
# @return [String] valule of the element or nil if not found
# @return [String] value of the element or nil if not found
def [](element)
if @vm_root
val = @vm_root.elements[element]
@ -77,6 +75,13 @@ module VNMNetwork
nil
end
# Gets the Hypervisor VMMMAD from the Template
# @return [String] name of the hypervisor driver
def hypervisor
xpath = 'HISTORY_RECORDS/HISTORY[last()]/VMMMAD'
@vm_root.root.elements[xpath].text
end
private
# Method to build the associated Hash from a NIC
@ -107,4 +112,4 @@ module VNMNetwork
end
end
end
end

View File

@ -27,33 +27,26 @@ module VNMMAD
# drivers FirewallDriver and SGDriver.
############################################################################
class VNMDriver
attr_reader :hypervisor, :vm
attr_reader :vm
# Creates new driver using:
# @param vm_tpl [String] XML String from oned
# @param xpath_filter [String] to get relevant NICs for the driver
# @param deploy_id [String]
# @param hypervisor [String]
def initialize(vm_tpl, xpath_filter, deploy_id = nil, hypervisor = nil)
def initialize(vm_tpl, xpath_filter, deploy_id = nil)
@locking ||= false
if !hypervisor
@hypervisor = detect_hypervisor
else
@hypervisor = hypervisor
end
@vm = VNMNetwork::VM.new(REXML::Document.new(vm_tpl).root,
xpath_filter, deploy_id, @hypervisor)
xpath_filter, deploy_id)
end
# Creates a new VNDriver using:
# Creates a new VNMDriver using:
# @param vm_64 [String] Base64 encoded XML String from oned
# @param deploy_id [String]
# @param hypervisor [String]
def self.from_base64(vm_64, deploy_id = nil, hypervisor = nil)
vm_xml = Base64::decode64(vm_64)
self.new(vm_xml, deploy_id, hypervisor)
def self.from_base64(vm_64, xpath_filter = nil, deploy_id = nil)
vm_xml = Base64::decode64(vm_64)
self.new(vm_xml, xpath_filter, deploy_id)
end
# Locking function to serialized driver operations if needed. Similar
@ -78,27 +71,11 @@ module VNMMAD
@vm.each_nic(block)
end
# Return a string for the hypervisor
# @return [String] "kvm", "xen" or nil
def detect_hypervisor
lsmod = `#{VNMNetwork::COMMANDS[:lsmod]}`
xen_file = "/proc/xen/capabilities"
kvm_dir = "/sys/class/misc/kvm"
if File.exists?(xen_file)
"xen"
elsif lsmod.match(/kvm/) || File.exists?(kvm_dir)
"kvm"
else
nil
end
end
# Returns a filter object based on the contents of the template
#
# @return SGDriver object
def self.filter_driver(vm_64, deploy_id, hypervisor, xpath)
SGDriver.new(vm_64, deploy_id, hypervisor, xpath)
def self.filter_driver(vm_64, xpath_filter, deploy_id)
SGDriver.new(vm_64, xpath_filter, deploy_id)
end
# Returns the associated command including sudo and other configuration

View File

@ -32,6 +32,8 @@ require 'sg_driver'
require 'vlan'
require 'scripts_common'
Dir["vnmmad-load.d/*.rb"].each{ |f| require f }
include OpenNebula
begin

View File

@ -24,10 +24,12 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
:black_ports_udp,
:icmp]
def initialize(vm, deploy_id = nil, hypervisor = nil)
super(vm,XPATH_FILTER,deploy_id,hypervisor)
def initialize(vm, xpath_filter = nil, deploy_id = nil)
@locking = false
xpath_filter ||= XPATH_FILTER
super(vm, xpath_filter, deploy_id)
@vm.nics.each do |nic|
if nic[:bridge_ovs] && !nic[:bridge_ovs].empty?
nic[:bridge] = nic[:bridge_ovs]

View File

@ -21,7 +21,9 @@ $: << File.join(File.dirname(__FILE__), "..")
require 'OpenvSwitch'
template64 = ARGV[0]
template64 = ARGV[0]
deploy_id = nil
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
ovs = OpenvSwitchVLAN.from_base64(template64)
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
ovs.deactivate

View File

@ -21,8 +21,10 @@ $: << File.join(File.dirname(__FILE__), "..")
require 'OpenvSwitch'
template64 = ARGV[0]
deploy_id = ARGV[1]
template64 = ARGV[0]
deploy_id = ARGV[1]
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
ovs = OpenvSwitchVLAN.from_base64(template64, deploy_id)
ovs.activate

View File

@ -23,16 +23,15 @@ require 'vxlan_driver'
template64 = ARGV[0]
deploy_id = nil
hypervisor = nil
xpath_filter = VXLANDriver::XPATH_FILTER
begin
hm = VXLANDriver.from_base64(template64)
hm = VXLANDriver.from_base64(template64, xpath_filter, deploy_id)
hm.deactivate
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.deactivate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -23,14 +23,12 @@ require 'vxlan_driver'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = VXLANDriver::XPATH_FILTER
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -21,5 +21,10 @@ $: << File.join(File.dirname(__FILE__), "..")
require 'vxlan_driver'
hm = VXLANDriver.from_base64(ARGV[0])
template64 = ARGV[0]
deploy_id = ARGV[1]
xpath_filter = VXLANDriver::XPATH_FILTER
hm = VXLANDriver.from_base64(template64, xpath_filter, deploy_id)
exit hm.activate

View File

@ -24,14 +24,12 @@ require 'vxlan_driver'
template64 = ARGV[0]
deploy_id = ARGV[1]
hypervisor = nil
xpath_filter = VXLANDriver::XPATH_FILTER
begin
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
deploy_id,
hypervisor,
xpath_filter)
xpath_filter,
deploy_id)
filter_driver.activate(true)
rescue Exception => e
OpenNebula.log_error(e.message)

View File

@ -32,10 +32,11 @@ class VXLANDriver < VNMMAD::VLANDriver
############################################################################
# Create driver device operations are locked
############################################################################
def initialize(vm, deploy_id = nil, hypervisor = nil)
def initialize(vm, xpath_filter = nil, deploy_id = nil)
@locking = true
super(vm, XPATH_FILTER, deploy_id, hypervisor)
xpath_filter ||= XPATH_FILTER
super(vm, xpath_filter, deploy_id)
end
############################################################################