#!/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_sntp
"""

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_sntp
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:
      auth:
        description: Network time protocol authentication
        type: bool
      auth_key:
        description: Authentication key
        type: list
        elements: dict
        suboptions:
          id:
            description: <1-4294967295> Key identifier
            required: true
            type: int
          pass:
            description: Password
            type: str
      client:
        description: Global SNTP service state
        type: bool
      max_poll:
        description: <3-17> Longest polling interval (in power of two seconds)
        type: int
      min_poll:
        description: <3-17> Shortest polling interval (in power of two seconds)
        type: int
      server:
        description: Network time protocol server configuration
        type: list
        elements: dict
        suboptions:
          address:
            description: IP address in a.b.c.d or X:X:X:X::X format
            required: true
            type: str
          key_id:
            description: <1-4294967295> Authentication key ID
            type: int
      source:
        description: Source IP address from which NTP server connection will be established
        type: dict
        suboptions:
          ipv4:
            description: IPv4 Address
            type: str
          ipv6:
            description: IPv6 Address
            type: str
  state:
    description:
    - The state the configuration should be left in
    type: str
    choices:
    - merged
    - replaced
    - overridden
    - deleted
    default: merged
"""
EXAMPLES = """
### Using Merged ###

dmos_sntp:
  config:
    - auth: false
      auth_key:
        - id: 10
          pass: test
        - id: 12
          pass: password
      client: true
      max_poll: 15
      min_poll: 12
      server:
        - address: 10.0.0.1
          key_id: 10
        - address: 20.0.0.2
          key_id: 12
      source:
        ipv4: 100.10.10.1
        ipv6: 1918::2019
  state: merged

# This configuration will result in the following commands:

# - no sntp authenticate
# - sntp authentication-key 10 md5 test
# - sntp authentication-key 12 md5 password
# - sntp client
# - sntp max-poll 15
# - sntp min-poll 12
# - sntp server 10.0.0.1 key 10
# - sntp server 20.0.0.2 key 12
# - sntp source ipv4 address 100.10.10.1
# - sntp source ipv6 address 1918::2019

### Using Delete ###

dmos_sntp:
  config:
    - auth: true
      auth_key:
        - id: 10
        - id: 12
          pass: password
      client: true
      max_poll: 15
      min_poll: 12
      server:
        - address: 10.0.0.1
          key_id: 10
        - address: 20.0.0.2
      source:
        ipv4: 100.10.10.1
        ipv6: 1918::2019
  state: deleted

# This configuration will result in the following commands:

# - no sntp authenticate
# - no sntp authentication-key 10
# - no sntp client
# - no sntp max-poll
# - no sntp min-poll
# - no sntp server 10.0.0.1 key
# - no sntp server 20.0.0.2
# - no sntp source ipv4
# - no sntp source ipv6
"""
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.sntp.sntp import SntpArgs
from ansible.module_utils.network.dmos.config.sntp.sntp import Sntp


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

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

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


if __name__ == '__main__':
    main()
