"Fossies" - the Fresh Open Source Software Archive

Member "zun-4.0.0/zun/scheduler/filters/cpuset_filter.py" (16 Oct 2019, 2252 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 "cpuset_filter.py" see the Fossies "Dox" file reference documentation.

    1 #    Copyright (c) 2018 National Engineering Laboratory of electronic
    2 #    commerce and electronic payment
    3 #    All Rights Reserved.
    4 #
    5 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    6 #    not use this file except in compliance with the License. You may obtain
    7 #    a copy of the License at
    8 #
    9 #         http://www.apache.org/licenses/LICENSE-2.0
   10 #
   11 #    Unless required by applicable law or agreed to in writing, software
   12 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   13 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   14 #    License for the specific language governing permissions and limitations
   15 #    under the License.
   16 
   17 from oslo_log import log as logging
   18 
   19 import zun.conf
   20 from zun.scheduler import filters
   21 
   22 LOG = logging.getLogger(__name__)
   23 CONF = zun.conf.CONF
   24 
   25 
   26 class CpuSetFilter(filters.BaseHostFilter):
   27     """Filter the host by cpu and memory request of cpuset"""
   28 
   29     run_filter_once_per_request = True
   30 
   31     def host_passes(self, host_state, container, extra_spec):
   32         if container.cpu_policy is None:
   33             container.cpu_policy = 'shared'
   34         if container.memory is None:
   35             container_memory = 0
   36         else:
   37             container_memory = int(container.memory)
   38         if container.cpu_policy == 'dedicated':
   39             if host_state.enable_cpu_pinning:
   40                 for numa_node in host_state.numa_topology.nodes:
   41                     if len(numa_node.cpuset) - len(
   42                             numa_node.pinned_cpus) >= container.cpu and \
   43                             numa_node.mem_available >= container_memory:
   44                         host_state.limits['cpuset'] = {
   45                             'node': numa_node.id,
   46                             'cpuset_cpu': numa_node.cpuset,
   47                             'cpuset_cpu_pinned': numa_node.pinned_cpus,
   48                             'cpuset_mem': numa_node.mem_available
   49                         }
   50                         return True
   51                 return False
   52             else:
   53                 return False
   54         if container.cpu_policy == 'shared':
   55             if CONF.compute.enable_cpu_pinning:
   56                 return False
   57             else:
   58                 return True