#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2019 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 dmos_linkagg
"""

from __future__ import absolute_import, division, print_function
__metaclass__ = type

ANSIBLE_METADATA = {
    'metadata_version': '1.1',
    'status': ['preview'],
    'supported_by': '<support_group>'
}

DOCUMENTATION = """
---
module: dmos_linkagg
version_added: 4.9
short_description: 'Manages <xxxx> attributes of <network_os> <resource>.'
description: 'Manages <xxxx> attributes of <network_os> <resource>'
author: Ansible Network Engineer
notes:
  - 'Tested against <network_os> <version>'
options:
  config:
    description: The provided configuration
    type: list
    elements: dict
    suboptions:
      sys_prio:
        description: <0-65535> The Priority for this system
        type: int
      lag:
        description: Link Aggregation Group configuration
        type: list
        elements: dict
        suboptions:
          lag_id:
            description: <1-8> LAG ID
            type: int
            required: true
          admin_status:
            description: The administrative status of this LAG interface
            type: str
            choices:
              - up
              - down
          description:
            description: A textual description of the interface
            type: str
          interface:
            description: Aggregatable interfaces configuration
            type: list
            elements: dict
            suboptions:
              name:
                description: Interface name
                type: str
                required: true
              port_prio:
                description: Specify port priority for a LAG member link
                type: int
          load_balance:
            description: The load balancing algorithm to apply to traffic forwarded on this LAG interface
            type: str
            choices:
              - dst-ip
              - dst-mac
              - dynamic
              - enhanced
              - src-dst-ip
              - src-dst-mac
              - src-ip
              - src-mac
          max_active:
            description: Specify the maximum number of links allowed to be simultaneously active in a LAG interface.
            type: int
          min_active:
            description: Specify the minimum number of links required to consider a LAG interface as active
            type: int
          mode:
            description: The desired mode of LACP operation for this LAG
            type: str
            choices:
              - active
              - passive
              - static
          period:
            description: LACPDU time interval configuration
            type: str
            choices:
              - long
              - short
  state:
    description:
    - The state the configuration should be left in
    type: str
    choices:
    - merged
    - replaced
    - overridden
    - deleted
    default: merged
"""
EXAMPLES = """
### Using Merged ###

dmos_linkagg:
  config:
    - lag:
      - lag_id: 1
        admin_status: up
        description: Hello World
        load_balance: dst-ip
        interface:
          - name: gigabit-ethernet-1/1/1
            port_prio: 12
          - name: gigabit-ethernet-1/1/3
            port_prio: 15
        max_active: 4
        min_active: 3
        mode: active
        period: long
      - lag_id: 2
        admin_status: down
        description: Hey Jude
        load_balance: enhanced
        interface:
          - name: gigabit-ethernet-1/1/2
            port_prio: 113
          - name: gigabit-ethernet-1/1/5
        max_active: 2
        min_active: 1
        mode: passive
        period: short
      sys_prio: 400
  state: merged

# This configuration will result in the following commands:

# - link-aggregation system-priority 400
# - link-aggregation interface lag 1 administrative-status up
# - link-aggregation interface lag 1 description "Hello World"
# - link-aggregation interface lag 1 interface gigabit-ethernet-1/1/1 port-priority 12
# - link-aggregation interface lag 1 interface gigabit-ethernet-1/1/3 port-priority 15
# - link-aggregation interface lag 1 load-balance dst-ip
# - link-aggregation interface lag 1 maximum-active links 4
# - link-aggregation interface lag 1 minimum-active links 3
# - link-aggregation interface lag 1 mode active
# - link-aggregation interface lag 1 period long
# - link-aggregation interface lag 2 administrative-status down
# - link-aggregation interface lag 2 description "Hey Jude"
# - link-aggregation interface lag 2 interface gigabit-ethernet-1/1/2 port-priority 113
# - link-aggregation interface lag 2 interface gigabit-ethernet-1/1/5
# - link-aggregation interface lag 2 load-balance enhanced
# - link-aggregation interface lag 2 maximum-active links 2
# - link-aggregation interface lag 2 minimum-active links 1
# - link-aggregation interface lag 2 mode passive
# - link-aggregation interface lag 2 period short

### Using Delete ###

dmos_linkagg:
  config:
    - lag:
      - lag_id: 1
        admin_status: up
        description: Hello World
        load_balance: dst-ip
        interface:
          - name: gigabit-ethernet-1/1/1
            port_prio: 12
          - name: gigabit-ethernet-1/1/3
        max_active: 4
        min_active: 3
        mode: active
        period: long
      - lag_id: 2
      sys_prio: 400
  state: deleted

# This configuration will result in the following commands:

# - no link-aggregation system-priority
# - no link-aggregation interface lag 1 administrative-status
# - no link-aggregation interface lag 1 description
# - no link-aggregation interface lag 1 interface gigabit-ethernet-1/1/1 port-priority
# - no link-aggregation interface lag 1 interface gigabit-ethernet-1/1/3
# - no link-aggregation interface lag 1 load-balance
# - no link-aggregation interface lag 1 maximum-active
# - no link-aggregation interface lag 1 minimum-active
# - no link-aggregation interface lag 1 mode
# - no link-aggregation interface lag 1 period
# - no link-aggregation interface lag 2
"""
RETURN = """
before:
  description: The configuration prior to the model invocation.
  returned: always
  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
  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: ['command 1', 'command 2', 'command 3']
changed:
  description: If configuration resulted in any change
  returned: always
  type: bool
  sample: True or False
msg:
  description: Error message
  returned: on error
  type: string
  sample: 'Aborted: reason'
response:
  description: The response of each executed commands
  returned: always
  type: list
  sample: ['Aborted: reason']
"""


from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.dmos.argspec.linkagg.linkagg import LinkaggArgs
from ansible.module_utils.network.dmos.config.linkagg.linkagg import Linkagg


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

    :returns: the result form module invocation
    """
    module = AnsibleModule(argument_spec=LinkaggArgs.argument_spec,
                           supports_check_mode=True)

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


if __name__ == '__main__':
    main()
