Skip to content
Draft
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
2 changes: 2 additions & 0 deletions ansible/group_vars/all/creds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ sonic_password: "password"

ceos_image_orig: ceosimage:4.23.2F
ceos_image: ceosimage:4.23.2F-1

csonic_image: docker-sonic-vs
6 changes: 6 additions & 0 deletions ansible/group_vars/sonic/sonic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# snmp variables
snmp_rocommunity: strcommunity
snmp_location: str
bgp_gr_timer: 700

csonic_image_mount_dir: /data/csonic
1 change: 1 addition & 0 deletions ansible/lab
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ iface_speed='40000'
lab-s6000-01 ansible_host=10.251.0.189
vlab-01 ansible_host=10.250.0.101
vlab-03 ansible_host=10.250.0.105
vlab-04 ansible_host=10.250.0.107

[sonic_s6000:vars]
hwsku="Force10-S6000"
Expand Down
20 changes: 20 additions & 0 deletions ansible/roles/sonic/tasks/csonic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- include_tasks: csonic_config.yml

- name: Create cSONiC container csonic_{{ vm_set_name }}_{{ inventory_hostname }}
become: yes
docker_container:
name: csonic_{{ vm_set_name }}_{{ inventory_hostname }}
image: "{{ csonic_image }}"
pull: no
state: started
restart: yes
tty: yes
network_mode: container:net_{{ vm_set_name }}_{{ inventory_hostname }}
detach: True
capabilities:
- net_admin
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to support ipv6

privileged: yes
volumes:
- /{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/sonic:/var/sonic
- /{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr:/etc/frr
delegate_to: "{{ VM_host[0] }}"
51 changes: 51 additions & 0 deletions ansible/roles/sonic/tasks/csonic_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
- name: Get netbase container info
docker_container_info:
name: net_{{ vm_set_name }}_{{ inventory_hostname }}
register: ctninfo
delegate_to: "{{ VM_host[0] }}"
become: yes

- debug: msg="{{ ctninfo.container.State.Pid }}"

- name: Get front panel port in netbase container
shell: nsenter -t {{ ctninfo.container.State.Pid }} -n ip link show | grep -E eth[0-9]+ | wc -l
register: fp_num
delegate_to: "{{ VM_host[0] }}"
become: yes

- debug: msg="{{ fp_num }}"

- name: Set EOS backplane port name
set_fact: bp_ifname="Ethernet{{ fp_num.stdout|int - 1}}"

- name: create directory for sonic config
become: yes
file:
path: "/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/sonic"
state: directory
delegate_to: "{{ VM_host[0] }}"

- name: create config db
become: yes
template: src="configdb-{{ topo }}-{{ props.swrole }}.j2"
dest="/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/sonic/config_db.json"
delegate_to: "{{ VM_host[0] }}"

- name: create directory for frr config
become: yes
file:
path: "/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr"
state: directory
delegate_to: "{{ VM_host[0] }}"

- name: create frr bgpd config
become: yes
template: src="frr-{{ topo }}-{{ props.swrole }}.j2"
dest="/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr/bgpd.conf"
delegate_to: "{{ VM_host[0] }}"

- name: create zebra config
become: yes
template: src="zebra-{{ topo }}-{{ props.swrole }}.j2"
dest="/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr/zebra.conf"
delegate_to: "{{ VM_host[0] }}"
41 changes: 41 additions & 0 deletions ansible/roles/sonic/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
- debug: msg="{{ vm_type }}"
- debug: msg="{{ vm_set_name }}"

- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"

- name: Include server vars
include_vars: "{{ host_var_file }}"

- name: Find current server group
set_fact: current_server={{ group_names | extract_by_prefix('server_') }}

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

- name: Get VM host name
set_fact: VM_host={{ groups[current_server] | difference(VM_list) }}

- name: Generate hostname for target VM
set_fact: hostname={{ VM_list | extract_hostname(topology['VMs'], VM_base, inventory_hostname) }}
when: topology['VMs'] is defined

- fail:
msg: "cannot find {{ inventory_hostname }} in the topology"
when: hostname == "hostname not found"

- name: Set properties list to default value, when properties are not defined
set_fact: properties_list=[]
when: configuration is not defined or configuration[hostname] is not defined or configuration[hostname]['properties'] is not defined

- name: Set properties list to values, when they're defined
set_fact: properties_list="{{ configuration[hostname]['properties'] }}"
when: configuration and configuration[hostname] and configuration[hostname]['properties'] is defined

- name: Expand {{ hostname }} properties into props
set_fact: props="{{ configuration_properties[item] | combine(props | default({})) }}"
with_items: "{{ properties_list }}"
when: hostname in configuration and configuration_properties[item] is defined

- include_tasks: csonic.yml
when: vm_type == "csonic"
41 changes: 41 additions & 0 deletions ansible/roles/sonic/templates/configdb-t0-leaf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% set host = configuration[hostname] %}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to support backplane interface

{
{% for name, iface in host['interfaces'].items() %}
{% if name.startswith('Port-Channel') %}
"PORTCHANNEL": {
"{{ name | replace("-", "") }}": {
"admin_status": "up",
"mtu": "9100"
}
},
"PORTCHANNEL_INTERFACE": {
"{{ name | replace("-", "") }}": {},
{% if iface['ipv4'] is defined %}
"{{ name | replace("-", "") }}|{{ iface['ipv4'] }}": {},
{% endif %}
{% if iface['ipv6'] is defined %}
"{{ name | replace("-", "") }}|{{ iface['ipv6'] }}": {}
{% endif %}
},
{% endif %}
{% if iface['lacp'] is defined %}
"PORTCHANNEL_MEMBER": {
{% set index = name | replace("Ethernet", "") | int - 1 %}
"PortChannel{{ iface['lacp'] }}|Ethernet{{ index * 4}}": {}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to bring up the Ethernet interface

},
{% endif %}
{% endfor %}
{% for name, iface in host['interfaces'].items() %}
{% if name.startswith('Loopback') %}
"LOOPBACK_INTERFACE": {
"{{ name }}": {},
{% if iface['ipv4'] is defined %}
"{{ name }}|{{ iface['ipv4'] }}": {},
{% endif %}
{% if iface['ipv6'] is defined %}
"{{ name }}|{{ iface['ipv6'] }}": {}
{% endif %}
}
{% endif %}
{% endfor %}
}
42 changes: 42 additions & 0 deletions ansible/roles/sonic/templates/frr-t0-leaf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% set host = configuration[hostname] %}
!
hostname {{ hostname }}
password zebra
enable password zebra
!
log syslog informational
log facility local4
!
router bgp {{ host['bgp']['asn'] }}
bgp router-id {{ host['interfaces']['Loopback0']['ipv4'] | ipaddr('address') }}
!
{% for asn, remote_ips in host['bgp']['peers'].items() %}
{% for remote_ip in remote_ips %}
neighbor {{ remote_ip }} remote-as {{ asn }}
neighbor {{ remote_ip }} description {{ asn }}
{% if remote_ip | ipv6 %}
address-family ipv6 unicast
neighbor {{ remote_ip }} activate
exit
{% endif %}
{% endfor %}
{% endfor %}
neighbor {{ props.nhipv4 }} remote-as {{ host['bgp']['asn'] }}
neighbor {{ props.nhipv4 }} description exabgp_v4
neighbor {{ props.nhipv6 }} remote-as {{ host['bgp']['asn'] }}
neighbor {{ props.nhipv6 }} description exabgp_v6
address-family ipv6
neighbor {{ props.nhipv6 }} activate
exit
!
{% for name, iface in host['interfaces'].items() if name.startswith('Loopback') %}
{% if iface['ipv4'] is defined %}
address-family ipv4 unicast
network {{ iface['ipv4'] }}
{% endif %}
{% if iface['ipv6'] is defined %}
address-family ipv6 unicast
network {{ iface['ipv6'] }}
{% endif %}
{% endfor %}
!
17 changes: 17 additions & 0 deletions ansible/roles/sonic/templates/zebra-t0-leaf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% set host = configuration[hostname] %}
hostname {{ hostname }}
password zebra
enable password zebra
!
log syslog informational
log facility local4
!
! end of template: common/daemons.common.conf.j2!
!
!
! Enable link-detect (default disabled)
{% for name, iface in host['interfaces'].items() %}
interface {{ name }}
link detect
!
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

DOCUMENTATION = '''
---
module: ceos_network
module: cnet_network
version_added: "0.1"
author: Guohan Lu ([email protected])
short_description: Create network for ceos container
short_description: Create network for container
description:
the module creates follow network interfaces
- 1 management interface which is added to management bridge
Expand All @@ -30,7 +30,7 @@

EXAMPLES = '''
- name: Create VMs network
ceos_network:
cnet_network:
name: net_{{ vm_set_name }}_{{ vm_name }}
vm_name: "{{ vm_name }}"
fp_mtu: "{{ fp_mtu_size }}"
Expand All @@ -42,8 +42,8 @@
DEFAULT_MTU = 0
NUM_FP_VLANS_PER_FP = 4
VM_SET_NAME_MAX_LEN = 8 # used in interface names. So restricted
CMD_DEBUG_FNAME = "/tmp/ceos_network.cmds.%s.txt"
EXCEPTION_DEBUG_FNAME = "/tmp/ceos_network.exception.%s.txt"
CMD_DEBUG_FNAME = "/tmp/cnet_network.cmds.%s.txt"
EXCEPTION_DEBUG_FNAME = "/tmp/cnet_network.exception.%s.txt"

OVS_FP_BRIDGE_REGEX = 'br-%s-\d+'
OVS_FP_BRIDGE_TEMPLATE = 'br-%s-%d'
Expand Down Expand Up @@ -316,4 +316,3 @@ def main():

if __name__ == "__main__":
main()

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
- net_admin
privileged: yes

- name: Create network for ceos container net_{{ vm_set_name }}_{{ item }}
- name: Create network for csonic/ceos container csonic|ceos_{{ vm_set_name }}_{{ item }}
become: yes
ceos_network:
cnet_network:
name: net_{{ vm_set_name }}_{{ item }}
vm_name: "{{ item }}"
fp_mtu: "{{ fp_mtu_size }}"
Expand Down
10 changes: 10 additions & 0 deletions ansible/roles/vm_set/tasks/add_cnet_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: Create VMs network
become: yes
vm_topology:
cmd: 'create'
vm_names: "{{ VM_hosts }}"
fp_mtu: "{{ fp_mtu_size }}"
max_fp_num: "{{ max_fp_num }}"

- include_tasks: add_cnet.yml
with_items: "{{ VM_targets }}"
5 changes: 4 additions & 1 deletion ansible/roles/vm_set/tasks/add_topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
become: yes
when: external_port is defined

- include_tasks: add_ceos_list.yml
- include_tasks: create_ceos_image.yml
when: vm_type is defined and vm_type == "ceos"

- include_tasks: add_cnet_list.yml
when: vm_type is defined and (vm_type == "ceos" or vm_type == "csonic")

- name: Bind topology {{ topo }} to VMs. base vm = {{ VM_base }}
vm_topology:
cmd: "bind"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
- name: Create VMs network
become: yes
vm_topology:
cmd: 'create'
vm_names: "{{ VM_hosts }}"
fp_mtu: "{{ fp_mtu_size }}"
max_fp_num: "{{ max_fp_num }}"

- name: create directory for build ceos image
become: yes
file:
Expand All @@ -24,6 +16,3 @@
path: "/tmp/ceosimage"
pull: no
source: build

- include_tasks: add_ceos.yml
with_items: "{{ VM_targets }}"
11 changes: 11 additions & 0 deletions ansible/roles/vm_set/tasks/remove_csonic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: Remove cSONiC container csonic_{{ vm_set_name }}_{{ item }}
become: yes
docker_container:
name: csonic_{{ vm_set_name }}_{{ item }}
state: absent

- name: Remove net base container net_{{ vm_set_name }}_{{ item }}
become: yes
docker_container:
name: net_{{ vm_set_name }}_{{ item }}
state: absent
2 changes: 2 additions & 0 deletions ansible/roles/vm_set/tasks/remove_csonic_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- include_tasks: remove_csonic.yml
with_items: "{{ VM_targets }}"
3 changes: 3 additions & 0 deletions ansible/roles/vm_set/tasks/remove_topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
- include_tasks: remove_ceos_list.yml
when: vm_type is defined and vm_type == "ceos"

- include_tasks: remove_csonic_list.yml
when: vm_type is defined and vm_type == "csonic"

- name: Remove vlan port for vlan tunnel
vlan_port:
external_port: "{{ external_port }}"
Expand Down
Loading