Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/network/netscaler/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyo

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
mZddlm
Z
dd
lmZddlZdefd��YZd�Zedkr�e�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�
---
module: netscaler_nitro_request
short_description: Issue Nitro API requests to a Netscaler instance.
description:
    - Issue Nitro API requests to a Netscaler instance.
    - This is intended to be a short hand for using the uri Ansible module to issue the raw HTTP requests directly.
    - It provides consistent return values and has no other dependencies apart from the base Ansible runtime environment.
    - This module is intended to run either on the Ansible control node or a bastion (jumpserver) with access to the actual Netscaler instance


version_added: "2.5.0"

author: George Nikolopoulos (@giorgos-nikolopoulos)

options:

    nsip:
        description:
            - The IP address of the Netscaler or MAS instance where the Nitro API calls will be made.
            - "The port can be specified with the colon C(:). E.g. C(192.168.1.1:555)."

    nitro_user:
        description:
            - The username with which to authenticate to the Netscaler node.
        required: true

    nitro_pass:
        description:
            - The password with which to authenticate to the Netscaler node.
        required: true

    nitro_protocol:
        choices: [ 'http', 'https' ]
        default: http
        description:
            - Which protocol to use when accessing the Nitro API objects.

    validate_certs:
        description:
            - If C(no), SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.
        default: 'yes'
        type: bool

    nitro_auth_token:
        description:
            - The authentication token provided by the C(mas_login) operation. It is required when issuing Nitro API calls through a MAS proxy.

    resource:
        description:
            - The type of resource we are operating on.
            - It is required for all I(operation) values except C(mas_login) and C(save_config).

    name:
        description:
            - The name of the resource we are operating on.
            - "It is required for the following I(operation) values: C(update), C(get), C(delete)."

    attributes:
        description:
            - The attributes of the Nitro object we are operating on.
            - "It is required for the following I(operation) values: C(add), C(update), C(action)."

    args:
        description:
            - A dictionary which defines the key arguments by which we will select the Nitro object to operate on.
            - "It is required for the following I(operation) values: C(get_by_args), C('delete_by_args')."

    filter:
        description:
            - A dictionary which defines the filter with which to refine the Nitro objects returned by the C(get_filtered) I(operation).

    operation:
        description:
            - Define the Nitro operation that we want to perform.
        choices:
            - add
            - update
            - get
            - get_by_args
            - get_filtered
            - get_all
            - delete
            - delete_by_args
            - count
            - mas_login
            - save_config
            - action

    expected_nitro_errorcode:
        description:
            - A list of numeric values that signify that the operation was successful.
        default: [0]
        required: true

    action:
        description:
            - The action to perform when the I(operation) value is set to C(action).
            - Some common values for this parameter are C(enable), C(disable), C(rename).

    instance_ip:
        description:
            - The IP address of the target Netscaler instance when issuing a Nitro request through a MAS proxy.

    instance_name:
        description:
            - The name of the target Netscaler instance when issuing a Nitro request through a MAS proxy.

    instance_id:
        description:
            - The id of the target Netscaler instance when issuing a Nitro request through a MAS proxy.
sD
- name: Add a server
  delegate_to: localhost
  netscaler_nitro_request:
    nsip: "{{ nsip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: add
    resource: server
    name: test-server-1
    attributes:
      name: test-server-1
      ipaddress: 192.168.1.1

- name: Update server
  delegate_to: localhost
  netscaler_nitro_request:
    nsip: "{{ nsip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: update
    resource: server
    name: test-server-1
    attributes:
      name: test-server-1
      ipaddress: 192.168.1.2

- name: Get server
  delegate_to: localhost
  register: result
  netscaler_nitro_request:
    nsip: "{{ nsip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: get
    resource: server
    name: test-server-1

- name: Delete server
  delegate_to: localhost
  register: result
  netscaler_nitro_request:
    nsip: "{{ nsip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: delete
    resource: server
    name: test-server-1

- name: Rename server
  delegate_to: localhost
  netscaler_nitro_request:
    nsip: "{{ nsip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: action
    action: rename
    resource: server
    attributes:
      name: test-server-1
      newname: test-server-2

- name: Get server by args
  delegate_to: localhost
  register: result
  netscaler_nitro_request:
    nsip: "{{ nsip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: get_by_args
    resource: server
    args:
      name: test-server-1

- name: Get server by filter
  delegate_to: localhost
  register: result
  netscaler_nitro_request:
    nsip: "{{ nsip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: get_filtered
    resource: server
    filter:
      ipaddress: 192.168.1.2

# Doing a NITRO request through MAS.
# Requires to have an authentication token from the mas_login and used as the nitro_auth_token parameter
# Also nsip is the MAS address and the target Netscaler IP must be defined with instance_ip
# The rest of the task arguments remain the same as when issuing the NITRO request directly to a Netscaler instance.

- name: Do mas login
  delegate_to: localhost
  register: login_result
  netscaler_nitro_request:
    nsip: "{{ mas_ip }}"
    nitro_user: "{{ nitro_user }}"
    nitro_pass: "{{ nitro_pass }}"
    operation: mas_login

- name: Add resource through MAS proxy
  delegate_to: localhost
  netscaler_nitro_request:
    nsip: "{{ mas_ip }}"
    nitro_auth_token: "{{ login_result.nitro_auth_token }}"
    instance_ip: "{{ nsip }}"
    operation: add
    resource: server
    name: test-server-1
    attributes:
      name: test-server-1
      ipaddress: 192.168.1.7
sI
nitro_errorcode:
    description: A numeric value containing the return code of the NITRO operation. When 0 the operation is successful. Any non zero value indicates an error.
    returned: always
    type: int
    sample: 0

nitro_message:
    description: A string containing a human readable explanation for the NITRO operation result.
    returned: always
    type: str
    sample: Success

nitro_severity:
    description: A string describing the severity of the NITRO operation error or NONE.
    returned: always
    type: str
    sample: NONE

http_response_data:
    description: A dictionary that contains all the HTTP response's data.
    returned: always
    type: dict
    sample: "status: 200"

http_response_body:
    description: A string with the actual HTTP response body content if existent. If there is no HTTP response body it is an empty string.
    returned: always
    type: str
    sample: "{ errorcode: 0, message: Done, severity: NONE }"

nitro_object:
    description: The object returned from the NITRO operation. This is applicable to the various get operations which return an object.
    returned: when applicable
    type: list
    sample:
        -
            ipaddress: "192.168.1.8"
            ipv6address: "NO"
            maxbandwidth: "0"
            name: "test-server-1"
            port: 0
            sp: "OFF"
            state: "ENABLED"

nitro_auth_token:
    description: The token returned by the C(mas_login) operation when successful.
    returned: when applicable
    type: str
    sample: "##E8D7D74DDBD907EE579E8BB8FF4529655F22227C1C82A34BFC93C9539D66"
(t	fetch_url(tenv_fallback(t
AnsibleModuleNtNitroAPICallerc*B`s3eZedededgf�dededgf�dededgfde�ded	d
dgdedgfd
d
�ded
edd�deddde�dedd�dedd�dedd�dedd�dedd�deddded	dddddd d!d"d#d$d%d&g�d'edd(d
d)g�d&edd�d*edd�d+edd�d,edd��Zd-�Zd.�Zd/�Zd0�Z	d1�Z
d2�Zd3�Zd4�Z
d5�Zd6�Zd7�Zd8�Zd9�Zd:�Zd;�Zd<�Zd=�Zd>�ZRS(?tnsiptfallbacktNETSCALER_NSIPt
nitro_usertNETSCALER_NITRO_USERt
nitro_passtNETSCALER_NITRO_PASStno_logtnitro_protocoltchoicesthttpthttpstNETSCALER_NITRO_PROTOCOLtdefaulttvalidate_certsttypetbooltnitro_auth_tokentstrtresourcetnamet
attributestdicttargstfiltert	operationtrequiredtaddtupdatetgettget_by_argstget_filteredtget_alltdeletetdelete_by_argstcountt	mas_logintsave_configtactiontexpected_nitro_errorcodetlistitinstance_ipt
instance_nametinstance_idcC`s�td|jdt�|_tdt�|_i|_d|jd<|jjddk	}d|jjd|jjdfk}|jjd	d
k}|r�|r�|j	dd�n|r�d
|jjd|jd<n|r|r|jjd|jd<|jjd|jd<n|jjddk	rF|jjd|jd<n`|jjddk	rv|jjd|jd<n0|jjddk	r�|jjd|jd<ndS(Nt
argument_spectsupports_check_modetfailedsapplication/jsonsContent-TypeRRRR%R0tmsgs=Cannot define both authentication token and username/passwordsNITRO_AUTH_TOKEN=%stCookiesX-NITRO-USERsX-NITRO-PASSR5t"_MPS_API_PROXY_MANAGED_INSTANCE_IPR6t$_MPS_API_PROXY_MANAGED_INSTANCE_NAMER7t"_MPS_API_PROXY_MANAGED_INSTANCE_ID(
R
t_argument_spectFalset_moduleR"t_module_resultt_headerstparamstNonetfail_module(tselft
have_tokent
have_userpasstlogin_operation((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyt__init__os.		
&
cC`s�|dk	r+tj|j�d�|d<n:d|kr[tj|dd�|d<|d=n
d|d<||d<d|d<d|d<d|d<|ddkr
y|jj|d�}Wntk
r�i}nX|jd	�|d<|jd
�|d<|jd�|d<n|ddkr�|djd�|krsd
|d<|djdd|dd�|d<d|d<q�d|d<d|d<d|d<ndS(Nsutf-8thttp_response_bodytbodytthttp_response_datatnitro_errorcodet
nitro_messagetnitro_severityt	errorcodetmessagetseverityRi����R;sHTTP status %stERRORitSuccesstNONE(RFtcodecstdecodetreadRBt	from_jsont
ValueErrorR)(RHtrtinfotresulttsuccess_statustdata((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pytedit_response_data�s4








&


cC`s�g|d<|ddkrw|ddkr~|jj|d�}|jjd|krt||jjd|d<qtq~n|d=dS(Ntnitro_objectRQiRMROR(RBR]RE(RHRaRc((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pythandle_get_return_object�s
!cK`sNt|jd<t|jd<|jj|�||jd<|jj|j�dS(NR:tchangedR;(tTrueRCRAR(RBt	fail_json(RHR;tkwargs((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyRG�s



cC`s|jjddkr%|j�}n|jjddkrJ|j�}n|jjddkro|j�}n|jjddkr�|j�}n|jjddkr�|j�}n|jjddkr�|j�}n|jjddkr|j�}n|jjdd	kr(|j	�}n|jjdd
krM|j
�}n|jjddkrr|j�}n|jjddkr�|j�}n|jjdd
kr�|j
�}n|d|jjdkr�|jdd|�n|jj|�|jj|j�dS(NR%R'R(R-R.R)R*R+R,R/R0R2R1RQR3R;s
NITRO Failure(RBRER'R(R-R.R)R*R+R,R/R0R2R1RGRCt	exit_json(RHRa((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pytmain�s8cC`s|jj�dS(N(RBRk(RH((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pytexit_module�sc
C`s0|jjddkr)|jdd�n|jjddkrR|jdd�nd|jjd|jjd|jjdf}|jji|jjd|jjd6�}t|jd	|d
|jd|dd
�\}}i}|j|||dd�|ddkrt|j	d<n
t
|j	d<|S(NRR;sNITRO resource is undefined.R!s(NITRO resource attributes are undefined.s%s://%s/nitro/v1/config/%sRRturltheadersRctmethodtPOSTRbi�RQiRg(RBRERFRGtjsonifyRRDRdRhRCRA(RHRnRcR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR'�s*

-		
c
C`sf|jjddkr)|jdd�n|jjddkrR|jdd�n|jjddkr{|jdd�nd|jjd	|jjd
|jjd|jjdf}|jji|jjd|jjd6�}t|jd|d|jd
|dd�\}}i}|j|||dd�|ddkrUt|j	d<n
t
|j	d<|S(NRR;sNITRO resource is undefined.R s!NITRO resource name is undefined.R!s(NITRO resource attributes are undefined.s%s://%s/nitro/v1/config/%s/%sRRRnRoRcRptPUTRbi�RQiRg(RBRERFRGRrRRDRdRhRCRA(RHRnRcR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR( s0


-		
cC`s�|jjddkr)|jdd�n|jjddkrR|jdd�nd|jjd|jjd|jjd|jjdf}t|jd	|d
|jdd�\}}i}|j|||d
d�|j|�t|j	d<|S(NRR;sNITRO resource is undefined.R s!NITRO resource name is undefined.s%s://%s/nitro/v1/config/%s/%sRRRnRoRptGETRbi�Rg(
RBRERFRGRRDRdRfRARC(RHRnR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR)Es&


		

cC`sI|jjddkr)|jdd�n|jjddkrR|jdd�nd|jjd|jjd|jjdf}|jjd}d	jg|D]}d
|||f^q��}d|}dj||g�}t|jd
|d|jdd�\}}i}|j|||dd�|j|�t	|j
d<|S(NRR;sNITRO resource is undefined.R#sNITRO args is undefined.s%s://%s/nitro/v1/config/%sRRt,s%s:%ssargs=t?RnRoRpRtRbi�Rg(RBRERFRGtjoinRRDRdRfRARC(RHRnt	args_dicttkR#R_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR*as,

0
		

c	C`s7|jjddkr)|jdd�n|jjddkrR|jdd�nt|jjdj��}|d}|jjd|}d||f}d|jjd	|jjd
|jjd|f}t|jd|d|jd
d�\}}i}|j|||dd�|j	|�t
|jd<|S(NRR;sNITRO resource is undefined.R$sNITRO filter is undefined.is%s:%ss$%s://%s/nitro/v1/config/%s?filter=%sRRRnRoRpRtRbi�Rg(RBRERFRGR4tkeysRRDRdRfRARC(	RHRzt
filter_keytfilter_valuet
filter_strRnR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR+�s.




		

cC`s�|jjddkr)|jdd�nd|jjd|jjd|jjdf}td|j�t|jd|d	|jd
d�\}}i}|j|||dd
�|j|�t	|j
d<|S(NRR;sNITRO resource is undefined.s%s://%s/nitro/v1/config/%sRRs
headers %sRnRoRpRtRbi�Rg(RBRERFRGtprintRDRRdRfRARC(RHRnR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR,�s"

		

cC`s
|jjddkr)|jdd�n|jjddkrR|jdd�nd|jjd|jjd|jjd|jjdf}t|jd|d	|jd
d�\}}i}|j|||dd
�|ddkr�t|jd<n
t	|jd<|S(NRR;sNITRO resource is undefined.R s%s://%s/nitro/v1/config/%s/%sRRRnRoRptDELETERbi�RQiRg(
RBRERFRGRRDRdRhRCRA(RHRnR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR-�s(


		
cC`s\|jjddkr)|jdd�n|jjddkrR|jdd�nd|jjd|jjd|jjdf}|jjd}d	jg|D]}d
|||f^q��}d|}dj||g�}t|jd
|d|jdd�\}}i}|j|||dd�|ddkrKt|j	d<n
t
|j	d<|S(NRR;sNITRO resource is undefined.R#sNITRO args is undefined.s%s://%s/nitro/v1/config/%sRRRus%s:%ssargs=RvRnRoRpRRbi�RQiRg(RBRERFRGRwRRDRdRhRCRA(RHRnRxRyR#R_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR.�s.

0
		
cC`s:|jjddkr)|jdd�nd|jjd|jjd|jjdf}t|jd|d|jd	d
�\}}i}|j|||�|ddkr)|jj|d�}|d
|d<|d|d<|d|d<|jjd|kr)||jjddd|d<q)nt|j	d<|S(NRR;sNITRO resource is undefined.s$%s://%s/nitro/v1/config/%s?count=yesRRRnRoRpRtRMRORTRQRURRRVRSit__counttnitro_countRg(
RBRERFRGRRDRdR]RARC(RHRnR_R`RaRc((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR/s,

		&
c
C`sf|jjddkr)|jdd�n|jjddkrR|jdd�n|jjddkr{|jdd�nd|jjd	|jjd
|jjd|jjdf}|jji|jjd|jjd6�}t|jd|d|jd
|dd�\}}i}|j|||dd�|ddkrUt|j	d<n
t
|j	d<|S(NRR;sNITRO resource is undefined.R!s(NITRO resource attributes are undefined.R2sNITRO action is undefined.s$%s://%s/nitro/v1/config/%s?action=%sRRRnRoRcRpRqRbi�RQiRg(RBRERFRGRrRRDRdRhRCRA(RHRnRcR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR2"s0


-		
c
C`sd|jjd|jjdf}ii|jjdd6|jjdd6d6}d	|jj|�}t|jd
|d|jd|d
d�\}}t||�i}|j|||dd�|ddkr|jj|d�}|ddd|d<nt|j	d<|S(Ns%s://%s/nitro/v1/config/loginRRRtusernameRtpasswordtlogins
object=
%sRnRoRcRpRqRbi�RQiRMt	sessionidRRg(
RBRERrRRDR~RdR]RARC(RHRntlogin_credentialsRcR_R`Rat	body_data((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR0Gs,
		

c
C`s�d|jjd|jjdf}|jjiid6�}t|jd|d|jd|dd	�\}}i}|j|||d
d�t|jd<|S(
Ns,%s://%s/nitro/v1/config/nsconfig?action=saveRRtnsconfigRnRoRcRpRqRbi�Rg(RBRERrRRDRdRARC(RHRnRcR_R`Ra((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR1ks 
	
		
(t__name__t
__module__R"R	RhR@RLRdRfRGRlRmR'R(R)R*R+R,R-R.R/R2R0R1(((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyR-s~					&	*	
		+		"	%		"	!		!	#	!	%	$cC`st�}|j�dS(N(RRl(tnitro_api_caller((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyRl�s	t__main__(t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNtansible.module_utils.urlsRtansible.module_utils.basicR	R
RZtobjectRRlR�(((s]/usr/lib/python2.7/site-packages/ansible/modules/network/netscaler/netscaler_nitro_request.pyt<module>s"


qr4��\	

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]