pvl.hosts: normalize host ethernet syntax
authorTero Marttila <terom@paivola.fi>
Mon, 31 Mar 2014 17:27:36 +0300
changeset 412 b557b472ffa1
parent 411 9ac5dae42adb
child 413 cb7782e5a2fd
pvl.hosts: normalize host ethernet syntax
pvl/hosts.py
--- a/pvl/hosts.py	Mon Mar 31 17:14:51 2014 +0300
+++ b/pvl/hosts.py	Mon Mar 31 17:27:36 2014 +0300
@@ -32,6 +32,13 @@
 class HostConfigError (HostError) :
     pass
 
+def parse_ethernet (value) :
+    """
+        Normalize ethernet str.
+    """
+
+    return ':'.join('%02x' % int(x, 16) for x in value.split(':'))
+
 class Host (object) :
     # the label used for alias4/6 hosts
     ALIAS4_FMT = '{host}-ipv4'
@@ -143,10 +150,10 @@
             
             if field == 'ethernet' :
                 if instance :
-                    ethernet[instance] = value
+                    ethernet[instance] = parse_ethernet(value)
                 else :
                     for eth in value.split() :
-                        ethernet[len(ethernet)] = eth
+                        ethernet[len(ethernet)] = parse_ethernet(eth)
             else :
                 raise ValueError("%s: Unknown host field: %s=%s" % (host, field, value))