diff options
| author | Ricardo Carrillo Cruz <emaildericky@gmail.com> | 2011-03-07 22:18:15 +0100 |
|---|---|---|
| committer | Ricardo Carrillo Cruz <emaildericky@gmail.com> | 2011-03-07 22:18:15 +0100 |
| commit | 0abd5bfecd279272e5fe1b0de04478909cd77010 (patch) | |
| tree | 858d0a2d0b682454ac9da3308a84b4cb10576a6c | |
| parent | 1eed366b7508c0f225b2c9691e1f62a6f88ee3f8 (diff) | |
| download | nova-0abd5bfecd279272e5fe1b0de04478909cd77010.tar.gz nova-0abd5bfecd279272e5fe1b0de04478909cd77010.tar.xz nova-0abd5bfecd279272e5fe1b0de04478909cd77010.zip | |
added network_get_by_cidr method to nova.db api
| -rwxr-xr-x | bin/nova-manage | 9 | ||||
| -rw-r--r-- | nova/db/api.py | 7 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 18 |
3 files changed, 26 insertions, 8 deletions
diff --git a/bin/nova-manage b/bin/nova-manage index 9557f2423..b274c5bd1 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -545,16 +545,9 @@ class NetworkCommands(object): network.dhcp_start, network.dns) - def delete(self, fixed_range): """Deletes a network""" - try: - network = [n for n in db.network_get_all(context.get_admin_context()) - if n.cidr == fixed_range][0] - - print network.id, network.cidr, network.project_id - except IndexError: - raise ValueError(_("Network does not exist")) + print db.network_get_by_cidr(context.get_admin_context(), fixed_range) class ServiceCommands(object): """Enable and disable running services""" diff --git a/nova/db/api.py b/nova/db/api.py index d23f14a3c..c73796487 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -459,6 +459,10 @@ def network_associate(context, project_id): """Associate a free network to a project.""" return IMPL.network_associate(context, project_id) +def network_is_associated(context, project_id): + """Returns true the the network is associated to a project""" + return IMPL.network_is_associated(context, project_id) + def network_count(context): """Return the number of networks.""" @@ -525,6 +529,9 @@ def network_get_by_bridge(context, bridge): """Get a network by bridge or raise if it does not exist.""" return IMPL.network_get_by_bridge(context, bridge) +def network_get_by_cidr(context, cidr): + """Get a network by cidr or raise if it does not exist""" + return IMPL.network_get_by_cidr(context, cidr) def network_get_by_instance(context, instance_id): """Get a network by instance id or raise if it does not exist.""" diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 919dda118..bd2de70c7 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -994,6 +994,13 @@ def network_associate(context, project_id): @require_admin_context +def network_is_associated(context, project_id): + session = get_session() + network = session.query(models.Network.project_id).filter(project_id=1).first() + print network + + +@require_admin_context def network_count(context): session = get_session() return session.query(models.Network).\ @@ -1117,6 +1124,17 @@ def network_get_by_bridge(context, bridge): @require_admin_context +def network_get_by_cidr(context, cidr): + session = get_session() + result = session.query(models.Network).\ + filter_by(cidr=cidr).first() + + if not result: + raise exception.NotFound(_('Network with cidr %s does not exist') % + cidr) + return result.id + +@require_admin_context def network_get_by_instance(_context, instance_id): session = get_session() rv = session.query(models.Network).\ |
