Merge lp:~rcarrillocruz/nova/lp715427 into lp:~hudson-openstack/nova/trunk

Proposed by Ricardo Carrillo Cruz
Status: Merged
Approved by: Devin Carlen
Approved revision: 765
Merged at revision: 775
Proposed branch: lp:~rcarrillocruz/nova/lp715427
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 109 lines (+52/-0)
4 files modified
bin/nova-manage (+9/-0)
nova/db/api.py (+12/-0)
nova/db/sqlalchemy/api.py (+21/-0)
nova/network/manager.py (+10/-0)
To merge this branch: bzr merge lp:~rcarrillocruz/nova/lp715427
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Jay Pipes (community) Approve
Review via email: mp+52722@code.launchpad.net

Description of the change

Hi guys

This branch fixes lp722982 (ability to delete networks with nova-manage) and lp715427 (nova-manage does not check if a network exists before creating it) .

Regards

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

very nice.

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 'bin/nova-manage'
2--- bin/nova-manage 2011-03-03 00:35:53 +0000
3+++ bin/nova-manage 2011-03-09 18:11:56 +0000
4@@ -545,6 +545,15 @@
5 network.dhcp_start,
6 network.dns)
7
8+ def delete(self, fixed_range):
9+ """Deletes a network"""
10+ network = db.network_get_by_cidr(context.get_admin_context(), \
11+ fixed_range)
12+ if network.project_id is not None:
13+ raise ValueError(_('Network must be disassociated from project %s'
14+ ' before delete' % network.project_id))
15+ db.network_delete_safe(context.get_admin_context(), network.id)
16+
17
18 class ServiceCommands(object):
19 """Enable and disable running services"""
20
21=== modified file 'nova/db/api.py'
22--- nova/db/api.py 2011-03-03 19:13:15 +0000
23+++ nova/db/api.py 2011-03-09 18:11:56 +0000
24@@ -517,6 +517,13 @@
25 return IMPL.network_create_safe(context, values)
26
27
28+def network_delete_safe(context, network_id):
29+ """Delete network with key network_id.
30+ This method assumes that the network is not associated with any project
31+ """
32+ return IMPL.network_delete_safe(context, network_id)
33+
34+
35 def network_create_fixed_ips(context, network_id, num_vpn_clients):
36 """Create the ips for the network, reserving sepecified ips."""
37 return IMPL.network_create_fixed_ips(context, network_id, num_vpn_clients)
38@@ -553,6 +560,11 @@
39 return IMPL.network_get_by_bridge(context, bridge)
40
41
42+def network_get_by_cidr(context, cidr):
43+ """Get a network by cidr or raise if it does not exist"""
44+ return IMPL.network_get_by_cidr(context, cidr)
45+
46+
47 def network_get_by_instance(context, instance_id):
48 """Get a network by instance id or raise if it does not exist."""
49 return IMPL.network_get_by_instance(context, instance_id)
50
51=== modified file 'nova/db/sqlalchemy/api.py'
52--- nova/db/sqlalchemy/api.py 2011-03-08 22:45:06 +0000
53+++ nova/db/sqlalchemy/api.py 2011-03-09 18:11:56 +0000
54@@ -1055,6 +1055,15 @@
55
56
57 @require_admin_context
58+def network_delete_safe(context, network_id):
59+ session = get_session()
60+ with session.begin():
61+ network_ref = network_get(context, network_id=network_id, \
62+ session=session)
63+ session.delete(network_ref)
64+
65+
66+@require_admin_context
67 def network_disassociate(context, network_id):
68 network_update(context, network_id, {'project_id': None,
69 'host': None})
70@@ -1128,6 +1137,18 @@
71
72
73 @require_admin_context
74+def network_get_by_cidr(context, cidr):
75+ session = get_session()
76+ result = session.query(models.Network).\
77+ filter_by(cidr=cidr).first()
78+
79+ if not result:
80+ raise exception.NotFound(_('Network with cidr %s does not exist') %
81+ cidr)
82+ return result
83+
84+
85+@require_admin_context
86 def network_get_by_instance(_context, instance_id):
87 session = get_session()
88 rv = session.query(models.Network).\
89
90=== modified file 'nova/network/manager.py'
91--- nova/network/manager.py 2011-03-01 20:58:28 +0000
92+++ nova/network/manager.py 2011-03-09 18:11:56 +0000
93@@ -563,6 +563,16 @@
94 # NOTE(vish): This makes ports unique accross the cloud, a more
95 # robust solution would be to make them unique per ip
96 net['vpn_public_port'] = vpn_start + index
97+ network_ref = None
98+ try:
99+ network_ref = db.network_get_by_cidr(context, cidr)
100+ except exception.NotFound:
101+ pass
102+
103+ if network_ref is not None:
104+ raise ValueError(_('Network with cidr %s already exists' %
105+ cidr))
106+
107 network_ref = self.db.network_create_safe(context, net)
108 if network_ref:
109 self._create_fixed_ips(context, network_ref['id'])