
    Vh                        d Z ddlmZmZmZ eZdgZdZdZ	dZ
ddlZddlmZ dd	lmZmZmZmZ  G d
 de      Zd Zedk(  r e        yy)zFAnsible module to perform operations on project and templates in DNAC.    )absolute_importdivisionprint_functionzIMadhan Sankaranarayanan, Rishita Chowdhary, Akash Bhaskaran, Muthu Rakesha+  
---
module: template_intent
short_description: Resource module for Template functions
description:
  - Manage operations create, update and delete of the resource Configuration Template.
  - API to create a template by project name and template name.
  - API to update a template by template name and project name.
  - API to delete a template by template name and project name.
  - API to export the projects for given projectNames.
  - API to export the templates for given templateIds.
  - API to manage operation create of the resource Configuration Template Import Project.
  - API to manage operation create of the resource Configuration Template Import Template.
version_added: '6.6.0'
extends_documentation_fragment:
  - cisco.dnac.intent_params
author: Madhan Sankaranarayanan (@madhansansel) Rishita Chowdhary (@rishitachowdhary)
  Akash Bhaskaran (@akabhask) Muthu Rakesh (@MUTHU-RAKESH-27)
options:
  config_verify:
    description: Set to True to verify the Cisco DNA Center after applying the playbook
      config.
    type: bool
    default: false
  state:
    description: The state of DNAC after module completion.
    type: str
    choices: [merged, deleted]
    default: merged
  config:
    description:
      - List of details of templates being managed.
    type: list
    elements: dict
    required: true
    suboptions:
      configuration_templates:
        description: Create/Update/Delete template.
        type: dict
        suboptions:
          author:
            description: Author of template.
            type: str
          composite:
            description: Is it composite template.
            type: bool
          containing_templates:
            description: Configuration Template Create's containingTemplates.
            suboptions:
              composite:
                description: Is it composite template.
                type: bool
              description:
                description: Description of template.
                type: str
              device_types:
                description: deviceTypes on which templates would be applied.
                type: list
                elements: dict
                suboptions:
                  product_family:
                    description: Device family.
                    type: str
                  product_series:
                    description: Device series.
                    type: str
                  product_type:
                    description: Device type.
                    type: str
              id:
                description: UUID of template.
                type: str
              language:
                description: Template language
                choices:
                  - JINJA
                  - VELOCITY
                type: str
              name:
                description: Name of template.
                type: str
              project_name:
                description: Name of the project under which templates are managed.
                type: str
              project_description:
                description: Description of the project created.
                type: str
              rollback_template_params:
                description: Params required for template rollback.
                type: list
                elements: dict
                suboptions:
                  binding:
                    description: Bind to source.
                    type: str
                  custom_order:
                    description: CustomOrder of template param.
                    type: int
                  data_type:
                    description: Datatype of template param.
                    type: str
                  default_value:
                    description: Default value of template param.
                    type: str
                  description:
                    description: Description of template param.
                    type: str
                  display_name:
                    description: Display name of param.
                    type: str
                  group:
                    description: Group.
                    type: str
                  id:
                    description: UUID of template param.
                    type: str
                  instruction_text:
                    description: Instruction text for param.
                    type: str
                  key:
                    description: Key.
                    type: str
                  not_param:
                    description: Is it not a variable.
                    type: bool
                  order:
                    description: Order of template param.
                    type: int
                  param_array:
                    description: Is it an array.
                    type: bool
                  parameter_name:
                    description: Name of template param.
                    type: str
                  provider:
                    description: Provider.
                    type: str
                  range:
                    description: Configuration Template Create's range.
                    type: list
                    elements: dict
                    suboptions:
                      id:
                        description: UUID of range.
                        type: str
                      max_value:
                        description: Max value of range.
                        type: int
                      min_value:
                        description: Min value of range.
                        type: int
                  required:
                    description: Is param required.
                    type: bool
                  selection:
                    description: Configuration Template Create's selection.
                    suboptions:
                      default_selected_values:
                        description: Default selection values.
                        elements: str
                        type: list
                      id:
                        description: UUID of selection.
                        type: str
                      selection_type:
                        description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                        type: str
                      selection_values:
                        description: Selection values.
                        type: dict
                    type: dict
              tags:
                description: Configuration Template Create's tags.
                suboptions:
                  id:
                    description: UUID of tag.
                    type: str
                  name:
                    description: Name of tag.
                    type: str
                type: list
                elements: dict
              template_content:
                description: Template content.
                type: str
              template_params:
                description: Configuration Template Create's templateParams.
                elements: dict
                suboptions:
                  binding:
                    description: Bind to source.
                    type: str
                  custom_order:
                    description: CustomOrder of template param.
                    type: int
                  data_type:
                    description: Datatype of template param.
                    type: str
                  default_value:
                    description: Default value of template param.
                    type: str
                  description:
                    description: Description of template param.
                    type: str
                  display_name:
                    description: Display name of param.
                    type: str
                  group:
                    description: Group.
                    type: str
                  id:
                    description: UUID of template param.
                    type: str
                  instruction_text:
                    description: Instruction text for param.
                    type: str
                  key:
                    description: Key.
                    type: str
                  not_param:
                    description: Is it not a variable.
                    type: bool
                  order:
                    description: Order of template param.
                    type: int
                  param_array:
                    description: Is it an array.
                    type: bool
                  parameter_name:
                    description: Name of template param.
                    type: str
                  provider:
                    description: Provider.
                    type: str
                  range:
                    description: Configuration Template Create's range.
                    suboptions:
                      id:
                        description: UUID of range.
                        type: str
                      max_value:
                        description: Max value of range.
                        type: int
                      min_value:
                        description: Min value of range.
                        type: int
                    type: list
                    elements: dict
                  required:
                    description: Is param required.
                    type: bool
                  selection:
                    description: Configuration Template Create's selection.
                    suboptions:
                      default_selected_values:
                        description: Default selection values.
                        elements: str
                        type: list
                      id:
                        description: UUID of selection.
                        type: str
                      selection_type:
                        description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                        type: str
                      selection_values:
                        description: Selection values.
                        type: dict
                    type: dict
                type: list
              version:
                description: Current version of template.
                type: str
            type: list
            elements: dict
          create_time:
            description: Create time of template.
            type: int
          custom_params_order:
            description: Custom Params Order.
            type: bool
          template_description:
            description: Description of template.
            type: str
          device_types:
            description: Configuration Template Create's deviceTypes. This field is
              mandatory to create a new template.
            suboptions:
              product_family:
                description: Device family.
                type: str
              product_series:
                description: Device series.
                type: str
              product_type:
                description: Device type.
                type: str
            type: list
            elements: dict
          failure_policy:
            description: Define failure policy if template provisioning fails.
            type: str
          id:
            description: UUID of template.
            type: str
          language:
            description: Template language
            choices:
              - JINJA
              - VELOCITY
            type: str
          last_update_time:
            description: Update time of template.
            type: int
          latest_version_time:
            description: Latest versioned template time.
            type: int
          template_name:
            description: Name of template. This field is mandatory to create a new
              template.
            type: str
          parent_template_id:
            description: Parent templateID.
            type: str
          project_id:
            description: Project UUID.
            type: str
          project_name:
            description: Project name.
            type: str
          project_description:
            description: Project Description.
            type: str
          rollback_template_content:
            description: Rollback template content.
            type: str
          rollback_template_params:
            description: Configuration Template Create's rollbackTemplateParams.
            suboptions:
              binding:
                description: Bind to source.
                type: str
              custom_order:
                description: CustomOrder of template param.
                type: int
              data_type:
                description: Datatype of template param.
                type: str
              default_value:
                description: Default value of template param.
                type: str
              description:
                description: Description of template param.
                type: str
              display_name:
                description: Display name of param.
                type: str
              group:
                description: Group.
                type: str
              id:
                description: UUID of template param.
                type: str
              instruction_text:
                description: Instruction text for param.
                type: str
              key:
                description: Key.
                type: str
              not_param:
                description: Is it not a variable.
                type: bool
              order:
                description: Order of template param.
                type: int
              param_array:
                description: Is it an array.
                type: bool
              parameter_name:
                description: Name of template param.
                type: str
              provider:
                description: Provider.
                type: str
              range:
                description: Configuration Template Create's range.
                suboptions:
                  id:
                    description: UUID of range.
                    type: str
                  max_value:
                    description: Max value of range.
                    type: int
                  min_value:
                    description: Min value of range.
                    type: int
                type: list
                elements: dict
              required:
                description: Is param required.
                type: bool
              selection:
                description: Configuration Template Create's selection.
                suboptions:
                  default_selected_values:
                    description: Default selection values.
                    elements: str
                    type: list
                  id:
                    description: UUID of selection.
                    type: str
                  selection_type:
                    description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                    type: str
                  selection_values:
                    description: Selection values.
                    type: dict
                type: dict
            type: list
            elements: dict
          software_type:
            description: Applicable device software type. This field is mandatory
              to create a new template.
            type: str
          software_variant:
            description: Applicable device software variant.
            type: str
          software_version:
            description: Applicable device software version.
            type: str
          template_tag:
            description: Configuration Template Create's tags.
            suboptions:
              id:
                description: UUID of tag.
                type: str
              name:
                description: Name of tag.
                type: str
            type: list
            elements: dict
          template_content:
            description: Template content.
            type: str
          template_params:
            description: Configuration Template Create's templateParams.
            suboptions:
              binding:
                description: Bind to source.
                type: str
              custom_order:
                description: CustomOrder of template param.
                type: int
              data_type:
                description: Datatype of template param.
                type: str
              default_value:
                description: Default value of template param.
                type: str
              description:
                description: Description of template param.
                type: str
              display_name:
                description: Display name of param.
                type: str
              group:
                description: Group.
                type: str
              id:
                description: UUID of template param.
                type: str
              instruction_text:
                description: Instruction text for param.
                type: str
              key:
                description: Key.
                type: str
              not_param:
                description: Is it not a variable.
                type: bool
              order:
                description: Order of template param.
                type: int
              param_array:
                description: Is it an array.
                type: bool
              parameter_name:
                description: Name of template param.
                type: str
              provider:
                description: Provider.
                type: str
              range:
                description: Configuration Template Create's range.
                suboptions:
                  id:
                    description: UUID of range.
                    type: str
                  max_value:
                    description: Max value of range.
                    type: int
                  min_value:
                    description: Min value of range.
                    type: int
                type: list
                elements: dict
              required:
                description: Is param required.
                type: bool
              selection:
                description: Configuration Template Create's selection.
                suboptions:
                  default_selected_values:
                    description: Default selection values.
                    elements: str
                    type: list
                  id:
                    description: UUID of selection.
                    type: str
                  selection_type:
                    description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                    type: str
                  selection_values:
                    description: Selection values.
                    type: dict
                type: dict
            type: list
            elements: dict
          validation_errors:
            description: Configuration Template Create's validationErrors.
            suboptions:
              rollback_template_errors:
                description: Validation or design conflicts errors of rollback template.
                elements: dict
                type: list
              template_errors:
                description: Validation or design conflicts errors.
                elements: dict
                type: list
              template_id:
                description: UUID of template.
                type: str
              template_version:
                description: Current version of template.
                type: str
            type: dict
          version:
            description: Current version of template.
            type: str
          version_description:
            description: Template version comments.
            type: str
      export:
        description: Export the project/template details.
        type: dict
        suboptions:
          project:
            description: Export the project.
            type: list
            elements: str
          template:
            description: Export the template.
            type: list
            elements: dict
            suboptions:
              project_name:
                description: Name of the project under the template available.
                type: str
              template_name:
                description: Name of the template which we need to export
                type: str
      import:
        description: Import the project/template details.
        type: dict
        suboptions:
          project:
            description: Import the project details.
            type: dict
            suboptions:
              do_version:
                description: DoVersion query parameter. If this flag is true, creates
                  a new version of the template with the imported contents, if the
                  templates already exists. " If false and if template already exists,
                  then operation fails with 'Template already exists' error.
                type: bool
          template:
            description: Import the template details.
            type: dict
            suboptions:
              do_version:
                description: DoVersion query parameter. If this flag is true, creates
                  a new version of the template with the imported contents, if the
                  templates already exists. " If false and if template already exists,
                  then operation fails with 'Template already exists' error.
                type: bool
              payload:
                description: Configuration Template Import Template's payload.
                elements: dict
                suboptions:
                  author:
                    description: Author of template.
                    type: str
                  composite:
                    description: Is it composite template.
                    type: bool
                  containing_templates:
                    description: Configuration Template Import Template's containingTemplates.
                    elements: dict
                    suboptions:
                      composite:
                        description: Is it composite template.
                        type: bool
                      description:
                        description: Description of template.
                        type: str
                      device_types:
                        description: Configuration Template Import Template's deviceTypes.
                        elements: dict
                        suboptions:
                          product_family:
                            description: Device family.
                            type: str
                          product_series:
                            description: Device series.
                            type: str
                          product_type:
                            description: Device type.
                            type: str
                        type: list
                      id:
                        description: UUID of template.
                        type: str
                      language:
                        description: Template language (JINJA or VELOCITY).
                        type: str
                      name:
                        description: Name of template.
                        type: str
                      project_name:
                        description: Project name.
                        type: str
                      rollback_template_params:
                        description: Configuration Template Import Template's rollbackTemplateParams.
                        elements: dict
                        suboptions:
                          binding:
                            description: Bind to source.
                            type: str
                          custom_order:
                            description: CustomOrder of template param.
                            type: int
                          data_type:
                            description: Datatype of template param.
                            type: str
                          default_value:
                            description: Default value of template param.
                            type: str
                          description:
                            description: Description of template param.
                            type: str
                          display_name:
                            description: Display name of param.
                            type: str
                          group:
                            description: Group.
                            type: str
                          id:
                            description: UUID of template param.
                            type: str
                          instruction_text:
                            description: Instruction text for param.
                            type: str
                          key:
                            description: Key.
                            type: str
                          not_param:
                            description: Is it not a variable.
                            type: bool
                          order:
                            description: Order of template param.
                            type: int
                          param_array:
                            description: Is it an array.
                            type: bool
                          parameter_name:
                            description: Name of template param.
                            type: str
                          provider:
                            description: Provider.
                            type: str
                          range:
                            description: Configuration Template Import Template's
                              range.
                            elements: dict
                            suboptions:
                              id:
                                description: UUID of range.
                                type: str
                              max_value:
                                description: Max value of range.
                                type: int
                              min_value:
                                description: Min value of range.
                                type: int
                            type: list
                          required:
                            description: Is param required.
                            type: bool
                          selection:
                            description: Configuration Template Import Template's
                              selection.
                            suboptions:
                              default_selected_values:
                                description: Default selection values.
                                elements: str
                                type: list
                              id:
                                description: UUID of selection.
                                type: str
                              selection_type:
                                description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                                type: str
                              selection_values:
                                description: Selection values.
                                type: dict
                            type: dict
                        type: list
                      tags:
                        description: Configuration Template Import Template's tags.
                        elements: dict
                        suboptions:
                          id:
                            description: UUID of tag.
                            type: str
                          name:
                            description: Name of tag.
                            type: str
                        type: list
                      template_content:
                        description: Template content.
                        type: str
                      template_params:
                        description: Configuration Template Import Template's templateParams.
                        elements: dict
                        suboptions:
                          binding:
                            description: Bind to source.
                            type: str
                          custom_order:
                            description: CustomOrder of template param.
                            type: int
                          data_type:
                            description: Datatype of template param.
                            type: str
                          default_value:
                            description: Default value of template param.
                            type: str
                          description:
                            description: Description of template param.
                            type: str
                          display_name:
                            description: Display name of param.
                            type: str
                          group:
                            description: Group.
                            type: str
                          id:
                            description: UUID of template param.
                            type: str
                          instruction_text:
                            description: Instruction text for param.
                            type: str
                          key:
                            description: Key.
                            type: str
                          not_param:
                            description: Is it not a variable.
                            type: bool
                          order:
                            description: Order of template param.
                            type: int
                          param_array:
                            description: Is it an array.
                            type: bool
                          parameter_name:
                            description: Name of template param.
                            type: str
                          provider:
                            description: Provider.
                            type: str
                          range:
                            description: Configuration Template Import Template's
                              range.
                            elements: dict
                            suboptions:
                              id:
                                description: UUID of range.
                                type: str
                              max_value:
                                description: Max value of range.
                                type: int
                              min_value:
                                description: Min value of range.
                                type: int
                            type: list
                          required:
                            description: Is param required.
                            type: bool
                          selection:
                            description: Configuration Template Import Template's
                              selection.
                            suboptions:
                              default_selected_values:
                                description: Default selection values.
                                elements: str
                                type: list
                              id:
                                description: UUID of selection.
                                type: str
                              selection_type:
                                description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                                type: str
                              selection_values:
                                description: Selection values.
                                type: dict
                            type: dict
                        type: list
                      version:
                        description: Current version of template.
                        type: str
                    type: list
                  create_time:
                    description: Create time of template.
                    type: int
                  custom_params_order:
                    description: Custom Params Order.
                    type: bool
                  description:
                    description: Description of template.
                    type: str
                  device_types:
                    description: Configuration Template Import Template's deviceTypes.
                    elements: dict
                    suboptions:
                      product_family:
                        description: Device family.
                        type: str
                      product_series:
                        description: Device series.
                        type: str
                      product_type:
                        description: Device type.
                        type: str
                    type: list
                  failure_policy:
                    description: Define failure policy if template provisioning fails.
                    type: str
                  id:
                    description: UUID of template.
                    type: str
                  language:
                    description: Template language (JINJA or VELOCITY).
                    type: str
                  last_update_time:
                    description: Update time of template.
                    type: int
                  latest_version_time:
                    description: Latest versioned template time.
                    type: int
                  name:
                    description: Name of template.
                    type: str
                  parent_template_id:
                    description: Parent templateID.
                    type: str
                  project_id:
                    description: Project UUID.
                    type: str
                  project_name:
                    description: Project name.
                    type: str
                  rollback_template_content:
                    description: Rollback template content.
                    type: str
                  rollback_template_params:
                    description: Configuration Template Import Template's rollbackTemplateParams.
                    elements: dict
                    suboptions:
                      binding:
                        description: Bind to source.
                        type: str
                      custom_order:
                        description: CustomOrder of template param.
                        type: int
                      data_type:
                        description: Datatype of template param.
                        type: str
                      default_value:
                        description: Default value of template param.
                        type: str
                      description:
                        description: Description of template param.
                        type: str
                      display_name:
                        description: Display name of param.
                        type: str
                      group:
                        description: Group.
                        type: str
                      id:
                        description: UUID of template param.
                        type: str
                      instruction_text:
                        description: Instruction text for param.
                        type: str
                      key:
                        description: Key.
                        type: str
                      not_param:
                        description: Is it not a variable.
                        type: bool
                      order:
                        description: Order of template param.
                        type: int
                      param_array:
                        description: Is it an array.
                        type: bool
                      parameter_name:
                        description: Name of template param.
                        type: str
                      provider:
                        description: Provider.
                        type: str
                      range:
                        description: Configuration Template Import Template's range.
                        elements: dict
                        suboptions:
                          id:
                            description: UUID of range.
                            type: str
                          max_value:
                            description: Max value of range.
                            type: int
                          min_value:
                            description: Min value of range.
                            type: int
                        type: list
                      required:
                        description: Is param required.
                        type: bool
                      selection:
                        description: Configuration Template Import Template's selection.
                        suboptions:
                          default_selected_values:
                            description: Default selection values.
                            elements: str
                            type: list
                          id:
                            description: UUID of selection.
                            type: str
                          selection_type:
                            description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                            type: str
                          selection_values:
                            description: Selection values.
                            type: dict
                        type: dict
                    type: list
                  software_type:
                    description: Applicable device software type.
                    type: str
                  software_variant:
                    description: Applicable device software variant.
                    type: str
                  software_version:
                    description: Applicable device software version.
                    type: str
                  tags:
                    description: Configuration Template Import Template's tags.
                    elements: dict
                    suboptions:
                      id:
                        description: UUID of tag.
                        type: str
                      name:
                        description: Name of tag.
                        type: str
                    type: list
                  template_content:
                    description: Template content.
                    type: str
                  template_params:
                    description: Configuration Template Import Template's templateParams.
                    elements: dict
                    suboptions:
                      binding:
                        description: Bind to source.
                        type: str
                      custom_order:
                        description: CustomOrder of template param.
                        type: int
                      data_type:
                        description: Datatype of template param.
                        type: str
                      default_value:
                        description: Default value of template param.
                        type: str
                      description:
                        description: Description of template param.
                        type: str
                      display_name:
                        description: Display name of param.
                        type: str
                      group:
                        description: Group.
                        type: str
                      id:
                        description: UUID of template param.
                        type: str
                      instruction_text:
                        description: Instruction text for param.
                        type: str
                      key:
                        description: Key.
                        type: str
                      not_param:
                        description: Is it not a variable.
                        type: bool
                      order:
                        description: Order of template param.
                        type: int
                      param_array:
                        description: Is it an array.
                        type: bool
                      parameter_name:
                        description: Name of template param.
                        type: str
                      provider:
                        description: Provider.
                        type: str
                      range:
                        description: Configuration Template Import Template's range.
                        elements: dict
                        suboptions:
                          id:
                            description: UUID of range.
                            type: str
                          max_value:
                            description: Max value of range.
                            type: int
                          min_value:
                            description: Min value of range.
                            type: int
                        type: list
                      required:
                        description: Is param required.
                        type: bool
                      selection:
                        description: Configuration Template Import Template's selection.
                        suboptions:
                          default_selected_values:
                            description: Default selection values.
                            elements: str
                            type: list
                          id:
                            description: UUID of selection.
                            type: str
                          selection_type:
                            description: Type of selection(SINGLE_SELECT or MULTI_SELECT).
                            type: str
                          selection_values:
                            description: Selection values.
                            type: dict
                        type: dict
                    type: list
                  validation_errors:
                    description: Configuration Template Import Template's validationErrors.
                    suboptions:
                      rollback_template_errors:
                        description: Validation or design conflicts errors of rollback
                          template.
                        type: dict
                      template_errors:
                        description: Validation or design conflicts errors.
                        type: dict
                      template_id:
                        description: UUID of template.
                        type: str
                      template_version:
                        description: Current version of template.
                        type: str
                    type: dict
                  version:
                    description: Current version of template.
                    type: str
                type: list
              project_name:
                description: ProjectName path parameter. Project name to create template
                  under the project.
                type: str
requirements:
  - dnacentersdk == 2.4.5
  - python >= 3.9
notes:
  - SDK Method used are configuration_templates.ConfigurationTemplates.create_template,
    configuration_templates.ConfigurationTemplates.deletes_the_template, configuration_templates.ConfigurationTemplates.update_template,
    configuration_templates.ConfigurationTemplates.export_projects, configuration_templates.ConfigurationTemplates.export_templates,
    configuration_templates.ConfigurationTemplates.imports_the_projects_provided,
    configuration_templates.ConfigurationTemplates.imports_the_templates_provided,
  - Paths used are post /dna/intent/api/v1/template-programmer/project/{projectId}/template,
    delete /dna/intent/api/v1/template-programmer/template/{templateId}, put /dna/intent/api/v1/template-programmer/template,
    post /dna/intent/api/v1/template-programmer/project/name/exportprojects, post
    /dna/intent/api/v1/template-programmer/template/exporttemplates, post /dna/intent/api/v1/template-programmer/project/importprojects,
    post
    /dna/intent/api/v1/template-programmer/project/name/{projectName}/template/importtemplates,
a  
- name: Create a new template, export and import the project and template.
  cisco.dnac.template_intent:
    dnac_host: "{{dnac_host}}"
    dnac_username: "{{dnac_username}}"
    dnac_password: "{{dnac_password}}"
    dnac_verify: "{{dnac_verify}}"
    dnac_port: "{{dnac_port}}"
    dnac_version: "{{dnac_version}}"
    dnac_debug: "{{dnac_debug}}"
    dnac_log: true
    dnac_log_level: "{{dnac_log_level}}"
    state: merged
    config_verify: true
    config:
      - configuration_templates:
          author: string
          composite: true
          create_time: 0
          custom_params_order: true
          description: string
          device_types:
            - product_family: string
              product_series: string
              product_type: string
          failure_policy: string
          id: string
          language: string
          last_update_time: 0
          latest_version_time: 0
          name: string
          parent_template_id: string
          project_id: string
          project_name: string
          project_description: string
          rollback_template_content: string
          software_type: string
          software_variant: string
          software_version: string
          tags:
            - id: string
              name: string
          template_content: string
          validation_errors:
            rollback_template_errors:
              - {}
            template_errors:
              - {}
            template_id: string
            template_version: string
          version: string
        export:
          project:
            - string
          template:
            - project_name: string
              template_name: string
        import:
          project:
            do_version: true
          export:
            do_version: true
            payload:
              - author: string
                composite: true
                containing_templates:
                  - composite: true
                    description: string
                    device_types:
                      - product_family: string
                        product_series: string
                        product_type: string
                    id: string
                    language: string
                    name: string
                    project_name: string
                    rollback_template_params:
                      - binding: string
                        custom_order: 0
                        data_type: string
                        default_value: string
                        description: string
                        display_name: string
                        group: string
                        id: string
                        instruction_text: string
                        key: string
                        not_param: true
                        order: 0
                        param_array: true
                        parameter_name: string
                        provider: string
                        range:
                          - id: string
                project_name: string
a-  
# Case_1: Successful creation/updation/deletion of template/project
response_1:
  description: A dictionary with versioning details of the template as returned by the DNAC Python SDK
  returned: always
  type: dict
  sample: >
    {
      "response": {
                        "endTime": 0,
                        "version": 0,
                        "data": String,
                        "startTime": 0,
                        "username": String,
                        "progress": String,
                        "serviceType": String, "rootId": String,
                        "isError": bool,
                        "instanceTenantId": String,
                        "id": String
                        "version": 0
                  },
      "msg": String
    }
# Case_2: Error while deleting a template or when given project is not found
response_2:
  description: A list with the response returned by the Cisco DNAC Python SDK
  returned: always
  type: list
  sample: >
    {
      "response": [],
      "msg": String
    }
# Case_3: Given template already exists and requires no update
response_3:
  description: A dictionary with the exisiting template deatails as returned by the Cisco DNAC Python SDK
  returned: always
  type: dict
  sample: >
    {
      "response": {},
      "msg": String
    }
# Case_4: Given template list that needs to be exported
response_4:
  description: Details of the templates in the list as returned by the Cisco DNAC Python SDK
  returned: always
  type: dict
  sample: >
    {
      "response": {},
      "msg": String
    }
# Case_5: Given project list that needs to be exported
response_5:
  description: Details of the projects in the list as returned by the Cisco DNAC Python SDK
  returned: always
  type: dict
  sample: >
    {
      "response": {},
      "msg": String
    }
N)AnsibleModule)DnacBasevalidate_list_of_dictsget_dict_resultdnac_compare_equalityc                        e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Z  xZ!S ) DnacTemplatez=Class containing member attributes for template intent modulec                     t         |   |       i | _        i | _        ddg| _        ddg| _        g | _        | j                  d   j                  i        y )NmergeddeletedJINJAVELOCITYresponse)	super__init__have_projecthave_templatesupported_statesaccepted_languagesexport_templateresultappend)selfmodule	__class__s     n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/dnac/plugins/modules/template_intent.pyr   zDnacTemplate.__init__  sY     !)9 5#*J"7!J&&r*    c                    | j                   sd| _        d| _        | S i dddddidddid	dd
idddidddiddd
idddidddddiddiddiddddidddidddidddidddidddidddidddiddiddiddiddiddiddiddiddiddiddiddiddiddidddddddddiddidddddddd ddddi ddd!ddddidddid	dd
idddidddiddd
idddidddddiddiddiddddidddidddidddidddidddidddiddiddiddiddiddiddiddiddiddiddiddiddiddid"d#dd$}| j                  | j                         | _         t	        | j                   |      \  }}|r.d%j                  d&j                  |            | _        d'| _        | S || _        | j                  d(j                  |      d)       d*| _        d| _        | S )+a5  
        Validate the fields provided in the playbook.
        Checks the configuration provided in the playbook against a predefined specification
        to ensure it adheres to the expected structure and data types.
        Parameters:
            self: The instance of the class containing the 'config' attribute to be validated.
        Returns:
            The method returns an instance of the class with updated attributes:
                - self.msg: A message describing the validation result.
                - self.status: The status of the validation (either 'success' or 'failed').
                - self.validated_config: If successful, a validated version of 'config' parameter.
        Example:
            To use this method, create an instance of the class and call 'validate_input' on it.
            If the validation succeeds, 'self.status' will be 'success' and 'self.validated_config'
            will contain the validated configuration. If it fails, 'self.status' will be 'failed',
            'self.msg' will describe the validation issues.

        z0config not available in playbook for validattionsuccesstypedicttagslistauthorstr	compositeboolcontaining_templatescreate_timeintcustom_params_orderdescriptiondevice_types)r#   elementsproduct_familyproduct_seriesproduct_typefailure_policyidlanguagelast_update_timelatest_version_timenameparent_template_id
project_id)project_nameproject_descriptionrollback_template_contentrollback_template_paramssoftware_typesoftware_variantsoftware_versiontemplate_contenttemplate_paramstemplate_namevalidation_errorsversionversion_description)r#   r1   )r#   r1   r=   rF   )r#   projecttemplateFalser#   default)r#   
do_versionr1   )r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   )r#   rO   payload)configuration_templatesexportimportz#Invalid parameters in playbook: {0}
failedz2Successfully validated playbook config params: {0}INFOzSuccessfully validated input)	configmsgstatuscamel_to_snake_caser   formatjoinvalidated_configlog)r   	temp_spec
valid_tempinvalid_paramss       r   validate_inputzDnacTemplate.validate_input  s3   ( {{IDH#DKK%(%((%( 65/%( ff-	%(
 '(8%( %( &'7%( %( " &'-uo'-uo%+UO!%(  !65/!%(" vuo#%($ VUO%%(& #VUO'%(( &)%(* +%(, %vuo-%(. vuo/%(0 "((..4e_-3V,<"(%%+UO%+UO%+UO$*F#3"(%&,f%5"E?(.I%(N $*>" &%+UO&,e_		 "+0W"E
 #+0W"E% % "F%   0%  !65/	% 
 $ff%5%  /0@%  &%  ./?%  &%  '$*(./5uo/5uo-3UO)% " )65/#% $ vuo%% & #VUO'% ( +VUO)% * .+% , -% . -vuo/% 0 (.uo)/066<e_5;V4D*0%-3UO-3UO-3UO,2F+;*0%.4f-=$*E?I% )0cb
	H ..t{{;%;KK&
"
N <CC		.)+DH"DKK *ELLZXZ`a1r    c                 L    |j                  d      |j                  d      d}|S )a  
        Store project parameters from the playbook for template processing in DNAC.

        Parameters:
            params (dict) - Playbook details containing Project information.

        Returns:
            project_params (dict) - Organized Project parameters.
        r=   r>   )r:   r/   )get)r   paramsproject_paramss      r   get_project_paramszDnacTemplate.get_project_params  s,     #)**^"<)/4I)J r    c                 @   |yg }d}|D ]  }|j                  i        |j                  d      }|||   j                  d|i       |j                  d      }|||   j                  d|i       gdt        |      z   | _        d| _        | j                         c S  |S )a  
        Store tags from the playbook for template processing in DNAC.
        Check using check_return_status()

        Parameters:
            tags (dict) - Tags details containing Template information.

        Returns:
            tags (dict) - Organized tags parameters.
        Nr   r6   r:   z&name is mandatory in tags in location rU   )r   rd   updater(   rX   rY   check_return_status)r   _tagsr%   iitemr6   r:   s          r   get_tagszDnacTemplate.get_tags  s     = 	2DKKO$B~Qbz*88F#DQ~.Cc!fL&//11	2 r    c                    |yg }d}|D ]  }|j                  i        |j                  d      }|||   j                  d|i       n d| _        d| _        | j                         c S |j                  d      }|||   j                  d|i       |j                  d	      }|||   j                  d
|i       |dz   } |S )aO  
        Store device types parameters from the playbook for template processing in DNAC.
        Check using check_return_status()

        Parameters:
            device_types (dict) - Device types details containing Template information.

        Returns:
            deviceTypes (dict) - Organized device types parameters.
        Nr   r2   productFamilyz+product_family is mandatory for deviceTypesrU   r3   productSeriesr4   productType   )r   rd   ri   rX   rY   rj   )r   r0   deviceTypesrl   rm   r2   r3   r4   s           r   get_device_typeszDnacTemplate.get_device_types  s       	Dr"!XX&67N)A%%&GHH&//11!XX&67N)A%%&GH88N3L'A%%}l&CDAA!	$ r    c                 @   |yi }|j                  d      }||j                  d|i       |j                  d      }||j                  d|i       |j                  d      }||j                  d|i       |j                  d      }||j                  d	|i       |S )
a5  
        Store template parameters from the playbook for template processing in DNAC.

        Parameters:
            validation_errors (dict) - Playbook details containing validation errors information.

        Returns:
            validationErrors (dict) - Organized validation errors parameters.
        Nrollback_template_errorsrollbackTemplateErrorstemplate_errorstemplateErrorstemplate_id
templateIdtemplate_versiontemplateVersion)rd   ri   )r   rG   validationErrorsrw   ry   r{   r}   s          r   get_validation_errorsz"DnacTemplate.get_validation_errors  s     $#4#8#89S#T #/##(*B%  ,//0AB&## /%  (++M:"##k%  -001CD'##!#3%   r    c                    |yg }d}| j                  dj                  |      d       |D ]  }| j                  dj                  |      d       |j                  i        |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       |j                  d	      }|||   j	                  d
|i       |j                  d      }|||   j	                  d|i       |j                  d      }	|	||   j	                  d|	i       |j                  d      }
|
||   j	                  d|
i       |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       |j                  d      }|||   j	                  d|i       n d| _        d| _        | j                         c S |j                  d      }g d}|||   j	                  d|i       n d | _        d| _        | j                         c S ||vr,d!t        |      z   | _        d| _        | j                         c S |j                  d"      }|||   j	                  d"|i       |j                  d#      }| j                  d$j                  |      d       |+||   j	                  d#g i       ||   j                  d#      }| j                  d%j                  |      d       d}|D ]  }|j                  i        |j                  d      }|||   j	                  d|i       |j                  d&      }|||   j	                  d'|i       n"d(| _        d| _        | j                         c c S |j                  d)      }|||   j	                  d'|i       n"d*| _        d| _        | j                         c c S |d+z   } | j                  dj                  |      d       |j                  d,      }| j                  d-j                  |      d       |||   j	                  d,i i       ||   j                  d,      }|j                  d      }||j	                  d|i       |j                  d.      }||j	                  d/|i       |j                  d0      }||j	                  d1|i       |j                  d2      } | |j	                  d3| i       |d+z   } |S )4aS  
        Store template params from the playbook for template processing in DNAC.
        Check using check_return_status()

        Parameters:
            template_params (dict) - Playbook details containing template params information.

        Returns:
            templateParams (dict) - Organized template params parameters.
        Nr   zTemplate params details: {0}DEBUGzTemplate params items: {0}bindingcustom_ordercustomOrderdefault_valuedefaultValuer/   display_namedisplayNamegroupr6   instruction_textinstructionTextkey	not_paramnotParamorderparam_array
paramArrayproviderparameter_nameparameterNamez4parameter_name is mandatory for the template_params.rU   	data_type)STRINGINTEGER	IPADDRESS
MACADDRESSSECTIONDIVIDERdataTypez.dataType is mandatory for the template_params.z-data_type under template_params should be in requiredrangezTemplate params range list: {0}zTemplate params range: {0}	max_valuemaxValuez6max_value is mandatory for range under template_params	min_valuez6min_value is mandatory for range under template_paramsrs   	selectionzTemplate params selection: {0}default_selected_valuesdefaultSelectedValuesselection_valuesselectionValuesselection_typeselectionType)	r^   r[   r   rd   ri   rX   rY   rj   r(   )!r   rE   templateParamsrl   rm   r   r   r   r/   r   r   r6   r   r   r   r   r   r   r   r   	datatypesr   r   _rangejvaluer   r   r   
_selectionr   r   r   s!                                    r   get_template_infozDnacTemplate.get_template_info'  s    "/66GQ# ~	DHH188>H!!"%hhy)G"q!(()W)=>88N3L'q!((-)FG HH_5M(q!((.-)HI((=1K&q!((-)EF88N3L'q!((-)FGHHW%E q!(('5)9:$B~q!(($4#xx(:;+q!((*;=M)NO((5/Cq!((%6-I$q!((*i)@AHHW%E q!(('5)9:((=1K&q!((,)DExx
+H#q!((*h)?@!XX&67N)q!((/>)JKQ&//11-IZI$q!((*i)@AK&//11	)JSQZ^[&//11xx
+H#q!((*h)?@HHW%EHH6==eDgN q!(('27'*..w75<<VDgN" EMM"%4B~q	(($4 %		+ 6I ,q	((*i)@A#[&.#7799 %		+ 6I ,q	((*i)@A#[&.#7799AA'* HH3::>JGT-IHH5<<YGQ$q!((+r):;+A.22;?
]]4(>%%tRj1*3--8Q*R'*6%%'>@W&XY#,==1C#D #/%%'8:J&KL!*/?!@!-%%&GHAA}~	@ r    c                    |yg }d}|D ]  }|j                  i        |j                  d      }|%||   j                  d| j                  |      i       |j                  d      }|||   j                  d|i       |j                  d      }|||   j                  d|i       |j                  d      }|%||   j                  d| j	                  |      i       |j                  d      }	|	||   j                  d|	i       |j                  d	      }
|
 d
| _        d| _        | j                         c S ||   j                  d	|
i       |j                  d      }| d| _        d| _        | j                         c S ddg}||vr,dt        |      z   | _        d| _        | j                         c S ||   j                  d|i       |j                  d      }|||   j                  d|i       n d| _        d| _        | j                         c S |j                  d      }|%||   j                  d| j                  |      i       |j                  d      }|||   j                  d|i       |j                  d      }|%||   j                  d| j                  |      i       |j                  d      }|||   j                  d|i        |S )ah  
        Store tags from the playbook for template processing in DNAC.
        Check using check_return_status()

        Parameters:
            containing_templates (dict) - Containing tempaltes details
            containing Template information.

        Returns:
            containingTemplates (dict) - Organized containing templates parameters.
        Nr   r%   r)   r/   r0   rt   r6   r:   z,name is mandatory under containing templatesrU   r7   z0language is mandatory under containing templatesr   r   z1language under containing templates should be in r=   projectNamez4project_name is mandatory under containing templatesr@   rollbackTemplateParamsrD   templateContentrE   r   rH   )
r   rd   ri   rn   ru   rX   rY   rj   r(   r   )r   r+   containingTemplatesrl   rm   rk   r)   r/   r0   r6   r:   r7   language_listr=   r@   rD   rE   rH   s                     r   get_containing_templatesz%DnacTemplate.get_containing_templates  s'     ' ( H	DD&&r*HHV$E #A&--vt}}U7K.LM-I$#A&--{I.FG((=1K&#A&--}k.JK88N3L'#A&--!4#8#8#F/  $B~#A&--tRj988F#D|I&//11"))64.9xx
+HM&//11$j1M},NQTUbQcc&//11")):x*@A88N3L'#A&--}l.KLQ&//11'+xx0J'K$'3#A&--,d.D.DE].^/   $xx(:;+#A&--/@BR.ST"hh'89O*#A&--$d&<&<_&M/  hhy)G"#A&--y'.BCQH	DT #"r    c                    | j                  dj                  |      d       i d| j                  |j                  d            d|j                  d      d|j                  d      d| j	                  |j                  d            d	|j                  d
      d|j                  d      d|j                  d      d| j                  |j                  d            d|j                  d      d|j                  d      d|j                  d      j                         d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d       |j                  d!      | j                  |j                  d"            |j                  d#      |j                  d$      |j                  d%      |j                  d&      | j                  |j                  d'            | j                  |j                  d(            |j                  d)      |j                  d      d*
}| j                  d+j                  |      d       t        j                  |      }|D ]  }||   	||=  | j                  d+j                  |      d       |S ),a  
        Store template parameters from the playbook for template processing in DNAC.

        Parameters:
            params (dict) - Playbook details containing Template information.

        Returns:
            temp_params (dict) - Organized template parameters.
        z%Template params playbook details: {0}r   r%   template_tagr'   r)   r   r+   
createTimer,   customParamsOrderr.   r/   template_descriptionrt   r0   failurePolicyr5   r6   r7   lastUpdateTimer8   latestVersionTimer9   r:   rF   parentTemplateIdr;   	projectIdr<   r   r=   r?   r@   rA   rB   rC   rD   rE   rG   rH   )
rollbackTemplateContentr   softwareTypesoftwareVariantsoftwareVersionr   r   r   rH   r<   z&Formatted template params details: {0})r^   r[   rn   rd   r   ru   upperr   r   copydeepcopy)r   re   temp_paramscopy_temp_paramsrm   s        r   get_template_paramsz DnacTemplate.get_template_params  s    	8??GQ!
DMM&**^"<=!
fjj*!
 K0!
 "--fjj9O.PQ!
 &**]3!
  ,A!B!
 6::&<=!
 %%fjj&@A!
 VZZ(89!
 &**T"!
 

:.446!
 fjj);<!
  ,A!B!
  FJJ/!!
" 

+? @#!
$ L1%!
& 6::n5'!
( (.zz2M'N&&vzz2L'MN"JJ7%zz*<=%zz*<=%zz*<=&&vzz2C'DE**6::6I+JKzz), **\2A!
D 	9@@MwW==5$ 	&D4 (%	& 	9@@MwWr    c           	          d} | j                   d   dddd|j                  d      i      }|r|}| j                  d	j                  |      d
       || j                  d<   |S )a   
        Get the template needed for updation or creation.

        Parameters:
            config (dict) - Playbook details containing Template information.

        Returns:
            result (dict) - Template details for the given template ID.
        NexecrQ   get_template_detailsTr{   r|   familyfunctionop_modifiesre   z6Received API response from 'get_template_details': {0}r   r   )
dnac_applyrd   r^   r[   r   )r   rW   r   itemss       r   get_templatezDnacTemplate.get_templateO  sq     '',+!6::l#;<	
 FIPPQVWY`a"'Jr    c                    i }|j                  d      j                  d      }d}| j                  |      }|rt        |t              s"| j	                  dj                  |      d       y|d   j                  d      }||k7  r"| j	                  dj                  |      d       y|d   j                  d	      }d
|d<   |d   j                  d      |d<   |d   j                  d      |d<   || _        |S )a  
        Get the current project related information from DNAC.

        Parameters:
            config (dict) - Playbook details containing Project information.

        Returns:
            template_available (list) - Current project information.
        rQ   r=   Nz:Project: {0} not found, need to create new project in DNACrV   r   r:   z2Project {0} provided is not exact match in DNAC DB	templatesTproject_foundr6   isDeletable)rd   get_project_details
isinstancer&   r^   r[   r   )r   rW   r   given_projectNametemplate_availableproject_detailsfetched_projectNames          r   get_have_projectzDnacTemplate.get_have_projecth  s
    "JJ'@AEEnU! 223DE  J$EHHQf./9-a044V<"33HHIf./9,Q/33K@(,_%,Q/33D9T&5a&8&<&<]&K]#(!!r    c           	      |   |j                  d      j                  d      }|j                  d      j                  d      }d}i }d|d<   d|d<   t        |d|      }|sA| j                  d	j                  ||      d
       dj                  |      | _        d| _        | S |j                  d      |d<   |j                  d      |d<    | j                  d   dddd|j                  d      i      }d|d<   |r~t        |t              rnt        |d|      }	|	r_| j                  |      }||d<   d|d<   |duxr t        |t              |d<   | j                  dj                  |t        |            d
       | j                  dj                  ||j                  d            d
       || _        d| _        d| _        | S )a  
        Get the current template related information from DNAC.

        Parameters:
            config (dict) - Playbook details containing Template information.
            template_available (list) -  Current project information.

        Returns:
            self
        rQ   r=   rF   NFisCommitPendingtemplate_foundr:   z%Template {0} not found in project {1}rV   z2Template : {0} missing, new template to be createdr"   r6   r|   r   gets_the_templates_availableTprojectNamesr   r   rK   z3Template {0} is found and template details are :{1}z+Commit pending for template name {0} is {1}zGSuccessfully collected all template parameters from dnac for comparison)rd   r	   r^   r[   rX   rY   r   r   r&   r   r$   r(   r   )
r   rW   r   r   templateNamerK   r   template_detailstemplate_listtemplate_infos
             r   get_have_templatezDnacTemplate.get_have_template  s    jj!:;??Ozz";<@@Q+0'(*/&'*+=+1+79  HH<f\;7AKRRS_`DH#DKK/33D9|.2248d//,3"FJJ}$=>	
 ,0'(Zt<+M,2,8:M ,,V4,4j)38/02:$2F 33"8T2 ./ ,,2F<X,OQWY
 	 !6,0A0ABS0TUW]	_ +\r    c                     |j                  d      }|rF|j                  d      sd| _        d| _        | S | j                  |      }|r| j	                  ||       d| _        d| _        | S )z
        Get the current project and template details from DNAC.

        Parameters:
            config (dict) - Playbook details containing Project/Template information.

        Returns:
            self
        rQ   r=   z.Mandatory Parameter project_name not availablerU   zgSuccessfully collected all project and template                     parameters from dnac for comparisonr"   )rd   rX   rY   r   r   )r   rW   rQ   r   s       r   get_havezDnacTemplate.get_have  sr     #)**-F"G"*..~>K&!%!6!6v!>!&&v/AB9r    c                 <     | j                   d   dddd|i      }|S )z
        Get the details of specific project name provided.

        Parameters:
            projectName (str) - Project Name

        Returns:
            items (dict) - Project details with given project name.
        r   rQ   get_projectsTr:   r   )r   )r   r   r   s      r   r   z DnacTemplate.get_project_details  s1     (',#K(	
 r    c                 ~   i }|j                  d      }| j                  dj                  |      d       |rq| j                  |      }| j	                  |      }|j                  d      }| j
                  j                  d      dk(  r| j                  |       ||d<   ||d<   ||d	<   || _        d
| _        d| _	        | S )z
        Get all the template and project related information from playbook
        that is needed to be created in DNAC.

        Parameters:
            config (dict) - Playbook details.

        Returns:
            self
        rQ   zPlaybook details: {0}rV   rI   stater   rE   rf   commentszBSuccessfully collected all parameters from playbook for comparisonr"   )
rd   r^   r[   r   rg   re   update_mandatory_parameterswantrX   rY   )r   rW   r   rQ   rE   rf   version_commentss          r   get_wantzDnacTemplate.get_want  s     "(**-F"G(//7@""667NOO!445LMN6::;PQ{{w'8300A&5D"#%3D!"/D	$r    c                    d}d}| j                  dj                  | j                        d       | j                  j                  d      }| j                  j                  d      }|r'|}dj                  |j                  d            }d	}d
}	n&|}dj                  |j                  d            }d}d}	 | j                  d   d|	d|      }
t        |
t              s%| j                  dj                  |	      d       ||fS |
j                  d      j                  d      }|s&| j                  dj                  ||	      d       ||fS |sW| j                  |      }|s&| j                  dj                  |	|      d       ||fS | j                  dj                  |	|      d       |j                  d      r&| j                  dj                  |	|      d       ||fS ||j                  d      vr3| j                  dj                  |	|j                  d      |      d       |j                  d      }| j                  |      }||j                  d      }n|j                  d       }|s$| j                  d!j                  |	|      d       Hd}|r
||d"<   ||d#<   |sW| j                  d$j                  ||      d       ||fS )%a-  
        Call DNAC API to create project or template based on the input provided.

        Parameters:
            is_create_project (bool) - Default value is False.

        Returns:
            creation_id (str) - Project Id.
            created (str) - True if Project created, else False.
        NFDesired State (want): {0}rV   rE   rf   project: {0}r:   zSuccessfully created projectcreate_projectztemplate: {0}zSuccessfully created templatecreate_templater   rQ   Tr   z.Response of '{0}' is not in dictionary format.CRITICALr   taskIdz Task id {0} not found for '{1}'.z3Failed to get task details of '{0}' for taskid: {1}zTask details for {0}: {1}r   isErrorz)Error occurred for '{0}' with taskid: {1}ERRORprogressz)'{0}' progress set to {1} for taskid: {2}datar|   z4Export data is not found for '{0}' with taskid : {1}r   r<   zNew {0} created with id {1})	r^   r[   r   rd   r   r   r$   get_task_detailscheck_string_dictionary)r   is_create_projectcreation_idcreatedrE   rf   
params_keyr:   validation_stringcreation_valuer   task_idtask_detailstask_details_datar   s                  r   create_project_or_templatez'DnacTemplate.create_project_or_template  s    ,33DII>G))--(9:'78'J!((););F)CDD >-N(J"))/*=*=f*EFD ?.N*4??6*,#	
 (D)HHEf^,j:'',,z*..x8HH7>>wWYcd''009LN &9:G"G++HH077UW^_	*D &97D"G++ (8(8(DDD &1A1A*1MwWY`b , 0 0 8001BCE}*..v6#ii5O &97DG  0;,0;-E H 	.55dKH'RG##r    c                 @   | j                   j                  d      rJ| j                  dj                  | j                   j                  d      j                  d            d       y| j                   j                  d      | j                  j                  d      | j                  dj                        d	       | j                  d
j                        d	       dddddg fdddddg fddddddddddddg fddd d!d"d"g fd#d#i fd$g}t        fd%|D              S )&ak  
        Check if the template config given requires update.

        Parameters:
            self - Current object.

        Returns:
            bool - True if any parameter specified in obj_params differs between
            current_obj and requested_obj, indicating that an update is required.
            False if all specified parameters are equal.
        r   zGTemplate '{0}' is in saved state and needs to be updated and committed.rK   r:   r   TrE   Current State (have): {0}rV   r   )r%   r%    )r'   r'   r  )r)   r)   Fr   )r   r   r  )r   r   F)r/   r/   r  rt   )r   r   r  )r6   r6   r  )r7   r7   r   )r   r   r  )r   r   r  )r:   r:   r  )r   r   r  )r   r   r  )r   r   r  )r   r   r  r   )r   r   r  )r   r   r  )r   r   r  )r   r   r  r   r   )rH   rH   r  c              3   ~   K   | ]4  \  }}}t        j                  ||      j                  |              6 y w)N)r
   rd   ).0
dnac_paramansible_paramrN   current_objrequested_objs       r   	<genexpr>z/DnacTemplate.requires_update.<locals>.<genexpr>  sH      K;
M7 -[__Z-Q-:->->}-MO O Ks   :=)r   rd   r^   r[   r   any)r   
obj_paramsr  r  s     @@r   requires_updatezDnacTemplate.requires_updatep  sN    !!"34HH^fT//33J?CCFKLgW((,,Z8		&78,33K@&I,33MBFK $-"$92>,=.M2.204: 8*.F%'?D0666/4!3R8&5

:  K?IK K 	Kr    c                    | j                   j                  d      |d<   | j                   j                  d      |d<   |j                  d      s-| j                  j                  d      j                  d      |d<   |j                  d      s-| j                  j                  d      j                  d      |d<   |j                  d      s.| j                  j                  d      j                  d      |d<   yy)	z
        Update parameters which are mandatory for creating a template.

        Parameters:
            template_params (dict) - Template information.

        Returns:
            None
        r6   r   r<   r7   rK   rt   r   N)r   rd   r   )r   rE   s     r   r   z(DnacTemplate.update_mandatory_parameters  s     (,'8'8'<'<T'B$(,(9(9(=(=d(C%"":.*.*<*<*@*@*LZ J'""=1-1-?-?-C-CJ-O]# M*"">2.2.@.@.D.DZ.P^$ N+ 3r    c                 |   | j                   j                  d      }|j                  d      j                         }|r8|| j                  vr/dj	                  | j                  |      | _        d| _        | S d|d<   |s2|j                  d      r|j                  d      sd| _        d| _        | S d	| _        d
| _        | S )a  
        Validate input after getting all the parameters from DNAC.
        "If mandate like deviceTypes, softwareType and language "
        "already present in DNAC for a template."
        "It is not required to be provided in playbook, "
        "but if it is new creation error will be thrown to provide these fields.

        Parameters:
            template_exists (bool) - True if template exists, else False.

        Returns:
            None
        rE   r7   z<Invalid value language {0} .Accepted language values are {1}rU   r   rt   r   zGDeviceTypes and SoftwareType are required arguments to create TemplateszInput validated for mergingr"   )r   rd   r   r   r[   rX   rY   )r   template_existsrE   r7   s       r   validate_input_mergez!DnacTemplate.validate_input_merge  s     ))--(9:"&&z288:t666>"F4#:#:HE  '*1OJ'"&&}5%)).9d&0r    c                    | j                   j                  dd      }|D ]G  }|j                  d      }| j                  dj	                  |      d       |j                  d      }| j                  dj	                  |      d       t        |d	|      }| j                  d
j	                  ||      d       |j                  d      }| j                  d
j	                  ||      d       |j                  d      }t        |d	|      }| j                  dj	                  ||      d       |d| _        d| _        | c S | j                  j                  |j                  d             J d| _        d| _        | S )z
        Get the export template values from the details provided by the playbook.

        Parameters:
            export_values (bool) - All the template available under the project.

        Returns:
            self
        rQ   get_projects_details)r   r   r=   z%Project name for export template: {0}r   r   zTemplate details: {0}r:   z0Template details under the project name {0}: {1}r   rF   z,Template details with template name {0}: {1}z0Invalid project_name and template_name in exportrU   r6   z.Successfully collected the export template IDsr"   )
dnac_execrd   r^   r[   r	   rX   rY   r   r   )r   export_valuesr   valuesr=   all_template_detailsrF   template_details           r   get_export_template_valuesz'DnacTemplate.get_export_template_values  s     99??,+ + 
 $ 	CF!::n5LHH<CCLQSZ[/33J?HH,334DEwO#23C393?$A  HHGf\+?@'K#7#;#;K#H HHGf\+?@'K"JJ7M-.B.4.;=O HHCf]O<gG&M&  ''(;(;D(AB/	C2 Dr    c                    |j                  d      }|r| j                  j                  d      }|sI| j                  d      \  }}|r"| j                  dj	                  |      d       nd| _        d| _        | S | j                  j                  d	      }| j                  j                  d
      }| j                  dj	                  |      d       | j                  dj	                  | j                        d       d}d}	| j                  |      j                          |r9| j                         r| j                  j                  d      }|j                  d|i       | j                  dj	                  | j                        d       | j                  dj	                  | j                        d        | j                  d   ddd|      }
d}	| j                  dj	                  | j                  j                  d      j                  d            d       nu| j                  j                  | j                  j                  d      dd       d| _        | S |j                  d      r| j                         \  }}	nd| _        d| _        | S |	r4| j                  j                  d      |d} | j                  d   ddd|      }
|
j                  d       j                  d!      }|sd"j	                  |      | _        d| _        | S | j                  |      }d| j                  d#<   |j                  d$      | j                  d%<   |j                  d      | j                  d&<   | j                  d'j	                  |      d       |r|n|
| j                  d <   | j                  j                  d%      sd(| _        d| _        | S yyy))z
        Update/Create templates and projects in DNAC with fields provided in DNAC.

        Parameters:
            config (dict) - Playbook details containing template information.

        Returns:
            self
        rQ   r   T)r  z#project created with projectId: {0}r   rU   zProject creation failedr   rE   zDesired template details: {0}zCurrent template details: {0}NFr6   r  rV   r   r   update_templater   z!Updating existing template '{0}'.rK   r:   zTemplate does not need update)r   rX   exitedz)missing required arguments: template_namer   )r   r|   version_templater   r   zTask id: {0} not foundchangedr   rX   diffz(Task details for 'version_template': {0}z#Error while versioning the template)rd   r   r  r^   r[   rY   rX   r   r   r  rj   r  ri   r   r   r   )r   rW   rQ   is_project_foundr<   project_createdis_template_foundrE   r{   template_updatedr   version_paramsr  r	  s                 r   update_configuration_templatesz+DnacTemplate.update_configuration_templates	  s~    #)**-F"G"#0044_E#33d3K ,
O"HHBII*UW^_"*DK8DHK $ 2 2 6 67G H"iimm,=>OHH4;;OLgVHH4;;D<N<NOQXYK$%%&78LLN '')"&"4"4"8"8">K#**D++>?HH8??@R@RSU[\HH8??		JFS6tv68!2$(.	 H (,$HH@$fT%7%7%;%;J%G%K%KF%STV\^ KK&&$($6$6$:$::$F>(  #+DKK"&&v.484S4S4U1K!1JDH"*DKK !%		j 9"-" 34??624/ $)	 #,,z266x@7>>wGDH"*DKK#44W=)-I&%1%5%5j%AE"&,jj1J&KF#CJJ<XZab:F,HJ'{{u-DDH"*DKK .1  e #r    c                 (   |j                  d      }|r}|j                  d      }| j                  dj                  |      d       |rq| j                  j	                  dddd|i	      }d
}| j                  ||d      j                          | j                  d   d   j                  d| j                  i       |j                  d      }|r| j                  |      j                          | j                  dj                  | j                        d       | j                  j	                  dddd| j                  i	      }d}| j                  ||d      j                          | j                  d   d   j                  d| j                  i       | S )z
        Export templates and projects in DNAC with fields provided in DNAC.

        Parameters:
            config (dict) - Playbook details containing template information.

        Returns:
            self
        rR   rJ   z$Export project playbook details: {0}r   rQ   export_projectsTrP   r   zsuccessfully exported projectr   r   exportProjectrK   z(Exporting template playbook details: {0}export_templateszsuccessfully exported templateexportTemplate)rd   r^   r[   r  r   check_task_response_statusrj   r   ri   rX   r%  r   )r   rW   rR   export_projectr   r  r!  s          r   handle_exportzDnacTemplate.handle_exportn	  s    H%#ZZ	2NHH;f^,g799??4. $%~6	 +  %D!//0A0466I6I6KJ'*11?DHH2MN"JJz2M//>RRTC &!5!56A99??4/ $%t';';<	 +  %E!//0A0466I6I6KJ'*113CTXX2NOr    c                 h   |j                  d      }|r|j                  d      j                  d      }d}|j                  d      j                  d      r!|j                  d      j                  d      }nd| _        d| _        | S ||d}| j                  d	j	                  |      d
       |rd| j
                  j                  ddd|      }d}| j                  ||      j                          | j                  d   d   j                  d|i       |j                  d      }|j                  d      rd| _        d| _        | S |j                  d      rd| _        d| _        | S |j                  d      }|j                  d      |j                  d      | j                  |      d}	| j                  dj	                  |      d
       |rd| j
                  j                  ddd|	      }d}| j                  ||      j                          | j                  d   d   j                  d|i       | S )z
        Import templates and projects in DNAC with fields provided in DNAC.

        Parameters:
            config (dict) - Playbook details containing template information.

        Returns:
            self
        rS   rJ   rO   NrP   z=Mandatory parameter payload is not found under import projectrU   )	doVersionrP   z0Importing project details from the playbook: {0}r   rQ   imports_the_projects_providedTr   zsuccessfully imported projectr   r   importProjectrK   r=   zBMandatory paramter project_name is not found under import templatez=Mandatory paramter payload is not found under import template)r;  r   rP   z.Import template details from the playbook: {0}imports_the_templates_providedzsuccessfully imported templateimportTemplate)rd   rX   rY   r^   r[   r  r   r7  rj   r   ri   r   )
r   rW   _importrO   rP   _import_projectr   r  _import_templateimport_templates
             r   handle_importzDnacTemplate.handle_import	  s,    **X& Y/33LAJG{{9%)))4!++i044Y?Z&'"O
 HHGf_-w899??4< $*	 +  %D!//:KL``bJ'*11?DU2VW&{{:6##N3_&##I.Z&&**>:G-11,?/33NC33G<O
 HHEf-.999??4= $*	 +  %E!//:KL``bJ'*113CEV2WXr    c                     | j                  |       | j                  dk(  r| S | j                  |       | j                  dk(  r| S | j                  |       | j                  dk(  r| S d| _        d| _        | S )ac  
        Update/Create templates and projects in DNAC with fields provided in DNAC.
        Export the tempaltes and projects.
        Import the templates and projects.
        Check using check_return_status().

        Parameters:
            config (dict) - Playbook details containing template information.

        Returns:
            self
        rU   z-Successfully completed merged state executionr"   )r1  rY   r9  rD  rX   )r   rW   s     r   get_diff_mergedzDnacTemplate.get_diff_merged	  st     	++F3;;("K6";;("K6";;("KBr    c                 |   |rOd| j                   j                  d      i}d}dj                  |j                  d      j                  d            }nZ| j                  j                  d      }d| j                  j                  d      i}d	}d
j                  |j                  d            } | j
                  d   d|d|      }|j                  d      j                  d      }|r| j                  |      }	d| j                  d<   |	j                  d      | j                  d<   |j                  d      | j                  d<   | j                  dj                  ||	      d       |	r|	n|| j                  d<   | j                  d   sd| j                  d<   d| _	        | S dj                  |      | _
        d| _	        | S )a/  
        Call DNAC API to delete project or template with provided inputs.

        Parameters:
            config (dict) - Playbook details containing template information.
            is_delete_project (bool) - True if we need to delete project, else False.

        Returns:
            self
        r<   r6   deletes_the_projectr   rQ   r=   rE   r{   deletes_the_templateztemplateName: {0}r   r   Tr   r   r   r*  r   rX   r+  zTask details for '{0}': {1}r   zError while deleting {name} : rU   zSuccessfully deleted {0} r"   )r   rd   r[   r   r   r   r   r   r^   rY   rX   )
r   rW   is_delete_projectr  deletion_valuer:   rE   r   r  r	  s
             r   delete_project_or_templatez'DnacTemplate.delete_project_or_template
  s    &(9(9(=(=d(CDJ2N!((4M)N)R)RSa)bcD"iimm,=>O'););)?)?)EFJ3N&--o.A.A..QRD*4??6*,#	
 ,,z*..x8009L%)DKK	"!-!1!1*!=DKK"(**-F"GDKKHH299.,WY`a6BlDKK
#;;u%%EE"&.55d;r    c                 6   |j                  d      }|rv| j                  j                  d      }|j                  d      j                  d      }|sdj                  |      | _        d| _        | S | j
                  j                  d      }| j                  j                  d      }|j                  d      j                  d      }|j                  d	      r3|r| j                  |       nd
j                  |      | _        d| _        | S | j                  dj                  |j                  d      j                  d            d       | j                  j                  d      }|r| j                  |d       nd| _        d| _        | S d| _        d| _        | S )z
        Delete projects or templates in DNAC with fields provided in playbook.

        Parameters:
            config (dict) - Playbook details containing template information.

        Returns:
            self
        rQ   r   r=   zProject {0} is not foundrU   r   rE   rF   r:   z"Invalid template {0} under projectzKTemplate name is empty, deleting the project '{0}' and associated templatesrV   r   T)rJ  zProject is not deletablez-Successfully completed delete state executionr"   )	rd   r   r[   rX   rY   r   r   rL  r^   )	r   rW   rQ   r,  r   r.  rE   r   is_project_deletables	            r   get_diff_deletedzDnacTemplate.get_diff_deleted1
  st    #)**-F"G"#0044_E **%>?CCNSK#5<<[I& $ 2 2 6 67G H"iimm,=>O!::&?@DD_UL""6*$33F;CJJ<XDH"*DKK 0 &,E!F!J!J>!Z[]ce (,'8'8'<'<]'K$'33Fd3S9DH"*DKKBr    c                 :   |j                  d      z| j                  |      }| j                  dj                  |      d       |sd| _        d| _        | S | j                  ||       | j                  dj                  | j                  j                  d            d       | j                  dj                  | j                  j                  d	            d       g d
}|D ]i  }| j                  j                  d	      j                  |      | j                  j                  d      j                  |      k7  sYd| _        d| _        | c S  | j                  dd       | j                  j                  d      j                  ddi       d| _        d| _        | S )a9  
        Validating the DNAC configuration with the playbook details
        when state is merged (Create/Update).

        Parameters:
            config (dict) - Playbook details containing Global Pool,
            Reserved Pool, and Network Management configuration.

        Returns:
            self
        rQ   zTemplate availability: {0}rV   9Configuration Template config is not applied to the DNAC.rU   r  rE   r   rK   )r7   r:   r   r   r   r   z: Configuration Template config is not applied to the DNAC.z;Successfully validated the Template in the Catalyst Center.r   
ValidationSuccessz3Successfully validated the Configuration Templates.r"   )rd   r   r^   r[   rX   rY   r   r   r   r   ri   )r   rW   is_template_availablerE   rm   s        r   verify_diff_mergedzDnacTemplate.verify_diff_merged`
  sj    ::/0<$($9$9&$A!HH1889NOQWX(V&""6+@AHH077		FW8XY[abHH0778J8J8N8Nz8Z[]cdEO'  %%))*599$?499==QbCcCgCghlCmm[DH"*DKK	 
 HHRTZ[KKOOJ'..i/HIHr    c           	      d   |j                  d      | j                  dj                  | j                        d       | j                  dj                  | j                        d        | j
                  d   dddd|j                  d	      i
      }|rOt        |t              r?|j                  d      j                  d      }t        |d|      }|rd| _	        d| _
        | S | j                  dd       | j                  j                  d      j                  ddi       d| _	        d| _
        | S )a3  
        Validating the DNAC configuration with the playbook details
        when state is deleted (delete).

        Parameters:
            config (dict) - Playbook details containing Global Pool,
            Reserved Pool, and Network Management configuration.

        Returns:
            self
        rQ   r  rV   r   r   r   Tr   r   r   rF   r:   rQ  rU   zBSuccessfully validated absence of template in the Catalyst Center.r   rR  rS  z;Successfully validated the absence of Template in the DNAC.r"   )rd   r^   r[   haver   r   r   r&   r	   rX   rY   r   ri   )r   rW   r   r   r   s        r   verify_diff_deletedz DnacTemplate.verify_diff_deleted
  s    ::/0<HH077		BFKHH077		BFK3DOOF307 &

=(AB	M M4!@%zz*CDHHY /060<!> !ZDH"*DKKHHY[abKKOOJ'..i/HIPr    c                     | j                   j                          | j                  j                          | j                  j                          y)z
        Reset all neccessary attributes to default values.

        Parameters:
            self - The current object.

        Returns:
            None
        N)r   clearr   r   )r   s    r   reset_valueszDnacTemplate.reset_values
  s6     	!  "		r    )F)"__name__
__module____qualname____doc__r   rb   rg   rn   ru   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r%  r1  r9  rD  rF  rL  rO  rU  rX  r[  __classcell__)r   s   @r   r   r     s    G+KZ B#J' RRh\#|4l2$"L?B2&BR$h5Kn%4$L*XY v.`EN<,\-^$L%Nr    r   c                     i ddddddddddd	d
gdddddddddddddddddddddddddddddddddddddddddddddd dd!dd"dd#d$d%d&d'd'd(gd)} t        | d*      }t        |      }|j                         j                          |j                  j                  d&      }|j                  j                  d      }||j                  vr-d+|_        d,j                  |      |_	        |j                          |j                  D ]  }|j                          |j                  |      j                          |j                  |      j                           |j                  |   |      j                          |sw |j                  |   |      j                            |j                   d.i |j"                   y-)/z& main entry point for module execution	dnac_hostTr(   )r   r#   	dnac_port443rM   dnac_usernameadminuser)r#   rN   aliasesdnac_password)r#   no_logdnac_verifyr*   Truednac_versionz2.2.3.3
dnac_debugFdnac_logdnac_log_levelWARNINGdnac_log_file_pathzdnac.logdnac_log_appendvalidate_response_schemaconfig_verifydnac_api_task_timeoutr-   i  dnac_task_poll_interval   rW   r&   r$   )r   r#   r1   r   r   r   )rN   choices)argument_specsupports_check_modeinvalidzState {0} is invalidN )r   r   rb   rj   re   rd   r   rY   r[   rX   r]   r[  r   r   get_diff_state_applyverify_diff_state_apply	exit_jsonr   )element_specr   dnac_templater   ru  rW   s         r   mainr  
  sl   KdE!B %E!B#eU[T\%] $et%D "Fv#F	
 #Uy$I !6e"D E B %u&K )5Z*P &4'H /D0Q $f%G ,e-M .!/L 4VT  x>ST!L$ /46F (M  "668  $$W-E!((,,_=MM222(299%@))+00 W""$v&::<v&::<1**51&9MMO8M11%8@TTVW F,}++,r    __main__)r_  
__future__r   r   r   r#   __metaclass__
__author__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   8ansible_collections.cisco.dnac.plugins.module_utils.dnacr   r   r	   r
   r   r  r\  r}  r    r   <module>r     ss   
 M @ @YZ
Zv"_@?
B  4 k8 k\-(-V zF r    