From 7a11688738b9b02f7b7c1e2e8724b048dfdaff95 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 12:35:55 +0100 Subject: [PATCH 1/2] feature #863: Remove the filtering functionality, just rely on the VLAN=yes option. --- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 32 +++------------- src/vnm_mad/remotes/OpenNebulaNic.rb | 48 ------------------------ src/vnm_mad/remotes/ebtables/post | 5 --- 3 files changed, 5 insertions(+), 80 deletions(-) diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index 25cf31d8be..79c8e14fa4 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -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 diff --git a/src/vnm_mad/remotes/OpenNebulaNic.rb b/src/vnm_mad/remotes/OpenNebulaNic.rb index d2916a91bd..2872de52ee 100644 --- a/src/vnm_mad/remotes/OpenNebulaNic.rb +++ b/src/vnm_mad/remotes/OpenNebulaNic.rb @@ -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 diff --git a/src/vnm_mad/remotes/ebtables/post b/src/vnm_mad/remotes/ebtables/post index e69f291c26..c142e41a2f 100755 --- a/src/vnm_mad/remotes/ebtables/post +++ b/src/vnm_mad/remotes/ebtables/post @@ -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 From 5f7cea8083675c1285eec0d3247c39cb2526e396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 2 Dec 2011 12:23:21 +0100 Subject: [PATCH 2/2] Feature #602 #863: Add VLAN tag to vnets and VM NIC attribute (cherry picked from commit cdf1231f819814b3e98b5c5747dd34b78203846d) Conflicts: src/cli/one_helper/onevnet_helper.rb src/vnm/test/VirtualNetworkPoolTest.cc --- include/VirtualNetwork.h | 5 +++++ src/cli/one_helper/onevnet_helper.rb | 5 +++++ src/vnm/VirtualNetwork.cc | 29 ++++++++++++++++++++++---- src/vnm/test/VirtualNetworkPoolTest.cc | 14 ++++++------- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index be02e86954..b398b8aee2 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -208,6 +208,11 @@ private: */ string vlan_id; + /** + * Whether or not to isolate this network with the vnm driver + */ + int vlan; + // ------------------------------------------------------------------------- // Virtual Network Description // ------------------------------------------------------------------------- diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 07a4dab8e9..6abd1a60dd 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -56,6 +56,11 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper puts str % ["USER", vn['UNAME']] puts str % ["GROUP", vn['GNAME']] puts str % ["PUBLIC", OpenNebulaHelper.boolean_to_str(vn['PUBLIC'])] + puts str % ["TYPE", vn.type_str] + puts str % ["BRIDGE", vn["BRIDGE"]] + puts str % ["VLAN", OpenNebulaHelper.boolean_to_str(vn['VLAN'])] + puts str % ["PHYSICAL DEVICE", vn["PHYDEV"]] if vn["PHYDEV"] + puts str % ["VLAN ID", vn["VLAN_ID"]] if vn["VLAN_ID"] puts str % ["USED LEASES", vn['TOTAL_LEASES']] puts diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 520ba533b5..77762d0830 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -25,6 +25,8 @@ #include "AuthManager.h" +#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper) + /* ************************************************************************** */ /* Virtual Network :: Constructor/Destructor */ /* ************************************************************************** */ @@ -207,6 +209,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) int rc; string pub; + string vlan_attr; string s_type; unsigned int default_size = VirtualNetworkPool::default_size(); @@ -219,7 +222,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) // ------------ TYPE ---------------------- erase_template_attribute("TYPE",s_type); - transform(s_type.begin(),s_type.end(),s_type.begin(),(int(*)(int))toupper); + TO_UPPER(s_type); if (s_type == "RANGED") { @@ -255,6 +258,14 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) erase_template_attribute("VLAN_ID",vlan_id); + // ------------ VLAN ---------------------- + + erase_template_attribute("VLAN", vlan_attr); + + TO_UPPER(vlan_attr); + + vlan = (vlan_attr == "YES"); + // ------------ BRIDGE -------------------- erase_template_attribute("BRIDGE",bridge); @@ -272,7 +283,6 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) oss << "onebr" << oid; bridge = oss.str(); - replace_template_attribute("BRIDGE",bridge); } } @@ -280,7 +290,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) erase_template_attribute("PUBLIC", pub); - transform (pub.begin(), pub.end(), pub.begin(), (int(*)(int))toupper); + TO_UPPER(pub); public_obj = (pub == "YES"); @@ -515,7 +525,8 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const "" << gname << "" << "" << name << "" << "" << type << "" << - "" << bridge << ""; + "" << bridge << ""<< + "" << vlan << ""; if (!phydev.empty()) { @@ -566,6 +577,7 @@ int VirtualNetwork::from_xml(const string &xml_str) rc += xpath(int_type, "/VNET/TYPE", -1); rc += xpath(bridge, "/VNET/BRIDGE", "not_found"); rc += xpath(public_obj, "/VNET/PUBLIC", 0); + rc += xpath(vlan, "/VNET/VLAN", 0); xpath(phydev, "/VNET/PHYDEV", ""); xpath(vlan_id, "/VNET/VLAN_ID",""); @@ -636,6 +648,15 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid) nic->replace("MAC" ,mac); nic->replace("IP" ,ip); + if ( vlan == 1 ) + { + nic->replace("VLAN", "YES"); + } + else + { + nic->replace("VLAN", "NO"); + } + if (!phydev.empty()) { nic->replace("PHYDEV", phydev); diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index e7854565e1..033a188943 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -71,18 +71,18 @@ const string templates[] = const string xmls[] = { - "01230the_useroneadminNet number one1br100130.10.0.150:20:20:20:20:200-1", + "01230the_useroneadminNet number one1br1000130.10.0.150:20:20:20:20:200-1", - "12610the_useroneadminA virtual network0br010", + "12610the_useroneadminA virtual network0br0010", - "01330the_useroneadminNet number two1br100130.10.2.150:20:20:20:20:200-1", + "01330the_useroneadminNet number two1br1000130.10.2.150:20:20:20:20:200-1", }; const string xml_dump = - "010the_useroneadminNet number one1br100120the_useroneadminA virtual network0br010"; + "010the_useroneadminNet number one1br1000120the_useroneadminA virtual network0br0010"; const string xml_dump_where = - "120the_useroneadminA virtual network0br010"; + "120the_useroneadminA virtual network0br0010"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -310,8 +310,8 @@ public: }; string phydev_xml[] = { - "000the_useroneadminBRIDGE and PHYDEV1br0eth000130.10.0.150:20:20:20:20:200-1", - "100the_useroneadminNo BRIDGE only PHYDEV1onebr1eth000130.10.0.150:20:20:20:20:200-1" + "000the_useroneadminBRIDGE and PHYDEV1br00eth000130.10.0.150:20:20:20:20:200-1", + "100the_useroneadminNo BRIDGE only PHYDEV1onebr10eth000130.10.0.150:20:20:20:20:200-1" }; // test vm with bridge and phydev