~soren/nova/lp658257

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/api.py

  • Committer: Tarmac
  • Author(s): Vishvananda Ishaya
  • Date: 2010-10-01 01:28:17 UTC
  • mfrom: (276.6.12 network-lease-fix)
  • Revision ID: hudson@openstack.org-20101001012817-9uj531c4nzzsr33r
Adds support for periodic_tasks on manager that are regularly called by the service and recovers fixed_ips that didn't get disassociated properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
Implementation of SQLAlchemy backend
20
20
"""
21
21
 
22
 
import sys
23
 
 
24
22
from nova import db
25
23
from nova import exception
26
24
from nova import flags
340
338
        fixed_ip_ref.save(session=session)
341
339
 
342
340
 
 
341
def fixed_ip_disassociate_all_by_timeout(_context, host, time):
 
342
    session = get_session()
 
343
    # NOTE(vish): The nested select is because sqlite doesn't support
 
344
    #             JOINs in UPDATEs.
 
345
    result = session.execute('UPDATE fixed_ips SET instance_id = NULL, '
 
346
                                                  'leased = 0 '
 
347
                             'WHERE network_id IN (SELECT id FROM networks '
 
348
                                                  'WHERE host = :host) '
 
349
                             'AND updated_at < :time '
 
350
                             'AND instance_id IS NOT NULL '
 
351
                             'AND allocated = 0',
 
352
                    {'host': host,
 
353
                     'time': time.isoformat()})
 
354
    return result.rowcount
 
355
 
 
356
 
343
357
def fixed_ip_get_by_address(_context, address):
344
358
    session = get_session()
345
 
    with session.begin():
346
 
        try:
347
 
            return session.query(models.FixedIp
348
 
                         ).options(joinedload_all('instance')
349
 
                         ).filter_by(address=address
350
 
                         ).filter_by(deleted=False
351
 
                         ).one()
352
 
        except NoResultFound:
353
 
            new_exc = exception.NotFound("No model for address %s" % address)
354
 
            raise new_exc.__class__, new_exc, sys.exc_info()[2]
 
359
    result = session.query(models.FixedIp
 
360
                   ).options(joinedload_all('instance')
 
361
                   ).filter_by(address=address
 
362
                   ).filter_by(deleted=False
 
363
                   ).first()
 
364
    if not result:
 
365
        raise exception.NotFound("No model for address %s" % address)
 
366
    return result
355
367
 
356
368
 
357
369
def fixed_ip_get_instance(_context, address):