-
Notifications
You must be signed in to change notification settings - Fork 1k
[testbed-cli] Code change on add-topo and deploy-minigraph for deploying testbed with peers on multiple servers #15643
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
Merged
wangxin
merged 10 commits into
sonic-net:master
from
w1nda:deploy-testbed-multi-servesr-pub
Jan 20, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
61baf4a
init
w1nda c4c798e
rm TODO
w1nda 3ece786
add default value
w1nda 2929848
Merge branch 'master' into deploy-testbed-multi-servesr-pub
w1nda 774551f
support remove-topo and redeploy-topo
w1nda 34694aa
support vlan id range set on fanout for add-topo
w1nda 3d76644
rename functions
w1nda a2b4a46
add multi-servers testbed demo in testbed.yaml
w1nda fc43fd3
Merge branch 'master' into deploy-testbed-multi-servesr-pub
w1nda 0713557
Merge branch 'master' into deploy-testbed-multi-servesr-pub
w1nda 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
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
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
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,66 @@ | ||
| class MultiServersUtils: | ||
w1nda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @staticmethod | ||
| def filter_by_dut_interfaces(values, dut_interfaces): | ||
| if not dut_interfaces: | ||
| return values | ||
|
|
||
| if isinstance(dut_interfaces, str) or isinstance(dut_interfaces, unicode): # noqa F821 | ||
| dut_interfaces = MultiServersUtils.parse_multi_servers_interface(dut_interfaces) | ||
|
|
||
| if isinstance(values, dict): | ||
| return {k: v for k, v in values.items() if int(k) in dut_interfaces} | ||
| elif isinstance(values, list): | ||
| return [v for v in values if int(v) in dut_interfaces] | ||
| else: | ||
| raise ValueError('Unsupported type "{}"'.format(type(values))) | ||
|
|
||
| @staticmethod | ||
| def parse_multi_servers_interface(intf_pattern): | ||
| intf_pattern = str(intf_pattern) | ||
| intfs = [] | ||
| for intf in iter(map(str.strip, intf_pattern.split(','))): | ||
| if intf.isdigit(): | ||
| intfs.append(int(intf)) | ||
| elif '-' in intf: | ||
| intf_range = list(map(int, map(str.strip, intf.split('-')))) | ||
| assert len(intf_range) == 2, 'Invalid interface range "{}"'.format(intf) | ||
| intfs.extend(list(range(intf_range[0], intf_range[1]+1))) | ||
| else: | ||
| raise ValueError('Unsupported format "{}"'.format(intf_pattern)) | ||
| if len(intfs) != len(set(intfs)): | ||
| raise ValueError('There are interface duplication/overlap in "{}"'.format(intf_pattern)) | ||
| return intfs | ||
|
|
||
| @staticmethod | ||
| def get_vms_by_dut_interfaces(VMs, dut_interfaces): | ||
| if not dut_interfaces: | ||
| return VMs | ||
|
|
||
| if isinstance(dut_interfaces, str) or isinstance(dut_interfaces, unicode): # noqa F821 | ||
| dut_interfaces = MultiServersUtils.parse_multi_servers_interface(dut_interfaces) | ||
|
|
||
| result = {} | ||
| offset = 0 | ||
| for hostname, attr in VMs.items(): | ||
| if dut_interfaces and attr['vlans'][0] not in dut_interfaces: | ||
| continue | ||
| result[hostname] = attr | ||
| result[hostname]['vm_offset'] = offset | ||
| offset += 1 | ||
| return result | ||
|
|
||
| @staticmethod | ||
| def generate_vm_name_mapping(servers_info, topo_vms): | ||
| _m = {} | ||
|
|
||
| for server_attr in servers_info.values(): | ||
| if 'dut_interfaces' in server_attr: | ||
| filtered_vms = MultiServersUtils.get_vms_by_dut_interfaces(topo_vms, server_attr['dut_interfaces']) | ||
| vm_base = server_attr['vm_base'] | ||
| vm_start_index = int(vm_base[2:]) | ||
| vm_name_fmt = 'VM%0{}d'.format(len(vm_base) - 2) | ||
|
|
||
| for hostname, host_attr in filtered_vms.items(): | ||
| vm_name = vm_name_fmt % (vm_start_index + host_attr['vm_offset']) | ||
| _m[hostname] = vm_name | ||
| return _m | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.