mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-20 14:03:36 +03:00
Feature #1722: Implement locks for concurrent driver actions
This commit is contained in:
parent
2288a38f54
commit
e05e0e725b
@ -17,14 +17,20 @@
|
||||
require 'OpenNebulaNetwork'
|
||||
|
||||
class OpenNebulaHM < OpenNebulaNetwork
|
||||
DRIVER = "802.1Q"
|
||||
|
||||
XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
@locking = false
|
||||
|
||||
@bridges = get_interfaces
|
||||
end
|
||||
|
||||
def activate
|
||||
lock
|
||||
|
||||
vm_id = @vm['ID']
|
||||
process do |nic|
|
||||
bridge = nic[:bridge]
|
||||
@ -53,6 +59,8 @@ class OpenNebulaHM < OpenNebulaNetwork
|
||||
end
|
||||
end
|
||||
|
||||
unlock
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -15,15 +15,20 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
class OpenNebulaFirewall < OpenNebulaNetwork
|
||||
DRIVER = "fw"
|
||||
|
||||
XPATH_FILTER = "TEMPLATE/NIC[ICMP|WHITE_PORTS_TCP|WHITE_PORTS_UDP|" <<
|
||||
"BLACK_PORTS_TCP|BLACK_PORTS_UDP]"
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
@locking = true
|
||||
end
|
||||
|
||||
def activate
|
||||
vm_id = @vm['ID']
|
||||
lock
|
||||
|
||||
vm_id = @vm['ID']
|
||||
process do |nic|
|
||||
#:white_ports_tcp => iptables_range
|
||||
#:white_ports_udp => iptables_range
|
||||
@ -66,9 +71,13 @@ class OpenNebulaFirewall < OpenNebulaNetwork
|
||||
process_chain(chain, tap, nic_rules)
|
||||
end
|
||||
end
|
||||
|
||||
unlock
|
||||
end
|
||||
|
||||
def deactivate
|
||||
lock
|
||||
|
||||
vm_id = @vm['ID']
|
||||
process do |nic|
|
||||
chain = "one-#{vm_id}-#{nic[:network_id]}"
|
||||
@ -78,6 +87,8 @@ class OpenNebulaFirewall < OpenNebulaNetwork
|
||||
purge_chain(chain, rule_num)
|
||||
end
|
||||
end
|
||||
|
||||
unlock
|
||||
end
|
||||
|
||||
def purge_chain(chain, rule_num)
|
||||
|
@ -101,6 +101,8 @@ class OpenNebulaNetwork
|
||||
end
|
||||
|
||||
def initialize(vm_tpl, xpath_filter, deploy_id = nil, hypervisor = nil)
|
||||
@locking = false
|
||||
|
||||
if !hypervisor
|
||||
@hypervisor = detect_hypervisor
|
||||
else
|
||||
@ -110,6 +112,20 @@ class OpenNebulaNetwork
|
||||
@vm = VM.new(REXML::Document.new(vm_tpl).root, xpath_filter, deploy_id, @hypervisor)
|
||||
end
|
||||
|
||||
def lock
|
||||
if @locking
|
||||
driver_name = self.class.name.downcase
|
||||
@locking_file = File.open("/tmp/onevnm-#{driver_name}-lock","w")
|
||||
@locking_file.flock(File::LOCK_EX)
|
||||
end
|
||||
end
|
||||
|
||||
def unlock
|
||||
if @locking
|
||||
@locking_file.close
|
||||
end
|
||||
end
|
||||
|
||||
def process(&block)
|
||||
@vm.each_nic(block)
|
||||
end
|
||||
|
@ -17,10 +17,13 @@
|
||||
require 'OpenNebulaNetwork'
|
||||
|
||||
class EbtablesVLAN < OpenNebulaNetwork
|
||||
DRIVER = "ebtables"
|
||||
|
||||
XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
@locking = true
|
||||
end
|
||||
|
||||
def ebtables(rule)
|
||||
@ -30,6 +33,8 @@ class EbtablesVLAN < OpenNebulaNetwork
|
||||
# Activates ebtables rules
|
||||
#
|
||||
def activate
|
||||
lock
|
||||
|
||||
process do |nic|
|
||||
tap = nic[:tap]
|
||||
if tap
|
||||
@ -49,10 +54,14 @@ class EbtablesVLAN < OpenNebulaNetwork
|
||||
end
|
||||
end
|
||||
|
||||
unlock
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
def deactivate
|
||||
lock
|
||||
|
||||
process do |nic|
|
||||
mac = nic[:mac]
|
||||
# remove 0-padding
|
||||
@ -68,6 +77,8 @@ class EbtablesVLAN < OpenNebulaNetwork
|
||||
remove_rules(tap)
|
||||
end
|
||||
|
||||
unlock
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
require 'OpenNebulaNetwork'
|
||||
|
||||
class OpenvSwitchVLAN < OpenNebulaNetwork
|
||||
DRIVER = "ovswitch"
|
||||
|
||||
FIREWALL_PARAMS = [:black_ports_tcp,
|
||||
:black_ports_udp,
|
||||
:icmp]
|
||||
@ -25,9 +27,12 @@ class OpenvSwitchVLAN < OpenNebulaNetwork
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
@locking = false
|
||||
end
|
||||
|
||||
def activate
|
||||
lock
|
||||
|
||||
process do |nic|
|
||||
@nic = nic
|
||||
|
||||
@ -40,16 +45,23 @@ class OpenvSwitchVLAN < OpenNebulaNetwork
|
||||
# Apply Firewall
|
||||
configure_fw if FIREWALL_PARAMS & @nic.keys != []
|
||||
end
|
||||
|
||||
unlock
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
def deactivate
|
||||
lock
|
||||
|
||||
process do |nic|
|
||||
@nic = nic
|
||||
|
||||
# Remove flows
|
||||
del_flows
|
||||
end
|
||||
|
||||
unlock
|
||||
end
|
||||
|
||||
def tag_vlan
|
||||
|
@ -37,11 +37,14 @@ require 'CommandManager'
|
||||
require 'OpenNebulaNetwork'
|
||||
|
||||
class OpenNebulaVMware < OpenNebulaNetwork
|
||||
DRIVER = "vmware"
|
||||
|
||||
XPATH_FILTER = "TEMPLATE/NIC"
|
||||
VCLI_PREFIX = "/usr/bin/vicfg"
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
@locking = false
|
||||
|
||||
@config = YAML::load(File.read(CONF_FILE))
|
||||
|
||||
@ -59,6 +62,8 @@ class OpenNebulaVMware < OpenNebulaNetwork
|
||||
end
|
||||
|
||||
def activate
|
||||
lock
|
||||
|
||||
vm_id = @vm['ID']
|
||||
hostname = @vm['HISTORY_RECORDS/HISTORY/HOSTNAME']
|
||||
process do |nic|
|
||||
@ -79,6 +84,8 @@ class OpenNebulaVMware < OpenNebulaNetwork
|
||||
add_pg(pg, switch, vlan) if !check_pg(pg, switch)
|
||||
end
|
||||
|
||||
unlock
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user