Commit eed7410e authored by Romain Courteaud's avatar Romain Courteaud

Stabilize the mac address generation.

Mac address is now stored in plaintext on the file system.
parent 3d460bf3
############################################################################## ##############################################################################
# #
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved. # Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
...@@ -26,15 +25,26 @@ ...@@ -26,15 +25,26 @@
# #
############################################################################## ##############################################################################
import random import random
import os
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
if os.path.exists(options['storage-path']):
open_file = open(options['storage-path'], 'r')
options['mac-address'] = open_file.read()
open_file.close()
if options.get('mac-address', '') == '':
# First octet has to represent a locally administered address # First octet has to represent a locally administered address
octet_list = [254] + [random.randint(0x00, 0xff) for x in range(5)] octet_list = [254] + [random.randint(0x00, 0xff) for x in range(5)]
options['mac-address'] = ':'.join(['%02x' % x for x in octet_list]) options['mac-address'] = ':'.join(['%02x' % x for x in octet_list])
return GenericBaseRecipe.__init__(self, buildout, name, options)
def install(self): def install(self):
return [] open_file = open(self.options['storage-path'], 'w')
open_file.write(self.options['mac-address'])
open_file.close()
return [self.options['storage-path']]
...@@ -33,6 +33,7 @@ ca-dir = $${rootdirectory:srv}/ssl ...@@ -33,6 +33,7 @@ ca-dir = $${rootdirectory:srv}/ssl
[create-mac] [create-mac]
recipe = slapos.cookbook:generate.mac recipe = slapos.cookbook:generate.mac
storage-path = $${rootdirectory:srv}/mac
[kvm-instance] [kvm-instance]
recipe = slapos.cookbook:kvm recipe = slapos.cookbook:kvm
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment