summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikyung Kang <mkkang@isi.edu>2012-10-01 17:00:33 -0400
committerDevananda van der Veen <devananda.vdv@gmail.com>2012-11-12 22:14:12 -0800
commitd25a84e93c9f692f3f0c2ea881312300540976eb (patch)
tree3cac7f9428532ebeb597da80148bae68be43877c
parent4c7bef9b236e2705ae83c7b3364baa33277b5696 (diff)
Added bare-metal host manager.
Part 6 of 6: blueprint general-bare-metal-provisioning-framework. The bare-metal host manager is used when multiple bare-metal instances are created by one request. The bare-metal host manager detects if a nova-compute is for VM or bare-metal. For VM instance provisioning, it simply calls the original host_manager. For bare-metal instance provisioning, BaremetalNodeState is used to manage bare-metal node's resources when an instance is provisioned to a bare-metal node. Change-Id: Ib207f495493db99a4a6cd1ac0044662fb7397322 Co-authored-by: Mikyung Kang <mkkang@isi.edu> Co-authored-by: David Kang <dkang@isi.edu> Co-authored-by: Ken Igarashi <igarashik@nttdocomo.co.jp> Co-authored-by: Arata Notsu <notsu@virtualtech.jp>
-rw-r--r--nova/scheduler/baremetal_host_manager.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/nova/scheduler/baremetal_host_manager.py b/nova/scheduler/baremetal_host_manager.py
new file mode 100644
index 000000000..df2261c32
--- /dev/null
+++ b/nova/scheduler/baremetal_host_manager.py
@@ -0,0 +1,77 @@
+# Copyright (c) 2012 NTT DOCOMO, INC.
+# Copyright (c) 2011 OpenStack, LLC.
+# All Rights Reserved.
+#
+# 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.
+
+"""
+Manage hosts in the current zone.
+"""
+
+from nova import flags
+from nova.openstack.common import log as logging
+from nova.scheduler import host_manager
+
+
+FLAGS = flags.FLAGS
+LOG = logging.getLogger(__name__)
+
+
+class BaremetalNodeState(host_manager.HostState):
+ """Mutable and immutable information tracked for a host.
+ This is an attempt to remove the ad-hoc data structures
+ previously used and lock down access.
+ """
+
+ def update_from_compute_node(self, compute):
+ """Update information about a host from its compute_node info."""
+ all_ram_mb = compute['memory_mb']
+
+ free_disk_mb = compute['free_disk_gb'] * 1024
+ free_ram_mb = compute['free_ram_mb']
+
+ self.free_ram_mb = free_ram_mb
+ self.total_usable_ram_mb = all_ram_mb
+ self.free_disk_mb = free_disk_mb
+ self.vcpus_total = compute['vcpus']
+ self.vcpus_used = compute['vcpus_used']
+
+ def consume_from_instance(self, instance):
+ self.free_ram_mb = 0
+ self.free_disk_mb = 0
+ self.vcpus_used = self.vcpus_total
+
+
+def new_host_state(self, host, node, capabilities=None, service=None):
+ """Returns an instance of BaremetalHostState or HostState according to
+ capabilities. If 'baremetal_driver' is in capabilities, it returns an
+ instance of BaremetalHostState. If not, returns an instance of HostState.
+ """
+ if capabilities is None:
+ capabilities = {}
+ cap = capabilities.get('compute', {})
+ if bool(cap.get('baremetal_driver')):
+ return BaremetalNodeState(host, node, capabilities, service)
+ else:
+ return host_manager.HostState(host, node, capabilities, service)
+
+
+class BaremetalHostManager(host_manager.HostManager):
+ """Bare-Metal HostManager class."""
+
+ # Override.
+ # Yes, this is not a class, and it is OK
+ host_state_cls = new_host_state
+
+ def __init__(self):
+ super(BaremetalHostManager, self).__init__()