[Kimchi-devel] [WIP PATCH 1/5] Make function "randomMAC" public
Crístian Viana
vianac at linux.vnet.ibm.com
Fri Oct 17 08:26:48 UTC 2014
A function from a different module might require a new random MAC so the
function "randomMAC", defined inside another function in VMIfacesModel,
should be declared in a public scope.
Move the definition of "randomMAC" to outside its outer function in
order to make it public.
Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
---
src/kimchi/model/vmifaces.py | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/kimchi/model/vmifaces.py b/src/kimchi/model/vmifaces.py
index 66b3827..721bf14 100644
--- a/src/kimchi/model/vmifaces.py
+++ b/src/kimchi/model/vmifaces.py
@@ -38,13 +38,6 @@ class VMIfacesModel(object):
return macs
def create(self, vm, params):
- def randomMAC():
- mac = [0x52, 0x54, 0x00,
- random.randint(0x00, 0x7f),
- random.randint(0x00, 0xff),
- random.randint(0x00, 0xff)]
- return ':'.join(map(lambda x: "%02x" % x, mac))
-
conn = self.conn.get()
networks = conn.listNetworks() + conn.listDefinedNetworks()
@@ -59,11 +52,10 @@ class VMIfacesModel(object):
macs = (iface.mac.get('address')
for iface in self.get_vmifaces(vm, self.conn))
- mac = randomMAC()
while True:
+ mac = VMIfacesModel.random_mac()
if mac not in macs:
break
- mac = randomMAC()
children = [E.mac(address=mac)]
("network" in params.keys() and
@@ -86,6 +78,14 @@ class VMIfacesModel(object):
return root.devices.findall("interface")
+ @staticmethod
+ def random_mac():
+ mac = [0x52, 0x54, 0x00,
+ random.randint(0x00, 0x7f),
+ random.randint(0x00, 0xff),
+ random.randint(0x00, 0xff)]
+ return ':'.join(map(lambda x: u'%02x' % x, mac))
+
class VMIfaceModel(object):
def __init__(self, **kargs):
--
1.9.3
More information about the Kimchi-devel
mailing list