mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-28 17:57:22 +03:00
F #2451: Add configurble hooks to the network drivers in the form of
pre.d, post.d and clean.d scripts Co-authored-by: Daniel Clavijo Coca <dclavijo@opennebula.systems>
This commit is contained in:
parent
99ded0f884
commit
1e15db5ac0
33
install.sh
33
install.sh
@ -289,14 +289,41 @@ VAR_DIRS="$VAR_LOCATION/remotes \
|
|||||||
$VAR_LOCATION/remotes/vmm/packet \
|
$VAR_LOCATION/remotes/vmm/packet \
|
||||||
$VAR_LOCATION/remotes/vnm \
|
$VAR_LOCATION/remotes/vnm \
|
||||||
$VAR_LOCATION/remotes/vnm/802.1Q \
|
$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 \
|
||||||
|
$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 \
|
||||||
|
$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 \
|
||||||
|
$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 \
|
||||||
|
$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 \
|
||||||
|
$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 \
|
||||||
|
$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 \
|
||||||
|
$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 \
|
||||||
|
$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/ \
|
||||||
$VAR_LOCATION/remotes/tm/dummy \
|
$VAR_LOCATION/remotes/tm/dummy \
|
||||||
$VAR_LOCATION/remotes/tm/shared \
|
$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"
|
src/vnm_mad/remotes/ebtables/Ebtables.rb"
|
||||||
|
|
||||||
NETWORK_FW_FILES="src/vnm_mad/remotes/fw/post \
|
NETWORK_FW_FILES="src/vnm_mad/remotes/fw/post \
|
||||||
src/vnm_mad/remotes/fw/pre \
|
src/vnm_mad/remotes/fw/pre \
|
||||||
src/vnm_mad/remotes/fw/update_sg \
|
src/vnm_mad/remotes/fw/update_sg \
|
||||||
src/vnm_mad/remotes/fw/clean"
|
src/vnm_mad/remotes/fw/clean"
|
||||||
|
|
||||||
NETWORK_OVSWITCH_FILES="src/vnm_mad/remotes/ovswitch/clean \
|
NETWORK_OVSWITCH_FILES="src/vnm_mad/remotes/ovswitch/clean \
|
||||||
src/vnm_mad/remotes/ovswitch/post \
|
src/vnm_mad/remotes/ovswitch/post \
|
||||||
|
@ -32,7 +32,7 @@ begin
|
|||||||
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.deactivate
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.deactivate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/802.1Q/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/802.1Q/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -29,7 +29,7 @@ begin
|
|||||||
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.activate
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.activate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/802.1Q/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/802.1Q/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,4 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = VLANTagDriver::XPATH_FILTER
|
xpath_filter = VLANTagDriver::XPATH_FILTER
|
||||||
|
|
||||||
hm = VLANTagDriver.from_base64(template64, xpath_filter, deploy_id)
|
hm = VLANTagDriver.from_base64(template64, xpath_filter, deploy_id)
|
||||||
exit hm.activate
|
exit hm.run_hooks(ARGV, template64) if hm.activate == 0
|
||||||
|
3
src/vnm_mad/remotes/802.1Q/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/802.1Q/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -27,9 +27,10 @@ xpath_filter = "TEMPLATE/NIC[VN_MAD='bridge']"
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
||||||
hm.deactivate
|
hm.run_hooks(ARGV, template64) if hm.deactivate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
3
src/vnm_mad/remotes/bridge/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/bridge/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
# -------------------------------------------------------------------------- #
|
# -------------------------------------------------------------------------- #
|
||||||
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
||||||
@ -16,4 +16,12 @@
|
|||||||
# limitations under the License. #
|
# limitations under the License. #
|
||||||
#--------------------------------------------------------------------------- #
|
#--------------------------------------------------------------------------- #
|
||||||
|
|
||||||
exit 0
|
$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)
|
||||||
|
3
src/vnm_mad/remotes/bridge/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/bridge/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,4 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = "TEMPLATE/NIC[VN_MAD='bridge']"
|
xpath_filter = "TEMPLATE/NIC[VN_MAD='bridge']"
|
||||||
|
|
||||||
hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
||||||
exit hm.activate
|
exit hm.run_hooks(ARGV, template64) if hm.activate == 0
|
||||||
|
3
src/vnm_mad/remotes/bridge/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/bridge/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
3
src/vnm_mad/remotes/dummy/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/dummy/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
3
src/vnm_mad/remotes/dummy/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/dummy/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
3
src/vnm_mad/remotes/dummy/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/dummy/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -95,7 +95,7 @@ class EbtablesVLAN < VNMMAD::NoVLANDriver
|
|||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
return 0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def rules
|
def rules
|
||||||
|
@ -32,7 +32,7 @@ begin
|
|||||||
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.deactivate
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.deactivate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/ebtables/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ebtables/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -32,7 +32,7 @@ begin
|
|||||||
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.activate
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.activate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/ebtables/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ebtables/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,4 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = EbtablesVLAN::XPATH_FILTER
|
xpath_filter = EbtablesVLAN::XPATH_FILTER
|
||||||
|
|
||||||
onevlan = EbtablesVLAN.from_base64(template64, xpath_filter, deploy_id)
|
onevlan = EbtablesVLAN.from_base64(template64, xpath_filter, deploy_id)
|
||||||
onevlan.activate
|
onevlan.run_hooks(ARGV, template64) if onevlan.activate == 0
|
||||||
|
3
src/vnm_mad/remotes/ebtables/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ebtables/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -32,7 +32,7 @@ begin
|
|||||||
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.deactivate
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.deactivate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/fw/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/fw/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -29,7 +29,7 @@ begin
|
|||||||
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.activate
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.activate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/fw/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/fw/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,4 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = "TEMPLATE/NIC[VN_MAD='fw']"
|
xpath_filter = "TEMPLATE/NIC[VN_MAD='fw']"
|
||||||
|
|
||||||
hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
hm = VNMMAD::NoVLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
||||||
exit hm.activate
|
exit hm.run_hooks(ARGV, template64) if hm.activate == 0
|
||||||
|
3
src/vnm_mad/remotes/fw/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/fw/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -64,7 +64,7 @@ module VNMMAD
|
|||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
return 0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
# This function needs to be implemented by any VLAN driver to
|
# This function needs to be implemented by any VLAN driver to
|
||||||
@ -116,6 +116,8 @@ module VNMMAD
|
|||||||
end if @bridges
|
end if @bridges
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#--------------------------------------------------------------------------- #
|
#--------------------------------------------------------------------------- #
|
||||||
|
|
||||||
require 'shellwords'
|
require 'shellwords'
|
||||||
|
require 'open3'
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# The VNMMAD module provides the basic abstraction to implement custom
|
# The VNMMAD module provides the basic abstraction to implement custom
|
||||||
@ -29,6 +30,7 @@ module VNMMAD
|
|||||||
# drivers FirewallDriver and SGDriver.
|
# drivers FirewallDriver and SGDriver.
|
||||||
############################################################################
|
############################################################################
|
||||||
class VNMDriver
|
class VNMDriver
|
||||||
|
|
||||||
attr_reader :vm
|
attr_reader :vm
|
||||||
|
|
||||||
# Creates new driver using:
|
# Creates new driver using:
|
||||||
@ -39,16 +41,16 @@ module VNMMAD
|
|||||||
@locking ||= false
|
@locking ||= false
|
||||||
|
|
||||||
@vm = VNMNetwork::VM.new(REXML::Document.new(vm_tpl).root,
|
@vm = VNMNetwork::VM.new(REXML::Document.new(vm_tpl).root,
|
||||||
xpath_filter, deploy_id)
|
xpath_filter, deploy_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a new VNMDriver using:
|
# Creates a new VNMDriver using:
|
||||||
# @param vm_64 [String] Base64 encoded XML String from oned
|
# @param vm_64 [String] Base64 encoded XML String from oned
|
||||||
# @param deploy_id [String]
|
# @param deploy_id [String]
|
||||||
def self.from_base64(vm_64, xpath_filter = nil, deploy_id = nil)
|
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
|
end
|
||||||
|
|
||||||
# Locking function to serialized driver operations if needed. Similar
|
# Locking function to serialized driver operations if needed. Similar
|
||||||
@ -56,7 +58,7 @@ module VNMMAD
|
|||||||
def lock
|
def lock
|
||||||
if @locking
|
if @locking
|
||||||
driver_name = self.class.name.downcase
|
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)
|
@locking_file.flock(File::LOCK_EX)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -64,19 +66,19 @@ module VNMMAD
|
|||||||
# Unlock driver execution mutex
|
# Unlock driver execution mutex
|
||||||
def unlock
|
def unlock
|
||||||
if @locking
|
if @locking
|
||||||
@locking_file.close
|
@locking_file.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes the given block on each NIC
|
# Executes the given block on each NIC
|
||||||
def process(&block)
|
def process
|
||||||
blk = lambda do |nic|
|
blk = lambda do |nic|
|
||||||
add_nic_conf(nic)
|
add_nic_conf(nic)
|
||||||
add_bridge_conf(nic)
|
add_bridge_conf(nic)
|
||||||
add_ovs_bridge_conf(nic)
|
add_ovs_bridge_conf(nic)
|
||||||
add_ip_link_conf(nic)
|
add_ip_link_conf(nic)
|
||||||
|
|
||||||
block.call(nic)
|
yield(nic)
|
||||||
end
|
end
|
||||||
|
|
||||||
@vm.each_nic(blk)
|
@vm.each_nic(blk)
|
||||||
@ -84,7 +86,7 @@ module VNMMAD
|
|||||||
|
|
||||||
# Parse network configuration and add it to the nic
|
# Parse network configuration and add it to the nic
|
||||||
def add_nic_conf(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 || {}
|
default_conf = CONF || {}
|
||||||
nic_conf = {}
|
nic_conf = {}
|
||||||
@ -118,16 +120,16 @@ module VNMMAD
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_command_conf(nic, conf_name)
|
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] || {}
|
default_conf = CONF[conf_name] || {}
|
||||||
nic_conf = {}
|
nic_conf = {}
|
||||||
|
|
||||||
# sanitize
|
# sanitize
|
||||||
default_conf.each do |key, value|
|
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
|
if value.class == String
|
||||||
value = Shellwords.escape(value.strip)
|
value = Shellwords.escape(value.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
nic_conf[option] = value
|
nic_conf[option] = value
|
||||||
@ -138,7 +140,7 @@ module VNMMAD
|
|||||||
if value == '__delete__'
|
if value == '__delete__'
|
||||||
nic_conf.delete(option.strip.downcase)
|
nic_conf.delete(option.strip.downcase)
|
||||||
else
|
else
|
||||||
option = Shellwords.escape(option.strip.downcase)
|
option = Shellwords.escape(option.strip.downcase)
|
||||||
if value == ''
|
if value == ''
|
||||||
value = nil
|
value = nil
|
||||||
else
|
else
|
||||||
@ -163,13 +165,13 @@ module VNMMAD
|
|||||||
# Returns the associated command including sudo and other configuration
|
# Returns the associated command including sudo and other configuration
|
||||||
# attributes
|
# attributes
|
||||||
def command(cmd)
|
def command(cmd)
|
||||||
if VNMNetwork::COMMANDS.keys.include?(cmd.to_sym)
|
if VNMNetwork::COMMANDS.key?(cmd.to_sym)
|
||||||
cmd_str = "#{VNMNetwork::COMMANDS[cmd.to_sym]}"
|
cmd_str = (VNMNetwork::COMMANDS[cmd.to_sym]).to_s
|
||||||
else
|
else
|
||||||
cmd_str = "#{cmd}"
|
cmd_str = cmd.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
return cmd_str
|
cmd_str
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_options(string)
|
def parse_options(string)
|
||||||
@ -178,7 +180,7 @@ module VNMMAD
|
|||||||
|
|
||||||
def self.parse_options(string)
|
def self.parse_options(string)
|
||||||
options = {}
|
options = {}
|
||||||
return options if !string
|
return options unless string
|
||||||
|
|
||||||
string.split(',').each do |op|
|
string.split(',').each do |op|
|
||||||
m = op.match(/^\s*(?<option>[^=]+)\s*=\s*(?<value>.*?)\s*$/)
|
m = op.match(/^\s*(?<option>[^=]+)\s*=\s*(?<value>.*?)\s*$/)
|
||||||
@ -189,6 +191,43 @@ module VNMMAD
|
|||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Runs hooks in action.d directory inside the particular vnm driver
|
||||||
|
# Params:
|
||||||
|
# +args+:: +array+ Arguments passed to each script
|
||||||
|
# +stdin+:: +string+ Variable passed as Standard Input to each script
|
||||||
|
def run_hooks(args, stdin)
|
||||||
|
dir = "#{$PROGRAM_NAME}.d"
|
||||||
|
|
||||||
|
return 0 unless Dir.exist? dir
|
||||||
|
return 0 if Dir["#{dir}/*"].empty?
|
||||||
|
|
||||||
|
programs(dir).each do |file|
|
||||||
|
OpenNebula.log "Running #{file}"
|
||||||
|
|
||||||
|
cmd = "#{file} #{args.join(' ')}"
|
||||||
|
|
||||||
|
_o, e, s = Open3.capture3(cmd, :stdin_data => stdin.to_s)
|
||||||
|
|
||||||
|
raise "Error running #{file}\n#{e}" unless s.exitstatus.zero?
|
||||||
|
end
|
||||||
|
|
||||||
|
0
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# returns files sorted alphabetically
|
||||||
|
# if executable by the user running this method
|
||||||
|
def programs(dir)
|
||||||
|
files = []
|
||||||
|
|
||||||
|
Dir["#{dir}/*"].each do |file|
|
||||||
|
files << file if File.executable?(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
files.sort
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the driver is executing action pre
|
# Returns true if the driver is executing action pre
|
||||||
|
@ -116,7 +116,7 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
|||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
return 0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def deactivate
|
def deactivate
|
||||||
@ -162,6 +162,8 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
|||||||
end
|
end
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def vlan
|
def vlan
|
||||||
|
@ -26,4 +26,4 @@ deploy_id = nil
|
|||||||
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
|
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
|
||||||
|
|
||||||
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
|
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
|
||||||
ovs.deactivate
|
ovs.run_hooks(ARGV, template64) if ovs.deactivate == 0
|
||||||
|
3
src/vnm_mad/remotes/ovswitch/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ovswitch/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,5 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
|
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
|
||||||
|
|
||||||
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
|
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
|
||||||
|
ovs.run_hooks(ARGV, template64) if ovs.activate == 0
|
||||||
ovs.activate
|
|
||||||
|
3
src/vnm_mad/remotes/ovswitch/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ovswitch/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,5 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
|
xpath_filter = OpenvSwitchVLAN::XPATH_FILTER
|
||||||
|
|
||||||
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
|
ovs = OpenvSwitchVLAN.from_base64(template64, xpath_filter, deploy_id)
|
||||||
|
ovs.run_hooks(ARGV, template64) if ovs.activate == 0
|
||||||
ovs.activate
|
|
3
src/vnm_mad/remotes/ovswitch/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ovswitch/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,4 +26,4 @@ deploy_id = nil
|
|||||||
xpath_filter = OpenvSwitchVXLAN::XPATH_FILTER
|
xpath_filter = OpenvSwitchVXLAN::XPATH_FILTER
|
||||||
|
|
||||||
ovs = OpenvSwitchVXLAN.from_base64(template64, xpath_filter, deploy_id)
|
ovs = OpenvSwitchVXLAN.from_base64(template64, xpath_filter, deploy_id)
|
||||||
ovs.deactivate
|
ovs.run_hooks(ARGV, template64) if ovs.deactivate == 0
|
||||||
|
3
src/vnm_mad/remotes/ovswitch_vxlan/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ovswitch_vxlan/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,5 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = OpenvSwitchVXLAN::XPATH_FILTER
|
xpath_filter = OpenvSwitchVXLAN::XPATH_FILTER
|
||||||
|
|
||||||
ovs = OpenvSwitchVXLAN.from_base64(template64, xpath_filter, deploy_id)
|
ovs = OpenvSwitchVXLAN.from_base64(template64, xpath_filter, deploy_id)
|
||||||
|
ovs.run_hooks(ARGV, template64) if ovs.activate == 0
|
||||||
ovs.activate
|
|
||||||
|
3
src/vnm_mad/remotes/ovswitch_vxlan/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ovswitch_vxlan/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -26,5 +26,4 @@ deploy_id = ARGV[0]
|
|||||||
xpath_filter = OpenvSwitchVXLAN::XPATH_FILTER
|
xpath_filter = OpenvSwitchVXLAN::XPATH_FILTER
|
||||||
|
|
||||||
ovs = OpenvSwitchVXLAN.from_base64(template64, xpath_filter, deploy_id)
|
ovs = OpenvSwitchVXLAN.from_base64(template64, xpath_filter, deploy_id)
|
||||||
|
ovs.run_hooks(ARGV, template64) if ovs.activate == 0
|
||||||
ovs.activate
|
|
||||||
|
3
src/vnm_mad/remotes/ovswitch_vxlan/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/ovswitch_vxlan/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
3
src/vnm_mad/remotes/vcenter/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/vcenter/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
3
src/vnm_mad/remotes/vcenter/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/vcenter/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
3
src/vnm_mad/remotes/vcenter/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/vcenter/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -33,6 +33,7 @@ begin
|
|||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.deactivate
|
filter_driver.deactivate
|
||||||
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.deactivate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/vxlan/clean.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/vxlan/clean.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -29,7 +29,7 @@ begin
|
|||||||
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
filter_driver = VNMMAD::VNMDriver.filter_driver(template64,
|
||||||
xpath_filter,
|
xpath_filter,
|
||||||
deploy_id)
|
deploy_id)
|
||||||
filter_driver.activate
|
filter_driver.run_hooks(ARGV, template64) if filter_driver.activate == 0
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
OpenNebula.log_error(e.message)
|
OpenNebula.log_error(e.message)
|
||||||
OpenNebula.log_error(e.backtrace)
|
OpenNebula.log_error(e.backtrace)
|
||||||
|
3
src/vnm_mad/remotes/vxlan/post.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/vxlan/post.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -25,6 +25,5 @@ template64 = STDIN.read
|
|||||||
deploy_id = ARGV[0]
|
deploy_id = ARGV[0]
|
||||||
xpath_filter = VXLANDriver::XPATH_FILTER
|
xpath_filter = VXLANDriver::XPATH_FILTER
|
||||||
|
|
||||||
|
|
||||||
hm = VXLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
hm = VXLANDriver.from_base64(template64, xpath_filter, deploy_id)
|
||||||
exit hm.activate
|
exit hm.run_hooks(ARGV, template64) if hm.activate == 0
|
||||||
|
3
src/vnm_mad/remotes/vxlan/pre.d/.gitignore
vendored
Normal file
3
src/vnm_mad/remotes/vxlan/pre.d/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Do not track files in this directory except for .gitignore file
|
||||||
|
*
|
||||||
|
!.gitignore
|
Loading…
x
Reference in New Issue
Block a user