Dan Yasny has uploaded a new change for review. Change subject: Hook: Cisco VM-FEX support vdsm hooks ......................................................................
Hook: Cisco VM-FEX support vdsm hooks Now using "with" for files Replaced all file() with open() Made pyflakes happy with the libvirtconnect import statement Change-Id: I2ce5fd0e0ada72970bd1b82502d563fe8f6e3713 Signed-off-by: Dan Yasny <[email protected]> Author: Dan Yasny <[email protected]> --- M vdsm_hooks/vmfex/before_vm_migrate_destination.py M vdsm_hooks/vmfex/before_vm_start.py 2 files changed, 38 insertions(+), 42 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/61/8761/1 diff --git a/vdsm_hooks/vmfex/before_vm_migrate_destination.py b/vdsm_hooks/vmfex/before_vm_migrate_destination.py index 23cf991..07f653f 100755 --- a/vdsm_hooks/vmfex/before_vm_migrate_destination.py +++ b/vdsm_hooks/vmfex/before_vm_migrate_destination.py @@ -3,14 +3,15 @@ import os import sys import traceback +import fcntl +from xml.dom import minidom try: #3.0 compat import libvirtconnection + libvirtconnection except ImportError: #3.1 compat from vdsm import libvirtconnection -import fcntl -from xml.dom import minidom ''' Placed in before_vm_migrate_destination @@ -59,9 +60,8 @@ nics = [] for root, dirs, names in os.walk('/sys/devices/'): if 'address' in names and 'pci' in root: - f = open(root + '/address', 'r') - mac = f.readlines()[0].strip() - f.close() + with open(root + '/address', 'r') as f: + mac = f.readlines()[0].strip() if mac == '00:00:00:00:00:00': eth = root.split('/')[-1] nics.append(eth) @@ -69,7 +69,7 @@ def createDirectPool(conn): - with file('/var/run/vdsm/hook-vmfex.lock', 'w') as f: + with open('/var/run/vdsm/hook-vmfex.lock', 'w') as f: fcntl.flock(f.fileno(), fcntl.LOCK_EX) try: xmlstr = '''<network> @@ -91,7 +91,7 @@ def removeDirectPool(conn): - with file('/var/run/vdsm/hook-vmfex.lock', 'w') as f: + with open('/var/run/vdsm/hook-vmfex.lock', 'w') as f: fcntl.flock(f.fileno(), fcntl.LOCK_EX) try: dpool = conn.networkLookupByName('direct-pool') @@ -126,26 +126,24 @@ def handleDirectPool(conn): - #TODO: take this part and everything it uses out and into a separate - # module + #TODO: take this part and everything it uses out and into a + #separate module #is direct-pool defined? If not, just create it and move on if 'direct-pool' not in conn.listNetworks(): createDirectPool(conn) return #Now we know for sure that the pool exists... - #are there VMs running? - if conn.listDomainsID(): - #does any of the running VMs havd a Qbh nic? - #if yes, can't touch the existing pool - if not qbhInUse(conn): - #no VMs use the existing pool, it can be checked and updated - #is the pool the same as list of available dNICs? - if not compareDPoolToUsableNics(conn): - #not the same, something changed, recreating - removeDirectPool(conn) - createDirectPool(conn) - #no VMs running, pool can be updated + #are there VMs running, and are they using 802.1Qbh? + #if yes, can't touch the existing pool + if not qbhInUse(conn): + #no VMs use the existing pool, it can be checked and updated + #is the pool the same as list of available dNICs? + if not compareDPoolToUsableNics(conn): + #not the same, something changed, recreating + removeDirectPool(conn) + createDirectPool(conn) + #no VMs running with Qbh, pool can be updated else: #is the pool the same as list of available dNICs? if not compareDPoolToUsableNics(conn): diff --git a/vdsm_hooks/vmfex/before_vm_start.py b/vdsm_hooks/vmfex/before_vm_start.py index 944bf0a..1ef86e4 100755 --- a/vdsm_hooks/vmfex/before_vm_start.py +++ b/vdsm_hooks/vmfex/before_vm_start.py @@ -4,15 +4,16 @@ import sys import hooking import traceback +import fcntl +import ast from xml.dom import minidom try: #3.0 compat import libvirtconnection + libvirtconnection except ImportError: #3.1 compat from vdsm import libvirtconnection -import fcntl -import ast ''' Placed in before_vm_start @@ -93,9 +94,8 @@ nics = [] for root, dirs, names in os.walk('/sys/devices/'): if 'address' in names and 'pci' in root: - f = open(root + '/address', 'r') - mac = f.readlines()[0].strip() - f.close() + with open(root + '/address', 'r') as f: + mac = f.readlines()[0].strip() if mac == '00:00:00:00:00:00': eth = root.split('/')[-1] nics.append(eth) @@ -103,7 +103,7 @@ def createDirectPool(conn): - with file('/var/run/vdsm/hook-vmfex.lock', 'w') as f: + with open('/var/run/vdsm/hook-vmfex.lock', 'w') as f: fcntl.flock(f.fileno(), fcntl.LOCK_EX) try: xmlstr = '''<network> @@ -125,7 +125,7 @@ def removeDirectPool(conn): - with file('/var/run/vdsm/hook-vmfex.lock', 'w') as f: + with open('/var/run/vdsm/hook-vmfex.lock', 'w') as f: fcntl.flock(f.fileno(), fcntl.LOCK_EX) try: dpool = conn.networkLookupByName('direct-pool') @@ -160,26 +160,24 @@ def handleDirectPool(conn): - #TODO: take this part and everything it uses out and into a separate - # module + #TODO: take this part and everything it uses out and into a + #separate module #is direct-pool defined? If not, just create it and move on if 'direct-pool' not in conn.listNetworks(): createDirectPool(conn) return #Now we know for sure that the pool exists... - #are there VMs running? - if conn.listDomainsID(): - #does any of the running VMs havd a Qbh nic? - #if yes, can't touch the existing pool - if not qbhInUse(conn): - #no VMs use the existing pool, it can be checked and updated - #is the pool the same as list of available dNICs? - if not compareDPoolToUsableNics(conn): - #not the same, something changed, recreating - removeDirectPool(conn) - createDirectPool(conn) - #no VMs running, pool can be updated + #are there VMs running, and are they using 802.1Qbh? + #if yes, can't touch the existing pool + if not qbhInUse(conn): + #no VMs use the existing pool, it can be checked and updated + #is the pool the same as list of available dNICs? + if not compareDPoolToUsableNics(conn): + #not the same, something changed, recreating + removeDirectPool(conn) + createDirectPool(conn) + #no VMs running with Qbh, pool can be updated else: #is the pool the same as list of available dNICs? if not compareDPoolToUsableNics(conn): -- To view, visit http://gerrit.ovirt.org/8761 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2ce5fd0e0ada72970bd1b82502d563fe8f6e3713 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Dan Yasny <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
