1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-20 10:50:08 +03:00

feature #863: Remove the filtering functionality, just rely on the VLAN=yes option.

This commit is contained in:
Jaime Melis 2011-12-02 12:35:55 +01:00 committed by Ruben S. Montero
parent a4e880d932
commit 7a11688738
3 changed files with 5 additions and 80 deletions

View File

@ -42,11 +42,8 @@ COMMANDS = {
:lsmod => "/sbin/lsmod"
}
#
#
#
class VM
attr_accessor :nics, :filtered_nics, :vm_info
attr_accessor :nics, :vm_info
def initialize(vm_root, hypervisor)
@vm_root = vm_root
@ -55,7 +52,7 @@ class VM
nics = Nics.new(@hypervisor)
@vm_root.elements.each("TEMPLATE/NIC") do |nic_element|
@vm_root.elements.each("TEMPLATE/NIC[VLAN=yes]") do |nic_element|
nic = nics.new_nic
nic_element.elements.each('*') do |nic_attribute|
@ -69,21 +66,12 @@ class VM
nics << nic
end
@nics = nics
@filtered_nics = nics
end
def filter(*filter)
@filtered_nics = @nics.get(*filter)
end
def unfilter
@filtered_nics = @nics
@nics = nics
end
def each_nic(block)
if @filtered_nics != nil
@filtered_nics.each do |the_nic|
if @nics != nil
@nics.each do |the_nic|
block.call(the_nic)
end
end
@ -118,16 +106,6 @@ class OpenNebulaNetwork
@vm = VM.new(REXML::Document.new(vm_tpl).root, @hypervisor)
end
def filter(*filter)
@vm.filter(*filter)
self
end
def unfilter
@vm.unfilter
self
end
def process(&block)
@vm.each_nic(block)
end

View File

@ -28,54 +28,6 @@ class Nics < Array
def new_nic
@nicClass.new
end
# finds nics that match 'args'
# 'args' can be a Hash, or an array
# args example:
# {:mac => "02:00:C0:A8:01:01", :bridge => "br0"}
# :mac, "02:00:C0:A8:01:01"
# key values may also be an array:
# {:mac => "02:00:C0:A8:01:01", :bridge => ["br0","br1"]}
def get(*args)
if args.length == 2
dict = Hash.new
dict[args[0]] = args[1]
elsif args.length == 1
dict = args[0]
else
return nil
end
matching = Array.new
self.each do |e|
e_filter = Hash.new
dict.each_key{|k| e_filter[k] = e[k]}
if compare(e_filter,dict)
matching << e
end
end
if matching.empty?
nil
else
matching
end
end
def compare(hash1, hash2)
#hash1 has a single value per key
#hash2 may contain an array of values
hash1.each do |k,v|
return false if !hash2[k]
v2 = hash2[k]
if hash2[k].kind_of?(Array)
return false if !v2.include? v
else
return false if v != v2
end
end
true
end
end

View File

@ -21,10 +21,5 @@ $: << File.join(File.dirname(__FILE__), "..")
require 'Ebtables'
# Uncomment to act only on the listed bridges.
#FILTERED_BRIDGES = ['br0']
onevlan = EbtablesVLAN.from_base64(ARGV[0])
onevlan.filter(:bridge => FILTERED_BRIDGES) if defined? FILTERED_BRIDGES
exit onevlan.activate