Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/network/aci/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/network/aci/aci_rest.pyc

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZy,ddlm
Z
mZmZmZeZWnek
r�eZnXyddlZeZWnek
r�eZnXydd
lmZeZWnek
reZnXyddlZeZWnek
rCeZnXddlmZddl m!Z!m"Z"ddl#m$Z$ddl%m&Z&d�Z'de!fd��YZ(d�Z)e*dkr�e)�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	certifiedtsupported_bys/

---
module: aci_rest
short_description: Direct access to the Cisco APIC REST API
description:
- Enables the management of the Cisco ACI fabric through direct access to the Cisco APIC REST API.
- Thanks to the idempotent nature of the APIC, this module is idempotent and reports changes.
version_added: '2.4'
requirements:
- lxml (when using XML payload)
- xmljson >= 0.1.8 (when using XML payload)
- python 2.7+ (when using xmljson)
options:
  method:
    description:
    - The HTTP method of the request.
    - Using C(delete) is typically used for deleting objects.
    - Using C(get) is typically used for querying objects.
    - Using C(post) is typically used for modifying objects.
    type: str
    choices: [ delete, get, post ]
    default: get
    aliases: [ action ]
  path:
    description:
    - URI being used to execute API calls.
    - Must end in C(.xml) or C(.json).
    type: str
    required: yes
    aliases: [ uri ]
  content:
    description:
    - When used instead of C(src), sets the payload of the API request directly.
    - This may be convenient to template simple requests.
    - For anything complex use the C(template) lookup plugin (see examples)
      or the M(template) module with parameter C(src).
    type: raw
  src:
    description:
    - Name of the absolute path of the filename that includes the body
      of the HTTP request being sent to the ACI fabric.
    - If you require a templated payload, use the C(content) parameter
      together with the C(template) lookup plugin, or use M(template).
    type: path
    aliases: [ config_file ]
extends_documentation_fragment: aci
notes:
- Certain payloads are known not to be idempotent, so be careful when constructing payloads,
  e.g. using C(status="created") will cause idempotency issues, use C(status="modified") instead.
  More information in :ref:`the ACI documentation <aci_guide_known_issues>`.
- Certain payloads (and used paths) are known to report no changes happened when changes did happen.
  This is a known APIC problem and has been reported to the vendor. A workaround for this issue exists.
  More information in :ref:`the ACI documentation <aci_guide_known_issues>`.
- XML payloads require the C(lxml) and C(xmljson) python libraries. For JSON payloads nothing special is needed.
seealso:
- module: aci_tenant
- name: Cisco APIC REST API Configuration Guide
  description: More information about the APIC REST API.
  link: http://www.cisco.com/c/en/us/td/docs/switches/datacenter/aci/apic/sw/2-x/rest_cfg/2_1_x/b_Cisco_APIC_REST_API_Configuration_Guide.html
author:
- Dag Wieers (@dagwieers)
s=
- name: Add a tenant using certificate authentication
  aci_rest:
    host: apic
    username: admin
    private_key: pki/admin.key
    method: post
    path: /api/mo/uni.xml
    src: /home/cisco/ansible/aci/configs/aci_config.xml
  delegate_to: localhost

- name: Add a tenant from a templated payload file from templates/
  aci_rest:
    host: apic
    username: admin
    private_key: pki/admin.key
    method: post
    path: /api/mo/uni.xml
    content: "{{ lookup('template', 'aci/tenant.xml.j2') }}"
  delegate_to: localhost

- name: Add a tenant using inline YAML
  aci_rest:
    host: apic
    username: admin
    private_key: pki/admin.key
    validate_certs: no
    path: /api/mo/uni.json
    method: post
    content:
      fvTenant:
        attributes:
          name: Sales
          descr: Sales department
  delegate_to: localhost

- name: Add a tenant using a JSON string
  aci_rest:
    host: apic
    username: admin
    private_key: pki/admin.key
    validate_certs: no
    path: /api/mo/uni.json
    method: post
    content:
      {
        "fvTenant": {
          "attributes": {
            "name": "Sales",
            "descr": "Sales department"
          }
        }
      }
  delegate_to: localhost

- name: Add a tenant using an XML string
  aci_rest:
    host: apic
    username: admin
    private_key: pki/{{ aci_username }}.key
    validate_certs: no
    path: /api/mo/uni.xml
    method: post
    content: '<fvTenant name="Sales" descr="Sales departement"/>'
  delegate_to: localhost

- name: Get tenants using password authentication
  aci_rest:
    host: apic
    username: admin
    password: SomeSecretPassword
    method: get
    path: /api/node/class/fvTenant.json
  delegate_to: localhost
  register: query_result

- name: Configure contracts
  aci_rest:
    host: apic
    username: admin
    private_key: pki/admin.key
    method: post
    path: /api/mo/uni.xml
    src: /home/cisco/ansible/aci/configs/contract_config.xml
  delegate_to: localhost

- name: Register leaves and spines
  aci_rest:
    host: apic
    username: admin
    private_key: pki/admin.key
    validate_certs: no
    method: post
    path: /api/mo/uni/controller/nodeidentpol.xml
    content: |
      <fabricNodeIdentPol>
        <fabricNodeIdentP name="{{ item.name }}" nodeId="{{ item.nodeid }}" status="{{ item.status }}" serial="{{ item.serial }}"/>
      </fabricNodeIdentPol>
  with_items:
  - '{{ apic_leavesspines }}'
  delegate_to: localhost

- name: Wait for all controllers to become ready
  aci_rest:
    host: apic
    username: admin
    private_key: pki/admin.key
    validate_certs: no
    path: /api/node/class/topSystem.json?query-target-filter=eq(topSystem.role,"controller")
  register: apics
  until: "'totalCount' in apics and apics.totalCount|int >= groups['apic']|count"
  retries: 120
  delay: 30
  delegate_to: localhost
  run_once: yes
s~
error_code:
  description: The REST ACI return code, useful for troubleshooting on failure
  returned: always
  type: int
  sample: 122
error_text:
  description: The REST ACI descriptive text, useful for troubleshooting on failure
  returned: always
  type: str
  sample: unknown managed object class foo
imdata:
  description: Converted output returned by the APIC REST (register this for post-processing)
  returned: always
  type: str
  sample: [{"error": {"attributes": {"code": "122", "text": "unknown managed object class foo"}}}]
payload:
  description: The (templated) payload send to the APIC REST API (xml or json)
  returned: always
  type: str
  sample: '<foo bar="boo"/>'
raw:
  description: The raw output returned by the APIC REST API (xml or json)
  returned: parse error
  type: str
  sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
response:
  description: HTTP response string
  returned: always
  type: str
  sample: 'HTTP Error 400: Bad Request'
status:
  description: HTTP status code
  returned: always
  type: int
  sample: 400
totalCount:
  description: Number of items in the imdata array
  returned: always
  type: str
  sample: '0'
url:
  description: URL used for APIC REST call
  returned: success
  type: str
  sample: https://1.2.3.4/api/mo/uni/tn-[Dag].json?rsp-subtree=modified
N(t	parse_qslt	urlencodeturlparset
urlunparse(tcobra(t
AnsibleModule(t	ACIModuletaci_argument_spec(t	fetch_url(tto_textcC`s�trUtt|��}tt|d��}|j|�t|�|d<t|�Sd|kr�|ddjg|j	�D]\}}d||f^q{�S|ddjg|j	�D]\}}d||f^q��SdS(s" Add or update a URL query string it?t&s%s=%sN(
tHAS_URLPARSEtlistR
tdictRtupdateR	Rtjointitems(turltparamst	url_partstquerytktv((sH/usr/lib/python2.7/site-packages/ansible/modules/network/aci/aci_rest.pyt
update_qsls

>t
ACIRESTModulecB`seZd�Zdd�ZRS(cC`s�t|t�rdx�|j�D]A\}}|dkrD|dkrDtS|j|�tkrtSqWn<t|t�r�x*|D]}|j|�tkrztSqzWntS(s  Check ACI response for changes Rtcreatedtmodifiedtdeleted(R"R#R$(t
isinstanceRRtTruetchangedRtFalse(tselftdRRti((sH/usr/lib/python2.7/site-packages/ansible/modules/network/aci/aci_rest.pyR''s
txmlcC`sO|dkr|j|�n
|j|�trK|j|j�|jd<ndS(s Handle APIC response output tjsonR'N(t
response_jsontresponse_xmlRR'timdatatresult(R)t	rawoutputt	rest_type((sH/usr/lib/python2.7/site-packages/ansible/modules/network/aci/aci_rest.pyt
response_type7s

(t__name__t
__module__R'R4(((sH/usr/lib/python2.7/site-packages/ansible/modules/network/aci/aci_rest.pyR!%s	c
C`st�}|jdtdddtddg�dtdddd	d
dd	dgdd
g�dtddddg�dtdd��td|dddgg�}|jd}|jd}|jd}t}|rtjj	|�r�t}q|j
dd|�n|jd�dkrXd}ts<|j
dd�nt
s�|j
dd�q�n.|jd�dkrvd}n|j
dd�t|�}d|jd<|}|r�t|d��}	|	j�}WdQXn|dkr�|rt|t�rtj|�}q'|r't|t�r'tr'ytjtj|��}Wq�tk
r}}
|j
dd t|
�d!t|
�d"|�q�Xq'n�|dkr'tr'|r�t|t�r�t
r�q'|r't|t�r'y"tjjtjj|��}Wq$tk
r }
|j
dd#t|
�d"|�q$Xq'nd$|jkri|jd$dk	rid%|j|j d&�|_!nd'|j|j d&�|_!|jdd	kr�|d(7}t"|j!id)d*6�|_!n|jd+dk	r�|j#d|d"|�n|jdj$�|_%t&||j!d,|d-|j'd|j%d.|jd.d/|jd/�\}}|d|_(|d|_)|dd0kr�y/|j*|d1|�|j
dd2|j+�Wq�t,k
r�|j
dd3|�q�Xn|j*|j�|�|j-|jd4<|j.|jd5<|j/|j�dS(6Ntpathttypetstrtrequiredtaliasesturitmethodtdefaulttgettchoicestdeletetposttactiontsrctconfig_filetcontenttrawt
argument_spectmutually_exclusivetmsgsCannot find/access src '%s's.xmli����R,s;The lxml python library is missing, or lacks etree support.s>The xmljson python library is missing, or lacks cobra support.s.jsonR-s>Failed to find REST API payload type (neither .xml nor .json).Rtrs.Failed to parse provided JSON/YAML payload: %st	exceptiontpayloads(Failed to parse provided XML payload: %stports!%(protocol)s://%(host)s:%(port)s/t/s%(protocol)s://%(host)s/s?rsp-subtree=modifiedR#srsp-subtreetprivate_keytdatatheadersttimeoutt	use_proxyi�tbodysAPIC Error %(code)s: %(text)ss&Connection failed for %(url)s. %(msg)sR0t
totalCount(0RRRR&R
RR(tosR7tisfilet	fail_jsontfindtHAS_LXML_ETREEtHAS_XMLJSON_COBRAR!R1topentreadR%R-tdumpsR9tHAS_YAMLtyamlt	safe_loadt	ExceptionRtlxmltetreettostringt
fromstringtNonetlstripRR t	cert_authtupperR=RRRtresponseRR4terrortKeyErrorR0RVt	exit_json(
RHtmoduleRFR7RDtfile_existsR3taciRMt
config_objecttetresptinfo((sH/usr/lib/python2.7/site-packages/ansible/modules/network/aci/aci_rest.pytmainDs�		-


		
6"*" 
		



t__main__(+t
__future__RRRR8t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR-RWt+ansible.module_utils.six.moves.urllib.parseRR	R
RR&RRcR(t
lxml.etreeRdR[tImportErrortxmljsonRR\RaR`tansible.module_utils.basicR
t$ansible.module_utils.network.aci.aciRRtansible.module_utils.urlsRtansible.module_utils._textRR R!RwR5(((sH/usr/lib/python2.7/site-packages/ansible/modules/network/aci/aci_rest.pyt<module>sL


?u0"











		u

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