summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrey Morris <trey.morris@rackspace.com>2011-06-17 18:38:35 -0500
committerTrey Morris <trey.morris@rackspace.com>2011-06-17 18:38:35 -0500
commit89ad3e4f219ff5e8f60624560e9a3ce3762040d5 (patch)
treea5cb6fa58981943005d89991d07846fcb2c7354c
parenta2f9e4be5ca400b407fbb8aa11dd0888aad21aa1 (diff)
updated fixed ip and floating ip exceptions
-rw-r--r--nova/db/sqlalchemy/api.py42
-rw-r--r--nova/exception.py28
2 files changed, 39 insertions, 31 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 8d12e25c0..2e18bdca9 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -446,7 +446,7 @@ def floating_ip_allocate_address(context, project_id):
# NOTE(vish): if with_lockmode isn't supported, as in sqlite,
# then this has concurrency issues
if not floating_ip_ref:
- raise db.NoMoreAddresses()
+ raise exception.NoMoreFloatingIps()
floating_ip_ref['project_id'] = project_id
session.add(floating_ip_ref)
return floating_ip_ref['address']
@@ -545,20 +545,26 @@ def floating_ip_set_auto_assigned(context, address):
@require_admin_context
def floating_ip_get_all(context):
session = get_session()
- return session.query(models.FloatingIp).\
- options(joinedload_all('fixed_ip.instance')).\
- filter_by(deleted=False).\
- all()
+ floating_ip_refs = session.query(models.FloatingIp).\
+ options(joinedload_all('fixed_ip.instance')).\
+ filter_by(deleted=False).\
+ all()
+ if not floating_ip_refs:
+ raise exception.NoFloatingIpsDefined()
+ return floating_ip_refs
@require_admin_context
def floating_ip_get_all_by_host(context, host):
session = get_session()
- return session.query(models.FloatingIp).\
- options(joinedload_all('fixed_ip.instance')).\
- filter_by(host=host).\
- filter_by(deleted=False).\
- all()
+ floating_ip_refs = session.query(models.FloatingIp).\
+ options(joinedload_all('fixed_ip.instance')).\
+ filter_by(host=host).\
+ filter_by(deleted=False).\
+ all()
+ if not floating_ip_refs:
+ raise exception.NoFloatingIpsDefinedForHost(host=host)
+ return floating_ip_refs
@require_context
@@ -566,12 +572,15 @@ def floating_ip_get_all_by_project(context, project_id):
authorize_project_context(context, project_id)
session = get_session()
# TODO(tr3buchet): why do we not want auto_assigned floating IPs here?
- return session.query(models.FloatingIp).\
- options(joinedload_all('fixed_ip.instance')).\
- filter_by(project_id=project_id).\
- filter_by(auto_assigned=False).\
- filter_by(deleted=False).\
- all()
+ floating_ip_refs = session.query(models.FloatingIp).\
+ options(joinedload_all('fixed_ip.instance')).\
+ filter_by(project_id=project_id).\
+ filter_by(auto_assigned=False).\
+ filter_by(deleted=False).\
+ all()
+ if not floating_ip_refs:
+ raise exception.NoFloatingIpFoundForProject(project_id=project_id)
+ return floating_ip_refs
@require_context
@@ -587,7 +596,6 @@ def floating_ip_get_by_address(context, address, session=None):
first()
if not result:
raise exception.FloatingIpNotFound(address=address)
-
return result
diff --git a/nova/exception.py b/nova/exception.py
index 5eec4b0cc..a4c1b2d30 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -361,16 +361,16 @@ class DatastoreNotFound(NotFound):
message = _("Could not find the datastore reference(s) which the VM uses.")
-class NoFixedIpsFoundForInstance(NotFound):
- message = _("Instance %(instance_id)s has zero fixed ips.")
+class NoFixedIpFound(NotFound):
+ message = _("No fixed IP associated with address %(address)s.")
-class NoFixedIpsFoundForVirtualInterface(NotFound):
- message = _("Virtual interface %(vif_id)s has zero associated fixed ips.")
+class NoFixedIpsFoundForInstance(NoFixedIpFound):
+ message = _("Instance %(instance_id)s has zero fixed ips.")
-class NoFixedIpFound(NotFound):
- message = _("No fixed IP associated with address %(address)s.")
+class NoFixedIpsFoundForVirtualInterface(NoFixedIpFound):
+ message = _("Virtual interface %(vif_id)s has zero associated fixed ips.")
class NoFixedIpsDefined(NotFound):
@@ -385,20 +385,20 @@ class FloatingIpNotFound(NotFound):
message = _("Floating ip not found for address %(address)s.")
-class NoFloatingIpsDefined(NotFound):
- message = _("Zero floating ips could be found.")
+class NoFloatingIpFoundForProject(FloatingIpNotFound):
+ message = _("Floating ip not found for project %(project_id)s.")
-class NoFloatingIpsDefinedForHost(NoFloatingIpsDefined):
- message = _("Zero floating ips defined for host %(host)s.")
+class NoMoreFloatingIps(FloatingIpNotFound):
+ message = _("Zero floating ips available.")
-class NoFloatingIpsDefinedForInstance(NoFloatingIpsDefined):
- message = _("Zero floating ips defined for instance %(instance_id)s.")
+class NoFloatingIpsDefined(NotFound):
+ message = _("Zero floating ips could be found.")
-class NoMoreFloatingIps(NotFound):
- message = _("Zero floating ips available.")
+class NoFloatingIpsDefinedForHost(NoFloatingIpsDefined):
+ message = _("Zero floating ips defined for host %(host)s.")
class KeypairNotFound(NotFound):