summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorKei Masumoto <masumotok@nttdata.co.jp>2011-01-17 04:12:27 +0900
committerKei Masumoto <masumotok@nttdata.co.jp>2011-01-17 04:12:27 +0900
commita56bc070784c7ea23528025463ea7f0bee133150 (patch)
tree67c16becb0b778500d06e0565461f26ecd7c5c33 /nova/db
parent525544e689334346305ecc11552105fc1b32a5dd (diff)
parent825652456ac826a2108956ba8a9cbdc8221520dc (diff)
merged trunk rev569
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py12
-rw-r--r--nova/db/sqlalchemy/api.py30
-rw-r--r--nova/db/sqlalchemy/models.py22
3 files changed, 57 insertions, 7 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 8c1e0d54d..6277cbac5 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -303,6 +303,10 @@ def fixed_ip_get_instance(context, address):
return IMPL.fixed_ip_get_instance(context, address)
+def fixed_ip_get_instance_v6(context, address):
+ return IMPL.fixed_ip_get_instance_v6(context, address)
+
+
def fixed_ip_get_network(context, address):
"""Get a network for a fixed ip by address."""
return IMPL.fixed_ip_get_network(context, address)
@@ -361,6 +365,10 @@ def instance_get_fixed_address(context, instance_id):
return IMPL.instance_get_fixed_address(context, instance_id)
+def instance_get_fixed_address_v6(context, instance_id):
+ return IMPL.instance_get_fixed_address_v6(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)
@@ -582,6 +590,10 @@ def project_get_network(context, project_id, associate=True):
return IMPL.project_get_network(context, project_id)
+def project_get_network_v6(context, project_id):
+ return IMPL.project_get_network_v6(context, project_id)
+
+
###################
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 9843b7edb..248a46f65 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -616,6 +616,17 @@ def fixed_ip_get_instance(context, address):
return fixed_ip_ref.instance
+@require_context
+def fixed_ip_get_instance_v6(context, address):
+ session = get_session()
+ mac = utils.to_mac(address)
+
+ result = session.query(models.Instance).\
+ filter_by(mac_address=mac).\
+ first()
+ return result
+
+
@require_admin_context
def fixed_ip_get_network(context, address):
fixed_ip_ref = fixed_ip_get_by_address(context, address)
@@ -774,6 +785,7 @@ def instance_get_by_id(context, instance_id):
if is_admin_context(context):
result = session.query(models.Instance).\
+ options(joinedload_all('fixed_ip.floating_ips')).\
options(joinedload('security_groups')).\
options(joinedload_all('fixed_ip.floating_ips')).\
filter_by(id=instance_id).\
@@ -804,6 +816,17 @@ def instance_get_fixed_address(context, instance_id):
@require_context
+def instance_get_fixed_address_v6(context, instance_id):
+ session = get_session()
+ with session.begin():
+ instance_ref = instance_get(context, instance_id, session=session)
+ network_ref = network_get_by_instance(context, instance_id)
+ prefix = network_ref.cidr_v6
+ mac = instance_ref.mac_address
+ return utils.to_global_ipv6(prefix, mac)
+
+
+@require_context
def instance_get_floating_address(context, instance_id):
session = get_session()
with session.begin():
@@ -889,7 +912,7 @@ def _instance_get_sum_by_host_and_project(context, column, hostname, proj_id):
@require_context
def instance_get_vcpu_sum_by_host_and_project(context, hostname, proj_id):
- return _instance_get_sum_by_host_and_project(context,
+ return _instance_get_sum_by_host_and_project(context,
'vcpus',
hostname,
proj_id)
@@ -1194,6 +1217,11 @@ def project_get_network(context, project_id, associate=True):
return result
+@require_context
+def project_get_network_v6(context, project_id):
+ return project_get_network(context, project_id)
+
+
###################
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index add37fe19..b28c64b59 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -90,8 +90,14 @@ class NovaBase(object):
setattr(self, k, v)
def iteritems(self):
- """Make the model object behave like a dict"""
- return iter(self)
+ """Make the model object behave like a dict.
+
+ Includes attributes from joins."""
+ local = dict(self)
+ joined = dict([(k, v) for k, v in self.__dict__.iteritems()
+ if not k[0] == '_'])
+ local.update(joined)
+ return local.iteritems()
# TODO(vish): Store images in the database instead of file system
@@ -162,11 +168,11 @@ class Service(BASE, NovaBase):
hypervisor_version = Column(Integer, nullable=False, default=-1)
# Note(masumotok): Expected Strings example:
#
- # '{"arch":"x86_64", "model":"Nehalem",
- # "topology":{"sockets":1, "threads":2, "cores":3},
+ # '{"arch":"x86_64", "model":"Nehalem",
+ # "topology":{"sockets":1, "threads":2, "cores":3},
# features:[ "tdtscp", "xtpr"]}'
#
- # Points are "json translatable" and it must have all
+ # Points are "json translatable" and it must have all
# dictionary keys above.
cpu_info = Column(String(512))
@@ -433,6 +439,10 @@ class Network(BASE, NovaBase):
injected = Column(Boolean, default=False)
cidr = Column(String(255), unique=True)
+ cidr_v6 = Column(String(255), unique=True)
+
+ ra_server = Column(String(255))
+
netmask = Column(String(255))
bridge = Column(String(255))
gateway = Column(String(255))
@@ -600,7 +610,7 @@ def register_models():
Volume, ExportDevice, IscsiTarget, FixedIp, FloatingIp,
Network, SecurityGroup, SecurityGroupIngressRule,
SecurityGroupInstanceAssociation, AuthToken, User,
- Project, Certificate, ConsolePool, Console, Host) # , Image
+ Project, Certificate, ConsolePool, Console) # , Host, Image
engine = create_engine(FLAGS.sql_connection, echo=False)
for model in models:
model.metadata.create_all(engine)