Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/remote_management/imc/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/remote_management/imc/imc_rest.pyc

�
�Udac@`s}ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlZddl
Z
ddlZdZyddlZeZWn#ek
r�ej�ZeZnXdZyddlmZeZWn#ek
rej�ZeZnXdd
lmZmZddlm Z dd�Z!d�Z"d�Z#d�Z$e%dkrye$�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys
---
module: imc_rest
short_description: Manage Cisco IMC hardware through its REST API
description:
- Provides direct access to the Cisco IMC REST API.
- Perform any configuration changes and actions that the Cisco IMC supports.
- More information about the IMC REST API is available from
  U(http://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/api/3_0/b_Cisco_IMC_api_301.html)
author:
- Dag Wieers (@dagwieers)
version_added: '2.4'
requirements:
- lxml
- xmljson >= 0.1.8
options:
  hostname:
    description:
    - IP Address or hostname of Cisco IMC, resolvable by Ansible control host.
    required: true
    aliases: [ host, ip ]
  username:
    description:
    - Username used to login to the switch.
    default: admin
    aliases: [ user ]
  password:
    description:
    - The password to use for authentication.
    default: password
  path:
    description:
    - Name of the absolute path of the filename that includes the body
      of the http request being sent to the Cisco IMC REST API.
    - Parameter C(path) is mutual exclusive with parameter C(content).
    aliases: [ 'src', 'config_file' ]
  content:
    description:
    - When used instead of C(path), sets the content of the API requests directly.
    - This may be convenient to template simple requests, for anything complex use the M(template) module.
    - You can collate multiple IMC XML fragments and they will be processed sequentially in a single stream,
      the Cisco IMC output is subsequently merged.
    - Parameter C(content) is mutual exclusive with parameter C(path).
  protocol:
    description:
    - Connection protocol to use.
    default: https
    choices: [ http, https ]
  timeout:
    description:
    - The socket level timeout in seconds.
    - This is the time that every single connection (every fragment) can spend.
      If this C(timeout) is reached, the module will fail with a
      C(Connection failure) indicating that C(The read operation timed out).
    default: 60
  validate_certs:
    description:
    - If C(no), SSL certificates will not be validated.
    - This should only set to C(no) used on personally controlled sites using self-signed certificates.
    type: bool
    default: 'yes'
notes:
- The XML fragments don't need an authentication cookie, this is injected by the module automatically.
- The Cisco IMC XML output is being translated to JSON using the Cobra convention.
- Any configConfMo change requested has a return status of 'modified', even if there was no actual change
  from the previous configuration. As a result, this module will always report a change on subsequent runs.
  In case this behaviour is fixed in a future update to Cisco IMC, this module will automatically adapt.
- If you get a C(Connection failure) related to C(The read operation timed out) increase the C(timeout)
  parameter. Some XML fragments can take longer than the default timeout.
- More information about the IMC REST API is available from
  U(http://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/api/3_0/b_Cisco_IMC_api_301.html)
s�
- name: Power down server
  imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    content: |
      <configConfMo><inConfig>
        <computeRackUnit dn="sys/rack-unit-1" adminPower="down"/>
      </inConfig></configConfMo>
  delegate_to: localhost

- name: Configure IMC using multiple XML fragments
  imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    timeout: 120
    content: |
      <!-- Configure Serial-on-LAN -->
      <configConfMo><inConfig>
        <solIf dn="sys/rack-unit-1/sol-if" adminState="enable" speed=="115200" comport="com0"/>
      </inConfig></configConfMo>

      <!-- Configure Console Redirection -->
      <configConfMo><inConfig>
        <biosVfConsoleRedirection dn="sys/rack-unit-1/bios/bios-settings/Console-redirection"
          vpBaudRate="115200"
          vpConsoleRedirection="com-0"
          vpFlowControl="none"
          vpTerminalType="vt100"
          vpPuttyKeyPad="LINUX"
          vpRedirectionAfterPOST="Always Enable"/>
      </inConfig></configConfMo>
  delegate_to: localhost

- name: Enable PXE boot and power-cycle server
  imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    content: |
      <!-- Configure PXE boot -->
      <configConfMo><inConfig>
        <lsbootLan dn="sys/rack-unit-1/boot-policy/lan-read-only" access="read-only" order="1" prot="pxe" type="lan"/>
      </inConfig></configConfMo>

      <!-- Power cycle server -->
      <configConfMo><inConfig>
        <computeRackUnit dn="sys/rack-unit-1" adminPower="cycle-immediate"/>
      </inConfig></configConfMo>
  delegate_to: localhost

- name: Reconfigure IMC to boot from storage
  imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    content: |
      <configConfMo><inConfig>
        <lsbootStorage dn="sys/rack-unit-1/boot-policy/storage-read-write" access="read-write" order="1" type="storage"/>
      </inConfig></configConfMo>
  delegate_to: localhost

- name: Add customer description to server
  imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    content: |
        <configConfMo><inConfig>
          <computeRackUnit dn="sys/rack-unit-1" usrLbl="Customer Lab - POD{{ pod_id }} - {{ inventory_hostname_short }}"/>
        </inConfig></configConfMo>
    delegate_to: localhost

- name: Disable HTTP and increase session timeout to max value 10800 secs
  imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    timeout: 120
    content: |
        <configConfMo><inConfig>
          <commHttp dn="sys/svc-ext/http-svc" adminState="disabled"/>
        </inConfig></configConfMo>

        <configConfMo><inConfig>
          <commHttps dn="sys/svc-ext/https-svc" adminState="enabled" sessionTimeout="10800"/>
        </inConfig></configConfMo>
    delegate_to: localhost
s�
aaLogin:
  description: Cisco IMC XML output for the login, translated to JSON using Cobra convention
  returned: success
  type: dict
  sample: |
    "attributes": {
        "cookie": "",
        "outCookie": "1498902428/9de6dc36-417c-157c-106c-139efe2dc02a",
        "outPriv": "admin",
        "outRefreshPeriod": "600",
        "outSessionId": "114",
        "outVersion": "2.0(13e)",
        "response": "yes"
    }
configConfMo:
  description: Cisco IMC XML output for any configConfMo XML fragments, translated to JSON using Cobra convention
  returned: success
  type: dict
  sample: |
elapsed:
  description: Elapsed time in seconds
  returned: always
  type: int
  sample: 31
response:
  description: HTTP response message, including content length
  returned: always
  type: str
  sample: OK (729 bytes)
status:
  description: The HTTP response status code
  returned: always
  type: dict
  sample: 200
error:
  description: Cisco IMC XML error output for last request, translated to JSON using Cobra convention
  returned: failed
  type: dict
  sample: |
    "attributes": {
        "cookie": "",
        "errorCode": "ERR-xml-parse-error",
        "errorDescr": "XML PARSING ERROR: Element 'computeRackUnit', attribute 'admin_Power': The attribute 'admin_Power' is not allowed. ",
        "invocationResult": "594",
        "response": "yes"
    }
error_code:
  description: Cisco IMC error code
  returned: failed
  type: str
  sample: ERR-xml-parse-error
error_text:
  description: Cisco IMC error message
  returned: failed
  type: str
  sample: |
    XML PARSING ERROR: Element 'computeRackUnit', attribute 'admin_Power': The attribute 'admin_Power' is not allowed.
input:
  description: RAW XML input sent to the Cisco IMC, causing the error
  returned: failed
  type: str
  sample: |
    <configConfMo><inConfig><computeRackUnit dn="sys/rack-unit-1" admin_Power="down"/></inConfig></configConfMo>
output:
  description: RAW XML output received from the Cisco IMC, with error details
  returned: failed
  type: str
  sample: >
    <error cookie=""
      response="yes"
      errorCode="ERR-xml-parse-error"
      invocationResult="594"
      errorDescr="XML PARSING ERROR: Element 'computeRackUnit', attribute 'admin_Power': The attribute 'admin_Power' is not allowed.\n"/>
N(tcobra(t
AnsibleModuletmissing_required_lib(t	fetch_urltcC`s�tjj|�}tj|�}|jd�r�|jd�r�|rR||d<n||d<|jd�|d<|jd�|d<|jdd||�n|S(	s Handle IMC returned data t	errorCodet
errorDescrtinputtoutputt
error_codet
error_texttmsgsRequest failed: %(error_text)s(tlxmltetreet
fromstringRtdatatgett	fail_json(tmodulet	rawoutputtrawinputt	xmloutputtresult((sR/usr/lib/python2.7/site-packages/ansible/modules/remote_management/imc/imc_rest.pytimc_responses

c	C`s;d||f}t||d|ddd|�\}}dS(s Perform a logout, if needed s&<aaaLogout cookie="%s" inCookie="%s"/>RtmethodtPOSTttimeoutN(R(RturltcookieR"Rtresptauth((sR/usr/lib/python2.7/site-packages/ansible/modules/remote_management/imc/imc_rest.pytlogout0sc`s�t�t�rTt�t�rTt��}|jt��fd��D���|St�t�r�t�t�r�gtj���D]\}}t||�^q�S�dkr��S�S(s1 Merge two complex nested datastructures into onec3`s4|]*}|t�j|d��|�fVqdS(N(tmergeRtNone(t.0tkey(tonettwo(sR/usr/lib/python2.7/site-packages/ansible/modules/remote_management/imc/imc_rest.pys	<genexpr>;sN(t
isinstancetdicttupdatetlistt	itertoolstizip_longestR(R)(R,R-tcopytalphatbeta((R,R-sR/usr/lib/python2.7/site-packages/ansible/modules/remote_management/imc/imc_rest.pyR(6s&2cC`s�tdtdtdddtdddg�d	tddd
dddg�d
tddd
d
dt�dtdd�dtdddddg�dtddd
ddddg�dtddd
d�dtddd
t��dtdddgg�}ts|jdtd�d t�nts@|jdtd!�d t�n|j	d}|j	d	}|j	d
}|j	d}|j	d}|j	d}|j	d}td"t
d#t
�}t
}	|r�tjj
|�r�t}	q�|jdd$|�ntjj�}
d%||f}d&||f}t||d'|d(d)d|�\}
}|
dks`|d*d+kr�tjj�|
j|d,<|jdd-||�n|jt||
j���y|d.d/d0}Wn$tk
r�|jdd1|�nXtjt||||�|r|}n-|	rBt|d2��}|j�}WdQXntjjd3|jd4d5��}x?t|�D]1}|j tjj!kr�qqn|j"d6|�tjj#|�}t||d'|d(d)d|�\}
}|
dks�|d*d+kr+tjj�|
j|d,<|jdd-||�n|
j�}t$|t||d7|��}|d|d8<|d*|d*<tjj|�}|j%d9�}d:|k|d#<qqWtjj�|
j|d,<|j&|�dS(;Nt
argument_specthostnamettypetstrtrequiredtaliasesthosttiptusernametdefaulttadmintusertpasswordtno_logtcontenttpathtconfig_filetsrctprotocolthttpstchoicesthttpR"tinti<tvalidate_certstbooltsupports_check_modetmutually_exclusiveRRt	exceptionsxmljson >= 0.1.8tfailedtchangedsCannot find/access path:
%ss
%s://%s/nuovas'<aaaLogin inName="%s" inPassword="%s"/>RR R!Ri�telapseds*Task failed with error %(status)s: %(msg)staaaLogint
attributest	outCookiesCould not find cookie in outputtrs<root>%s</root>s
RR$Rtresponses!/configConfMo/outConfig/*/@statustmodified('R	R/tTruetHAS_LXML_ETREERR
tLXML_ETREE_IMP_ERRtHAS_XMLJSON_COBRAtXMLJSON_COBRA_IMP_ERRtparamstFalsetosRFtisfiletdatetimetutcnowRR)tsecondsR0Rtreadt	ExceptiontatexittregisterR'topenRRRtreplaceR1ttagtCommenttsetttostringR(txpatht	exit_json(RR8R?RCRERFRIR"Rtfile_existststartR#RR%R&R$trawdatat
config_objecttxmldatatxmldoctinfoRRtresults((sR/usr/lib/python2.7/site-packages/ansible/modules/remote_management/imc/imc_rest.pytmainDs�!!






		'
	"'t__main__(&t
__future__RRRR9t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNRjReR2Rct	tracebackR)R^t
lxml.etreeRR\R]tImportErrort
format_excRbR`txmljsonRR_tansible.module_utils.basicR	R
tansible.module_utils.urlsRRR'R(R|t__name__(((sR/usr/lib/python2.7/site-packages/ansible/modules/remote_management/imc/imc_rest.pyt<module>sD


IbL





			k

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