Created
October 27, 2015 02:35
-
-
Save mgagne/41aad133192595f52179 to your computer and use it in GitHub Desktop.
AggregateImageOsTypeIsolationFilter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nova/scheduler/filters/aggregate_image_os_type_isolation.py | |
from oslo_config import cfg | |
from oslo_log import log as logging | |
from nova import db | |
from nova.scheduler import filters | |
isolated_opts = [ | |
cfg.ListOpt('isolated_image_os_type', | |
default=[], | |
help='Image os_type to run on isolated host'), | |
] | |
CONF = cfg.CONF | |
CONF.register_opts(isolated_opts) | |
LOG = logging.getLogger(__name__) | |
class AggregateImageOsTypeIsolationFilter(filters.BaseHostFilter): | |
"""Filter compute nodes that satisfy instance image os_type property. | |
The AggregateImageOsTypeIsolationFilter filters compute nodes that satisfy | |
the os_type property specified on the instance's image properties. | |
Image properties are contained in the image dictionary in the request_spec. | |
""" | |
# Aggregate data and Image Properties do not change within a request | |
run_filter_once_per_request = True | |
def host_passes(self, host_state, filter_properties): | |
"""Check if host passes specified os_type image property. | |
Returns True for compute nodes that satisfy image properties | |
contained in the request_spec. | |
""" | |
spec = filter_properties.get('request_spec', {}) | |
image_props = spec.get('image', {}).get('properties', {}) | |
image_os_type = image_props.get('os_type') | |
context = filter_properties['context'].elevated() | |
metadata = db.aggregate_metadata_get_by_host(context, host_state.host) | |
host_os_type = metadata.get('os_type') | |
# If host has os_type part of its aggregate metadatas, it is reserved | |
# for images with the matching os_type property. | |
if host_os_type: | |
return image_os_type in host_os_type | |
else: | |
# Host without os_type can only run images not in the list of | |
# isolated os_type. | |
return image_os_type not in CONF.isolated_image_os_type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment