diff options
author | Michael Davies <michael@the-davies.net> | 2014-07-15 16:47:11 +0930 |
---|---|---|
committer | Devananda van der Veen <devananda.vdv@gmail.com> | 2014-07-22 06:33:24 -0700 |
commit | d0629b25b88aa7344617e3079891838f3d32f283 (patch) | |
tree | 1baa9d748fab6b3ba72252a2021628049a823e6c | |
parent | c52e06c335d73710894ff513ef5e79936a1d3ce3 (diff) | |
download | ironic-d0629b25b88aa7344617e3079891838f3d32f283.tar.gz |
Import fixes from Nova scheduler reviews
Import fixes from the Nova scheduler driver review, based upon
revision 4 of https://review.openstack.org/#/c/103165
- create BaseBaremetalHostManager class
- import and refactor the BaremetalHostManager
- refactor IronicHostManager
- minor updates to ExactMatch filters
Note that this change also adds back in copyright notices from
baremetal_host_manager to the ironic_host_manager to reflect
the common heritage of the code.
Change-Id: Iab0d0f1c05474bf341828a2e5aba95715bf71d82
-rw-r--r-- | ironic/nova/scheduler/baremetal_host_manager.py | 44 | ||||
-rw-r--r-- | ironic/nova/scheduler/base_baremetal_host_manager.py | 57 | ||||
-rw-r--r-- | ironic/nova/scheduler/filters/exact_core_filter.py | 11 | ||||
-rw-r--r-- | ironic/nova/scheduler/filters/exact_disk_filter.py | 13 | ||||
-rw-r--r-- | ironic/nova/scheduler/filters/exact_ram_filter.py | 8 | ||||
-rw-r--r-- | ironic/nova/scheduler/ironic_host_manager.py | 50 |
6 files changed, 136 insertions, 47 deletions
diff --git a/ironic/nova/scheduler/baremetal_host_manager.py b/ironic/nova/scheduler/baremetal_host_manager.py new file mode 100644 index 000000000..6d23ef18d --- /dev/null +++ b/ironic/nova/scheduler/baremetal_host_manager.py @@ -0,0 +1,44 @@ +# Copyright (c) 2012 NTT DOCOMO, INC. +# Copyright (c) 2011 OpenStack Foundation +# 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. +""" + +import ironic.nova.scheduler.base_baremetal_host_manager as bbhm + +from nova.openstack.common import jsonutils +from nova.scheduler import host_manager + + +class BaremetalNodeState(bbhm.BaseBaremetalNodeState): + """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. + """ + pass + + +class BaremetalHostManager(bbhm.BaseBaremetalHostManager): + """Bare-Metal HostManager class.""" + + def host_state_cls(self, host, node, **kwargs): + """Factory function/property to create a new HostState""" + compute = kwargs.get('compute') + if compute and compute.get('cpu_info') == 'baremetal cpu': + return BaremetalNodeState(host, node, **kwargs) + else: + return host_manager.HostState(host, node, **kwargs) diff --git a/ironic/nova/scheduler/base_baremetal_host_manager.py b/ironic/nova/scheduler/base_baremetal_host_manager.py new file mode 100644 index 000000000..99baba117 --- /dev/null +++ b/ironic/nova/scheduler/base_baremetal_host_manager.py @@ -0,0 +1,57 @@ +# Copyright (c) 2012 NTT DOCOMO, INC. +# Copyright (c) 2011 OpenStack Foundation +# 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.openstack.common import jsonutils +from nova.scheduler import host_manager + + +class BaseBaremetalNodeState(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.""" + self.vcpus_total = compute['vcpus'] + self.vcpus_used = compute['vcpus_used'] + + self.free_ram_mb = compute['free_ram_mb'] + self.total_usable_ram_mb = compute['memory_mb'] + self.free_disk_mb = compute['free_disk_gb'] * 1024 + + stats = compute.get('stats', '{}') + self.stats = jsonutils.loads(stats) + + def consume_from_instance(self, instance): + """Consume nodes entire resources regardless of instance request.""" + self.free_ram_mb = 0 + self.free_disk_mb = 0 + self.vcpus_used = self.vcpus_total + + +class BaseBaremetalHostManager(host_manager.HostManager): + """Base class for Baremetal and Ironic HostManager classes.""" + + def host_state_cls(self, host, node, **kwargs): + """Factory function to create a new HostState. May be overridden + in subclasses to extend functionality. + """ + return BaseBaremetalNodeState(host, node, **kwargs) diff --git a/ironic/nova/scheduler/filters/exact_core_filter.py b/ironic/nova/scheduler/filters/exact_core_filter.py index f3e9042b5..3954f0569 100644 --- a/ironic/nova/scheduler/filters/exact_core_filter.py +++ b/ironic/nova/scheduler/filters/exact_core_filter.py @@ -23,9 +23,10 @@ LOG = logging.getLogger(__name__) class ExactCoreFilter(filters.BaseHostFilter): + """Exact Core Filter.""" def host_passes(self, host_state, filter_properties): - """Return True if host has sufficient CPU cores.""" + """Return True if host has the exact number of CPU cores.""" instance_type = filter_properties.get('instance_type') if not instance_type: return True @@ -33,15 +34,15 @@ class ExactCoreFilter(filters.BaseHostFilter): if not host_state.vcpus_total: # Fail safe LOG.warning(_("VCPUs not set; assuming CPU collection broken")) - return True + return False required_vcpus = instance_type['vcpus'] usable_vcpus = host_state.vcpus_total - host_state.vcpus_used if required_vcpus != usable_vcpus: - LOG.debug("%(host_state)s does not have %(requested_vcpus)s " - "cores of usable vcpu, it only has %(usable_vcpus)s " - "cores of usable vcpu.", + LOG.debug("%(host_state)s does not have exactly " + "%(requested_vcpus)s cores of usable vcpu, it has " + "%(usable_vcpus)s.", {'host_state': host_state, 'requested_vcpus': required_vcpus, 'usable_vcpus': usable_vcpus}) diff --git a/ironic/nova/scheduler/filters/exact_disk_filter.py b/ironic/nova/scheduler/filters/exact_disk_filter.py index ecc0df43f..543eb4c75 100644 --- a/ironic/nova/scheduler/filters/exact_disk_filter.py +++ b/ironic/nova/scheduler/filters/exact_disk_filter.py @@ -23,18 +23,19 @@ class ExactDiskFilter(filters.BaseHostFilter): """Exact Disk Filter.""" def host_passes(self, host_state, filter_properties): - """Filter based on disk usage.""" + """Return True if host has the exact amount of disk available.""" instance_type = filter_properties.get('instance_type') requested_disk = (1024 * (instance_type['root_gb'] + instance_type['ephemeral_gb']) + instance_type['swap']) if requested_disk != host_state.free_disk_mb: - LOG.debug("%(host_state)s does not have %(requested_disk)s MB " - "usable disk, it only has %(usable_disk_mb)s MB usable " - "disk.", {'host_state': host_state, - 'requested_disk': requested_disk, - 'usable_disk_mb': host_state.free_disk_mb}) + LOG.debug("%(host_state)s does not have exactly " + "%(requested_disk)s MB usable disk, it " + "has %(usable_disk_mb)s.", + {'host_state': host_state, + 'requested_disk': requested_disk, + 'usable_disk_mb': host_state.free_disk_mb}) return False return True diff --git a/ironic/nova/scheduler/filters/exact_ram_filter.py b/ironic/nova/scheduler/filters/exact_ram_filter.py index 868e5bb8b..efd845aa6 100644 --- a/ironic/nova/scheduler/filters/exact_ram_filter.py +++ b/ironic/nova/scheduler/filters/exact_ram_filter.py @@ -20,14 +20,16 @@ LOG = logging.getLogger(__name__) class ExactRamFilter(filters.BaseHostFilter): + """Exact RAM Filter.""" def host_passes(self, host_state, filter_properties): - """Only return hosts with sufficient available RAM.""" + """Return True if host has the exact amount of RAM available.""" instance_type = filter_properties.get('instance_type') requested_ram = instance_type['memory_mb'] if requested_ram != host_state.free_ram_mb: - LOG.debug("%(host_state)s does not have %(requested_ram)s MB " - "usable ram, it only has %(usable_ram)s MB usable ram.", + LOG.debug("%(host_state)s does not have exactly " + "%(requested_ram)s MB usable RAM, it has " + "%(usable_ram)s.", {'host_state': host_state, 'requested_ram': requested_ram, 'usable_ram': host_state.free_ram_mb}) diff --git a/ironic/nova/scheduler/ironic_host_manager.py b/ironic/nova/scheduler/ironic_host_manager.py index 130a43af2..89c7d6b66 100644 --- a/ironic/nova/scheduler/ironic_host_manager.py +++ b/ironic/nova/scheduler/ironic_host_manager.py @@ -1,4 +1,5 @@ -# Copyright (c) 2014 OpenStack Foundation +# Copyright (c) 2012 NTT DOCOMO, INC. +# Copyright (c) 2011-2014 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -22,6 +23,8 @@ subdivided into multiple instances. """ from oslo.config import cfg +import ironic.nova.scheduler.base_baremetal_host_manager as bbhm + from nova.openstack.common import jsonutils from nova.openstack.common import log as logging from nova.openstack.common import timeutils @@ -54,7 +57,7 @@ CONF.register_opts(host_manager_opts) LOG = logging.getLogger(__name__) -class IronicNodeState(host_manager.HostState): +class IronicNodeState(bbhm.BaseBaremetalNodeState): """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. @@ -62,50 +65,31 @@ class IronicNodeState(host_manager.HostState): def update_from_compute_node(self, compute): """Update information about a host from its compute_node info.""" - self.free_ram_mb = compute['free_ram_mb'] - self.total_usable_ram_mb = compute['memory_mb'] + super(IronicNodeState, self).update_from_compute_node(compute) - self.free_disk_mb = compute['free_disk_gb'] * 1024 self.total_usable_disk_gb = compute['local_gb'] - - self.vcpus_total = compute['vcpus'] - self.vcpus_used = compute['vcpus_used'] - - stats = compute.get('stats', '{}') - self.stats = jsonutils.loads(stats) - self.updated = compute['updated_at'] def consume_from_instance(self, instance): """Consume nodes entire resources regardless of instance request.""" - self.free_ram_mb = 0 - self.free_disk_mb = 0 - self.vcpus_used = self.vcpus_total - self.updated = timeutils.utcnow() - + super(IronicNodeState, self).consume_from_instance(instance) -def new_host_state(self, host, node, **kwargs): - """Returns an instance of IronicNodeState or HostState according to - compute['cpu_info']. If 'cpu_info' equals 'baremetal cpu', it returns an - instance of IronicNodeState. If not, returns an instance of HostState. - """ - compute = kwargs.get('compute') - - if compute and compute.get('cpu_info') == 'baremetal cpu': - return IronicNodeState(host, node, **kwargs) - else: - return host_manager.HostState(host, node, **kwargs) + self.updated = timeutils.utcnow() -class IronicHostManager(host_manager.HostManager): +class IronicHostManager(bbhm.BaseBaremetalHostManager): """Ironic HostManager class.""" - # Override. - # Yes, this is not a class, and it is OK - host_state_cls = new_host_state - def __init__(self): super(IronicHostManager, self).__init__() if CONF.scheduler_use_baremetal_filters: baremetal_default = CONF.baremetal_scheduler_default_filters CONF.scheduler_default_filters = baremetal_default + + def host_state_cls(self, host, node, **kwargs): + """Factory function/property to create a new HostState""" + compute = kwargs.get('compute') + if compute and compute.get('cpu_info') == 'baremetal cpu': + return IronicNodeState(host, node, **kwargs) + else: + return host_manager.HostState(host, node, **kwargs) |