--- # Copyright 2019 Nokia # 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. - name: Prepare. set_fact: cpu_remain: [] cpu_sets: {} - name: Get CPU topology. get_cpu_topology: var: cpu_topology - debug: var: cpu_topology - name: Make default performance profile. set_fact: perf_profile: { platform_cpus: "{{ cpu_topology | cpu_topology_defaults(hosts[hostname]['service_profiles'], platform_cpus, virtual_env, hosts | length < 2) }}" } - debug: var: perf_profile - name: Get performance profile. set_fact: perf_profile: "{{ perf_profile | combine(performance_profiles[hosts[hostname]['performance_profiles'][0]]) }}" when: "'performance_profiles' in hosts[hostname]" - debug: var: perf_profile - name: Make CPU sets. include_tasks: make_cpu_sets.yaml loop_control: loop_var: cpu_set with_items: - { 'name': 'ovs_dpdk', 'opt': "{{ cpu_set_mapping['ovs_dpdk']['opt'] }}", 'where': 'tail' } - { 'name': 'platform', 'opt': "{{ cpu_set_mapping['platform']['opt'] }}", 'where': 'head' } when: "cpu_set.opt in perf_profile" - name: Initialize VM CPU share. set_fact: vm_share_percent: 100 - name: Set collocated VM CPU set. set_fact: vm_share_percent: "{{ 100 - (perf_profile['caas_cpu_pool_share'] | default(caas_cpu_pool_share_default) | int) }}" when: - "'compute' in hosts[hostname]['service_profiles']" - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles) - name: Make VM CPU sets. include_tasks: make_cpu_sets.yaml loop_control: loop_var: cpu_set with_items: - { 'name': 'vm', 'request': "{{ cpu_topology | get_cpu_count_by_percent(vm_share_percent) }}", 'where': 'tail' } when: - "'compute' in hosts[hostname]['service_profiles']" - name: Make CaaS default CPU set. include_tasks: make_cpu_sets.yaml loop_control: loop_var: cpu_set with_items: - { 'name': 'caas_default', 'request': "{{ cpu_topology | cpu_topology_defaults(hosts[hostname]['service_profiles'], caas_default_pool_cpus, virtual_env, hosts | length < 2) }}", 'where': 'tail' } when: - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles) - name: Calculate CaaS CPU counts set_fact: perf_profile: "{{ perf_profile | combine({ item.key: cpu_topology | get_cpu_count_by_percent(item.value) }) }}" with_dict: "{{ perf_profile['caas_cpu_pools'] | default({}) }}" when: hosts[hostname]['service_profiles'] | intersect(caas_service_profiles) - name: Make CaaS CPU sets. include_tasks: make_cpu_sets.yaml loop_control: loop_var: cpu_set with_items: - { 'name': 'caas_exclusive', 'opt': "{{ cpu_set_mapping['caas_exclusive']['opt'] }}", 'where': 'tail' } - { 'name': 'caas_shared', 'opt': "{{ cpu_set_mapping['caas_shared']['opt'] }}", 'where': 'tail' } when: - "cpu_set.opt in perf_profile" - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles) - name: Make set of remaining CPUs. set_fact: cpu_remain: "{{ cpu_remain | union(item) }}" with_items: "{{ cpu_topology.values() }}" - debug: var: cpu_remain - name: Allocate remaining CPUs to CaaS default. set_fact: cpu_sets: "{{ cpu_sets | combine({ 'caas_default': cpu_sets['caas_default'] | default([]) | union(cpu_remain) }) }}" cpu_remain: [] when: - "cpu_remain | length > 0" - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles) - name: Allocate remaining CPUs to platform. set_fact: cpu_sets: "{{ cpu_sets | combine({ 'platform': cpu_sets['platform'] | default([]) | union(cpu_remain) }) }}" cpu_remain: [] when: - "cpu_remain | length > 0" - not hosts[hostname]['service_profiles'] | intersect(caas_service_profiles) - debug: var: cpu_sets - name: Make sure facts directory exists. file: path: "{{ allocation_fact_file | dirname }}" state: directory mode: 0755 - name: Save CPU allocation. template: src: cpu_allocation.fact.j2 dest: "{{ allocation_fact_file }}" register: cpu_allocation - name: Refresh facts. setup: when: - cpu_allocation.changed - not skip_facts_reload | default(False)