"Fossies" - the Fresh Open Source Software Archive

Member "zun-4.0.0/zun/scheduler/filters/availability_zone_filter.py" (16 Oct 2019, 1653 Bytes) of package /linux/misc/openstack/zun-4.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "availability_zone_filter.py" see the Fossies "Dox" file reference documentation.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 from oslo_log import log as logging
   14 
   15 import zun.conf
   16 from zun.scheduler import filters
   17 
   18 
   19 LOG = logging.getLogger(__name__)
   20 CONF = zun.conf.CONF
   21 
   22 
   23 class AvailabilityZoneFilter(filters.BaseHostFilter):
   24     """Filters Hosts by availability zone."""
   25 
   26     # Availability zones do not change within a request
   27     run_filter_once_per_request = True
   28 
   29     def host_passes(self, host_state, container, extra_spec):
   30         availability_zone = extra_spec.get('availability_zone') or \
   31             CONF.default_schedule_zone
   32         if not availability_zone:
   33             return True
   34 
   35         host_az = host_state.service.availability_zone
   36         if not host_az:
   37             host_az = CONF.default_availability_zone
   38 
   39         hosts_passes = availability_zone == host_az
   40         if not hosts_passes:
   41             LOG.debug("Availability Zone '%(az)s' requested. "
   42                       "%(host_state)s has AZs: %(host_az)s",
   43                       {'host_state': host_state,
   44                        'az': availability_zone,
   45                        'host_az': host_az})
   46 
   47         return hosts_passes