diff --git a/install.sh b/install.sh index 3abcdff66a..9d8512648f 100755 --- a/install.sh +++ b/install.sh @@ -909,6 +909,7 @@ NETWORK_FILES="src/vnm_mad/remotes/lib/vnm_driver.rb \ src/vnm_mad/remotes/lib/command.rb \ src/vnm_mad/remotes/lib/vm.rb \ src/vnm_mad/remotes/lib/vlan.rb \ + src/vnm_mad/remotes/lib/dummy_vlan.rb \ src/vnm_mad/remotes/lib/security_groups.rb \ src/vnm_mad/remotes/lib/security_groups_iptables.rb \ src/vnm_mad/remotes/lib/nic.rb" diff --git a/src/vnm_mad/remotes/dummy/clean b/src/vnm_mad/remotes/dummy/clean index b3570d8b45..f84fc84919 100755 --- a/src/vnm_mad/remotes/dummy/clean +++ b/src/vnm_mad/remotes/dummy/clean @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2018, OpenNebula Project, OpenNebula Systems # @@ -16,4 +16,20 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 \ No newline at end of file +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'vnmmad' + +template64 = ARGV[0] +deploy_id = nil +xpath_filter = "TEMPLATE/NIC[VN_MAD='dummy']" + +begin + hm = VNMMAD::DummyVLANDriver.from_base64(template64, xpath_filter, deploy_id) + hm.deactivate +rescue Exception => e + OpenNebula.log_error(e.message) + OpenNebula.log_error(e.backtrace) + exit 1 +end diff --git a/src/vnm_mad/remotes/dummy/pre b/src/vnm_mad/remotes/dummy/pre index b3570d8b45..5252bae104 100755 --- a/src/vnm_mad/remotes/dummy/pre +++ b/src/vnm_mad/remotes/dummy/pre @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2018, OpenNebula Project, OpenNebula Systems # @@ -16,4 +16,14 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 \ No newline at end of file +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'vnmmad' + +template64 = ARGV[0] +deploy_id = ARGV[1] +xpath_filter = "TEMPLATE/NIC[VN_MAD='dummy']" + +hm = VNMMAD::DummyVLANDriver.from_base64(template64, xpath_filter, deploy_id) +exit hm.activate diff --git a/src/vnm_mad/remotes/ebtables/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb index 25e97fef91..654557e94d 100644 --- a/src/vnm_mad/remotes/ebtables/Ebtables.rb +++ b/src/vnm_mad/remotes/ebtables/Ebtables.rb @@ -16,7 +16,7 @@ require 'vnmmad' -class EbtablesVLAN < VNMMAD::VNMDriver +class EbtablesVLAN < VNMMAD::DummyVLANDriver DRIVER = "ebtables" XPATH_FILTER = "TEMPLATE/NIC[VN_MAD='ebtables']" @@ -34,29 +34,33 @@ class EbtablesVLAN < VNMMAD::VNMDriver # Activates ebtables rules # - def activate - lock + def activate(pre_action=false) + if pre_action + super() + else + lock - process do |nic| - tap = nic[:tap] - if tap - iface_mac = nic[:mac] + process do |nic| + tap = nic[:tap] + if tap + iface_mac = nic[:mac] - mac = iface_mac.split(':') - mac[-1] = '00' + mac = iface_mac.split(':') + mac[-1] = '00' - net_mac = mac.join(':') + net_mac = mac.join(':') - in_rule="FORWARD -s ! #{net_mac}/ff:ff:ff:ff:ff:00 " << - "-o #{tap} -j DROP" - out_rule="FORWARD -s ! #{iface_mac} -i #{tap} -j DROP" + in_rule="FORWARD -s ! #{net_mac}/ff:ff:ff:ff:ff:00 " << + "-o #{tap} -j DROP" + out_rule="FORWARD -s ! #{iface_mac} -i #{tap} -j DROP" - ebtables(in_rule) if nic[:filter_mac_spoofing] =~ /yes/i - ebtables(out_rule) + ebtables(in_rule) if nic[:filter_mac_spoofing] =~ /yes/i + ebtables(out_rule) + end end - end - unlock + unlock + end return 0 end @@ -88,6 +92,8 @@ class EbtablesVLAN < VNMMAD::VNMDriver unlock + super + return 0 end diff --git a/src/vnm_mad/remotes/ebtables/pre b/src/vnm_mad/remotes/ebtables/pre index b3570d8b45..6289c03e04 100755 --- a/src/vnm_mad/remotes/ebtables/pre +++ b/src/vnm_mad/remotes/ebtables/pre @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2018, OpenNebula Project, OpenNebula Systems # @@ -16,4 +16,14 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 \ No newline at end of file +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'Ebtables' + +template64 = ARGV[0] +deploy_id = ARGV[1] +xpath_filter = EbtablesVLAN::XPATH_FILTER + +onevlan = EbtablesVLAN.from_base64(template64, xpath_filter, deploy_id) +onevlan.activate(pre_action=true) diff --git a/src/vnm_mad/remotes/fw/clean b/src/vnm_mad/remotes/fw/clean index a3973f6ee2..0d461dd49f 100755 --- a/src/vnm_mad/remotes/fw/clean +++ b/src/vnm_mad/remotes/fw/clean @@ -23,9 +23,12 @@ require 'vnmmad' template64 = ARGV[0] deploy_id = nil -xpath_filter = nil +xpath_filter = "TEMPLATE/NIC[VN_MAD='fw']" begin + hm = VNMMAD::DummyVLANDriver.from_base64(template64, xpath_filter, deploy_id) + hm.deactivate + filter_driver = VNMMAD::VNMDriver.filter_driver(template64, xpath_filter, deploy_id) diff --git a/src/vnm_mad/remotes/fw/post b/src/vnm_mad/remotes/fw/post index 0b0b918955..9d665aa005 100755 --- a/src/vnm_mad/remotes/fw/post +++ b/src/vnm_mad/remotes/fw/post @@ -23,7 +23,7 @@ require 'vnmmad' template64 = ARGV[0] deploy_id = ARGV[1] -xpath_filter = nil +xpath_filter = "TEMPLATE/NIC[VN_MAD='fw']" begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, diff --git a/src/vnm_mad/remotes/fw/pre b/src/vnm_mad/remotes/fw/pre index b72c78c910..b9219bc722 100755 --- a/src/vnm_mad/remotes/fw/pre +++ b/src/vnm_mad/remotes/fw/pre @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2018, OpenNebula Project, OpenNebula Systems # @@ -16,4 +16,14 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'vnmmad' + +template64 = ARGV[0] +deploy_id = ARGV[1] +xpath_filter = "TEMPLATE/NIC[VN_MAD='fw']" + +hm = VNMMAD::DummyVLANDriver.from_base64(template64, xpath_filter, deploy_id) +exit hm.activate diff --git a/src/vnm_mad/remotes/fw/update_sg b/src/vnm_mad/remotes/fw/update_sg index d4a7613f33..dad77b3732 100755 --- a/src/vnm_mad/remotes/fw/update_sg +++ b/src/vnm_mad/remotes/fw/update_sg @@ -23,7 +23,7 @@ require 'vnmmad' template64 = ARGV[0] deploy_id = ARGV[1] -xpath_filter = nil +xpath_filter = "TEMPLATE/NIC[VN_MAD='fw']" begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, diff --git a/src/vnm_mad/remotes/lib/dummy_vlan.rb b/src/vnm_mad/remotes/lib/dummy_vlan.rb new file mode 100644 index 0000000000..14c68903a5 --- /dev/null +++ b/src/vnm_mad/remotes/lib/dummy_vlan.rb @@ -0,0 +1,38 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +module VNMMAD + class DummyVLANDriver< VNMMAD::VLANDriver + def initialize(vm, xpath_filter, deploy_id = nil) + @locking = true + + super(vm, xpath_filter, deploy_id) + end + + def create_vlan_dev + true + end + + private + def get_vlan_dev_name + @nic[:vlan_dev] = @nic[:phydev] if @nic[:phydev] + end + + def validate_vlan_id + true + end + end +end diff --git a/src/vnm_mad/remotes/lib/vlan.rb b/src/vnm_mad/remotes/lib/vlan.rb index 6e619bf37c..bd14ec7054 100644 --- a/src/vnm_mad/remotes/lib/vlan.rb +++ b/src/vnm_mad/remotes/lib/vlan.rb @@ -105,7 +105,8 @@ module VNMMAD # Delete the vlan device. OpenNebula.exec_and_log("#{command(:ip)} link delete"\ - " #{@nic[:vlan_dev]}") + " #{@nic[:vlan_dev]}") if @nic[:vlan_dev] != @nic[:phydev] + @bridges[@nic[:bridge]].delete(@nic[:vlan_dev]) # Delete the bridge. diff --git a/src/vnm_mad/remotes/lib/vnm_driver.rb b/src/vnm_mad/remotes/lib/vnm_driver.rb index c1eb899a19..07846cc3c2 100644 --- a/src/vnm_mad/remotes/lib/vnm_driver.rb +++ b/src/vnm_mad/remotes/lib/vnm_driver.rb @@ -87,7 +87,7 @@ module VNMMAD default_conf = CONF || {} nic_conf = {} - if nic[:conf] + if nic[:conf] and nic[:conf].is_a? String parse_options(nic[:conf]).each do |option, value| case value.downcase when 'true', 'yes' @@ -129,7 +129,7 @@ module VNMMAD nic_conf[option] = value end - if nic[conf_name] + if nic[conf_name] and nic[conf_name].is_a? String parse_options(nic[conf_name]).each do |option, value| if value == '__delete__' nic_conf.delete(option.strip.downcase) diff --git a/src/vnm_mad/remotes/lib/vnmmad.rb b/src/vnm_mad/remotes/lib/vnmmad.rb index c81ad0324e..414a283cdc 100644 --- a/src/vnm_mad/remotes/lib/vnmmad.rb +++ b/src/vnm_mad/remotes/lib/vnmmad.rb @@ -30,6 +30,7 @@ require 'security_groups_iptables' require 'vnm_driver' require 'sg_driver' require 'vlan' +require 'dummy_vlan' require 'scripts_common' Dir[File.expand_path('vnmmad-load.d', File.dirname(__FILE__)) + "/*.rb"].each{ |f| require f }