b1c835fe65b973061f1c0381ba50a47c2b4281ba
[ta/infra-ansible.git] / roles / allocate_cpu_cores / tasks / main.yml
1 ---
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain 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,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 - name: Prepare.
19   set_fact:
20     cloud_cpu_remain: []
21     cloud_cpu_sets: {}
22
23 - name: Get CPU topology.
24   get_cpu_topology:
25     var: cloud_cpu_topology
26 - debug:
27     var: cloud_cpu_topology
28
29 - name: Make default performance profile.
30   set_fact:
31     perf_profile: {
32       platform_cpus: "{{ cloud_cpu_topology | cpu_topology_defaults(hosts[hostname]['service_profiles'], cloud_default_platform_cpus, virtual_env, hosts | length < 2) }}"
33     }
34 - debug:
35     var: perf_profile
36
37 - name: Get performance profile.
38   set_fact:
39     perf_profile: "{{ perf_profile | combine(performance_profiles[hosts[hostname]['performance_profiles'][0]]) }}"
40   when: "'performance_profiles' in hosts[hostname]"
41 - debug:
42     var: perf_profile
43
44 - name: Make CPU sets.
45   include_tasks: make_cpu_sets.yaml
46   loop_control:
47     loop_var: cpu_set
48   with_items:
49       - { 'name': 'ovs_dpdk', 'opt': "{{ cpu_set_mapping['ovs_dpdk']['opt'] }}", 'where': 'tail' }
50       - { 'name': 'platform', 'opt': "{{ cpu_set_mapping['platform']['opt'] }}", 'where': 'head' }
51   when: "cpu_set.opt in perf_profile"
52
53 - name: Initialize VM CPU share.
54   set_fact:
55     vm_share_percent: 100
56
57 - name: Set collocated VM CPU set.
58   set_fact:
59     vm_share_percent: "{{ 100 - (perf_profile['caas_cpu_pool_share'] | default(100) | int) }}"
60   when:
61     - "'compute' in hosts[hostname]['service_profiles']"
62     - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
63
64 - name: Make VM CPU sets.
65   include_tasks: make_cpu_sets.yaml
66   loop_control:
67     loop_var: cpu_set
68   with_items:
69     - { 'name': 'vm', 'request': "{{ cloud_cpu_topology | get_cpu_count_by_percent(vm_share_percent) }}", 'where': 'tail' }
70   when:
71     - "'compute' in hosts[hostname]['service_profiles']"
72
73 - name: Calculate CaaS CPU counts
74   set_fact:
75     perf_profile: "{{ perf_profile | combine({ item.key: cloud_cpu_topology | get_cpu_count_by_percent(item.value) }) }}"
76   with_dict: "{{ perf_profile['caas_cpu_pools'] | default({}) }}"
77   when: hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
78
79 - name: Make CaaS CPU sets.
80   include_tasks: make_cpu_sets.yaml
81   loop_control:
82     loop_var: cpu_set
83   with_items:
84     - { 'name': 'caas_exclusive', 'opt': "{{ cpu_set_mapping['caas_exclusive']['opt'] }}", 'where': 'tail' }
85     - { 'name': 'caas_shared',    'opt': "{{ cpu_set_mapping['caas_shared']['opt'] }}",    'where': 'tail' }
86   when:
87     - "cpu_set.opt in perf_profile"
88     - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
89
90 - name: Make set of remaining CPUs.
91   set_fact:
92     cloud_cpu_remain: "{{ cloud_cpu_remain | union(item) }}"
93   with_items: "{{ cloud_cpu_topology.values() }}"
94 - debug:
95     var: cloud_cpu_remain
96
97 - name: Allocate remaining CPUs to platform.
98   set_fact:
99     cloud_cpu_sets: "{{ cloud_cpu_sets | combine({ 'platform': cloud_cpu_sets['platform'] | default([]) | union(cloud_cpu_remain) }) }}"
100     cloud_cpu_remain: []
101   when: "cloud_cpu_remain | length > 0"
102
103 - debug:
104     var: cloud_cpu_sets
105
106 - name: Make sure facts directory exists.
107   file:
108     path: "{{ allocation_fact_file | dirname }}"
109     state: directory
110     mode: 0755
111
112 - name: Save CPU allocation.
113   template:
114     src: cloud_cpu_allocation.fact.j2
115     dest: "{{ allocation_fact_file }}"
116   register: cpu_allocation
117
118 - name: Refresh facts.
119   setup:
120   when:
121     - cpu_allocation.changed
122     - not skip_facts_reload | default(False)