Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Fedora/Linux Management Tools (http://www.linux-archive.org/fedora-linux-management-tools/)
-   -   comparing MAC address is changed to case insensitive (http://www.linux-archive.org/fedora-linux-management-tools/73419-comparing-mac-address-changed-case-insensitive.html)

Hiroyuki Kaguchi 04-21-2008 08:02 AM

comparing MAC address is changed to case insensitive
 
Hi Rich.

Thank you for your advice.

On 2008/04/11 20:42, Richard W.M. Jones wrote:
> You also have to note that 1:2:3:4:5:6 is the same as
> 01:02:03:04:05:06. Comparing MAC addresses is hard :-)

I remake the patch.
This patch compares two MAC addresses ignoring leading zeros.

Signed-off-by: Hiroyuki Kaguchi <fj7025cf@aa.jp.fujitsu.com>
diff -r 6462dfd3e606 -r 6ec83c2a5c36 virtinst/Guest.py
--- a/virtinst/Guest.py Tue Apr 08 15:35:49 2008 -0400
+++ b/virtinst/Guest.py Mon Apr 21 15:44:24 2008 +0900
@@ -368,13 +368,10 @@
continue
ctx = doc.xpathNewContext()
try:
- try:
- count += ctx.xpathEval("count(/domain/devices/interface/mac[@address='%s'])"
- % self.macaddr.upper())
- count += ctx.xpathEval("count(/domain/devices/interface/mac[@address='%s'])"
- % self.macaddr.lower())
- except:
- continue
+ for mac in ctx.xpathEval("/domain/devices/interface/mac"):
+ macaddr = mac.xpathEval("attribute::address")[0].content
+ if util.compareMAC(self.macaddr, macaddr) == 0:
+ count += 1
finally:
if ctx is not None:
ctx.xpathFreeContext()
diff -r 6462dfd3e606 -r 6ec83c2a5c36 virtinst/util.py
--- a/virtinst/util.py Tue Apr 08 15:35:49 2008 -0400
+++ b/virtinst/util.py Mon Apr 21 15:44:24 2008 +0900
@@ -222,3 +222,22 @@
str = str.replace("<", "&lt;")
str = str.replace(">", "&gt;")
return str
+
+def compareMAC(p, q):
+ """Compare two MAC addresses"""
+ pa = p.split(":")
+ qa = q.split(":")
+
+ if len(pa) != len(qa):
+ if p > q:
+ return 1
+ else:
+ return -1
+
+ for i in xrange(len(pa)):
+ n = int(pa[i], 0x10) - int(qa[i], 0x10)
+ if n > 0:
+ return 1
+ elif n < 0:
+ return -1
+ return 0
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

Cole Robinson 04-21-2008 08:39 PM

comparing MAC address is changed to case insensitive
 
Hiroyuki Kaguchi wrote:
> Hi Rich.
>
> Thank you for your advice.
>
> On 2008/04/11 20:42, Richard W.M. Jones wrote:
> > You also have to note that 1:2:3:4:5:6 is the same as
> > 01:02:03:04:05:06. Comparing MAC addresses is hard :-)
>
> I remake the patch.
> This patch compares two MAC addresses ignoring leading zeros.
>
> Signed-off-by: Hiroyuki Kaguchi <fj7025cf@aa.jp.fujitsu.com>
>
>

I've applied this.

http://hg.et.redhat.com/virt/applications/virtinst--devel?cs=a33443874046

Thanks!
Cole


_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools


All times are GMT. The time now is 10:40 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.