mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
B #4903: Do not fail link if exists. Linting
This reverts commit5b030d2869
. This reverts commitfd03fafb8f
.
This commit is contained in:
parent
57a69c580d
commit
a20016ba11
@ -43,7 +43,13 @@ class VLANTagDriver < VNMMAD::VLANDriver
|
||||
# This function creates and activate a VLAN device
|
||||
############################################################################
|
||||
def create_vlan_dev
|
||||
@nic[:mtu] ? mtu = "mtu #{@nic[:mtu]}" : mtu = "mtu #{CONF[:vlan_mtu]}"
|
||||
mtu = ''
|
||||
|
||||
if @nic[:mtu]
|
||||
mtu = "mtu #{@nic[:mtu]}"
|
||||
else
|
||||
mtu = "mtu #{CONF[:vlan_mtu]}"
|
||||
end
|
||||
|
||||
ip_link_conf = ''
|
||||
|
||||
@ -58,30 +64,23 @@ class VLANTagDriver < VNMMAD::VLANDriver
|
||||
ip_link_conf << "#{option} #{value} "
|
||||
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
|
||||
|
||||
# Do not fail if the device exists to prevent race conditions.
|
||||
# ip link add returns 2 on "RTNETLINK answers: File exists"
|
||||
OpenNebula.exec_and_log("#{command(:ip)} link add link"\
|
||||
" #{@nic[:phydev]} name #{@nic[:vlan_dev]} #{mtu} type vlan id"\
|
||||
" #{@nic[:vlan_id]} #{ip_link_conf}")
|
||||
" #{@nic[:vlan_id]} #{ip_link_conf}", nil, 2)
|
||||
|
||||
OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:vlan_dev]} up")
|
||||
end
|
||||
|
||||
def delete_vlan_dev
|
||||
return unless @nic[:vlan_dev] != @nic[:phydev]
|
||||
|
||||
OpenNebula.exec_and_log("\
|
||||
#{command(:ip)} link delete #{@nic[:vlan_dev]}")
|
||||
OpenNebula.exec_and_log("#{command(:ip)} link delete"\
|
||||
" #{@nic[:vlan_dev]}") if @nic[:vlan_dev] != @nic[:phydev]
|
||||
end
|
||||
|
||||
def list_interface_vlan(name)
|
||||
text, status = nic_exist?(name)
|
||||
|
||||
return if status == false
|
||||
text = %x(#{command(:ip_unpriv)} -d link show #{name})
|
||||
return nil if $?.exitstatus != 0
|
||||
|
||||
text.each_line do |line|
|
||||
m = line.match(/vlan protocol 802.1Q id (\d+)/)
|
||||
@ -91,5 +90,4 @@ class VLANTagDriver < VNMMAD::VLANDriver
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ module VNMMAD
|
||||
# @param xpath_filter [String] to get relevant NICs for the driver
|
||||
# @param deploy_id [String]
|
||||
def initialize(vm_tpl, xpath_filter, deploy_id = nil)
|
||||
@locking = false
|
||||
@locking ||= false
|
||||
|
||||
@vm = VNMNetwork::VM.new(REXML::Document.new(vm_tpl).root,
|
||||
xpath_filter, deploy_id)
|
||||
@ -47,8 +47,8 @@ module VNMMAD
|
||||
# Creates a new VNMDriver using:
|
||||
# @param vm_64 [String] Base64 encoded XML String from oned
|
||||
# @param deploy_id [String]
|
||||
def self.from_base64(vm64, xpath_filter = nil, deploy_id = nil)
|
||||
vm_xml = Base64.decode64(vm64)
|
||||
def self.from_base64(vm_64, xpath_filter = nil, deploy_id = nil)
|
||||
vm_xml = Base64.decode64(vm_64)
|
||||
|
||||
new(vm_xml, xpath_filter, deploy_id)
|
||||
end
|
||||
@ -156,8 +156,8 @@ module VNMMAD
|
||||
# Returns a filter object based on the contents of the template
|
||||
#
|
||||
# @return SGDriver object
|
||||
def self.filter_driver(vm64, xpath_filter, deploy_id)
|
||||
SGDriver.new(vm64, xpath_filter, deploy_id)
|
||||
def self.filter_driver(vm_64, xpath_filter, deploy_id)
|
||||
SGDriver.new(vm_64, xpath_filter, deploy_id)
|
||||
end
|
||||
|
||||
# Returns the associated command including sudo and other configuration
|
||||
@ -214,17 +214,6 @@ module VNMMAD
|
||||
0
|
||||
end
|
||||
|
||||
# Checks wether a NIC exist or not. Returns true/false and the NIC info
|
||||
def nic_exist?(name)
|
||||
cmd = "#{command(:ip)} link show #{name}"
|
||||
|
||||
_o, _e, s = Open3.capture3(cmd)
|
||||
|
||||
return true, text if s.exitstatus.zero?
|
||||
|
||||
[false, text]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# returns files sorted alphabetically
|
||||
|
Loading…
Reference in New Issue
Block a user