---
# Regular user operation
- name: Create internal network
  os_network:
     cloud: "{{ cloud }}"
     state: present
     name: "{{ network_name }}"
     external: false

- name: Create subnet1
  os_subnet:
     cloud: "{{ cloud }}"
     state: present
     network_name: "{{ network_name }}"
     name: shade_subnet1
     cidr: 10.7.7.0/24

- name: Create router
  os_router:
     cloud: "{{ cloud }}"
     state: present
     name: "{{ router_name }}"

- name: Update router (add interface)
  os_router:
     cloud: "{{ cloud }}"
     state: present
     name: "{{ router_name }}"
     interfaces:
         - shade_subnet1

# Admin operation
- name: Create external network
  os_network:
     cloud: "{{ cloud }}"
     state: present
     name: "{{ external_network_name }}"
     external: "{{ network_external }}"
  when:
    - network_external

- name: Create subnet2
  os_subnet:
     cloud: "{{ cloud }}"
     state: present
     network_name: "{{ external_network_name }}"
     name: shade_subnet2
     cidr: 10.6.6.0/24
  when:
    - network_external

- name: Update router (add external gateway)
  os_router:
     cloud: "{{ cloud }}"
     state: present
     name: "{{ router_name }}"
     network: "{{ external_network_name }}"
     interfaces:
         - shade_subnet1
  when:
    - network_external

- name: Delete router
  os_router:
     cloud: "{{ cloud }}"
     state: absent
     name: "{{ router_name }}"

- name: Delete subnet1
  os_subnet:
     cloud: "{{ cloud }}"
     state: absent
     name: shade_subnet1

- name: Delete subnet2
  os_subnet:
     cloud: "{{ cloud }}"
     state: absent
     name: shade_subnet2
  when:
    - network_external

- name: Delete internal network
  os_network:
     cloud: "{{ cloud }}"
     state: absent
     name: "{{ network_name }}"

- name: Delete external network
  os_network:
     cloud: "{{ cloud }}"
     state: absent
     name: "{{ external_network_name }}"
  when:
    - network_external
