---
- name: setup
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: absent
  register: netoffer
- name: verify setup
  assert:
    that:
    - netoffer is successful

- name: test fail if missing name
  action: cs_network_offering
  register: netoffer
  ignore_errors: true
- name: verify results of fail if missing name
  assert:
    that:
    - netoffer is failed
    - 'netoffer.msg == "missing required arguments: name"'

- name: test fail if missing params
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
  register: netoffer
  ignore_errors: true
- name: verify results of fail if missing params
  assert:
    that:
    - netoffer is failed
    - 'netoffer.msg == "missing required arguments: display_text, guest_ip_type, supported_services, service_providers"'

- name: test create network offer in check mode
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    max_connections: 300
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
  register: netoffer
  check_mode: yes
- name: verify results of network offer in check mode
  assert:
    that:
    - netoffer is successful
    - netoffer is changed

- name: test create network offer
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    max_connections: 300
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
  register: netoffer
- name: verify results of network offer
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description"

- name: test create network offer idempotence
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    max_connections: 300
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
  register: netoffer
- name: verify results of create network offer idempotence
  assert:
    that:
    - netoffer is successful
    - netoffer is not changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description"

- name: test enabling existing network offer in check_mode
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: enabled
  register: netoffer
  check_mode: yes
- name: verify results of enabling existing network offer in check_mode
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description"

- name: test enabling existing network offer
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: enabled
  register: netoffer
- name: verify results of enabling existing network offer
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Enabled"
    - netoffer.display_text == "network offering description"

- name: test enabling existing network offer idempotence
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: enabled
  register: netoffer
- name: verify results of enabling existing network idempotence
  assert:
    that:
    - netoffer is successful
    - netoffer is not changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Enabled"
    - netoffer.display_text == "network offering description"

- name: test disabling network offer in check_mode
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: netoffer
  check_mode: yes
- name: verify results of disabling network offer in check_mode
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Enabled"
    - netoffer.display_text == "network offering description"

- name: test disabling network offer
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: netoffer
- name: verify results of disabling network offer
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description"

- name: test disabling network offer idempotence
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: netoffer
- name: verify results of disabling network idempotence
  assert:
    that:
    - netoffer is successful
    - netoffer is not changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description"

- name: test rename network offer in check_mode
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description renamed"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: netoffer
  check_mode: yes
- name: verify results of rename network offer in check_mode
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description"

- name: test rename network offer
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description renamed"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: netoffer
- name: verify results of rename network offer
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description renamed"

- name: test rename network offer idempotence
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description renamed"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: netoffer
- name: verify results of rename network offer idempotence
  assert:
    that:
    - netoffer is successful
    - netoffer is not changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description renamed"

- name: test update offer with minimal params in check_mode
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description update"
    max_connections: 400
  register: netoffer
  check_mode: yes
- name: verify results of update offer with minimal params in check_mode
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description renamed"
    - netoffer.max_connections == 300

- name: test update offer with minimal params
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description update"
    max_connections: 400
  register: netoffer
- name: verify results of update offer with minimal params
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description update"
    - netoffer.max_connections == 400

- name: test update offer with minimal params idempotency
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description update"
    max_connections: 400
  register: netoffer
- name: verify results of update offer with minimal params idempotency
  assert:
    that:
    - netoffer is successful
    - netoffer is not changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description update"
    - netoffer.max_connections == 400

- name: test remove network offer in check_mode
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: absent
  register: netoffer
  check_mode: yes
- name: verify results of rename network offer in check_mode
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description update"

- name: test remove network offer
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: absent
  register: netoffer
- name: verify results of rename network offer
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Disabled"
    - netoffer.display_text == "network offering description update"

- name: test remove network offer idempotence
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: absent
  register: netoffer
- name: verify results of rename network offer idempotence
  assert:
    that:
    - netoffer is successful
    - netoffer is not changed

- name: test create enabled network offer in check mode
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: enabled
  register: netoffer
  check_mode: yes
- name: verify results of create enabled network offer in check mode
  assert:
    that:
    - netoffer is successful
    - netoffer is changed

- name: test create enabled network offer
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: enabled
  register: netoffer
- name: verify results of create enabled network offer
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Enabled"
    - netoffer.display_text == "network offering description"

- name: test create enabled network offer idempotence
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    display_text: "network offering description"
    guest_ip_type: Isolated
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, Firewall, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: enabled
  register: netoffer
- name: verify results of create enabled network offer idempotence
  assert:
    that:
    - netoffer is successful
    - netoffer is not changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Enabled"
    - netoffer.display_text == "network offering description"

- name: remove network offer
  cs_network_offering:
    name: "{{ cs_resource_prefix }}_name"
    state: absent
  register: netoffer
- name: verify results of remove network offer
  assert:
    that:
    - netoffer is successful
    - netoffer is changed
    - netoffer.name == "{{ cs_resource_prefix }}_name"
    - netoffer.guest_ip_type == "Isolated"
    - netoffer.state == "Enabled"
    - netoffer.display_text == "network offering description"