Created
August 26, 2016 18:34
-
-
Save mgagne/7e1376b8f5260f1add73549412f5ba83 to your computer and use it in GitHub Desktop.
This file contains 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
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