
    Vh                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ 	 d dlZdZd Zedk(  r e        yy# e$ r dZY w xY w)    )absolute_importdivisionprint_functionaq  
module: grpc_get
version_added: "3.1.0"
author:
    - "Ganesh Nalawade (@ganeshrn)"
    - "Gomathi Selvi S (@GomathiselviS)"
short_description: Fetch configuration/state data from gRPC enabled target hosts.
description:
    - gRPC is a high performance, open-source universal RPC framework.
    - This module allows the user to fetch configuration and state data from gRPC
      enabled devices.
options:
  section:
    description:
      - This option specifies the string which acts as a filter to restrict the portions of
        the data to be retrieved from the target host device. If this option is not specified the entire
        configuration or state data is returned in response provided it is supported by target host.
    aliases:
    - filter
    type: str
  command:
    description:
      - The option specifies the command to be executed on the target host and return the response
        in result. This option is supported if the gRPC target host supports executing CLI command
        over the gRPC connection.
    type: str
  display:
    description:
      - Encoding scheme to use when serializing output from the device. The encoding scheme
        value depends on the capability of the gRPC server running on the target host.
        The values can be I(json), I(text) etc.
    type: str
  data_type:
    description:
      - The type of data that should be fetched from the target host. The value depends on the
        capability of the gRPC server running on target host. The values can be I(config), I(oper)
        etc. based on what is supported by the gRPC server. By default it will return both configuration
        and operational state data in response.
    type: str
requirements:
  - grpcio
  - protobuf
notes:
  - This module requires the gRPC system service be enabled on
    the target host being managed.
  - This module supports the use of connection=ansible.netcommon.grpc.
  - This module requires the value of 'ansible_network_os or grpc_type' configuration option (refer ansible.netcommon.grpc
    connection plugin documentation) be defined as an inventory variable.
  - Tested against iosxrv 9k version 6.1.2.
z
- name: Get bgp configuration data
  grpc_get:
    section:
      Cisco-IOS-XR-ip-static-cfg:router-static:
        - null
- name: run cli command
  grpc_get:
    command: "show version"
    display: text
a  
stdout:
  description: The raw string containing configuration or state data
               received from the gRPC server.
  returned: always apart from low-level errors (such as action plugin)
  type: str
  sample: '...'
stdout_lines:
  description: The value of stdout split into a list
  returned: always apart from low-level errors (such as action plugin)
  type: list
  sample: ['...', '...']
output:
  description: A dictionary representing a JSON-formatted response, if the response
               is a valid json string
  returned: when the device response is valid JSON
  type: list
  sample: |
        [{
            "Cisco-IOS-XR-ip-static-cfg:router-static": {
                "default-vrf": {
                    "address-family": {
                        "vrfipv4": {
                            "vrf-unicast": {
                                "vrf-prefixes": {
                                    "vrf-prefix": [
                                        {
                                            "prefix": "0.0.0.0",
                                            "prefix-length": 0,
                                            "vrf-route": {
                                                "vrf-next-hop-table": {
                                                    "vrf-next-hop-interface-name-next-hop-address": [
                                                        {
                                                            "interface-name": "MgmtEth0/RP0/CPU0/0",
                                                            "next-hop-address": "10.0.2.2"
                                                        }
                                                    ]
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        }]
N)to_text)AnsibleModule)ConnectionError)to_list)getget_capabilitiesrun_cliTFc                     t        t        ddg      t        d      t        d      t        d            } ddgg}t        | |d	      }t        |      }|d
   }|j                  d   r6t	        j
                  t        j                  |j                  d               }nd}|j                  d   }|j                  d   }|j                  d   }|j                  dg       }	|r,||	vr(|j                  d|d|	j                  d      d       |r'|j                  dd      s|j                  d|z         |j                  dg       }
|r+||
vr'|j                  d|d|
j                  d             ddi}g }	 |rt        |||      \  }}nt        |||      \  }}	 t	        j                  |      }|d<   |rt%        |      |d<   nt%        |      |d<    |j&                  di | y# t        $ r |j                  t        |d             Y ^w xY w# t         $ r2}|j                  t        |d      |j"                         Y d}~d}~ww xY w) z entry point for module executionstrfilter)typealiases)r   )sectioncommanddisplay	data_typer   r   T)argument_specmutually_exclusivesupports_check_modeserver_capabilitiesNr   r   zdisplay option 'z?' is not supported on this target host. Valid value is one of 'z, ')msgsupports_cli_commandFz8command option '%s' is not supported on this target hostzdata_type option 'z>' is not supported on this target host. Valid value is one of ,changedsurrogate_then_replace)errors)r   codestdoutoutput )dictr   r   paramsjsondumpsyaml	safe_loadr
   	fail_jsonjoinr   loads
ValueErrorwarnr   r   r!   r	   	exit_json)r   r   modulecapabilities
operationsr   r   r   r   supported_displaysupported_data_typeresultr#   responseerrexcs                   n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/ansible/netcommon/plugins/modules/grpc_get.pymainr;      sj   %(4% % E"	M %i01#- F
 $F+L34J}}Y**T^^FMM),DEFmmI&GmmI&Gk*I"y"57"33)..t46 	 	

 z~~&<eDWZaab$..b9Y&99-22379 	 	

 FF[#FGW=MHc;MHc	GZZ)F  F8"6?x"8,xFv  	GKK,DEF	G  [WS1IJQTQYQYZZ[s6    #H $G0 0%HH HH 	I$(II__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr'   ansible.module_utils._textr   ansible.module_utils.basicr   ansible.module_utils.connectionr   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr	   Lansible_collections.ansible.netcommon.plugins.module_utils.network.grpc.grpcr
   r   r   r)   HAS_YAMLImportErrorr;   __name__r$       r:   <module>rK      s    A @ 1f
0
b  . 4 ; c H
AH zF Q  Hs   A AA