summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-08-25 13:14:49 -0700
committerVishvananda Ishaya <vishvananda@yahoo.com>2010-08-25 13:14:49 -0700
commit674a5dae7c0630aef346e22950706db0caeb244b (patch)
tree596b34fdc90ca7675e7751679e2a6eef37aa1057 /nova/db
parent199b9b828d75ec6fa08481585aa5df462497c50f (diff)
more data layer breakouts, lots of fixes to cloud.py
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py39
-rw-r--r--nova/db/sqlalchemy/api.py54
2 files changed, 71 insertions, 22 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index edc3b7bdc..9efbcf76b 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -47,6 +47,7 @@ _impl = utils.LazyPluggable(FLAGS['db_backend'],
class AddressNotAllocated(exception.Error):
pass
+
class NoMoreAddresses(exception.Error):
pass
@@ -185,14 +186,9 @@ def instance_get_all(context):
return _impl.instance_get_all(context)
-def instance_get_by_ip(context, ip):
- """Gets an instance by fixed ipaddress or raise if it does not exist."""
- return _impl.instance_get_by_ip(context, ip)
-
-
-def instance_get_by_name(context, name):
- """Get an instance by name."""
- return _impl.instance_get_by_project(context, name)
+def instance_get_by_address(context, address):
+ """Gets an instance by fixed ip address or raise if it does not exist."""
+ return _impl.instance_get_by_address(context, address)
def instance_get_by_project(context, project_id):
@@ -205,9 +201,24 @@ def instance_get_by_reservation(context, reservation_id):
return _impl.instance_get_by_reservation(context, reservation_id)
+def instance_get_fixed_address(context, instance_id):
+ """Get the fixed ip address of an instance."""
+ return _impl.instance_get_fixed_address(context, instance_id)
+
+
+def instance_get_floating_address(context, instance_id):
+ """Get the first floating ip address of an instance."""
+ return _impl.instance_get_floating_address(context, instance_id)
+
+
+def instance_get_by_str(context, str_id):
+ """Get an instance by string id."""
+ return _impl.instance_get_by_str(context, str_id)
+
+
def instance_get_host(context, instance_id):
"""Get the host that the instance is running on."""
- return _impl.instance_get_all(context, instance_id)
+ return _impl.instance_get_host(context, instance_id)
def instance_is_vpn(context, instance_id):
@@ -365,6 +376,16 @@ def volume_get_by_project(context, project_id):
return _impl.volume_get_by_project(context, project_id)
+def volume_get_by_str(context, str_id):
+ """Get a volume by string id."""
+ return _impl.volume_get_by_str(context, str_id)
+
+
+def volume_get_host(context, volume_id):
+ """Get the host that the volume is running on."""
+ return _impl.volume_get_host(context, volume_id)
+
+
def volume_get_shelf_and_blade(context, volume_id):
"""Get the shelf and blade allocated to the volume."""
return _impl.volume_get_shelf_and_blade(context, volume_id)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 2ce54a1d7..047a6c108 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -70,21 +70,21 @@ def floating_ip_allocate_address(context, node_name, project_id):
def floating_ip_fixed_ip_associate(context, floating_address, fixed_address):
- floating_ip_ref = models.FloatingIp.find_by_ip_str(floating_address)
- fixed_ip_ref = models.FixedIp.find_by_ip_str(fixed_address)
+ floating_ip_ref = models.FloatingIp.find_by_str(floating_address)
+ fixed_ip_ref = models.FixedIp.find_by_str(fixed_address)
floating_ip_ref.fixed_ip = fixed_ip_ref
floating_ip_ref.save()
def floating_ip_disassociate(context, address):
- floating_ip_ref = models.FloatingIp.find_by_ip_str(address)
+ floating_ip_ref = models.FloatingIp.find_by_str(address)
fixed_ip_address = floating_ip_ref.fixed_ip['ip_str']
floating_ip_ref['fixed_ip'] = None
floating_ip_ref.save()
return fixed_ip_address
def floating_ip_deallocate(context, address):
- floating_ip_ref = models.FloatingIp.find_by_ip_str(address)
+ floating_ip_ref = models.FloatingIp.find_by_str(address)
floating_ip_ref['project_id'] = None
floating_ip_ref.save()
@@ -108,11 +108,11 @@ def fixed_ip_allocate(context, network_id):
def fixed_ip_get_by_address(context, address):
- return models.FixedIp.find_by_ip_str(address)
+ return models.FixedIp.find_by_str(address)
def fixed_ip_get_network(context, address):
- return models.FixedIp.find_by_ip_str(address).network
+ return models.FixedIp.find_by_str(address).network
def fixed_ip_lease(context, address):
@@ -172,13 +172,11 @@ def instance_get_all(context):
return models.Instance.all()
-def instance_get_by_ip(context, ip):
- raise Exception("fixme(vish): add logic here!")
-
-
-def instance_get_by_name(context, name):
- # NOTE(vish): remove the 'i-'
- return models.Instance.find(name[2:])
+def instance_get_by_address(context, address):
+ fixed_ip_ref = db.fixed_ip_get_by_address(address)
+ if not fixed_ip_ref.instance:
+ raise exception.NotFound("No instance found for address %s" % address)
+ return fixed_ip_ref.instance
def instance_get_by_project(context, project_id):
@@ -197,6 +195,27 @@ def instance_get_by_reservation(context, reservation_id):
return results
+def instance_get_by_str(context, str_id):
+ return models.Instance.find_by_str(str_id)
+
+
+def instance_get_fixed_address(context, instance_id):
+ instance_ref = instance_get(context, instance_id)
+ if not instance_ref.fixed_ip:
+ return None
+ return instance_ref.fixed_ip['str_id']
+
+
+def instance_get_floating_address(context, instance_id):
+ instance_ref = instance_get(context, instance_id)
+ if not instance_ref.fixed_ip:
+ return None
+ if not instance_ref.fixed_ip.floating_ips:
+ return None
+ # NOTE(vish): this just returns the first floating ip
+ return instance_ref.fixed_ip.floating_ips[0]['str_id']
+
+
def instance_get_host(context, instance_id):
instance_ref = instance_get(context, instance_id)
return instance_ref['node_name']
@@ -453,6 +472,15 @@ def volume_get_by_project(context, project_id):
return results
+def volume_get_by_str(context, str_id):
+ return models.Volume.find_by_str(str_id)
+
+
+def volume_get_host(context, volume_id):
+ volume_ref = volume_get(context, volume_id)
+ return volume_ref['node_name']
+
+
def volume_get_shelf_and_blade(context, volume_id):
volume_ref = volume_get(context, volume_id)
export_device = volume_ref.export_device