diff --git a/install.sh b/install.sh index ac4c1e9362..694510fa29 100755 --- a/install.sh +++ b/install.sh @@ -289,14 +289,41 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/vmm/packet \ $VAR_LOCATION/remotes/vnm \ $VAR_LOCATION/remotes/vnm/802.1Q \ + $VAR_LOCATION/remotes/vnm/802.1Q/pre.d \ + $VAR_LOCATION/remotes/vnm/802.1Q/post.d \ + $VAR_LOCATION/remotes/vnm/802.1Q/clean.d \ $VAR_LOCATION/remotes/vnm/vxlan \ + $VAR_LOCATION/remotes/vnm/vxlan/pre.d \ + $VAR_LOCATION/remotes/vnm/vxlan/post.d \ + $VAR_LOCATION/remotes/vnm/vxlan/clean.d \ $VAR_LOCATION/remotes/vnm/dummy \ + $VAR_LOCATION/remotes/vnm/dummy/pre.d \ + $VAR_LOCATION/remotes/vnm/dummy/post.d \ + $VAR_LOCATION/remotes/vnm/dummy/clean.d \ $VAR_LOCATION/remotes/vnm/bridge \ + $VAR_LOCATION/remotes/vnm/bridge/pre.d \ + $VAR_LOCATION/remotes/vnm/bridge/post.d \ + $VAR_LOCATION/remotes/vnm/bridge/clean.d \ $VAR_LOCATION/remotes/vnm/ebtables \ + $VAR_LOCATION/remotes/vnm/ebtables/pre.d \ + $VAR_LOCATION/remotes/vnm/ebtables/post.d \ + $VAR_LOCATION/remotes/vnm/ebtables/clean.d \ $VAR_LOCATION/remotes/vnm/fw \ + $VAR_LOCATION/remotes/vnm/fw/pre.d \ + $VAR_LOCATION/remotes/vnm/fw/post.d \ + $VAR_LOCATION/remotes/vnm/fw/clean.d \ $VAR_LOCATION/remotes/vnm/ovswitch \ + $VAR_LOCATION/remotes/vnm/ovswitch/pre.d \ + $VAR_LOCATION/remotes/vnm/ovswitch/post.d \ + $VAR_LOCATION/remotes/vnm/ovswitch/clean.d \ $VAR_LOCATION/remotes/vnm/ovswitch_vxlan \ + $VAR_LOCATION/remotes/vnm/ovswitch_vxlan/pre.d \ + $VAR_LOCATION/remotes/vnm/ovswitch_vxlan/post.d \ + $VAR_LOCATION/remotes/vnm/ovswitch_vxlan/clean.d \ $VAR_LOCATION/remotes/vnm/vcenter \ + $VAR_LOCATION/remotes/vnm/vcenter/pre.d \ + $VAR_LOCATION/remotes/vnm/vcenter/post.d \ + $VAR_LOCATION/remotes/vnm/vcenter/clean.d \ $VAR_LOCATION/remotes/tm/ \ $VAR_LOCATION/remotes/tm/dummy \ $VAR_LOCATION/remotes/tm/shared \ @@ -1091,9 +1118,9 @@ NETWORK_EBTABLES_FILES="src/vnm_mad/remotes/ebtables/clean \ src/vnm_mad/remotes/ebtables/Ebtables.rb" NETWORK_FW_FILES="src/vnm_mad/remotes/fw/post \ - src/vnm_mad/remotes/fw/pre \ - src/vnm_mad/remotes/fw/update_sg \ - src/vnm_mad/remotes/fw/clean" + src/vnm_mad/remotes/fw/pre \ + src/vnm_mad/remotes/fw/update_sg \ + src/vnm_mad/remotes/fw/clean" NETWORK_OVSWITCH_FILES="src/vnm_mad/remotes/ovswitch/clean \ src/vnm_mad/remotes/ovswitch/post \ diff --git a/src/vnm_mad/remotes/802.1Q/clean b/src/vnm_mad/remotes/802.1Q/clean index 42a02de43f..5725cfb6ba 100755 --- a/src/vnm_mad/remotes/802.1Q/clean +++ b/src/vnm_mad/remotes/802.1Q/clean @@ -32,7 +32,7 @@ begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, xpath_filter, deploy_id) - filter_driver.deactivate + filter_driver.run_hooks(ARGV, template64) if filter_driver.deactivate == 0 rescue Exception => e OpenNebula.log_error(e.message) OpenNebula.log_error(e.backtrace) diff --git a/src/vnm_mad/remotes/802.1Q/clean.d/.gitignore b/src/vnm_mad/remotes/802.1Q/clean.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/clean.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/802.1Q/post b/src/vnm_mad/remotes/802.1Q/post index 2f75209331..b3c95d1940 100755 --- a/src/vnm_mad/remotes/802.1Q/post +++ b/src/vnm_mad/remotes/802.1Q/post @@ -29,7 +29,7 @@ begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, xpath_filter, deploy_id) - filter_driver.activate + filter_driver.run_hooks(ARGV, template64) if filter_driver.activate == 0 rescue Exception => e OpenNebula.log_error(e.message) OpenNebula.log_error(e.backtrace) diff --git a/src/vnm_mad/remotes/802.1Q/post.d/.gitignore b/src/vnm_mad/remotes/802.1Q/post.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/post.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/802.1Q/pre b/src/vnm_mad/remotes/802.1Q/pre index d15f89ffbc..8d0fa130fb 100755 --- a/src/vnm_mad/remotes/802.1Q/pre +++ b/src/vnm_mad/remotes/802.1Q/pre @@ -26,4 +26,4 @@ deploy_id = ARGV[0] xpath_filter = VLANTagDriver::XPATH_FILTER hm = VLANTagDriver.from_base64(template64, xpath_filter, deploy_id) -exit hm.activate +exit hm.run_hooks(ARGV, template64) if hm.activate == 0 diff --git a/src/vnm_mad/remotes/802.1Q/pre.d/.gitignore b/src/vnm_mad/remotes/802.1Q/pre.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/pre.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/bridge/clean b/src/vnm_mad/remotes/bridge/clean index aef983e8cd..3c2efa07aa 100755 --- a/src/vnm_mad/remotes/bridge/clean +++ b/src/vnm_mad/remotes/bridge/clean @@ -27,9 +27,10 @@ xpath_filter = "TEMPLATE/NIC[VN_MAD='bridge']" begin hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id) - hm.deactivate + hm.run_hooks(ARGV, template64) if hm.deactivate == 0 rescue Exception => e OpenNebula.log_error(e.message) OpenNebula.log_error(e.backtrace) exit 1 end + diff --git a/src/vnm_mad/remotes/bridge/clean.d/.gitignore b/src/vnm_mad/remotes/bridge/clean.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/bridge/clean.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/bridge/post b/src/vnm_mad/remotes/bridge/post index 65b76ef2ee..29c8388b6c 100755 --- a/src/vnm_mad/remotes/bridge/post +++ b/src/vnm_mad/remotes/bridge/post @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # @@ -16,4 +16,12 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 \ No newline at end of file +$LOAD_PATH << File.dirname(__FILE__) +$LOAD_PATH << File.join(File.dirname(__FILE__), '..') + +require 'vnmmad' + +template64 = STDIN.read + +hm = VNMMAD::VNMDriver.from_base64(template64) +exit hm.run_hooks(ARGV, template64) diff --git a/src/vnm_mad/remotes/bridge/post.d/.gitignore b/src/vnm_mad/remotes/bridge/post.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/bridge/post.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/bridge/pre b/src/vnm_mad/remotes/bridge/pre index 54ea3e4363..89536c17b3 100755 --- a/src/vnm_mad/remotes/bridge/pre +++ b/src/vnm_mad/remotes/bridge/pre @@ -26,4 +26,4 @@ deploy_id = ARGV[0] xpath_filter = "TEMPLATE/NIC[VN_MAD='bridge']" hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id) -exit hm.activate +exit hm.run_hooks(ARGV, template64) if hm.activate == 0 diff --git a/src/vnm_mad/remotes/bridge/pre.d/.gitignore b/src/vnm_mad/remotes/bridge/pre.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/bridge/pre.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/dummy/clean.d/.gitignore b/src/vnm_mad/remotes/dummy/clean.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/clean.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/dummy/post.d/.gitignore b/src/vnm_mad/remotes/dummy/post.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/post.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/dummy/pre.d/.gitignore b/src/vnm_mad/remotes/dummy/pre.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/pre.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/ebtables/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb index f9443f924e..f3fc9d59fb 100644 --- a/src/vnm_mad/remotes/ebtables/Ebtables.rb +++ b/src/vnm_mad/remotes/ebtables/Ebtables.rb @@ -95,7 +95,7 @@ class EbtablesVLAN < VNMMAD::NoVLANDriver super - return 0 + 0 end def rules diff --git a/src/vnm_mad/remotes/ebtables/clean b/src/vnm_mad/remotes/ebtables/clean index 02e5073188..3932355e1b 100755 --- a/src/vnm_mad/remotes/ebtables/clean +++ b/src/vnm_mad/remotes/ebtables/clean @@ -32,7 +32,7 @@ begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, xpath_filter, deploy_id) - filter_driver.deactivate + filter_driver.run_hooks(ARGV, template64) if filter_driver.deactivate == 0 rescue Exception => e OpenNebula.log_error(e.message) OpenNebula.log_error(e.backtrace) diff --git a/src/vnm_mad/remotes/ebtables/clean.d/.gitignore b/src/vnm_mad/remotes/ebtables/clean.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/ebtables/clean.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/ebtables/post b/src/vnm_mad/remotes/ebtables/post index 8150265040..17262abf44 100755 --- a/src/vnm_mad/remotes/ebtables/post +++ b/src/vnm_mad/remotes/ebtables/post @@ -32,7 +32,7 @@ begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, xpath_filter, deploy_id) - filter_driver.activate + filter_driver.run_hooks(ARGV, template64) if filter_driver.activate == 0 rescue Exception => e OpenNebula.log_error(e.message) OpenNebula.log_error(e.backtrace) diff --git a/src/vnm_mad/remotes/ebtables/post.d/.gitignore b/src/vnm_mad/remotes/ebtables/post.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/ebtables/post.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/ebtables/pre b/src/vnm_mad/remotes/ebtables/pre index dff731119b..0a594af801 100755 --- a/src/vnm_mad/remotes/ebtables/pre +++ b/src/vnm_mad/remotes/ebtables/pre @@ -26,4 +26,4 @@ deploy_id = ARGV[0] xpath_filter = EbtablesVLAN::XPATH_FILTER onevlan = EbtablesVLAN.from_base64(template64, xpath_filter, deploy_id) -onevlan.activate +onevlan.run_hooks(ARGV, template64) if onevlan.activate == 0 diff --git a/src/vnm_mad/remotes/ebtables/pre.d/.gitignore b/src/vnm_mad/remotes/ebtables/pre.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/ebtables/pre.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/fw/clean b/src/vnm_mad/remotes/fw/clean index 41386415cf..a01f720bb3 100755 --- a/src/vnm_mad/remotes/fw/clean +++ b/src/vnm_mad/remotes/fw/clean @@ -32,7 +32,7 @@ begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, xpath_filter, deploy_id) - filter_driver.deactivate + filter_driver.run_hooks(ARGV, template64) if filter_driver.deactivate == 0 rescue Exception => e OpenNebula.log_error(e.message) OpenNebula.log_error(e.backtrace) diff --git a/src/vnm_mad/remotes/fw/clean.d/.gitignore b/src/vnm_mad/remotes/fw/clean.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/fw/clean.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/fw/post b/src/vnm_mad/remotes/fw/post index 726f1ab7ef..89c2a8119d 100755 --- a/src/vnm_mad/remotes/fw/post +++ b/src/vnm_mad/remotes/fw/post @@ -29,7 +29,7 @@ begin filter_driver = VNMMAD::VNMDriver.filter_driver(template64, xpath_filter, deploy_id) - filter_driver.activate + filter_driver.run_hooks(ARGV, template64) if filter_driver.activate == 0 rescue Exception => e OpenNebula.log_error(e.message) OpenNebula.log_error(e.backtrace) diff --git a/src/vnm_mad/remotes/fw/post.d/.gitignore b/src/vnm_mad/remotes/fw/post.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/fw/post.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/fw/pre b/src/vnm_mad/remotes/fw/pre index 58a65999d7..cfdca956ed 100755 --- a/src/vnm_mad/remotes/fw/pre +++ b/src/vnm_mad/remotes/fw/pre @@ -26,4 +26,4 @@ deploy_id = ARGV[0] xpath_filter = "TEMPLATE/NIC[VN_MAD='fw']" hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id) -exit hm.activate +exit hm.run_hooks(ARGV, template64) if hm.activate == 0 diff --git a/src/vnm_mad/remotes/fw/pre.d/.gitignore b/src/vnm_mad/remotes/fw/pre.d/.gitignore new file mode 100644 index 0000000000..cfb6127211 --- /dev/null +++ b/src/vnm_mad/remotes/fw/pre.d/.gitignore @@ -0,0 +1,3 @@ +# Do not track files in this directory except for .gitignore file +* +!.gitignore diff --git a/src/vnm_mad/remotes/lib/vlan.rb b/src/vnm_mad/remotes/lib/vlan.rb index a431c7f290..dedfa54ef0 100644 --- a/src/vnm_mad/remotes/lib/vlan.rb +++ b/src/vnm_mad/remotes/lib/vlan.rb @@ -64,7 +64,7 @@ module VNMMAD unlock - return 0 + 0 end # This function needs to be implemented by any VLAN driver to @@ -116,6 +116,8 @@ module VNMMAD end if @bridges unlock + + 0 end private diff --git a/src/vnm_mad/remotes/lib/vnm_driver.rb b/src/vnm_mad/remotes/lib/vnm_driver.rb index 8b4cb2af39..a1c63d0f01 100644 --- a/src/vnm_mad/remotes/lib/vnm_driver.rb +++ b/src/vnm_mad/remotes/lib/vnm_driver.rb @@ -15,6 +15,7 @@ #--------------------------------------------------------------------------- # require 'shellwords' +require 'open3' ################################################################################ # The VNMMAD module provides the basic abstraction to implement custom @@ -29,6 +30,7 @@ module VNMMAD # drivers FirewallDriver and SGDriver. ############################################################################ class VNMDriver + attr_reader :vm # Creates new driver using: @@ -39,16 +41,16 @@ module VNMMAD @locking ||= false @vm = VNMNetwork::VM.new(REXML::Document.new(vm_tpl).root, - xpath_filter, deploy_id) + xpath_filter, deploy_id) end # Creates a new VNMDriver using: # @param vm_64 [String] Base64 encoded XML String from oned # @param deploy_id [String] def self.from_base64(vm_64, xpath_filter = nil, deploy_id = nil) - vm_xml = Base64::decode64(vm_64) + vm_xml = Base64.decode64(vm_64) - self.new(vm_xml, xpath_filter, deploy_id) + new(vm_xml, xpath_filter, deploy_id) end # Locking function to serialized driver operations if needed. Similar @@ -56,7 +58,7 @@ module VNMMAD def lock if @locking driver_name = self.class.name.downcase - @locking_file = File.open("/tmp/onevnm-#{driver_name}-lock","w") + @locking_file = File.open("/tmp/onevnm-#{driver_name}-lock", 'w') @locking_file.flock(File::LOCK_EX) end end @@ -64,19 +66,19 @@ module VNMMAD # Unlock driver execution mutex def unlock if @locking - @locking_file.close + @locking_file.close end end # Executes the given block on each NIC - def process(&block) + def process blk = lambda do |nic| add_nic_conf(nic) add_bridge_conf(nic) add_ovs_bridge_conf(nic) add_ip_link_conf(nic) - block.call(nic) + yield(nic) end @vm.each_nic(blk) @@ -84,7 +86,7 @@ module VNMMAD # Parse network configuration and add it to the nic def add_nic_conf(nic) - return if nic[:conf] and nic[:conf].instance_of? Hash + return if nic[:conf] && nic[:conf].instance_of?(Hash) default_conf = CONF || {} nic_conf = {} @@ -118,16 +120,16 @@ module VNMMAD end def add_command_conf(nic, conf_name) - return if nic[conf_name] and nic[conf_name].instance_of? Hash + return if nic[conf_name] && nic[conf_name].instance_of?(Hash) default_conf = CONF[conf_name] || {} nic_conf = {} # sanitize default_conf.each do |key, value| - option = Shellwords.escape(key.to_s.strip.downcase) + option = Shellwords.escape(key.to_s.strip.downcase) if value.class == String - value = Shellwords.escape(value.strip) + value = Shellwords.escape(value.strip) end nic_conf[option] = value @@ -138,7 +140,7 @@ module VNMMAD if value == '__delete__' nic_conf.delete(option.strip.downcase) else - option = Shellwords.escape(option.strip.downcase) + option = Shellwords.escape(option.strip.downcase) if value == '' value = nil else @@ -163,13 +165,13 @@ module VNMMAD # Returns the associated command including sudo and other configuration # attributes def command(cmd) - if VNMNetwork::COMMANDS.keys.include?(cmd.to_sym) - cmd_str = "#{VNMNetwork::COMMANDS[cmd.to_sym]}" + if VNMNetwork::COMMANDS.key?(cmd.to_sym) + cmd_str = (VNMNetwork::COMMANDS[cmd.to_sym]).to_s else - cmd_str = "#{cmd}" + cmd_str = cmd.to_s end - return cmd_str + cmd_str end def parse_options(string) @@ -178,7 +180,7 @@ module VNMMAD def self.parse_options(string) options = {} - return options if !string + return options unless string string.split(',').each do |op| m = op.match(/^\s*(?