Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion ansible/roles/vm_set/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
set_fact: current_server={{ group_names | extract_by_prefix('server_') }}

- name: Extract VM names from the inventory
set_fact: VM_hosts={{ groups[current_server] | filter_by_prefix('VM') }}
set_fact: VM_hosts={{ groups[current_server] | filter_by_prefix('VM') | sort}}

- name: Limit VM
set_fact: VM_hosts="{{ VM_hosts | first_n_elements(VM_num) }}"
Expand Down
8 changes: 8 additions & 0 deletions ansible/roles/vm_set/tasks/start.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"
when: topo is defined

- name: Filter VMs for specified topology
set_fact: VM_hosts={{ VM_hosts | filter_vm_targets(topology['VMs'], VM_base) | sort }}
when: topology['VMs'] is defined and VM_base is defined

- name: Create directory for vm images and vm disks
file: path={{ item }} state=directory mode=0755
with_items:
Expand Down
8 changes: 8 additions & 0 deletions ansible/roles/vm_set/tasks/stop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"
when: topo is defined

- name: Filter VMs for specified topology
set_fact: VM_hosts={{ VM_hosts | filter_vm_targets(topology['VMs'], VM_base) | sort }}
when: topology['VMs'] is defined and VM_base is defined

- name: Remove VMs.
include_tasks: stop_vm.yml
vars:
Expand Down
39 changes: 36 additions & 3 deletions ansible/testbed-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function usage
echo "testbed-cli. Interface to testbeds"
echo "Usage:"
echo " $0 [options] (start-vms | stop-vms) <server-name> <vault-password-file>"
echo " $0 [options] (start-topo-vms | stop-topo-vms) <topo-name> <vault-password-file>"
echo " $0 [options] (add-topo | remove-topo | renumber-topo | connect-topo) <topo-name> <vault-password-file>"
echo " $0 [options] refresh-dut <topo-name> <vault-password-file>"
echo " $0 [options] (connect-vms | disconnect-vms) <topo-name> <vault-password-file>"
Expand All @@ -25,7 +26,7 @@ function usage
echo " <topo-name> : Name of the target topology"
echo " <inventory> : Name of the Ansible inventory containing the DUT"
echo
echo "To start VMs on a server: $0 start-vms 'server-name' ~/.password"
echo "To start all VMs on a server: $0 start-vms 'server-name' ~/.password"
echo "To restart a subset of VMs:"
echo " $0 start-vms server-name vault-password-file -e respin_vms=[vm_list]"
echo " vm_list is separated by comma and shouldn't have space in the list."
Expand All @@ -34,7 +35,9 @@ function usage
echo " $0 start-vms server-name vault-password-file -e batch_size=2 -e interval=60"
echo "To enable autostart of VMs:"
echo " $0 start-vms server-name vault-password-file -e autostart=yes"
echo "To stop VMs on a server: $0 stop-vms 'server-name' ~/.password"
echo "To start VMs for specified topology on server: $0 start-topo-vms 'topo-name' ~/.password"
echo "To stop all VMs on a server: $0 stop-vms 'server-name' ~/.password"
echo "To stop VMs for specified topology on server: $0 stop-topo-vms 'topo-name' ~/.password"
echo "To deploy a topology on a server: $0 add-topo 'topo-name' ~/.password"
echo " Optional argument for add-topo:"
echo " -e ptf_imagetag=<tag> # Use PTF image with specified tag for creating PTF container"
Expand Down Expand Up @@ -114,6 +117,32 @@ function stop_vms
ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_stop_VMs.yml --vault-password-file="${passwd}" -l "${server}" $@
}

function start_topo_vms
{
topology=$1
passwd=$2
shift
shift
read_file ${topology}

echo "Starting VMs for topology '${topology}' on server '${server}'"

ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_start_VMs.yml --vault-password-file="${passwd}" -l "${server}" -e VM_base="$vm_base" -e topo="$topo" $@
}

function stop_topo_vms
{
topology=$1
passwd=$2
shift
shift
read_file ${topology}

echo "Stopping VMs for topology '${topology}' on server '${server}'"

ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_stop_VMs.yml --vault-password-file="${passwd}" -l "${server}" -e VM_base="$vm_base" -e topo="$topo" $@
}

function add_topo
{
topology=$1
Expand All @@ -124,7 +153,7 @@ function add_topo

read_file ${topology}

ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_add_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e vm_type="$vm_type" $@
ANSIBLE_SCP_IF_SSH=y ansible-playbook -i $vmfile testbed_add_vm_topology.yml --vault-password-file="${passwd}" -l "$server" -e topo_name="$topo_name" -e dut_name="$duts" -e VM_base="$vm_base" -e ptf_ip="$ptf_ip" -e topo="$topo" -e vm_set_name="$testbed_name" -e ptf_imagename="$ptf_imagename" -e vm_type="$vm_type" $@

ansible-playbook fanout_connect.yml -i $vmfile --limit "$server" --vault-password-file="${passwd}" -e "dut=$duts" $@

Expand Down Expand Up @@ -316,6 +345,10 @@ case "${subcmd}" in
;;
stop-vms) stop_vms $@
;;
start-topo-vms) start_topo_vms $@
;;
stop-topo-vms) stop_topo_vms $@
;;
add-topo) add_topo $@
;;
remove-topo) remove_topo $@
Expand Down