Revision 18b1d400 lib/config.py
b/lib/config.py | ||
---|---|---|
39 | 39 |
import logging |
40 | 40 |
import time |
41 | 41 |
import itertools |
42 |
from functools import wraps |
|
42 | 43 |
|
43 | 44 |
from ganeti import errors |
44 | 45 |
from ganeti import locking |
... | ... | |
218 | 219 |
""" |
219 | 220 |
return os.path.exists(constants.CLUSTER_CONF_FILE) |
220 | 221 |
|
221 |
def _GenerateOneMAC(self): |
|
222 |
def _GenerateMACPrefix(self, net=None): |
|
223 |
def _get_mac_prefix(view_func): |
|
224 |
def _decorator(*args, **kwargs): |
|
225 |
prefix = self._config_data.cluster.mac_prefix |
|
226 |
if net: |
|
227 |
net_uuid = self._UnlockedLookupNetwork(net) |
|
228 |
if net_uuid: |
|
229 |
nobj = self._UnlockedGetNetwork(net_uuid) |
|
230 |
if nobj.mac_prefix: |
|
231 |
prefix = nobj.mac_prefix |
|
232 |
suffix = view_func(*args, **kwargs) |
|
233 |
return prefix+':'+suffix |
|
234 |
return wraps(view_func)(_decorator) |
|
235 |
return _get_mac_prefix |
|
236 |
|
|
237 |
def _GenerateMACSuffix(self): |
|
222 | 238 |
"""Generate one mac address |
223 | 239 |
|
224 | 240 |
""" |
225 |
prefix = self._config_data.cluster.mac_prefix |
|
226 | 241 |
byte1 = random.randrange(0, 256) |
227 | 242 |
byte2 = random.randrange(0, 256) |
228 | 243 |
byte3 = random.randrange(0, 256) |
229 |
mac = "%s:%02x:%02x:%02x" % (prefix, byte1, byte2, byte3)
|
|
230 |
return mac
|
|
244 |
suffix = "%02x:%02x:%02x" % (byte1, byte2, byte3)
|
|
245 |
return suffix
|
|
231 | 246 |
|
232 | 247 |
@locking.ssynchronized(_config_lock, shared=1) |
233 | 248 |
def GetNdParams(self, node): |
... | ... | |
276 | 291 |
return self._config_data.cluster.SimpleFillDP(group.diskparams) |
277 | 292 |
|
278 | 293 |
@locking.ssynchronized(_config_lock, shared=1) |
279 |
def GenerateMAC(self, ec_id): |
|
294 |
def GenerateMAC(self, net, ec_id):
|
|
280 | 295 |
"""Generate a MAC for an instance. |
281 | 296 |
|
282 | 297 |
This should check the current instances for duplicates. |
283 | 298 |
|
284 | 299 |
""" |
285 | 300 |
existing = self._AllMACs() |
286 |
return self._temporary_ids.Generate(existing, self._GenerateOneMAC, ec_id) |
|
301 |
gen_mac = self._GenerateMACPrefix(net)(self._GenerateMACSuffix) |
|
302 |
return self._temporary_ids.Generate(existing, gen_mac, ec_id) |
|
287 | 303 |
|
288 | 304 |
@locking.ssynchronized(_config_lock, shared=1) |
289 | 305 |
def ReserveMAC(self, mac, ec_id): |
Also available in: Unified diff