Revision beb81ea5 lib/config.py

b/lib/config.py
162 162

  
163 163
  return result
164 164

  
165
def _GenerateMACSuffix():
166
  """Generate one mac address
167

  
168
  """
169
  byte1 = random.randrange(0, 256)
170
  byte2 = random.randrange(0, 256)
171
  byte3 = random.randrange(0, 256)
172
  suffix = "%02x:%02x:%02x" % (byte1, byte2, byte3)
173
  return suffix
174

  
165 175

  
166 176
class ConfigWriter:
167 177
  """The interface to the cluster configuration.
......
235 245
      return wraps(view_func)(_decorator)
236 246
    return _get_mac_prefix
237 247

  
238
  def _GenerateMACSuffix(self):
239
    """Generate one mac address
240

  
241
    """
242
    byte1 = random.randrange(0, 256)
243
    byte2 = random.randrange(0, 256)
244
    byte3 = random.randrange(0, 256)
245
    suffix = "%02x:%02x:%02x" % (byte1, byte2, byte3)
246
    return suffix
247

  
248 248
  @locking.ssynchronized(_config_lock, shared=1)
249 249
  def GetNdParams(self, node):
250 250
    """Get the node params populated with cluster defaults.
......
299 299

  
300 300
    """
301 301
    existing = self._AllMACs()
302
    gen_mac = self._GenerateMACPrefix(net)(self._GenerateMACSuffix)
302
    gen_mac = self._GenerateMACPrefix(net)(_GenerateMACSuffix)
303 303
    return self._temporary_ids.Generate(existing, gen_mac, ec_id)
304 304

  
305 305
  @locking.ssynchronized(_config_lock, shared=1)
......
343 343
    as reserved.
344 344

  
345 345
    """
346
    nobj = self._UnlockedGetNetwork(net_uuid)
347
    pool = network.AddressPool(nobj)
348 346
    self._temporary_ips.Reserve(ec_id, ('release', address, net_uuid))
349 347

  
350 348
  @locking.ssynchronized(_config_lock, shared=1)
351
  def ReleaseIp(self, network, address, ec_id):
349
  def ReleaseIp(self, net, address, ec_id):
352 350
    """Give a specified IP address back to an IP pool.
353 351

  
354 352
    This is just a wrapper around _UnlockedReleaseIp.
355 353

  
356 354
    """
357
    net_uuid = self._UnlockedLookupNetwork(network)
355
    net_uuid = self._UnlockedLookupNetwork(net)
358 356
    if net_uuid:
359 357
      self._UnlockedReleaseIp(net_uuid, address, ec_id)
360 358

  
......
375 373
        raise errors.ReservationError("Cannot generate IP. Network is full")
376 374
      return ("reserve", ip, net_uuid)
377 375

  
378
    _ ,address, _ = self._temporary_ips.Generate([], gen_one, ec_id)
376
    _, address, _ = self._temporary_ips.Generate([], gen_one, ec_id)
379 377
    return address
380 378

  
381 379
  def _UnlockedReserveIp(self, net_uuid, address, ec_id):
......
2409 2407
    """Get a list of network names
2410 2408

  
2411 2409
    """
2412
    names = [network.name
2413
             for network in self._config_data.networks.values()]
2410
    names = [net.name
2411
             for net in self._config_data.networks.values()]
2414 2412
    return names
2415 2413

  
2416 2414
  def _UnlockedGetNetwork(self, uuid):
......
2568 2566
    for net_uuid in nodegroup_info.networks.keys():
2569 2567
      net_info = self._UnlockedGetNetwork(net_uuid)
2570 2568
      pool = network.AddressPool(net_info)
2571
      if pool._Contains(ip):
2569
      if pool.Contains(ip):
2572 2570
        return (net_info.name, nodegroup_info.networks[net_uuid])
2573 2571

  
2574 2572
    return (None, None)

Also available in: Unified diff