<gh_stars>0
begin_unit
comment|'# Copyright (c) 2014 OpenStack Foundation'
nl|'\n'
comment|'#'
nl|'\n'
comment|'# All Rights Reserved.'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Licensed under the Apache License, Version 2.0 (the "License"); you may'
nl|'\n'
comment|'#    not use this file except in compliance with the License. You may obtain'
nl|'\n'
comment|'#    a copy of the License at'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#         http://www.apache.org/licenses/LICENSE-2.0'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Unless required by applicable law or agreed to in writing, software'
nl|'\n'
comment|'#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT'
nl|'\n'
comment|'#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the'
nl|'\n'
comment|'#    License for the specific language governing permissions and limitations'
nl|'\n'
comment|'#    under the License.'
nl|'\n'
nl|'\n'
name|'from'
name|'oslo_log'
name|'import'
name|'log'
name|'as'
name|'logging'
newline|'\n'
nl|'\n'
name|'from'
name|'nova'
op|'.'
name|'i18n'
name|'import'
name|'_LW'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'scheduler'
name|'import'
name|'filters'
newline|'\n'
nl|'\n'
DECL|variable|LOG
name|'LOG'
op|'='
name|'logging'
op|'.'
name|'getLogger'
op|'('
name|'__name__'
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|ExactCoreFilter
name|'class'
name|'ExactCoreFilter'
op|'('
name|'filters'
op|'.'
name|'BaseHostFilter'
op|')'
op|':'
newline|'\n'
indent|'    '
string|'"""Exact Core Filter."""'
newline|'\n'
nl|'\n'
DECL|member|host_passes
name|'def'
name|'host_passes'
op|'('
name|'self'
op|','
name|'host_state'
op|','
name|'spec_obj'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Return True if host has the exact number of CPU cores."""'
newline|'\n'
name|'if'
name|'not'
name|'host_state'
op|'.'
name|'vcpus_total'
op|':'
newline|'\n'
comment|'# Fail safe'
nl|'\n'
indent|'            '
name|'LOG'
op|'.'
name|'warning'
op|'('
name|'_LW'
op|'('
string|'"VCPUs not set; assuming CPU collection broken"'
op|')'
op|')'
newline|'\n'
name|'return'
name|'False'
newline|'\n'
nl|'\n'
dedent|''
name|'required_vcpus'
op|'='
name|'spec_obj'
op|'.'
name|'vcpus'
newline|'\n'
name|'usable_vcpus'
op|'='
name|'host_state'
op|'.'
name|'vcpus_total'
op|'-'
name|'host_state'
op|'.'
name|'vcpus_used'
newline|'\n'
nl|'\n'
name|'if'
name|'required_vcpus'
op|'!='
name|'usable_vcpus'
op|':'
newline|'\n'
indent|'            '
name|'LOG'
op|'.'
name|'debug'
op|'('
string|'"%(host_state)s does not have exactly "'
nl|'\n'
string|'"%(requested_vcpus)s cores of usable vcpu, it has "'
nl|'\n'
string|'"%(usable_vcpus)s."'
op|','
nl|'\n'
op|'{'
string|"'host_state'"
op|':'
name|'host_state'
op|','
nl|'\n'
string|"'requested_vcpus'"
op|':'
name|'required_vcpus'
op|','
nl|'\n'
string|"'usable_vcpus'"
op|':'
name|'usable_vcpus'
op|'}'
op|')'
newline|'\n'
name|'return'
name|'False'
newline|'\n'
nl|'\n'
comment|'# NOTE(mgoddard): Setting the limit ensures that it is enforced in'
nl|'\n'
comment|'# compute. This ensures that if multiple instances are scheduled to a'
nl|'\n'
comment|'# single host, then all after the first will fail in the claim.'
nl|'\n'
dedent|''
name|'host_state'
op|'.'
name|'limits'
op|'['
string|"'vcpu'"
op|']'
op|'='
name|'host_state'
op|'.'
name|'vcpus_total'
newline|'\n'
name|'return'
name|'True'
newline|'\n'
dedent|''
dedent|''
endmarker|''
end_unit

begin_unit
comment|'# Copyright (c) 2014 OpenStack Foundation'
nl|'\n'
comment|'#'
nl|'\n'
comment|'# All Rights Reserved.'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Licensed under the Apache License, Version 2.0 (the "License"); you may'
nl|'\n'
comment|'#    not use this file except in compliance with the License. You may obtain'
nl|'\n'
comment|'#    a copy of the License at'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#         http://www.apache.org/licenses/LICENSE-2.0'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Unless required by applicable law or agreed to in writing, software'
nl|'\n'
comment|'#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT'
nl|'\n'
comment|'#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the'
nl|'\n'
comment|'#    License for the specific language governing permissions and limitations'
nl|'\n'
comment|'#    under the License.'
nl|'\n'
nl|'\n'
name|'from'
name|'oslo_log'
name|'import'
name|'log'
name|'as'
name|'logging'
newline|'\n'
nl|'\n'
name|'from'
name|'nova'
op|'.'
name|'i18n'
name|'import'
name|'_LW'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'scheduler'
name|'import'
name|'filters'
newline|'\n'
nl|'\n'
DECL|variable|LOG
name|'LOG'
op|'='
name|'logging'
op|'.'
name|'getLogger'
op|'('
name|'__name__'
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|ExactCoreFilter
name|'class'
name|'ExactCoreFilter'
op|'('
name|'filters'
op|'.'
name|'BaseHostFilter'
op|')'
op|':'
newline|'\n'
indent|'    '
string|'"""Exact Core Filter."""'
newline|'\n'
nl|'\n'
DECL|member|host_passes
name|'def'
name|'host_passes'
op|'('
name|'self'
op|','
name|'host_state'
op|','
name|'spec_obj'
op|')'
op|':'
newline|'\n'
indent|'        '
string|'"""Return True if host has the exact number of CPU cores."""'
newline|'\n'
name|'if'
name|'not'
name|'host_state'
op|'.'
name|'vcpus_total'
op|':'
newline|'\n'
comment|'# Fail safe'
nl|'\n'
indent|'            '
name|'LOG'
op|'.'
name|'warning'
op|'('
name|'_LW'
op|'('
string|'"VCPUs not set; assuming CPU collection broken"'
op|')'
op|')'
newline|'\n'
name|'return'
name|'False'
newline|'\n'
nl|'\n'
dedent|''
name|'required_vcpus'
op|'='
name|'spec_obj'
op|'.'
name|'vcpus'
newline|'\n'
name|'usable_vcpus'
op|'='
name|'host_state'
op|'.'
name|'vcpus_total'
op|'-'
name|'host_state'
op|'.'
name|'vcpus_used'
newline|'\n'
nl|'\n'
name|'if'
name|'required_vcpus'
op|'!='
name|'usable_vcpus'
op|':'
newline|'\n'
indent|'            '
name|'LOG'
op|'.'
name|'debug'
op|'('
string|'"%(host_state)s does not have exactly "'
nl|'\n'
string|'"%(requested_vcpus)s cores of usable vcpu, it has "'
nl|'\n'
string|'"%(usable_vcpus)s."'
op|','
nl|'\n'
op|'{'
string|"'host_state'"
op|':'
name|'host_state'
op|','
nl|'\n'
string|"'requested_vcpus'"
op|':'
name|'required_vcpus'
op|','
nl|'\n'
string|"'usable_vcpus'"
op|':'
name|'usable_vcpus'
op|'}'
op|')'
newline|'\n'
name|'return'
name|'False'
newline|'\n'
nl|'\n'
comment|'# NOTE(mgoddard): Setting the limit ensures that it is enforced in'
nl|'\n'
comment|'# compute. This ensures that if multiple instances are scheduled to a'
nl|'\n'
comment|'# single host, then all after the first will fail in the claim.'
nl|'\n'
dedent|''
name|'host_state'
op|'.'
name|'limits'
op|'['
string|"'vcpu'"
op|']'
op|'='
name|'host_state'
op|'.'
name|'vcpus_total'
newline|'\n'
name|'return'
name|'True'
newline|'\n'
dedent|''
dedent|''
endmarker|''
end_unit
Exact Core Filter. Return True if host has the exact number of CPU cores.