mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-20 10:50:08 +03:00
feature #3175: Fix bugs. New method to access commands
This commit is contained in:
parent
ae0bf32400
commit
0fcbadea80
@ -92,18 +92,18 @@ class VLANDriver < VNMMAD::VNMDriver
|
||||
end
|
||||
|
||||
def create_bridge(bridge)
|
||||
OpenNebula.exec_and_log("#{VNMMAD::COMMANDS[:brctl]} addbr #{bridge}")
|
||||
OpenNebula.exec_and_log("#{command(:brctl)} addbr #{bridge}")
|
||||
@bridges[bridge] = Array.new
|
||||
end
|
||||
|
||||
def device_exists?(dev, vlan=nil)
|
||||
dev = "#{dev}.#{vlan}" if vlan
|
||||
`#{VNMMAD::COMMANDS[:ip]} link show #{dev}`
|
||||
`#{command(:ip)} link show #{dev}`
|
||||
$?.exitstatus == 0
|
||||
end
|
||||
|
||||
def create_dev_vlan(dev, vlan)
|
||||
cmd = "#{VNMMAD::COMMANDS[:ip]} link add link #{dev}"
|
||||
cmd = "#{command(:ip)} link add link #{dev}"
|
||||
cmd << " name #{dev}.#{vlan} type vlan id #{vlan}"
|
||||
|
||||
OpenNebula.exec_and_log(cmd)
|
||||
@ -111,18 +111,20 @@ class VLANDriver < VNMMAD::VNMDriver
|
||||
|
||||
def attached_bridge_dev?(bridge, dev, vlan=nil)
|
||||
return false if !bridge_exists? bridge
|
||||
|
||||
dev = "#{dev}.#{vlan}" if vlan
|
||||
@bridges[bridge].include? dev
|
||||
end
|
||||
|
||||
def attach_brigde_dev(bridge, dev, vlan=nil)
|
||||
dev = "#{dev}.#{vlan}" if vlan
|
||||
OpenNebula.exec_and_log("#{VNMMAD::COMMANDS[:brctl]} addif #{bridge} #{dev}")
|
||||
|
||||
OpenNebula.exec_and_log("#{command(:brctl)} addif #{bridge} #{dev}")
|
||||
@bridges[bridge] << dev
|
||||
end
|
||||
|
||||
def ifup(dev, vlan=nil)
|
||||
dev = "#{dev}.#{vlan}" if vlan
|
||||
OpenNebula.exec_and_log("#{VNMMAD::COMMANDS[:ip]} link set #{dev} up")
|
||||
OpenNebula.exec_and_log("#{command(:ip)} link set #{dev} up")
|
||||
end
|
||||
end
|
||||
|
@ -96,7 +96,7 @@ module VNMMAD
|
||||
vm_id = @vm['ID']
|
||||
process do |nic|
|
||||
chain = "one-#{vm_id}-#{nic[:network_id]}"
|
||||
iptables_out = `#{VNMMAD::COMMANDS[:iptables]} -n -v --line-numbers -L FORWARD`
|
||||
iptables_out = `#{command(:iptables)} -n -v --line-numbers -L FORWARD`
|
||||
if m = iptables_out.match(/.*#{chain}.*/)
|
||||
rule_num = m[0].split(/\s+/)[0]
|
||||
purge_chain(chain, rule_num)
|
||||
@ -162,7 +162,7 @@ module VNMMAD
|
||||
end
|
||||
|
||||
def tap_to_chain(tap, chain)
|
||||
iptables_out = `#{VNMMAD::COMMANDS[:iptables]} -n -v --line-numbers -L FORWARD`
|
||||
iptables_out = `#{command(:iptables)} -n -v --line-numbers -L FORWARD`
|
||||
|
||||
# Insert the rule on top of the 'opennebula' chain if it exists, so it
|
||||
# doesn't conflict with the security groups driver
|
||||
@ -187,13 +187,13 @@ module VNMMAD
|
||||
end
|
||||
|
||||
def chain_exists?(chain)
|
||||
iptables_nl =`#{VNMMAD::COMMANDS[:iptables]} -nL`
|
||||
iptables_nl =`#{command(:iptables)} -nL`
|
||||
chains = iptables_nl.scan(/(one-.*?) .*references/).flatten
|
||||
chains.include? chain
|
||||
end
|
||||
|
||||
def rule(rule)
|
||||
"#{VNMMAD::COMMANDS[:iptables]} #{rule}"
|
||||
"#{command(:iptables)} #{rule}"
|
||||
end
|
||||
end
|
||||
end
|
@ -142,5 +142,17 @@ module VNMMAD
|
||||
SGDriver.new(vm_xml, deploy_id, hypervisor)
|
||||
end
|
||||
end
|
||||
|
||||
# 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]}"
|
||||
else
|
||||
cmd_str = "#{cmd}"
|
||||
end
|
||||
|
||||
return cmd_str
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -91,7 +91,7 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
||||
end
|
||||
|
||||
def tag_vlan
|
||||
cmd = "#{VNMMAD::COMMANDS[:ovs_vsctl]} set Port #{@nic[:tap]} "
|
||||
cmd = "#{command(:ovs_vsctl)} set Port #{@nic[:tap]} "
|
||||
cmd << "tag=#{vlan}"
|
||||
|
||||
run cmd
|
||||
@ -100,7 +100,7 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
||||
def tag_trunk_vlans
|
||||
range = @nic[:vlan_tagged_id]
|
||||
if range? range
|
||||
ovs_vsctl_cmd = "#{VNMMAD::COMMANDS[:ovs_vsctl]} set Port #{@nic[:tap]}"
|
||||
ovs_vsctl_cmd = "#{command(:ovs_vsctl)} set Port #{@nic[:tap]}"
|
||||
|
||||
cmd = "#{ovs_vsctl_cmd} trunks=#{range}"
|
||||
run cmd
|
||||
@ -159,7 +159,7 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
||||
def del_flows
|
||||
in_port = ""
|
||||
|
||||
dump_flows = "#{VNMMAD::COMMANDS[:ovs_ofctl]} dump-flows #{@nic[:bridge]}"
|
||||
dump_flows = "#{command(:ovs_ofctl)} dump-flows #{@nic[:bridge]}"
|
||||
`#{dump_flows}`.lines do |flow|
|
||||
next unless flow.match("#{@nic[:mac]}")
|
||||
flow = flow.split.select{|e| e.match(@nic[:mac])}.first
|
||||
@ -175,13 +175,13 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
||||
def add_flow(filter,action,priority=nil)
|
||||
priority = (priority.to_s.empty? ? "" : "priority=#{priority},")
|
||||
|
||||
run "#{VNMMAD::COMMANDS[:ovs_ofctl]} add-flow " <<
|
||||
run "#{command(:ovs_ofctl)} add-flow " <<
|
||||
"#{@nic[:bridge]} #{filter},#{priority}actions=#{action}"
|
||||
end
|
||||
|
||||
def del_flow(filter)
|
||||
filter.gsub!(/priority=(\d+)/,"")
|
||||
run "#{VNMMAD::COMMANDS[:ovs_ofctl]} del-flows " <<
|
||||
run "#{command(:ovs_ofctl)} del-flows " <<
|
||||
"#{@nic[:bridge]} #{filter}"
|
||||
end
|
||||
|
||||
@ -192,7 +192,7 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
||||
def port
|
||||
return @nic[:port] if @nic[:port]
|
||||
|
||||
dump_ports = `#{VNMMAD::COMMANDS[:ovs_ofctl]} \
|
||||
dump_ports = `#{command(:ovs_ofctl)} \
|
||||
dump-ports #{@nic[:bridge]} #{@nic[:tap]}`
|
||||
|
||||
@nic[:port] = dump_ports.scan(/^\s*port\s*(\d+):/).flatten.first
|
||||
|
Loading…
x
Reference in New Issue
Block a user