Change in vdsm[master]: Removed trailing spaces and added extra traceback logging
dyasny at gmail.com
dyasny at gmail.com
Tue Aug 28 15:52:19 UTC 2012
Dan Yasny has uploaded a new change for review.
Change subject: Removed trailing spaces and added extra traceback logging
......................................................................
Removed trailing spaces and added extra traceback logging
Change-Id: Ifbce514ffb5547aa90e56495771802409cbc0dbc
Signed-off-by: Dan Yasny <dyasny at gmail.com>
---
M vdsm_hooks/vmfex/Makefile.am
M vdsm_hooks/vmfex/README
M vdsm_hooks/vmfex/before_vm_migrate_destination.py
M vdsm_hooks/vmfex/before_vm_start.py
4 files changed, 32 insertions(+), 40 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/48/7548/1
diff --git a/vdsm_hooks/vmfex/Makefile.am b/vdsm_hooks/vmfex/Makefile.am
index b921275..2a6c244 100644
--- a/vdsm_hooks/vmfex/Makefile.am
+++ b/vdsm_hooks/vmfex/Makefile.am
@@ -22,7 +22,7 @@
before_vm_migrate_destination.py \
before_vm_start.py \
-install-data-local:
+install-data-local:
$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start
$(INSTALL_SCRIPT) $(srcdir)/before_vm_start.py \
$(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_vmfex
diff --git a/vdsm_hooks/vmfex/README b/vdsm_hooks/vmfex/README
index 1eb7629..030f145 100644
--- a/vdsm_hooks/vmfex/README
+++ b/vdsm_hooks/vmfex/README
@@ -7,8 +7,8 @@
Will add 2 virtual nics attached to profile1 and profile2 using the vnic
MAC addresses specified, replacing the actual NICs assigned to the VM.
- The mapping is by order of NIC<number> in the parameters, mapped to the
- order of the "interface" elements in the devices of the VM xml, as well
+ The mapping is by order of NIC<number> in the parameters, mapped to the
+ order of the "interface" elements in the devices of the VM xml, as well
as the NICs defined for a VM in the RHEV-M admin GUI.
Libvirt internals:
@@ -18,7 +18,7 @@
<model type="virtio"/>
<source bridge="<logical network>"/>
</interface>
-
+
with the following interface xml:
<interface type='network'>
<mac address='<mac>'/>
@@ -28,7 +28,7 @@
</virtualport>
<model type='virtio'/>
</interface>
-
+
Dynamic network with libvirt (define a NIC pool, so libvirt can assign VMs to NICs dynamically):
<network>
diff --git a/vdsm_hooks/vmfex/before_vm_migrate_destination.py b/vdsm_hooks/vmfex/before_vm_migrate_destination.py
index a80df7f..301f015 100755
--- a/vdsm_hooks/vmfex/before_vm_migrate_destination.py
+++ b/vdsm_hooks/vmfex/before_vm_migrate_destination.py
@@ -3,7 +3,6 @@
import os
import subprocess
import sys
-import hooking
import traceback
import libvirtconnection
@@ -46,13 +45,13 @@
'''
def getUsableNics():
- # Scan localhost for physical NICs and return list of physical nics
+ # Scan localhost for physical NICs and return list of physical nics
# that have all zeroes MAC
# Example ['eth0','eth1']
nics = []
cmd = "find /sys/devices/pci* | grep '/net/' |grep address"
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
- s = p.stdout.read().split()
+ s = p.stdout.read().split()
for i in s:
mac = open(i).read().strip()
if mac == '00:00:00:00:00:00':
@@ -64,42 +63,40 @@
for i in getUsableNics():
s = '<interface dev="' + str(i) + '"/> \n'
xmlstr += s
-
+
xmlstr += """ </forward> \n </network> """
conn.networkDefineXML(xmlstr)
dpool = conn.networkLookupByName('direct-pool')
dpool.setAutostart(1)
dpool.create()
-
-
if os.environ.has_key('vmfex'):
try:
#connect to libvirtd
conn = libvirtconnection.get('qemu:///system')
-
+
#check for running VMs. If there are VMs running, skip creating a dNIC pool
if len(conn.listDomainsID()) == 0:
#check if direct-pool is created
if 'direct-pool' not in conn.listNetworks():
createDirectPool(conn)
- else:
+ else:
if conn.networkLookupByName('direct-pool').isActive() == 0:
conn.networkLookupByName('direct-pool').create()
conn.networkLookupByName('direct-pool').setAutostart(1)
-
+
#check if the defined dNIC pool didn't change
dpool = conn.networkLookupByName('direct-pool')
definedNics = []
for i in dpool.split():
if 'dev=' in i:
definedNics.append(str(i.split('=')[1].split('/')[0].strip("'")))
- #if the defined NIC pool doesn't match the usable NIC list, recreate the network
+ #if the defined NIC pool doesn't match the usable NIC list, recreate the network
if set(definedNics) != set(getUsableNics()):
conn.networkLookupByName('direct-pool').destroy()
conn.networkLookupByName('direct-pool').undefine()
createDirectPool(conn)
-
+
if 'direct-pool' not in conn.listNetworks():
createDirectPool(conn)
diff --git a/vdsm_hooks/vmfex/before_vm_start.py b/vdsm_hooks/vmfex/before_vm_start.py
index 9002e3f..dc32f8d 100755
--- a/vdsm_hooks/vmfex/before_vm_start.py
+++ b/vdsm_hooks/vmfex/before_vm_start.py
@@ -3,10 +3,8 @@
import os
import subprocess
import sys
-import xml
import hooking
import traceback
-from xml.dom import minidom
import libvirtconnection
'''
@@ -19,8 +17,8 @@
Will add 2 virtual nics attached to profile1 and profile2 using the vnic
MAC addresses specified, replacing the actual NICs assigned to the VM.
- The mapping is by order of NIC<number> in the parameters, mapped to the
- order of the "interface" elements in the devices of the VM xml, as well
+ The mapping is by order of NIC<number> in the parameters, mapped to the
+ order of the "interface" elements in the devices of the VM xml, as well
as the NICs defined for a VM in the RHEV-M admin GUI.
Libvirt internals:
@@ -30,7 +28,7 @@
<model type="virtio"/>
<source bridge="<logical network>"/>
</interface>
-
+
with the following interface xml:
<interface type='network'>
<mac address='<mac>'/>
@@ -40,7 +38,7 @@
</virtualport>
<model type='virtio'/>
</interface>
-
+
Dynamic network with libvirt (define a NIC pool, so libvirt can assign VMs to NICs dynamically):
<network>
@@ -75,13 +73,13 @@
'''
def getUsableNics():
- # Scan localhost for physical NICs and return list of physical nics
+ # Scan localhost for physical NICs and return list of physical nics
# that have all zeroes MAC
# Example ['eth0','eth1']
nics = []
cmd = "find /sys/devices/pci* | grep '/net/' |grep address"
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
- s = p.stdout.read().split()
+ s = p.stdout.read().split()
for i in s:
mac = open(i).read().strip()
if mac == '00:00:00:00:00:00':
@@ -102,37 +100,35 @@
for i in getUsableNics():
s = '<interface dev="' + str(i) + '"/> \n'
xmlstr += s
-
+
xmlstr += """ </forward> \n </network> """
conn.networkDefineXML(xmlstr)
dpool = conn.networkLookupByName('direct-pool')
dpool.setAutostart(1)
dpool.create()
-
-
if os.environ.has_key('vmfex'):
try:
#connect to libvirtd
conn = libvirtconnection.get('qemu:///system')
-
+
#check for running VMs. If there are VMs running, skip creating a dNIC pool
if len(conn.listDomainsID()) == 0:
#check if direct-pool is created
if 'direct-pool' not in conn.listNetworks():
createDirectPool(conn)
- else:
+ else:
if conn.networkLookupByName('direct-pool').isActive() == 0:
conn.networkLookupByName('direct-pool').create()
conn.networkLookupByName('direct-pool').setAutostart(1)
-
+
#check if the defined dNIC pool didn't change
dpool = conn.networkLookupByName('direct-pool')
definedNics = []
for i in dpool.split():
if 'dev=' in i:
definedNics.append(str(i.split('=')[1].split('/')[0].strip("'")))
- #if the defined NIC pool doesn't match the usable NIC list, recreate the network
+ #if the defined NIC pool doesn't match the usable NIC list, recreate the network
if set(definedNics) != set(getUsableNics()):
conn.networkLookupByName('direct-pool').destroy()
conn.networkLookupByName('direct-pool').undefine()
@@ -140,11 +136,11 @@
if 'direct-pool' not in conn.listNetworks():
createDirectPool(conn)
-
+
except:
- pass
-
-
+ sys.stderr.write('vmfex: Error in libvirt network definition: %s\n' % entry)
+ sys.exit(2)
+
try:
#Get the vmfex line
vmfex = os.environ['vmfex']
@@ -153,12 +149,11 @@
domxml = hooking.read_domxml()
devices = domxml.getElementsByTagName('devices')[0]
vnicmap = enumNics(devices)
-
+
counter = 0
-
for entry in vmfex.split(','):
sys.stderr.write('vmfex: adding interface to profile: %s\n' % entry)
- try:
+ try:
nicnum = int(entry.split(':')[0][3:])
profile = entry.split(':')[1]
mynic = vnicmap[nicnum]
@@ -168,7 +163,7 @@
source = mynic.getElementsByTagName('source')[0]
source.removeAttribute('bridge')
source.setAttribute('network', 'direct-pool')
-
+
virtualport = domxml.createElement('virtualport')
virtualport.setAttribute('type', '802.1Qbh')
mynic.appendChild(virtualport)
@@ -176,7 +171,7 @@
parameters = domxml.createElement('parameters')
parameters.setAttribute('profileid', profile)
virtualport.appendChild(parameters)
-
+
except:
sys.stderr.write('vmfex: Error in vmfex custom property line: %s\n' % entry)
sys.exit(2)
--
To view, visit http://gerrit.ovirt.org/7548
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifbce514ffb5547aa90e56495771802409cbc0dbc
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Yasny <dyasny at gmail.com>
More information about the vdsm-patches
mailing list