Created
April 30, 2018 16:25
-
-
Save mgagne/462e7fa8417843055aa6da7c5fd51c00 to your computer and use it in GitHub Desktop.
Strict image isolation for Nova - Mitaka
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
# 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. | |
from oslo_config import cfg | |
from oslo_log import log as logging | |
from nova.scheduler import filters | |
from nova.scheduler.filters import utils | |
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, spec_obj): | |
"""Check if host passes specified os_type image property. | |
Returns True for compute nodes that satisfy image properties | |
contained in the request_spec. | |
""" | |
image_props = spec_obj.image.properties if spec_obj.image else {} | |
image_os_type = image_props.get('os_type') | |
metadata = utils.aggregate_metadata_get_by_host(host_state) | |
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