summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-23 22:02:03 +0000
committerGerrit Code Review <review@openstack.org>2012-02-23 22:02:03 +0000
commit5baaa3117ab2c1cab8a573a2bd488a55478b6189 (patch)
tree84fee7991e937963788589f9698821f4c2b19ff0
parente1001f6f11d14c2f69eb666888c9a3f3eb9eed8b (diff)
parent3e157d586fddb1430f5cacc343fd158de4b803cc (diff)
Merge "Add hypervisor_hostname to compute_nodes table and use it in XenServer."
-rw-r--r--nova/db/api.py4
-rw-r--r--nova/db/sqlalchemy/api.py5
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/080_add_hypervisor_hostname_to_compute_nodes.py33
-rw-r--r--nova/db/sqlalchemy/models.py1
-rw-r--r--nova/virt/xenapi_conn.py19
5 files changed, 57 insertions, 5 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 10c0d2d58..d18e5da9c 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -194,12 +194,12 @@ def compute_node_create(context, values):
return IMPL.compute_node_create(context, values)
-def compute_node_update(context, compute_id, values):
+def compute_node_update(context, compute_id, values, auto_adjust=True):
"""Set the given properties on an computeNode and update it.
Raises NotFound if computeNode does not exist.
"""
- return IMPL.compute_node_update(context, compute_id, values)
+ return IMPL.compute_node_update(context, compute_id, values, auto_adjust)
def compute_node_get_by_host(context, host):
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 130be0d2e..0ba1764ac 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -506,11 +506,12 @@ def compute_node_create(context, values, session=None):
@require_admin_context
-def compute_node_update(context, compute_id, values):
+def compute_node_update(context, compute_id, values, auto_adjust):
"""Creates a new ComputeNode and populates the capacity fields
with the most recent data."""
session = get_session()
- _adjust_compute_node_values_for_utilization(context, values, session)
+ if auto_adjust:
+ _adjust_compute_node_values_for_utilization(context, values, session)
with session.begin(subtransactions=True):
compute_ref = compute_node_get(context, compute_id, session=session)
compute_ref.update(values)
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/080_add_hypervisor_hostname_to_compute_nodes.py b/nova/db/sqlalchemy/migrate_repo/versions/080_add_hypervisor_hostname_to_compute_nodes.py
new file mode 100644
index 000000000..c53297fab
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/080_add_hypervisor_hostname_to_compute_nodes.py
@@ -0,0 +1,33 @@
+# Copyright 2012 OpenStack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from sqlalchemy import *
+
+
+meta = MetaData()
+
+compute_nodes = Table("compute_nodes", meta, Column("id", Integer(),
+ primary_key=True, nullable=False))
+
+hypervisor_hostname = Column("hypervisor_hostname", String(255))
+
+
+def upgrade(migrate_engine):
+ meta.bind = migrate_engine
+ compute_nodes.create_column(hypervisor_hostname)
+
+
+def downgrade(migrate_engine):
+ meta.bind = migrate_engine
+ compute_nodes.drop_column(hypervisor_hostname)
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 33438444f..8bd56e394 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -135,6 +135,7 @@ class ComputeNode(BASE, NovaBase):
local_gb_used = Column(Integer)
hypervisor_type = Column(Text)
hypervisor_version = Column(Integer)
+ hypervisor_hostname = Column(String(255))
# Free Ram, amount of activity (resize, migration, boot, etc) and
# the number of running VM's are a good starting point for what's
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index 85e94c431..6fae558b5 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -181,6 +181,8 @@ class XenAPIConnection(driver.ComputeDriver):
self._initiator = None
self._pool = pool.ResourcePool(self._session)
+ self._capture_dom0_hostname()
+
@property
def host_state(self):
if not self._host_state:
@@ -194,6 +196,22 @@ class XenAPIConnection(driver.ComputeDriver):
#e.g. to do session logout?
pass
+ def _capture_dom0_hostname(self):
+ """Find dom0's hostname and log it to the DB."""
+ ctxt = context.get_admin_context()
+ service = db.service_get_by_host_and_topic(ctxt, FLAGS.host, "compute")
+
+ try:
+ compute_node = db.compute_node_get_for_service(ctxt, service["id"])
+ except TypeError:
+ return
+
+ host_stats = self.get_host_stats()
+
+ db.compute_node_update(ctxt, compute_node["id"],
+ {"hypervisor_hostname": host_stats["host_hostname"]},
+ auto_adjust=False)
+
def list_instances(self):
"""List VM instances"""
return self._vmops.list_instances()
@@ -390,7 +408,6 @@ class XenAPIConnection(driver.ComputeDriver):
:param host: hostname that compute manager is currently running
"""
-
try:
service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
except exception.NotFound: