#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2020 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

#############################################
#                WARNING                    #
#############################################
#
# This file is auto generated by the resource
#   module builder playbook.
#
# Do not edit this file manually.
#
# Changes to this file will be over written
#   by the resource module builder.
#
# Changes should be made in the model used to
#   generate this file or in the resource module
#   builder template.
#
#############################################

"""
The module file for nxos_ospfv3
"""

from __future__ import absolute_import, division, print_function


__metaclass__ = type

DOCUMENTATION = """
module: nxos_ospfv3
short_description: OSPFv3 resource module
description:
- This module manages OSPFv3 configuration on devices running Cisco NX-OS.
version_added: 1.2.0
notes:
- Tested against NX-OS 7.0(3)I5(1).
- Unsupported for Cisco MDS
- This module works with connection C(network_cli) and C(httpapi).
author: Nilashish Chakraborty (@NilashishC)
options:
  running_config:
    description:
    - This option is used only with state I(parsed).
    - The value of this option should be the output received from the NX-OS device
      by executing the command B(show running-config | section "^router ospfv3").
    - The state I(parsed) reads the configuration from C(running_config) option and
      transforms it into Ansible structured data as per the resource module's argspec
      and the value is then returned in the I(parsed) key within the result.
    type: str
  config:
    description: A list of OSPFv3 process configuration.
    type: dict
    suboptions:
      processes:
        description:
        - A list of OSPFv3 instances' configurations.
        type: list
        elements: dict
        suboptions:
          address_family:
            description:
            - IPv6 unicast address-family OSPFv3 settings.
            type: dict
            suboptions:
              afi:
                description:
                - Configure OSPFv3 settings under IPv6 address-family.
                type: str
                choices: ['ipv6']
              safi:
                description:
                - Configure OSPFv3 settings under IPv6 unicast address-family.
                type: str
                choices: ['unicast']
              areas:
                description:
                - Configure properties of OSPF Areas under address-family.
                type: list
                elements: dict
                suboptions:
                  area_id:
                    description:
                    - The Area ID in IP Address format.
                    type: str
                    required: true
                  default_cost:
                    description:
                    - Specify the default cost.
                    type: int
                  filter_list:
                    description:
                    - Filter prefixes between OSPF areas.
                    type: list
                    elements: dict
                    suboptions:
                      route_map:
                        description:
                        - The Route-map name.
                        type: str
                        required: true
                      direction:
                        description:
                        - The direction to apply the route map.
                        type: str
                        choices: [in, out]
                        required: true
                  ranges:
                    description:
                    - Configure an address range for the area.
                    type: list
                    elements: dict
                    suboptions:
                      prefix:
                        description:
                        - IP in Prefix format (x.x.x.x/len)
                        type: str
                        required: true
                      cost:
                        description:
                        - Cost to use for the range.
                        type: int
                      not_advertise:
                        description:
                        - Suppress advertising the specified range.
                        type: bool
              default_information:
                description:
                - Control distribution of default routes.
                type: dict
                suboptions:
                  originate:
                    description:
                    - Distribute a default route.
                    type: dict
                    suboptions:
                      set:
                        description:
                        - Enable distribution of default route.
                        type: bool
                      always:
                        description:
                        - Always advertise a default route.
                        type: bool
                      route_map:
                        description:
                        - Policy to control distribution of default routes
                        type: str
              distance:
                description:
                - Configure the OSPF administrative distance.
                type: int
              maximum_paths:
                description:
                - Maximum paths per destination.
                type: int
              redistribute:
                description:
                - Redistribute information from another routing protocol.
                type: list
                elements: dict
                suboptions:
                  protocol:
                    description:
                    - The name of the protocol.
                    type: str
                    choices: [bgp, direct, eigrp, isis, lisp, ospfv3, rip, static]
                    required: true
                  id:
                    description:
                    - The identifier for the protocol specified.
                    type: str
                  route_map:
                    description:
                    - The route map policy to constrain redistribution.
                    type: str
                    required: true
              summary_address:
                description:
                - Configure route summarization for redistribution.
                type: list
                elements: dict
                suboptions:
                  prefix:
                    description:
                    - IPv6 prefix format 'xxxx:xxxx/ml', 'xxxx:xxxx::/ml' or 'xxxx::xx/128'
                    type: str
                    required: true
                  not_advertise:
                    description:
                    - Suppress advertising the specified summary.
                    type: bool
                  tag:
                    description:
                    - A 32-bit tag value.
                    type: int
              table_map:
                description:
                - Policy for filtering/modifying OSPF routes before sending them to
                  RIB.
                type: dict
                suboptions:
                  name:
                    description:
                    - The Route Map name.
                    type: str
                    required: true
                  filter:
                    description:
                    - Block the OSPF routes from being sent to RIB.
                    type: bool
              timers:
                description:
                - Configure timer related constants.
                type: dict
                suboptions:
                  throttle:
                    description:
                    - Configure throttle related constants.
                    type: dict
                    suboptions:
                      spf:
                        description:
                        - Set OSPF SPF timers.
                        type: dict
                        suboptions:
                          initial_spf_delay:
                            description:
                            - Initial SPF schedule delay in milliseconds.
                            type: int
                          min_hold_time:
                            description:
                            - Minimum hold time between SPF calculations.
                            type: int
                          max_wait_time:
                            description:
                            - Maximum wait time between SPF calculations.
                            type: int
          areas:
            description:
            - Configure properties of OSPF Areas.
            type: list
            elements: dict
            suboptions:
              area_id:
                description:
                - The Area ID in IP Address format.
                type: str
                required: true
              nssa:
                description:
                - NSSA settings for the area.
                type: dict
                suboptions:
                  set:
                    description:
                    - Configure area as NSSA.
                    type: bool
                  default_information_originate:
                    description:
                    - Originate Type-7 default LSA into NSSA area.
                    type: bool
                  no_redistribution:
                    description:
                    - Do not send redistributed LSAs into NSSA area.
                    type: bool
                  no_summary:
                    description:
                    - Do not send summary LSAs into NSSA area.
                    type: bool
                  route_map:
                    description:
                    - Policy to control distribution of default route.
                    type: str
                  translate:
                    description:
                    - Translate LSA.
                    type: dict
                    suboptions:
                      type7:
                        description:
                        - Translate from Type 7 to Type 5.
                        type: dict
                        suboptions:
                          always:
                            description:
                            - Always translate LSAs
                            type: bool
                          never:
                            description:
                            - Never translate LSAs
                            type: bool
                          supress_fa:
                            description:
                            - Suppress forwarding address in translated LSAs.
                            type: bool
              stub:
                description:
                - Settings for configuring the area as a stub.
                type: dict
                suboptions:
                  set:
                    description:
                    - Configure the area as a stub.
                    type: bool
                  no_summary:
                    description:
                    - Prevent ABR from sending summary LSAs into stub area.
                    type: bool
          auto_cost:
            description:
            - Calculate OSPF cost according to bandwidth.
            type: dict
            suboptions:
              reference_bandwidth:
                description:
                - Reference bandwidth used to assign OSPF cost.
                type: int
                required: true
              unit:
                description:
                - Specify in which unit the reference bandwidth is specified.
                type: str
                required: true
                choices: [Gbps, Mbps]
          flush_routes:
            description:
            - Flush routes on a non-graceful controlled restart.
            type: bool
          graceful_restart:
            description:
            - Configure graceful restart.
            type: dict
            suboptions:
              set:
                description:
                - Enable graceful-restart.
                type: bool
              grace_period:
                description:
                - Configure maximum interval to restart gracefully.
                type: int
              helper_disable:
                description:
                - Enable/Disable helper mode.
                type: bool
              planned_only:
                description:
                - Enable graceful restart only for a planned restart
                type: bool
          isolate:
            description:
            - Isolate this router from OSPF perspective.
            type: bool
          log_adjacency_changes:
            description:
            - Log changes in adjacency state.
            type: dict
            suboptions:
              log:
                description:
                - Enable/disable logging changes in adjacency state.
                type: bool
              detail:
                description:
                - Notify all state changes.
                type: bool
          max_lsa:
            description:
            - Feature to limit the number of non-self-originated LSAs.
            type: dict
            suboptions:
              max_non_self_generated_lsa:
                description:
                - Set the maximum number of non self-generated LSAs.
                type: int
                required: true
              threshold:
                description:
                - Threshold value (%) at which to generate a warning message.
                type: int
              ignore_count:
                description:
                - Set count on how many times adjacencies can be suppressed.
                type: int
              ignore_time:
                description:
                - Set time during which all adjacencies are suppressed.
                type: int
              reset_time:
                description:
                - Set number of minutes after which ignore-count is reset to zero.
                type: int
              warning_only:
                description:
                - Log a warning message when limit is exceeded.
                type: bool
          max_metric:
            description:
            - Maximize the cost metric.
            type: dict
            suboptions:
              router_lsa:
                description:
                - Router LSA configuration.
                type: dict
                suboptions:
                  set:
                    description:
                    - Set router-lsa attribute.
                    type: bool
                  external_lsa:
                    description:
                    - External LSA configuration.
                    type: dict
                    suboptions:
                      set:
                        description:
                        - Set external-lsa attribute.
                        type: bool
                      max_metric_value:
                        description:
                        - Set max metric value for external LSAs.
                        type: int
                  stub_prefix_lsa:
                    description:
                    - Advertise Max metric for Stub links as well.
                    type: bool
                  on_startup:
                    description:
                    - Effective only at startup.
                    type: dict
                    suboptions:
                      set:
                        description:
                        - Set on-startup attribute.
                        type: bool
                      wait_period:
                        description:
                        - Wait period in seconds after startup.
                        type: int
                      wait_for_bgp_asn:
                        description:
                        - ASN of BGP to wait for.
                        type: int
                  inter_area_prefix_lsa:
                    description:
                    - Inter-area-prefix LSAs configuration.
                    type: dict
                    suboptions:
                      set:
                        description:
                        - Set summary-lsa attribute.
                        type: bool
                      max_metric_value:
                        description:
                        - Max metric value for summary LSAs.
                        type: int
          name_lookup:
            description:
            - Display OSPF router ids as DNS names.
            type: bool
          passive_interface:
            description:
            - Suppress routing updates on the interface.
            type: dict
            suboptions:
              default:
                description:
                - Interfaces passive by default.
                type: bool
          process_id:
            description:
            - The OSPF process tag.
            type: str
            required: true
          router_id:
            description:
            - Set OSPF process router-id.
            type: str
          shutdown:
            description:
            - Shutdown the OSPF protocol instance.
            type: bool
          timers:
            description:
            - Configure timer related constants.
            type: dict
            suboptions:
              lsa_arrival:
                description:
                - Mimimum interval between arrival of a LSA.
                type: int
              lsa_group_pacing:
                description:
                - LSA group refresh/maxage interval.
                type: int
              throttle:
                description:
                - Configure throttle related constants.
                type: dict
                suboptions:
                  lsa:
                    description:
                    - Set rate-limiting for LSA generation.
                    type: dict
                    suboptions:
                      start_interval:
                        description:
                        - The start interval.
                        type: int
                      hold_interval:
                        description:
                        - The hold interval.
                        type: int
                      max_interval:
                        description:
                        - The max interval.
                        type: int
          vrfs:
            description:
            - Configure VRF specific OSPF settings.
            type: list
            elements: dict
            suboptions:
              areas:
                description:
                - Configure properties of OSPF Areas.
                type: list
                elements: dict
                suboptions:
                  area_id:
                    description:
                    - The Area ID in IP Address format.
                    type: str
                    required: true
                  nssa:
                    description:
                    - NSSA settings for the area.
                    type: dict
                    suboptions:
                      set:
                        description:
                        - Configure area as NSSA.
                        type: bool
                      default_information_originate:
                        description:
                        - Originate Type-7 default LSA into NSSA area.
                        type: bool
                      no_redistribution:
                        description:
                        - Do not send redistributed LSAs into NSSA area.
                        type: bool
                      no_summary:
                        description:
                        - Do not send summary LSAs into NSSA area.
                        type: bool
                      route_map:
                        description:
                        - Policy to control distribution of default route.
                        type: str
                      translate:
                        description:
                        - Translate LSA.
                        type: dict
                        suboptions:
                          type7:
                            description:
                            - Translate from Type 7 to Type 5.
                            type: dict
                            suboptions:
                              always:
                                description:
                                - Always translate LSAs
                                type: bool
                              never:
                                description:
                                - Never translate LSAs
                                type: bool
                              supress_fa:
                                description:
                                - Suppress forwarding address in translated LSAs.
                                type: bool
                  stub:
                    description:
                    - Settings for configuring the area as a stub.
                    type: dict
                    suboptions:
                      set:
                        description:
                        - Configure the area as a stub.
                        type: bool
                      no_summary:
                        description:
                        - Prevent ABR from sending summary LSAs into stub area.
                        type: bool
              auto_cost:
                description:
                - Calculate OSPF cost according to bandwidth.
                type: dict
                suboptions:
                  reference_bandwidth:
                    description:
                    - Reference bandwidth used to assign OSPF cost.
                    type: int
                    required: true
                  unit:
                    description:
                    - Specify in which unit the reference bandwidth is specified.
                    type: str
                    required: true
                    choices: [Gbps, Mbps]
              graceful_restart:
                description:
                - Configure graceful restart.
                type: dict
                suboptions:
                  set:
                    description:
                    - Enable graceful-restart.
                    type: bool
                  grace_period:
                    description:
                    - Configure maximum interval to restart gracefully.
                    type: int
                  helper_disable:
                    description:
                    - Enable/Disable helper mode.
                    type: bool
                  planned_only:
                    description:
                    - Enable graceful restart only for a planned restart
                    type: bool
              log_adjacency_changes:
                description:
                - Log changes in adjacency state.
                type: dict
                suboptions:
                  log:
                    description:
                    - Enable/disable logging changes in adjacency state.
                    type: bool
                  detail:
                    description:
                    - Notify all state changes.
                    type: bool
              max_lsa:
                description:
                - Feature to limit the number of non-self-originated LSAs.
                type: dict
                suboptions:
                  max_non_self_generated_lsa:
                    description:
                    - Set the maximum number of non self-generated LSAs.
                    type: int
                    required: true
                  threshold:
                    description:
                    - Threshold value (%) at which to generate a warning message.
                    type: int
                  ignore_count:
                    description:
                    - Set count on how many times adjacencies can be suppressed.
                    type: int
                  ignore_time:
                    description:
                    - Set time during which all adjacencies are suppressed.
                    type: int
                  reset_time:
                    description:
                    - Set number of minutes after which ignore-count is reset to zero.
                    type: int
                  warning_only:
                    description:
                    - Log a warning message when limit is exceeded.
                    type: bool
              max_metric:
                description:
                - Maximize the cost metric.
                type: dict
                suboptions:
                  router_lsa:
                    description:
                    - Router LSA configuration.
                    type: dict
                    suboptions:
                      set:
                        description:
                        - Set router-lsa attribute.
                        type: bool
                      external_lsa:
                        description:
                        - External LSA configuration.
                        type: dict
                        suboptions:
                          set:
                            description:
                            - Set external-lsa attribute.
                            type: bool
                          max_metric_value:
                            description:
                            - Set max metric value for external LSAs.
                            type: int
                      stub_prefix_lsa:
                        description:
                        - Advertise Max metric for Stub links as well.
                        type: bool
                      on_startup:
                        description:
                        - Effective only at startup.
                        type: dict
                        suboptions:
                          set:
                            description:
                            - Set on-startup attribute.
                            type: bool
                          wait_period:
                            description:
                            - Wait period in seconds after startup.
                            type: int
                          wait_for_bgp_asn:
                            description:
                            - ASN of BGP to wait for.
                            type: int
                      inter_area_prefix_lsa:
                        description:
                        - Inter-area-prefix LSAs configuration.
                        type: dict
                        suboptions:
                          set:
                            description:
                            - Set summary-lsa attribute.
                            type: bool
                          max_metric_value:
                            description:
                            - Max metric value for summary LSAs.
                            type: int
              name_lookup:
                description:
                - Display OSPF router ids as DNS names.
                type: bool
              passive_interface:
                description:
                - Suppress routing updates on the interface.
                type: dict
                suboptions:
                  default:
                    description:
                    - Interfaces passive by default.
                    type: bool
              router_id:
                description:
                - Set OSPF process router-id.
                type: str
              shutdown:
                description:
                - Shutdown the OSPF protocol instance.
                type: bool
              timers:
                description:
                - Configure timer related constants.
                type: dict
                suboptions:
                  lsa_arrival:
                    description:
                    - Mimimum interval between arrival of a LSA.
                    type: int
                  lsa_group_pacing:
                    description:
                    - LSA group refresh/maxage interval.
                    type: int
                  throttle:
                    description:
                    - Configure throttle related constants.
                    type: dict
                    suboptions:
                      lsa:
                        description:
                        - Set rate-limiting for LSA generation.
                        type: dict
                        suboptions:
                          start_interval:
                            description:
                            - The start interval.
                            type: int
                          hold_interval:
                            description:
                            - The hold interval.
                            type: int
                          max_interval:
                            description:
                            - The max interval.
                            type: int
              vrf:
                description:
                - Name/Identifier of the VRF.
                type: str
                required: true
  state:
    description:
    - The state the configuration should be left in.
    type: str
    choices:
    - merged
    - replaced
    - overridden
    - deleted
    - gathered
    - parsed
    - rendered
    default: merged
"""
EXAMPLES = """
# Using merged

# Before state:
# -------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# nxos-9k-rdo#

- name: Merge the provided configuration with the existing running configuration
  cisco.nxos.nxos_ospfv3:
    config:
      processes:
        - process_id: 100
          router_id: 203.0.113.20
        - process_id: 102
          router_id: 198.51.100.1
          address_family:
            afi: ipv6
            safi: unicast
            areas:
              - area_id: 0.0.0.100
                filter_list:
                  - route_map: rmap_1
                    direction: in
                  - route_map: rmap_2
                    direction: out
                ranges:
                  - prefix: '2001:db2::/32'
                    not_advertise: true
                  - prefix: '2001:db3::/32'
                    cost: 120
            redistribute:
              - protocol: eigrp
                id: 120
                route_map: rmap_1
              - protocol: direct
                route_map: ospf102-direct-connect
          vrfs:
            - vrf: zone1
              router_id: 198.51.100.129
              areas:
                - area_id: 0.0.0.102
                  nssa:
                    default_information_originate: true
                    no_summary: true
                - area_id: 0.0.0.103
                  nssa:
                    no_summary: true
                    translate:
                      type7:
                        always: true
            - vrf: zone2
              auto_cost:
                reference_bandwidth: 45
                unit: Gbps
    state: merged

# Task output:
# ------------
# before: {}
#
# commands:
#  - router ospf 102
#  - router-id 198.51.100.1
#  - address-family ipv6 unicast
#  - redistribute eigrp 120 route-map rmap_1
#  - redistribute direct route-map ospf102-direct-connect
#  - area 0.0.0.100 filter-list route-map rmap_1 in
#  - area 0.0.0.100 filter-list route-map rmap_2 out
#  - area 0.0.0.100 range 2001:db2::/32 not-advertise
#  - area 0.0.0.100 range 2001:db3::/32 cost 120
#  - vrf zone1
#  - router-id 198.51.100.129
#  - area 0.0.0.102 nssa no-summary default-information-originate
#  - area 0.0.0.103 nssa no-summary
#  - area 0.0.0.103 nssa translate type7 always
#  - vrf zone2
#  - auto-cost reference-bandwidth 45 Gbps
#  - router ospf 100
#  - router-id 203.0.113.20
#
# after:
#    processes:
#    - process_id: "100"
#      router_id: 203.0.113.20
#    - address_family:
#        afi: ipv4
#        safi: unicast
#        areas:
#        - area_id: 0.0.0.100
#          filter_list:
#          - direction: out
#            route_map: rmap_2
#          - direction: in
#            route_map: rmap_1
#          ranges:
#          - not_advertise: true
#            prefix: 2001:db2::/32
#          - cost: 120
#            prefix: 2001:db3::/32
#        redistribute:
#        - protocol: direct
#          route_map: ospf102-direct-connect
#        - id: "120"
#          protocol: eigrp
#          route_map: rmap_1
#      process_id: "102"
#      router_id: 198.51.100.1
#      vrfs:
#      - areas:
#        - area_id: 0.0.0.102
#          nssa:
#            default_information_originate: true
#            no_summary: true
#        - area_id: 0.0.0.103
#          nssa:
#            no_summary: true
#            translate:
#              type7:
#                always: true
#        router_id: 198.51.100.129
#        vrf: zone1
#      - auto_cost:
#          reference_bandwidth: 45
#          unit: Gbps
#        vrf: zone2
#

# After state:
# ------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# router ospfv3 100
#   router-id 203.0.113.20
# router ospfv3 102
#   router-id 198.51.100.1
#   address-family ipv6 unicast
#     redistribute direct route-map ospf102-direct-connect
#     redistribute eigrp 120 route-map rmap_1
#     area 0.0.0.100 filter-list route-map rmap_2 out
#     area 0.0.0.100 filter-list route-map rmap_1 in
#     area 0.0.0.100 range 2001:db2::/32 not-advertise
#     area 0.0.0.100 range 2001:db3::/32 cost 120
#   vrf zone1
#     router-id 198.51.100.129
#     area 0.0.0.102 nssa no-summary default-information-originate
#     area 0.0.0.103 nssa no-summary
#     area 0.0.0.103 nssa translate type7 always
#   vrf zone2
#     auto-cost reference-bandwidth 45 Gbps

# Using replaced

# Before state:
# -------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# router ospfv3 100
#   router-id 203.0.113.20
# router ospfv3 102
#   router-id 198.51.100.1
#   address-family upv6 unicast
#     redistribute direct route-map ospf102-direct-connect
#     redistribute eigrp 120 route-map rmap_1
#     area 0.0.0.100 filter-list route-map rmap_2 out
#     area 0.0.0.100 filter-list route-map rmap_1 in
#     area 0.0.0.100 range 2001:db2::/32 not-advertise
#     area 0.0.0.100 range 2001:db3::/32 cost 120
#   vrf zone1
#     router-id 198.51.100.129
#     area 0.0.0.102 nssa no-summary default-information-originate
#     area 0.0.0.103 nssa no-summary
#     area 0.0.0.103 nssa translate type7 always
#   vrf zone2
#     auto-cost reference-bandwidth 45 Gbps

- name: Replace device configurations of listed OSPFv3 processes with provided configurations
  cisco.nxos.nxos_ospfv3:
    config:
      processes:
        - process_id: 102
          router_id: 198.51.100.1
          address_family:
            afi: ipv6
            safi: unicast
            areas:
              - area_id: 0.0.0.100
                filter_list:
                  - route_map: rmap_8
                    direction: in
                ranges:
                  - not_advertise: true
                    prefix: 2001:db2::/32
            redistribute:
              - protocol: eigrp
                id: 130
                route_map: rmap_1
              - protocol: direct
                route_map: ospf102-direct-connect
          vrfs:
            - vrf: zone1
              router_id: 198.51.100.129
              areas:
                - area_id: 0.0.0.102
                  nssa:
                    default_information_originate: true
                    no_summary: true
    state: replaced

# Task output:
# ------------
# before:
#    processes:
#    - process_id: "100"
#      router_id: 203.0.113.20
#    - address_family:
#        afi: ipv4
#        safi: unicast
#        areas:
#        - area_id: 0.0.0.100
#          filter_list:
#          - direction: out
#            route_map: rmap_2
#          - direction: in
#            route_map: rmap_1
#          ranges:
#          - not_advertise: true
#            prefix: 2001:db2::/32
#          - cost: 120
#            prefix: 2001:db3::/32
#        redistribute:
#        - protocol: direct
#          route_map: ospf102-direct-connect
#        - id: "120"
#          protocol: eigrp
#          route_map: rmap_1
#      process_id: "102"
#      router_id: 198.51.100.1
#      vrfs:
#      - areas:
#        - area_id: 0.0.0.102
#          nssa:
#            default_information_originate: true
#            no_summary: true
#        - area_id: 0.0.0.103
#          nssa:
#            no_summary: true
#            translate:
#              type7:
#                always: true
#        router_id: 198.51.100.129
#        vrf: zone1
#      - auto_cost:
#          reference_bandwidth: 45
#          unit: Gbps
#        vrf: zone2
#
#  commands:
#  - router ospf 102
#  - address-family ipv6 unicast
#  - redistribute eigrp 130 route-map rmap_1
#  - no redistribute eigrp 120 route-map rmap_1
#  - area 0.0.0.100 filter-list route-map rmap_8 in
#  - no area 0.0.0.100 filter-list route-map rmap_2 out
#  - no area 0.0.0.100 range 2001:db3::/32
#  - vrf zone1
#  - no area 0.0.0.103 nssa
#  - no area 0.0.0.103 nssa translate type7 always
#  - no vrf zone2
#
# after:
#    processes:
#    - process_id: "100"
#      router_id: 203.0.113.20
#    - address_family:
#        afi: ipv6
#        safi: unicast
#        areas:
#        - area_id: 0.0.0.100
#          filter_list:
#          - direction: in
#            route_map: rmap_8
#          ranges:
#          - not_advertise: true
#            prefix: 2001:db2::/32
#        redistribute:
#        - protocol: direct
#          route_map: ospf102-direct-connect
#        - id: "130"
#          protocol: eigrp
#          route_map: rmap_1
#      process_id: "102"
#      router_id: 198.51.100.1
#      vrfs:
#      - areas:
#        - area_id: 0.0.0.102
#          nssa:
#            default_information_originate: true
#            no_summary: true
#        router_id: 198.51.100.129
#        vrf: zone1

# After state:
# ------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# router ospfv3 100
#   router-id 203.0.113.20
# router ospfv3 102
#   router-id 198.51.100.1
#   address-family ipv6 unicast
#     redistribute direct route-map ospf102-direct-connect
#     redistribute eigrp 130 route-map rmap_1
#     area 0.0.0.100 filter-list route-map rmap_8 in
#     area 0.0.0.100 range 198.51.100.64/27 not-advertise
#   vrf zone1
#     router-id 198.51.100.129
#     area 0.0.0.102 nssa no-summary default-information-originate

# Using overridden

# Before state:
# -------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# router ospfv3 100
#   router-id 203.0.113.20
# router ospfv3 102
#   router-id 198.51.100.1
#   address-family ipv6 unicast
#     redistribute direct route-map ospf102-direct-connect
#     redistribute eigrp 120 route-map rmap_1
#     area 0.0.0.100 filter-list route-map rmap_2 out
#     area 0.0.0.100 filter-list route-map rmap_1 in
#     area 0.0.0.100 range 2001:db2::/32 not-advertise
#     area 0.0.0.100 range 2001:db3::/32 cost 120
#   vrf zone1
#     router-id 198.51.100.129
#     area 0.0.0.102 nssa no-summary default-information-originate
#     area 0.0.0.103 nssa no-summary
#     area 0.0.0.103 nssa translate type7 always
#   vrf zone2
#     auto-cost reference-bandwidth 45 Gbps

- name: Override all OSPFv3 configuration with provided configuration
  cisco.nxos.nxos_ospfv3:
    config:
      processes:
        - process_id: 104
          router_id: 203.0.113.20
        - process_id: 102
          router_id: 198.51.100.1
          shutdown: true
    state: overridden

# Task output:
# ------------
# before:
#    processes:
#    - process_id: "100"
#      router_id: 203.0.113.20
#    - address_family:
#        afi: ipv4
#        safi: unicast
#        areas:
#        - area_id: 0.0.0.100
#          filter_list:
#          - direction: out
#            route_map: rmap_2
#          - direction: in
#            route_map: rmap_1
#          ranges:
#          - not_advertise: true
#            prefix: 2001:db2::/32
#          - cost: 120
#            prefix: 2001:db3::/32
#        redistribute:
#        - protocol: direct
#          route_map: ospf102-direct-connect
#        - id: "120"
#          protocol: eigrp
#          route_map: rmap_1
#      process_id: "102"
#      router_id: 198.51.100.1
#      vrfs:
#      - areas:
#        - area_id: 0.0.0.102
#          nssa:
#            default_information_originate: true
#            no_summary: true
#        - area_id: 0.0.0.103
#          nssa:
#            no_summary: true
#            translate:
#              type7:
#                always: true
#        router_id: 198.51.100.129
#        vrf: zone1
#      - auto_cost:
#          reference_bandwidth: 45
#          unit: Gbps
#        vrf: zone2
#
# commands:
#  - no router ospfv3 100
#  - router ospfv3 104
#  - router-id 203.0.113.20
#  - router ospfv3 102
#  - shutdown
#  - address-family ipv6 unicast
#  - no redistribute direct route-map ospf102-direct-connect
#  - no redistribute eigrp 120 route-map rmap_1
#  - no area 0.0.0.100 filter-list route-map rmap_2 out
#  - no area 0.0.0.100 filter-list route-map rmap_1 in
#  - no area 0.0.0.100 range 2001:db2::/32
#  - no area 0.0.0.100 range 2001:db3::/32
#  - no vrf zone1
#  - no vrf zone2
#
# after:
#    processes:
#    - process_id: "102"
#      router_id: 198.51.100.1
#      shutdown: true
#      address_family:
#        afi: ipv6
#        safi: unicast
#    - process_id: "104"
#      router_id: 203.0.113.20

# After state:
# ------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# router ospfv3 102
#   router-id 198.51.100.1
#   address-family ipv6 unicast
#   shutdown
# router ospfv3 104
#   router-id 203.0.113.20

# Using deleted to delete a single OSPF process

# Before state:
# -------------
# nxos-9k-rdo# sh running-config | section "^router ospf .*"
# router ospfv3 100
#   router-id 203.0.113.20
# router ospfv3 102
#   router-id 198.51.100.1
#   address-family ipv6 unicast
#     redistribute direct route-map ospf102-direct-connect
#     redistribute eigrp 120 route-map rmap_1
#     area 0.0.0.100 filter-list route-map rmap_2 out
#     area 0.0.0.100 filter-list route-map rmap_1 in
#     area 0.0.0.100 range 2001:db2::/32 not-advertise
#     area 0.0.0.100 range 2001:db3::/32 cost 120
#   vrf zone1
#     router-id 198.51.100.129
#     area 0.0.0.102 nssa no-summary default-information-originate
#     area 0.0.0.103 nssa no-summary
#     area 0.0.0.103 nssa translate type7 always
#   vrf zone2
#     auto-cost reference-bandwidth 45 Gbps

- name: Delete a single OSPFv3 process
  cisco.nxos.nxos_ospfv3:
    config:
      processes:
        - process_id: 102
    state: deleted

# Task output:
# ------------
# before:
#    processes:
#    - process_id: "100"
#      router_id: 203.0.113.20
#    - address_family:
#        afi: ipv4
#        safi: unicast
#        areas:
#        - area_id: 0.0.0.100
#          filter_list:
#          - direction: out
#            route_map: rmap_2
#          - direction: in
#            route_map: rmap_1
#          ranges:
#          - not_advertise: true
#            prefix: 2001:db2::/32
#          - cost: 120
#            prefix: 2001:db3::/32
#        redistribute:
#        - protocol: direct
#          route_map: ospf102-direct-connect
#        - id: "120"
#          protocol: eigrp
#          route_map: rmap_1
#      process_id: "102"
#      router_id: 198.51.100.1
#      vrfs:
#      - areas:
#        - area_id: 0.0.0.102
#          nssa:
#            default_information_originate: true
#            no_summary: true
#        - area_id: 0.0.0.103
#          nssa:
#            no_summary: true
#            translate:
#              type7:
#                always: true
#        router_id: 198.51.100.129
#        vrf: zone1
#      - auto_cost:
#          reference_bandwidth: 45
#          unit: Gbps
#        vrf: zone2
#
# commands:
#   - no router ospfv3 102
#
# after:
#   processes:
#   - process_id: "100"
#     router_id: 203.0.113.20

# After state:
# ------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# router ospfv3 100
#   router-id 203.0.113.20

# Using deleted all OSPFv3 processes from the device

# Before state:
# -------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# router ospfv3 100
#   router-id 203.0.113.20
# router ospfv3 102
#   router-id 198.51.100.1
#   address-family ipv6 unicast
#     redistribute direct route-map ospf102-direct-connect
#     redistribute eigrp 120 route-map rmap_1
#     area 0.0.0.100 filter-list route-map rmap_2 out
#     area 0.0.0.100 filter-list route-map rmap_1 in
#     area 0.0.0.100 range 2001:db2::/32 not-advertise
#     area 0.0.0.100 range 2001:db3::/32 cost 120
#   vrf zone1
#     router-id 198.51.100.129
#     area 0.0.0.102 nssa no-summary default-information-originate
#     area 0.0.0.103 nssa no-summary
#     area 0.0.0.103 nssa translate type7 always
#   vrf zone2
#     auto-cost reference-bandwidth 45 Gbps

- name: Delete all OSPFv3 processes from the device
  cisco.nxos.nxos_ospfv3:
    state: deleted

# Task output:
# ------------
# before:
#    processes:
#    - process_id: "100"
#      router_id: 203.0.113.20
#    - address_family:
#        afi: ipv4
#        safi: unicast
#        areas:
#        - area_id: 0.0.0.100
#          filter_list:
#          - direction: out
#            route_map: rmap_2
#          - direction: in
#            route_map: rmap_1
#          ranges:
#          - not_advertise: true
#            prefix: 2001:db2::/32
#          - cost: 120
#            prefix: 2001:db3::/32
#        redistribute:
#        - protocol: direct
#          route_map: ospf102-direct-connect
#        - id: "120"
#          protocol: eigrp
#          route_map: rmap_1
#      process_id: "102"
#      router_id: 198.51.100.1
#      vrfs:
#      - areas:
#        - area_id: 0.0.0.102
#          nssa:
#            default_information_originate: true
#            no_summary: true
#        - area_id: 0.0.0.103
#          nssa:
#            no_summary: true
#            translate:
#              type7:
#                always: true
#        router_id: 198.51.100.129
#        vrf: zone1
#      - auto_cost:
#          reference_bandwidth: 45
#          unit: Gbps
#        vrf: zone2
#
# commands:
#  - no router ospfv3 100
#  - no router ospfv3 102
#
#  after: {}

# After state:
# ------------
# nxos-9k-rdo# sh running-config | section "^router ospfv3"
# nxos-9k-rdo#

# Using rendered

- name: Render platform specific configuration lines with state rendered (without connecting to the device)
  cisco.nxos.nxos_ospfv3:
    config:
      processes:
        - process_id: 100
          router_id: 203.0.113.20
        - process_id: 102
          router_id: 198.51.100.1
          address_family:
            afi: ipv6
            safi: unicast
            areas:
              - area_id: 0.0.0.100
                filter_list:
                  - route_map: rmap_1
                    direction: in
                  - route_map: rmap_2
                    direction: out
                ranges:
                  - prefix: 2001:db2::/32
                    not_advertise: true
                  - prefix: 2001:db3::/32
                    cost: 120
            redistribute:
              - protocol: eigrp
                id: 120
                route_map: rmap_1
              - protocol: direct
                route_map: ospf102-direct-connect
          vrfs:
            - vrf: zone1
              router_id: 198.51.100.129
              areas:
                - area_id: 0.0.0.102
                  nssa:
                    default_information_originate: true
                    no_summary: true
                - area_id: 0.0.0.103
                  nssa:
                    no_summary: true
                    translate:
                      type7:
                        always: true
            - vrf: zone2
              auto_cost:
                reference_bandwidth: 45
                unit: Gbps
    state: rendered

# Task output:
# ------------
# rendered:
#  - router ospfv3 100
#  - router-id 203.0.113.20
#  - router ospfv3 102
#  - router-id 198.51.100.1
#  - address-family ipv6 unicast
#  - redistribute eigrp 120 route-map rmap_1
#  - redistribute direct route-map ospf102-direct-connect
#  - area 0.0.0.100 filter-list route-map rmap_1 in
#  - area 0.0.0.100 filter-list route-map rmap_2 out
#  - area 0.0.0.100 range 2001:db2::/32 not-advertise
#  - area 0.0.0.100 range 2001:db3::/32 cost 120
#  - vrf zone1
#  - router-id 198.51.100.129
#  - area 0.0.0.102 nssa no-summary default-information-originate
#  - area 0.0.0.103 nssa no-summary
#  - area 0.0.0.103 nssa translate type7 always
#  - vrf zone2
#  - auto-cost reference-bandwidth 45 Gbps

# Using parsed

# parsed.cfg
# ------------
# router ospfv3 100
#   router-id 192.0.100.1
#   address-family ipv6 unicast
#     redistribute direct route-map ospf-direct-connect
#     redistribute eigrp 120 route-map rmap_1
#     area 0.0.0.100 filter-list route-map rmap_2 out
#     area 0.0.0.100 filter-list route-map rmap_1 in
#     area 0.0.0.100 range 2001:db2::/32 not-advertise
#     area 0.0.0.100 range 2001:db3::/32 cost 120
#   vrf zone1
#     router-id 198.51.100.129
#     area 0.0.100.1 nssa no-summary no-redistribution
# router ospfv3 102
#   router-id 198.54.100.1
#   shutdown

- name: Parse externally provided OSPFv3 config
  cisco.nxos.nxos_ospfv3:
    running_config: "{{ lookup('file', 'ospfv2.cfg') }}"
    state: parsed

# Task output:
# ------------
# parsed:
#   processes:
#   - process_id: "100"
#     address_family:
#       afi: ipv6
#       safi: unicast
#       areas:
#       - area_id: 0.0.0.101
#         nssa:
#           no_redistribution: true
#           no_summary: true
#       - area_id: 0.0.0.102
#         stub:
#           no_summary: true
#         filter_list:
#           - direction: out
#             route_map: rmap_2
#           - direction: in
#             route_map: rmap_1
#         ranges:
#           - not_advertise: true
#             prefix: 192.0.2.0/24
#           - cost: 120
#             prefix: 192.0.3.0/24
#       redistribute:
#       - protocol: direct
#         route_map: ospf-direct-connect
#       - id: "120"
#         protocol: eigrp
#         route_map: rmap_1
#     router_id: 192.0.100.1
#     vrfs:
#       - vrf: zone1
#         areas:
#           - area_id: 0.0.100.1
#             nssa:
#               no_redistribution: true
#               no_summary: true
#         router_id: 192.0.100.2
#   - process_id: "102"
#     router_id: 198.54.100.1
#     shutdown: true

# Using gathered

- name: Gather OSPFv3 facts using gathered
  cisco.nxos.nxos_ospfv3:
    state: gathered

# Task output:
# ------------
#  gathered:
#    processes:
#    - process_id: "100"
#      router_id: 203.0.113.20
#    - address_family:
#        afi: ipv4
#        safi: unicast
#        areas:
#        - area_id: 0.0.0.100
#          filter_list:
#          - direction: out
#            route_map: rmap_2
#          - direction: in
#            route_map: rmap_1
#          ranges:
#          - not_advertise: true
#            prefix: 2001:db2::/32
#          - cost: 120
#            prefix: 2001:db3::/32
#        redistribute:
#        - protocol: direct
#          route_map: ospf102-direct-connect
#        - id: "120"
#          protocol: eigrp
#          route_map: rmap_1
#      process_id: "102"
#      router_id: 198.51.100.1
#      vrfs:
#      - areas:
#        - area_id: 0.0.0.102
#          nssa:
#            default_information_originate: true
#            no_summary: true
#        - area_id: 0.0.0.103
#          nssa:
#            no_summary: true
#            translate:
#              type7:
#                always: true
#        router_id: 198.51.100.129
#        vrf: zone1
#      - auto_cost:
#          reference_bandwidth: 45
#          unit: Gbps
#        vrf: zone2
#
"""
RETURN = """
before:
  description: The configuration prior to the model invocation.
  returned: always
  type: dict
  sample: >
    The configuration returned will always be in the same format
     of the parameters above.
after:
  description: The resulting configuration model invocation.
  returned: when changed
  type: dict
  sample: >
    The configuration returned will always be in the same format
     of the parameters above.
commands:
  description: The set of commands pushed to the remote device.
  returned: always
  type: list
  sample:
    - "router ospfv3 102"
    - "router-id 198.54.100.1"
    - "router ospfv3 100"
    - "router-id 192.0.100.1"
    - "address-family ipv6 unicast"
    - "redistribute eigrp 120 route-map rmap_1"
    - "redistribute direct route-map ospf-direct-connect"
    - "area 0.0.0.100 filter-list route-map rmap_1 in"
    - "area 0.0.0.100 filter-list route-map rmap_2 out"
    - "area 0.0.0.100 range 2001:db2::/32 not-advertise"
    - "area 0.0.0.100 range 2001:db3::/32 cost 120"
    - "vrf zone1"
    - "router-id 192.0.100.2"
    - "vrf zone2"
    - "auto-cost reference-bandwidth 45 Gbps"
rendered:
  description: The provided configuration in the task rendered in device-native format (offline).
  returned: when I(state) is C(rendered)
  type: list
  sample:
    - "router ospfv3 102"
    - "router-id 198.54.100.1"
    - "router ospfv3 100"
gathered:
  description: Facts about the network resource gathered from the remote device as structured data.
  returned: when I(state) is C(gathered)
  type: dict
  sample: >
    This output will always be in the same format as the
    module argspec.
parsed:
  description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
  returned: when I(state) is C(parsed)
  type: dict
  sample: >
    This output will always be in the same format as the
    module argspec.
"""

from ansible.module_utils.basic import AnsibleModule

from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.ospfv3.ospfv3 import (
    Ospfv3Args,
)
from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.ospfv3.ospfv3 import (
    Ospfv3,
)


def main():
    """
    Main entry point for module execution

    :returns: the result form module invocation
    """
    module = AnsibleModule(
        argument_spec=Ospfv3Args.argument_spec,
        mutually_exclusive=[["config", "running_config"]],
        required_if=[
            ["state", "merged", ["config"]],
            ["state", "replaced", ["config"]],
            ["state", "overridden", ["config"]],
            ["state", "rendered", ["config"]],
            ["state", "parsed", ["running_config"]],
        ],
        supports_check_mode=True,
    )

    result = Ospfv3(module).execute_module()
    module.exit_json(**result)


if __name__ == "__main__":
    main()
