Revision 5b27366d 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 |
... | ... | |
219 | 220 |
""" |
220 | 221 |
return os.path.exists(pathutils.CLUSTER_CONF_FILE) |
221 | 222 |
|
222 |
def _GenerateOneMAC(self): |
|
223 |
def _GenerateMACPrefix(self, net=None): |
|
224 |
def _get_mac_prefix(view_func): |
|
225 |
def _decorator(*args, **kwargs): |
|
226 |
prefix = self._config_data.cluster.mac_prefix |
|
227 |
if net: |
|
228 |
net_uuid = self._UnlockedLookupNetwork(net) |
|
229 |
if net_uuid: |
|
230 |
nobj = self._UnlockedGetNetwork(net_uuid) |
|
231 |
if nobj.mac_prefix: |
|
232 |
prefix = nobj.mac_prefix |
|
233 |
suffix = view_func(*args, **kwargs) |
|
234 |
return prefix+':'+suffix |
|
235 |
return wraps(view_func)(_decorator) |
|
236 |
return _get_mac_prefix |
|
237 |
|
|
238 |
def _GenerateMACSuffix(self): |
|
223 | 239 |
"""Generate one mac address |
224 | 240 |
|
225 | 241 |
""" |
226 |
prefix = self._config_data.cluster.mac_prefix |
|
227 | 242 |
byte1 = random.randrange(0, 256) |
228 | 243 |
byte2 = random.randrange(0, 256) |
229 | 244 |
byte3 = random.randrange(0, 256) |
230 |
mac = "%s:%02x:%02x:%02x" % (prefix, byte1, byte2, byte3)
|
|
231 |
return mac
|
|
245 |
suffix = "%02x:%02x:%02x" % (byte1, byte2, byte3)
|
|
246 |
return suffix
|
|
232 | 247 |
|
233 | 248 |
@locking.ssynchronized(_config_lock, shared=1) |
234 | 249 |
def GetNdParams(self, node): |
... | ... | |
277 | 292 |
return self._config_data.cluster.SimpleFillDP(group.diskparams) |
278 | 293 |
|
279 | 294 |
@locking.ssynchronized(_config_lock, shared=1) |
280 |
def GenerateMAC(self, ec_id): |
|
295 |
def GenerateMAC(self, net, ec_id):
|
|
281 | 296 |
"""Generate a MAC for an instance. |
282 | 297 |
|
283 | 298 |
This should check the current instances for duplicates. |
284 | 299 |
|
285 | 300 |
""" |
286 | 301 |
existing = self._AllMACs() |
287 |
return self._temporary_ids.Generate(existing, self._GenerateOneMAC, ec_id) |
|
302 |
gen_mac = self._GenerateMACPrefix(net)(self._GenerateMACSuffix) |
|
303 |
return self._temporary_ids.Generate(existing, gen_mac, ec_id) |
|
288 | 304 |
|
289 | 305 |
@locking.ssynchronized(_config_lock, shared=1) |
290 | 306 |
def ReserveMAC(self, mac, ec_id): |
Also available in: Unified diff