-
Notifications
You must be signed in to change notification settings - Fork 68
Add vm planner helper script #845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
agurenko
wants to merge
1
commit into
redhat-performance:main
Choose a base branch
from
agurenko:vm-planner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| # Render Coredns.hosts template to match provided ansible inventory | ||
| # Requires to run with vm-planner.py generated inventory | ||
| # | ||
| # Example Usage: | ||
| # | ||
| # ansible-playbook -i ansible/inventory/cloud42.local ansible/bastion-match-coredns-to-inventory.yml | ||
| # | ||
|
|
||
| - name: Render Coredns.hosts template to match provided ansible inventory | ||
| hosts: bastion | ||
| gather_facts: false | ||
| vars_files: | ||
| - vars/lab.yml | ||
| - vars/all.yml | ||
| roles: | ||
| - role: bastion-coredns | ||
| vars: | ||
| match_dns_to_inventory: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
ansible/roles/bastion-coredns/templates/Corefile.hosts.match.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| # CoreDNS file that matches the inventory | ||
| # Bastion/API/VM/Compact/Standard resolution | ||
| {# Pull vm-planner metadata from hv_vm host vars (they live in [hv_vm:vars], not bastion scope). | ||
| Fall back to backwards-compatible defaults when vm-planner metadata is absent. #} | ||
| {% if groups['hv_vm'] | length > 0 %} | ||
| {% set vm_cluster_type_list = hostvars[groups['hv_vm'][0]].vm_cluster_type_list | default(["jumbo", "standard", "compact", "sno"]) %} | ||
| {% set vm_cluster_count = hostvars[groups['hv_vm'][0]].vm_cluster_count | default(0) %} | ||
| {% else %} | ||
| {% set vm_cluster_type_list = ["jumbo", "standard", "compact", "sno"] %} | ||
| {% set vm_cluster_count = 0 %} | ||
| {% endif %} | ||
| hosts { | ||
| # Bastion | ||
| {% for network in controlplane_network %} | ||
| {{ network | ansible.utils.nthhost(1) }} {{ groups['bastion'][0] }} | ||
| {% endfor %} | ||
|
|
||
| {% if cluster_type in ["mno", "vmno"] %} | ||
| # MNO Cluster API | ||
| {% for network in controlplane_network %} | ||
| {{ network | ansible.utils.nthhost(3) }} api.{{ cluster_name }}.{{ base_dns_name }} | ||
| {% endfor %} | ||
| {% else %} | ||
| {% for sno in groups['sno'] %} | ||
| # SNO Cluster API | ||
| {{ hostvars[sno].ip }} api.{{ sno }}.{{ base_dns_name }} | ||
| {% if hostvars[sno].ipv6 is defined %} | ||
| {{ hostvars[sno].ipv6 }} api.{{ sno }}.{{ base_dns_name }} | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endif %} | ||
|
|
||
| # VM | ||
| {% for vm in groups['hv_vm'] %} | ||
| {{ hostvars[vm].ip }} {{ vm }} | ||
| {% if "sno" in vm_cluster_type_list %} | ||
| {{ hostvars[vm].ip }} api.{{ vm }}.{{ base_dns_name }} | ||
| {% endif %} | ||
| {% if hostvars[vm].ipv6 is defined %} | ||
| {{ hostvars[vm].ipv6 }} {{ vm }} | ||
| {% if "sno" in vm_cluster_type_list %} | ||
| {{ hostvars[vm].ipv6 }} api.{{ vm }}.{{ base_dns_name }} | ||
| {% endif %} | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% if groups['hv_vm'] | length > 0 %} | ||
| {% if "jumbo" in vm_cluster_type_list %} | ||
|
|
||
| # jumbocluster00 | ||
| {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost(-2) }} jumbocluster00 | ||
| {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost(-2) }} api.jumbocluster00.{{ base_dns_name }} | ||
| {% endif %} | ||
| {% if "standard" in vm_cluster_type_list %} | ||
|
|
||
| {% set _standard_count = vm_cluster_count | int if vm_cluster_count | int > 0 else standard_cluster_dns_count | int %} | ||
| # Standard cluster DNS ({{ _standard_count }} Entries) | ||
| {% for cluster in range(1, _standard_count + 1, 1) %} | ||
| {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost(cluster * -2) }} standard-{{ '%05d' | format(cluster) }} | ||
| {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost(cluster * -2) }} api.standard-{{ '%05d' | format(cluster) }}.{{ base_dns_name }} | ||
| {% endfor %} | ||
| {% endif %} | ||
| {% if "compact" in vm_cluster_type_list %} | ||
|
|
||
| {% set _compact_count = vm_cluster_count | int if vm_cluster_count | int > 0 else compact_cluster_dns_count | int %} | ||
| # Compact cluster DNS ({{ _compact_count }} Entries) | ||
| {% for cluster in range(1, _compact_count + 1, 1) %} | ||
| {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost((cluster + standard_cluster_dns_count) * -2) }} compact-{{ '%05d' | format(cluster) }} | ||
| {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost((cluster + standard_cluster_dns_count) * -2) }} api.compact-{{ '%05d' | format(cluster) }}.{{ base_dns_name }} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| {% endfor %} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| {% endif %} | ||
| {% endif %} | ||
| fallthrough | ||
| } | ||
|
|
||
| # *.apps All Clusters | ||
| {% if cluster_type in ["mno", "vmno"] %} | ||
| # *.apps for hub cluster | ||
| {% for network in controlplane_network %} | ||
| {% if network | ansible.utils.ipv4 %} | ||
| template IN A {{ cluster_name }}.{{ base_dns_name }} { | ||
| match .*.apps.{{ cluster_name }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ network | ansible.utils.nthhost(4) }}" | ||
| fallthrough | ||
| } | ||
| {% else %} | ||
| template IN AAAA {{ cluster_name }}.{{ base_dns_name }} { | ||
| match .*.apps.{{ cluster_name }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ network | ansible.utils.nthhost(4) }}" | ||
| fallthrough | ||
| } | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% else %} | ||
| {% for sno in groups['sno'] %} | ||
| # *.apps for {{ sno }} SNO | ||
| {% if hostvars[sno].ip | ansible.utils.ipv4 %} | ||
| template IN A {{ sno }}.{{ base_dns_name }} { | ||
| {% else %} | ||
| template IN AAAA {{ sno }}.{{ base_dns_name }} { | ||
| {% endif %} | ||
| match .*.apps.{{ sno }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ hostvars[sno].ip }}" | ||
| fallthrough | ||
| } | ||
| {% if hostvars[sno].ipv6 is defined %} | ||
| template IN AAAA {{ sno }}.{{ base_dns_name }} { | ||
| match .*.apps.{{ sno }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ hostvars[sno].ipv6 }}" | ||
| fallthrough | ||
| } | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endif %} | ||
|
|
||
| {% if "sno" in vm_cluster_type_list %} | ||
| # *.apps for VMs | ||
| {% for vm in groups['hv_vm'] %} | ||
| {% if hostvars[vm].ip | ansible.utils.ipv4 %} | ||
| template IN A {{ vm }}.{{ base_dns_name }} { | ||
| {% else %} | ||
| template IN AAAA {{ vm }}.{{ base_dns_name }} { | ||
| {% endif %} | ||
| match .*.apps.{{ vm }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ hostvars[vm].ip }}" | ||
| fallthrough | ||
| } | ||
| {% if hostvars[vm].ipv6 is defined %} | ||
| template IN AAAA {{ vm }}.{{ base_dns_name }} { | ||
| match .*.apps.{{ vm }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ hostvars[vm].ipv6 }}" | ||
| fallthrough | ||
| } | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endif %} | ||
| {% if groups['hv_vm'] | length > 0 %} | ||
| {% if "jumbo" in vm_cluster_type_list %} | ||
|
|
||
| # *.apps for jumbocluster00 | ||
| template IN AAAA jumbocluster00.{{ base_dns_name }} { | ||
| match .*.apps.jumbocluster00.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost(-3) }}" | ||
| fallthrough | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| {% endif %} | ||
| {% if "standard" in vm_cluster_type_list %} | ||
|
|
||
| {% set _standard_apps_count = vm_cluster_count | int if vm_cluster_count | int > 0 else standard_cluster_dns_count | int %} | ||
| # *.apps for standard clusters | ||
| {% for cluster in range(1, _standard_apps_count + 1, 1) %} | ||
| template IN AAAA standard-{{ '%05d' | format(cluster) }}.{{ base_dns_name }} { | ||
| match .*.apps.standard-{{ '%05d' | format(cluster) }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost( (cluster * -2) - 1 ) }}" | ||
| fallthrough | ||
| } | ||
| {% endfor %} | ||
| {% endif %} | ||
| {% if "compact" in vm_cluster_type_list %} | ||
|
|
||
| {% set _compact_apps_count = vm_cluster_count | int if vm_cluster_count | int > 0 else compact_cluster_dns_count | int %} | ||
| # *.apps for compact clusters | ||
| {% for cluster in range(1, _compact_apps_count + 1, 1) %} | ||
| template IN AAAA compact-{{ '%05d' | format(cluster) }}.{{ base_dns_name }} { | ||
| match .*.apps.compact-{{ '%05d' | format(cluster) }}.{{ base_dns_name }} | ||
| answer "{%raw%}{{ .Name }} 60 in {{ .Type }}{%endraw%} {{ hostvars[groups['hv_vm'][0]]['machine_network'] | ansible.utils.nthhost( ((cluster + standard_cluster_dns_count) * -2) - 1 ) }}" | ||
| fallthrough | ||
| } | ||
| {% endfor %} | ||
| {% endif %} | ||
| {% endif %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| [all:vars] | ||
| controlplane_network=['198.18.0.0/16'] | ||
| controlplane_network_prefix=[16] | ||
|
|
||
| [hv] | ||
| hv00.example.com bmc_address=mgmt-hv00.example.com vendor=Dell ip=198.18.0.6 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv01.example.com bmc_address=mgmt-hv01.example.com vendor=Dell ip=198.18.0.7 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv02.example.com bmc_address=mgmt-hv02.example.com vendor=Dell ip=198.18.0.8 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv03.example.com bmc_address=mgmt-hv03.example.com vendor=Dell ip=198.18.0.9 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv04.example.com bmc_address=mgmt-hv04.example.com vendor=Dell ip=198.18.0.10 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv05.example.com bmc_address=mgmt-hv05.example.com vendor=Dell ip=198.18.0.11 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
|
|
||
| [hv:vars] | ||
| ansible_user=root | ||
| ansible_ssh_pass=testpass | ||
| bmc_user=test | ||
| bmc_password=testpass | ||
| network_prefix=16 | ||
|
|
||
| [hv_vm] | ||
|
|
||
| [hv_vm:vars] | ||
| ansible_user=root | ||
| ansible_ssh_pass=testpass | ||
| base_domain=example.com | ||
| machine_network=198.18.0.0/16 | ||
| network_prefix=16 | ||
| gateway=198.18.0.1 | ||
| bw_limit=False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| [all:vars] | ||
| controlplane_network=['198.18.0.0/16'] | ||
| controlplane_network_prefix=[16] | ||
|
|
||
| [hv] | ||
| hv00.example.com bmc_address=mgmt-hv00.example.com vendor=Dell ip=198.18.0.6 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv01.example.com bmc_address=mgmt-hv01.example.com vendor=Dell ip=198.18.0.7 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv02.example.com bmc_address=mgmt-hv02.example.com vendor=Dell ip=198.18.0.8 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv03.example.com bmc_address=mgmt-hv03.example.com vendor=Dell ip=198.18.0.9 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv04.example.com bmc_address=mgmt-hv04.example.com vendor=Dell ip=198.18.0.10 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
| hv05.example.com bmc_address=mgmt-hv05.example.com vendor=Dell ip=198.18.0.11 nic=eno1 disk2_enable=True disk2_device=nvme0n1 | ||
|
|
||
| [hv:vars] | ||
| ansible_user=root | ||
| ansible_ssh_pass=testpass | ||
| bmc_user=test | ||
| bmc_password=testpass | ||
| network_prefix=16 | ||
|
|
||
| [hv_vm] | ||
|
|
||
| [hv_vm:vars] | ||
| ansible_user=root | ||
| ansible_ssh_pass=testpass | ||
| base_domain=example.com | ||
| machine_network=198.18.0.0/16 | ||
| network_prefix=16 | ||
| gateway=198.18.0.1 | ||
| bw_limit=False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| { | ||
| "_comment": "Test fixture for test_vm_planner.py (paired with test_cloud00.local).", | ||
| "vm_types": { | ||
| "worker": { | ||
| "per_hv": 1, | ||
| "cpus": 8, | ||
| "memory": 16, | ||
| "disk_size": 100, | ||
| "bw_avg": 11500, | ||
| "bw_peak": 12500, | ||
| "bw_burst": 11750, | ||
| "disk_location": "/var/lib/libvirt/images" | ||
| }, | ||
| "master": { | ||
| "per_hv": 3, | ||
| "cpus": 16, | ||
| "memory": 32, | ||
| "disk_size": 120, | ||
| "bw_avg": 25000, | ||
| "bw_peak": 30000, | ||
| "bw_burst": 28000, | ||
| "disk_location": "/var/lib/libvirt/images" | ||
| }, | ||
| "sno": { | ||
| "cpus": 32, | ||
| "memory": 64, | ||
| "disk_size": 200, | ||
| "bw_avg": 25000, | ||
| "bw_peak": 30000, | ||
| "bw_burst": 28000, | ||
| "disk_location": "/var/lib/libvirt/images" | ||
| }, | ||
| "alex": { | ||
| "per_hv": 1, | ||
| "cpus": 11, | ||
| "memory": 111, | ||
| "disk_size": 1111, | ||
| "bw_avg": 25000, | ||
| "bw_peak": 30000, | ||
| "bw_burst": 28000, | ||
| "disk_location": "/var/lib/libvirt/images" | ||
| } | ||
| }, | ||
| "cluster_types": { | ||
| "vmno": { | ||
| "count": 1, | ||
| "vms": { | ||
| "master": 3, | ||
| "worker": 5 | ||
| } | ||
| }, | ||
| "compact": { | ||
| "count": 1, | ||
| "vms": { | ||
| "master": 3 | ||
| } | ||
| }, | ||
| "standard": { | ||
| "count": 12, | ||
| "vms": { | ||
| "master": 3, | ||
| "worker": 3 | ||
| } | ||
| }, | ||
| "sno": { | ||
| "count": 109, | ||
| "vms": { | ||
| "sno": 1 | ||
| } | ||
| }, | ||
| "crazy": { | ||
| "count": 12, | ||
| "vms": { | ||
| "master": 3, | ||
| "worker": 2, | ||
| "alex": 2 | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix the
loopsequence indentation before merging.The lint check reports incorrect indentation on Line 23. Align each sequence marker with
loop:.Proposed fix
As per path instructions, this Ansible role requires proper YAML syntax and consistent indentation.
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: lint
[failure] 23-23:
23:5 [indentation] wrong indentation: expected 2 but found 4
🤖 Prompt for AI Agents
Sources: Path instructions, Linters/SAST tools