FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

kvm: Aqcuire lock when running security group Python script by wido · Pull Request #1408 · apache/cloudstack · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 27 additions & 1 deletion scripts/vm/network/security_group.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
from optparse import OptionParser, OptionGroup, OptParseError, BadOptionError, OptionError, OptionConflictError, OptionValueError
import re
import libvirt
import fcntl
import time

logpath = "/var/run/cloud/" # FIXME: Logs should reside in /var/log/cloud
lock_file = "/var/lock/cloudstack_security_group.lock"
iptables = Command("iptables")
bash = Command("/bin/bash")
ebtables = Command("ebtables")
Expand All @@ -36,6 +39,21 @@
hyper = cfo.getEntry("hypervisor.type")
if hyper == "lxc":
driver = "lxc:///"

lock_handle = None

def obtain_file_lock(path):
global lock_handle

try:
lock_handle = open(path, 'w')
fcntl.flock(lock_handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
return True
except IOError:
pass

return False

def execute(cmd):
logging.debug(cmd)
return bash("-c", cmd).stdout
Expand Down Expand Up @@ -303,7 +321,7 @@ def default_network_rules_systemvm(vm_name, localbrname):
for bridge in bridges:
if bridge != localbrname:
if not addFWFramework(bridge):
return False
return False
brfw = getBrfw(bridge)
vifs = getVifsForBridge(vm_name, bridge)
for vif in vifs:
Expand Down Expand Up @@ -1029,6 +1047,14 @@ def addFWFramework(brname):
sys.exit(1)
cmd = args[0]
logging.debug("Executing command: " + str(cmd))

for i in range(0, 30):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this can be refactored separately as an acquire lock method that may optionally accept a timeout

if obtain_file_lock(lock_file) is False:
logging.warn("Lock on %s is being held by other process. Waiting for release." % lock_file)
time.sleep(0.5)
else:
break

if cmd == "can_bridge_firewall":
can_bridge_firewall(args[1])
elif cmd == "default_network_rules":
Expand Down

Back | FazBrowse Home | New Git URL