Revision c01a7953 lib/config.py

b/lib/config.py
330 330
    """Commit all reserved IP address to their respective pools
331 331

  
332 332
    """
333
    for action, address, net_uuid in self._temporary_ips.GetECReserved(ec_id):
334
      self._UnlockedCommitIp(action, net_uuid, address)
333
    for action, address, net_uuid, external in \
334
          self._temporary_ips.GetECReserved(ec_id):
335
      self._UnlockedCommitIp(action, net_uuid, address, external)
335 336

  
336
  def _UnlockedCommitIp(self, action, net_uuid, address):
337
  def _UnlockedCommitIp(self, action, net_uuid, address, external):
337 338
    """Commit a reserved IP address to an IP pool.
338 339

  
339 340
    The IP address is taken from the network's IP pool and marked as reserved.
......
342 343
    nobj = self._UnlockedGetNetwork(net_uuid)
343 344
    pool = network.AddressPool(nobj)
344 345
    if action == constants.RESERVE_ACTION:
345
      pool.Reserve(address)
346
      pool.Reserve(address, external)
346 347
    elif action == constants.RELEASE_ACTION:
347
      pool.Release(address)
348
      pool.Release(address, external)
348 349

  
349
  def _UnlockedReleaseIp(self, net_uuid, address, ec_id):
350
  def _UnlockedReleaseIp(self, net_uuid, address, external, ec_id):
350 351
    """Give a specific IP address back to an IP pool.
351 352

  
352 353
    The IP address is returned to the IP pool designated by pool_id and marked
......
354 355

  
355 356
    """
356 357
    self._temporary_ips.Reserve(ec_id,
357
                                (constants.RELEASE_ACTION, address, net_uuid))
358
                                (constants.RELEASE_ACTION,
359
                                address, net_uuid, external))
358 360

  
359 361
  @locking.ssynchronized(_config_lock, shared=1)
360
  def ReleaseIp(self, net_uuid, address, ec_id):
362
  def ReleaseIp(self, net_uuid, address, external, ec_id):
361 363
    """Give a specified IP address back to an IP pool.
362 364

  
363 365
    This is just a wrapper around _UnlockedReleaseIp.
364 366

  
365 367
    """
366 368
    if net_uuid:
367
      self._UnlockedReleaseIp(net_uuid, address, ec_id)
369
      self._UnlockedReleaseIp(net_uuid, address, external, ec_id)
368 370

  
369 371
  @locking.ssynchronized(_config_lock, shared=1)
370 372
  def GenerateIp(self, net_uuid, ec_id):
......
378 380
      try:
379 381
        ip = pool.GenerateFree()
380 382
      except errors.AddressPoolError:
381
        raise errors.ReservationError("Cannot generate IP. Network is full")
382
      return (constants.RESERVE_ACTION, ip, net_uuid)
383
        raise errors.OpPrereqError("Cannot generate IP."
384
                                   " Network '%s' is full." % nobj.name,
385
                                   errors.ECODE_STATE)
386
      return (constants.RESERVE_ACTION, ip, net_uuid, False)
383 387

  
384
    _, address, _ = self._temporary_ips.Generate([], gen_one, ec_id)
388
    _, address, _, _ = self._temporary_ips.Generate([], gen_one, ec_id)
385 389
    return address
386 390

  
387
  def _UnlockedReserveIp(self, net_uuid, address, ec_id):
391
  def _UnlockedReserveIp(self, net_uuid, address, external, ec_id):
388 392
    """Reserve a given IPv4 address for use by an instance.
389 393

  
390 394
    """
391 395
    nobj = self._UnlockedGetNetwork(net_uuid)
392 396
    pool = network.AddressPool(nobj)
393
    try:
394
      isreserved = pool.IsReserved(address)
395
    except errors.AddressPoolError:
396
      raise errors.ReservationError("IP address not in network")
397
    if isreserved:
398
      raise errors.ReservationError("IP address already in use")
397
    if pool.IsReserved(address):
398
      raise errors.OpPrereqError("IP address '%s' already in use." %
399
                                 address, errors.ECODE_EXISTS)
399 400

  
400 401
    return self._temporary_ips.Reserve(ec_id,
401 402
                                       (constants.RESERVE_ACTION,
402
                                        address, net_uuid))
403
                                        address, net_uuid, external))
403 404

  
404 405
  @locking.ssynchronized(_config_lock, shared=1)
405
  def ReserveIp(self, net_uuid, address, ec_id):
406
  def ReserveIp(self, net_uuid, address, external, ec_id):
406 407
    """Reserve a given IPv4 address for use by an instance.
407 408

  
408 409
    """
409 410
    if net_uuid:
410
      return self._UnlockedReserveIp(net_uuid, address, ec_id)
411
      return self._UnlockedReserveIp(net_uuid, address, external, ec_id)
411 412

  
412 413
  @locking.ssynchronized(_config_lock, shared=1)
413 414
  def ReserveLV(self, lv_name, ec_id):
......
1487 1488
    for nic in instance.nics:
1488 1489
      if nic.network and nic.ip:
1489 1490
        # Return all IP addresses to the respective address pools
1490
        self._UnlockedCommitIp(constants.RELEASE_ACTION, nic.network, nic.ip)
1491
        self._UnlockedCommitIp(constants.RELEASE_ACTION,
1492
                               nic.network, nic.ip, False)
1491 1493

  
1492 1494
    del self._config_data.instances[instance_name]
1493 1495
    self._config_data.cluster.serial_no += 1
......
2438 2440
    if isinstance(target, objects.Instance):
2439 2441
      self._UnlockedReleaseDRBDMinors(target.name)
2440 2442

  
2441
    if ec_id is not None:
2442
      # Commit all ips reserved by OpInstanceSetParams and OpGroupSetParams
2443
      self._UnlockedCommitTemporaryIps(ec_id)
2443
    self._UnlockedCommitTemporaryIps(ec_id)
2444 2444

  
2445 2445
    self._WriteConfig(feedback_fn=feedback_fn)
2446 2446

  

Also available in: Unified diff