mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
Co-authored-by: Daniel Clavijo Coca <dclavijo@opennebula.io>
This commit is contained in:
parent
00eae96b85
commit
fd03fafb8f
@ -26,7 +26,7 @@ require 'vnmmad'
|
|||||||
class VLANTagDriver < VNMMAD::VLANDriver
|
class VLANTagDriver < VNMMAD::VLANDriver
|
||||||
|
|
||||||
# DRIVER name and XPATH for relevant NICs
|
# DRIVER name and XPATH for relevant NICs
|
||||||
DRIVER = "802.1Q"
|
DRIVER = '802.1Q'
|
||||||
XPATH_FILTER = "TEMPLATE/NIC[VN_MAD='802.1Q']"
|
XPATH_FILTER = "TEMPLATE/NIC[VN_MAD='802.1Q']"
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
@ -43,21 +43,27 @@ class VLANTagDriver < VNMMAD::VLANDriver
|
|||||||
# This function creates and activate a VLAN device
|
# This function creates and activate a VLAN device
|
||||||
############################################################################
|
############################################################################
|
||||||
def create_vlan_dev
|
def create_vlan_dev
|
||||||
mtu = @nic[:mtu] ? "mtu #{@nic[:mtu]}" : "mtu #{CONF[:vlan_mtu]}"
|
@nic[:mtu] ? mtu = "mtu #{@nic[:mtu]}" : mtu = "mtu #{CONF[:vlan_mtu]}"
|
||||||
|
|
||||||
ip_link_conf = ""
|
ip_link_conf = ''
|
||||||
|
|
||||||
@nic[:ip_link_conf].each do |option, value|
|
@nic[:ip_link_conf].each do |option, value|
|
||||||
case value
|
case value
|
||||||
when true
|
when true
|
||||||
value = "on"
|
value = 'on'
|
||||||
when false
|
when false
|
||||||
value = "off"
|
value = 'off'
|
||||||
end
|
end
|
||||||
|
|
||||||
ip_link_conf << "#{option} #{value} "
|
ip_link_conf << "#{option} #{value} "
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Delete vlan if it stuck in another bridge.
|
||||||
|
if nic_exist?(@nic[:vlan_dev])[0]
|
||||||
|
cmd = "#{command(:ip)} link delete #{@nic[:vlan_dev]}"
|
||||||
|
OpenNebula.exec_and_log(cmd)
|
||||||
|
end
|
||||||
|
|
||||||
OpenNebula.exec_and_log("#{command(:ip)} link add link"\
|
OpenNebula.exec_and_log("#{command(:ip)} link add link"\
|
||||||
" #{@nic[:phydev]} name #{@nic[:vlan_dev]} #{mtu} type vlan id"\
|
" #{@nic[:phydev]} name #{@nic[:vlan_dev]} #{mtu} type vlan id"\
|
||||||
" #{@nic[:vlan_id]} #{ip_link_conf}")
|
" #{@nic[:vlan_id]} #{ip_link_conf}")
|
||||||
@ -66,13 +72,16 @@ class VLANTagDriver < VNMMAD::VLANDriver
|
|||||||
end
|
end
|
||||||
|
|
||||||
def delete_vlan_dev
|
def delete_vlan_dev
|
||||||
OpenNebula.exec_and_log("#{command(:ip)} link delete"\
|
return unless @nic[:vlan_dev] != @nic[:phydev]
|
||||||
" #{@nic[:vlan_dev]}") if @nic[:vlan_dev] != @nic[:phydev]
|
|
||||||
end
|
OpenNebula.exec_and_log("\
|
||||||
|
#{command(:ip)} link delete #{@nic[:vlan_dev]}")
|
||||||
|
end
|
||||||
|
|
||||||
def list_interface_vlan(name)
|
def list_interface_vlan(name)
|
||||||
text = %x(#{command(:ip_unpriv)} -d link show #{name})
|
text, status = nic_exist?(name)
|
||||||
return nil if $?.exitstatus != 0
|
|
||||||
|
return if status == false
|
||||||
|
|
||||||
text.each_line do |line|
|
text.each_line do |line|
|
||||||
m = line.match(/vlan protocol 802.1Q id (\d+)/)
|
m = line.match(/vlan protocol 802.1Q id (\d+)/)
|
||||||
@ -82,4 +91,5 @@ class VLANTagDriver < VNMMAD::VLANDriver
|
|||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
require 'shellwords'
|
require 'shellwords'
|
||||||
require 'open3'
|
require 'open3'
|
||||||
|
require 'English'
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# The VNMMAD module provides the basic abstraction to implement custom
|
# The VNMMAD module provides the basic abstraction to implement custom
|
||||||
@ -38,7 +39,7 @@ module VNMMAD
|
|||||||
# @param xpath_filter [String] to get relevant NICs for the driver
|
# @param xpath_filter [String] to get relevant NICs for the driver
|
||||||
# @param deploy_id [String]
|
# @param deploy_id [String]
|
||||||
def initialize(vm_tpl, xpath_filter, deploy_id = nil)
|
def initialize(vm_tpl, xpath_filter, deploy_id = nil)
|
||||||
@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)
|
||||||
@ -47,8 +48,8 @@ module VNMMAD
|
|||||||
# 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(vm64, xpath_filter = nil, deploy_id = nil)
|
||||||
vm_xml = Base64.decode64(vm_64)
|
vm_xml = Base64.decode64(vm64)
|
||||||
|
|
||||||
new(vm_xml, xpath_filter, deploy_id)
|
new(vm_xml, xpath_filter, deploy_id)
|
||||||
end
|
end
|
||||||
@ -56,18 +57,16 @@ module VNMMAD
|
|||||||
# Locking function to serialized driver operations if needed. Similar
|
# Locking function to serialized driver operations if needed. Similar
|
||||||
# to flock. File is created as /tmp/onevnm-<driver>-lock
|
# to flock. File is created as /tmp/onevnm-<driver>-lock
|
||||||
def lock
|
def lock
|
||||||
if @locking
|
return unless @locking
|
||||||
driver_name = self.class.name.downcase
|
|
||||||
@locking_file = File.open("/tmp/onevnm-#{driver_name}-lock", 'w')
|
driver_name = self.class.name.downcase
|
||||||
@locking_file.flock(File::LOCK_EX)
|
@locking_file = File.open("/tmp/onevnm-#{driver_name}-lock", 'w')
|
||||||
end
|
@locking_file.flock(File::LOCK_EX)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Unlock driver execution mutex
|
# Unlock driver execution mutex
|
||||||
def unlock
|
def unlock
|
||||||
if @locking
|
@locking_file.close if @locking
|
||||||
@locking_file.close
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes the given block on each NIC
|
# Executes the given block on each NIC
|
||||||
@ -158,8 +157,8 @@ module VNMMAD
|
|||||||
# Returns a filter object based on the contents of the template
|
# Returns a filter object based on the contents of the template
|
||||||
#
|
#
|
||||||
# @return SGDriver object
|
# @return SGDriver object
|
||||||
def self.filter_driver(vm_64, xpath_filter, deploy_id)
|
def self.filter_driver(vm64, xpath_filter, deploy_id)
|
||||||
SGDriver.new(vm_64, xpath_filter, deploy_id)
|
SGDriver.new(vm64, xpath_filter, deploy_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the associated command including sudo and other configuration
|
# Returns the associated command including sudo and other configuration
|
||||||
@ -216,6 +215,16 @@ module VNMMAD
|
|||||||
0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Checks wether a NIC exist or not. Returns true/false and the NIC info
|
||||||
|
def nic_exist?(name)
|
||||||
|
text = `#{command(:ip)} link show #{name}`
|
||||||
|
status = $CHILD_STATUS.exitstatus
|
||||||
|
|
||||||
|
return true, text if status == 0
|
||||||
|
|
||||||
|
[false, text]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# returns files sorted alphabetically
|
# returns files sorted alphabetically
|
||||||
|
Loading…
Reference in New Issue
Block a user