Merge lp:~vishvananda/nova/lp720393 into lp:~hudson-openstack/nova/trunk

Proposed by Vish Ishaya
Status: Merged
Approved by: Devin Carlen
Approved revision: 688
Merged at revision: 700
Proposed branch: lp:~vishvananda/nova/lp720393
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 58 lines (+15/-12)
1 file modified
nova/network/manager.py (+15/-12)
To merge this branch: bzr merge lp:~vishvananda/nova/lp720393
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Soren Hansen (community) Approve
Review via email: mp+50058@code.launchpad.net

Description of the change

Makes FlatDHCPManager clean up old fixed_ips like VlanManager.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

So what calls periodic_tasks?

review: Needs Information
Revision history for this message
Soren Hansen (soren) wrote :

Devin, nova.service.Service() sets up a LoopingCall that calls the manager's periodic_tasks method every FLAGS.periodic_interval seconds.

Revision history for this message
Soren Hansen (soren) wrote :

I don't like that we have the exact same code in two places (the exact same code is in VlanManager's periodic_tasks).

Maybe you could make it a module level function or move it into the NetworkManager class and make it conditional on a "needs_dhcp_cleanup" class variable that is set appropriately for the various managers?

Revision history for this message
Soren Hansen (soren) :
review: Needs Fixing
Revision history for this message
Vish Ishaya (vishvananda) wrote :

Soren: good point. I used timeout_fixed_ips as the flag.

Revision history for this message
Vish Ishaya (vishvananda) wrote :

oops, had an extra copy of periodic_tasks. Deleted.

lp:~vishvananda/nova/lp720393 updated
688. By Vish Ishaya

remove leftover periodic tasks

Revision history for this message
Soren Hansen (soren) wrote :

Lovely! lgtm

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/network/manager.py'
2--- nova/network/manager.py 2011-02-17 21:47:02 +0000
3+++ nova/network/manager.py 2011-02-17 22:54:16 +0000
4@@ -110,6 +110,7 @@
5
6 This class must be subclassed to support specific topologies.
7 """
8+ timeout_fixed_ips = True
9
10 def __init__(self, network_driver=None, *args, **kwargs):
11 if not network_driver:
12@@ -138,6 +139,19 @@
13 self.driver.ensure_floating_forward(floating_ip['address'],
14 fixed_address)
15
16+ def periodic_tasks(self, context=None):
17+ """Tasks to be run at a periodic interval."""
18+ super(NetworkManager, self).periodic_tasks(context)
19+ if self.timeout_fixed_ips:
20+ now = utils.utcnow()
21+ timeout = FLAGS.fixed_ip_disassociate_timeout
22+ time = now - datetime.timedelta(seconds=timeout)
23+ num = self.db.fixed_ip_disassociate_all_by_timeout(context,
24+ self.host,
25+ time)
26+ if num:
27+ LOG.debug(_("Dissassociated %s stale fixed ip(s)"), num)
28+
29 def set_network_host(self, context, network_id):
30 """Safely sets the host of the network."""
31 LOG.debug(_("setting network host"), context=context)
32@@ -306,6 +320,7 @@
33 not do any setup in this mode, it must be done manually. Requests to
34 169.254.169.254 port 80 will need to be forwarded to the api server.
35 """
36+ timeout_fixed_ips = False
37
38 def allocate_fixed_ip(self, context, instance_id, *args, **kwargs):
39 """Gets a fixed ip from the pool."""
40@@ -457,18 +472,6 @@
41 instances in its subnet.
42 """
43
44- def periodic_tasks(self, context=None):
45- """Tasks to be run at a periodic interval."""
46- super(VlanManager, self).periodic_tasks(context)
47- now = datetime.datetime.utcnow()
48- timeout = FLAGS.fixed_ip_disassociate_timeout
49- time = now - datetime.timedelta(seconds=timeout)
50- num = self.db.fixed_ip_disassociate_all_by_timeout(context,
51- self.host,
52- time)
53- if num:
54- LOG.debug(_("Dissassociated %s stale fixed ip(s)"), num)
55-
56 def init_host(self):
57 """Do any initialization that needs to be run if this is a
58 standalone service.