%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/proxy/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/proxy/panos.pyc

�
���^c@@sdZddlmZmZmZddlZddlmZddl	Z
ddljj
ZddlmZdgZidd6ZiZeje�ZdZd	�Zd
�Zd�Zdd�Zd
d�Zd�Zd�Zd�Z d�Z!d�Z"dS(u
Proxy Minion interface module for managing Palo Alto firewall devices
=====================================================================

.. versionadded:: 2018.3.0

:codeauthor: ``Spencer Ervin <spencer_ervin@hotmail.com>``
:maturity:   new
:depends:    none
:platform:   unix

This proxy minion enables Palo Alto firewalls (hereafter referred to
as simply 'panos') to be treated individually like a Salt Minion.

The panos proxy leverages the XML API functionality on the Palo Alto
firewall. The Salt proxy must have access to the Palo Alto firewall on
HTTPS (tcp/443).

More in-depth conceptual reading on Proxy Minions can be found in the
:ref:`Proxy Minion <proxy-minion>` section of Salt's
documentation.


Configuration
=============

To use this integration proxy module, please configure the following:

Pillar
------

Proxy minions get their configuration from Salt's Pillar. Every proxy must
have a stanza in Pillar and a reference in the Pillar top-file that matches
the ID. There are four connection options available for the panos proxy module.

- Direct Device (Password)
- Direct Device (API Key)
- Panorama Pass-Through (Password)
- Panorama Pass-Through (API Key)


Direct Device (Password)
------------------------

The direct device configuration configures the proxy to connect directly to
the device with username and password.

.. code-block:: yaml

    proxy:
      proxytype: panos
      host: <ip or dns name of panos host>
      username: <panos username>
      password: <panos password>

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

host
^^^^

The location, or ip/dns, of the panos host. Required.

username
^^^^^^^^

The username used to login to the panos host. Required.

password
^^^^^^^^

The password used to login to the panos host. Required.

Direct Device (API Key)
------------------------

Palo Alto devices allow for access to the XML API with a generated 'API key'_
instead of username and password.

.. _API key: https://www.paloaltonetworks.com/documentation/71/pan-os/xml-api/get-started-with-the-pan-os-xml-api/get-your-api-key

.. code-block:: yaml

    proxy:
      proxytype: panos
      host: <ip or dns name of panos host>
      apikey: <panos generated api key>

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

host
^^^^

The location, or ip/dns, of the panos host. Required.

apikey
^^^^^^

The generated XML API key for the panos host. Required.

Panorama Pass-Through (Password)
--------------------------------

The Panorama pass-through method sends all connections through the Panorama
management system. It passes the connections to the appropriate device using
the serial number of the Palo Alto firewall.

This option will reduce the number of connections that must be present for the
proxy server. It will only require a connection to the Panorama server.

The username and password will be for authentication to the Panorama server,
not the panos device.

.. code-block:: yaml

    proxy:
      proxytype: panos
      serial: <serial number of panos host>
      host: <ip or dns name of the panorama server>
      username: <panorama server username>
      password: <panorama server password>

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

serial
^^^^^^

The serial number of the panos host. Required.

host
^^^^

The location, or ip/dns, of the Panorama server. Required.

username
^^^^^^^^

The username used to login to the Panorama server. Required.

password
^^^^^^^^

The password used to login to the Panorama server. Required.

Panorama Pass-Through (API Key)
-------------------------------

The Panorama server can also utilize a generated 'API key'_ for authentication.

.. _API key: https://www.paloaltonetworks.com/documentation/71/pan-os/xml-api/get-started-with-the-pan-os-xml-api/get-your-api-key

.. code-block:: yaml

    proxy:
      proxytype: panos
      serial: <serial number of panos host>
      host: <ip or dns name of the panorama server>
      apikey: <panos generated api key>

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

serial
^^^^^^

The serial number of the panos host. Required.

host
^^^^

The location, or ip/dns, of the Panorama server. Required.

apikey
^^^^^^^^

The generated XML API key for the Panorama server. Required.
i(tabsolute_importtprint_functiontunicode_literalsN(tElementTree(tsixupanosu	Palo AltouvendorcC@stS(u7
    Only return if all the modules are available.
    (t__virtualname__(((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pyt__virtual__�scC@se|jjdd�}|rD|jjdd�|jjdd�nx|D]}t|�}qKW|S(u�
    Removes dirtyID tags from the candidate config result. Palo Alto devices will make the candidate configuration with
    a dirty ID after a change. This can cause unexpected results when parsing.
    udirtyIduadminutimeN(tattribtpoptNonet_strip_dirty(txmltreetdirtytchild((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pyR
�s
cC@sd|dkr!tjd�tSd|dkrvd|dkrRtjd�tSd|dkrvtjd�tSnd	j|dd�td
<|ddtd<d|dkrS|djd�td<d|dkrtjd�d
td<|djd�td<q�tjd�dtd<|djd�td<|djd�td<n�d|dkr�tjd�dtd<|djd�td<nEtjd�dtd<|djd�td<|djd�td<tjd�idd6dd6}t|�tjd�ttd<dS(u�
    This function gets called when the proxy starts up. For
    panos devices, a determination is made on the connection type
    and the appropriate connection details that must be cached.
    uhostuproxyu-No 'host' key found in pillar for this proxy.uapikeyuusernameu1No 'username' key found in pillar for this proxy.upasswordu2No 'passwords' key found in pillar for this proxy.uhttps://{0}/api/uurluserialu/Selected pan_key method for panos proxy module.upan_keyumethodu0Selected pan_pass method for panos proxy module.upan_passu/Selected dev_key method for panos proxy module.udev_keyu0Selected dev_pass method for panos proxy module.udev_passu*Attempting to connect to panos proxy host.uoputypeu+<show><system><info></info></system></show>ucmdu+Successfully connected to panos proxy host.uinitializedN(	tlogtcriticaltFalsetformattDETAILStgettdebugtcalltTrue(toptstquery((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pytinit�sF













cC@sVd+}y�tddkrxitdd6}|j|�tdtdd|dd	d
ddtd
tdtdt�}nbtddkr�tdtddtddtdd|dd	d
ddtd
tdtdt�	}n�tddkrWitdd6tdd6}|j|�tdtdd|dd	d
ddtd
tdtdt�}n�tddkr�itdd6}|j|�tdtddtddtdd|dd	d
ddtd
tdtdt�	}nWn%tk
r}tjj	d��nX|stjj	d��nt
j|d�d,krt
j|d�dkretjj	d��qt
j|d�d kr�tjj	d!��qt
j|d�d"kr�tjj	d#��qt
j|d�d$kr�tjj	d%��qtjj	d��ntj
|d&�}|d'd(krF|d)d*krFt|�}ntj|t�S(-uW
    This function captures the query string and sends it to the Palo Alto device.
    umethodudev_keyuapikeyukeyu
http.queryuurltdatatmethoduPOSTtdecode_typeuplaintdecodet
verify_ssltstatustraise_errorudev_passtusernameuusernametpasswordupasswordupan_keyuserialutargetupan_passu+Did not receive a valid response from host.ustatusu200u201u204u400u<The server cannot process the request due to a client error.u401upThe server cannot process the request because it lacks valid authentication credentials for the target resource.u403u,The server refused to authorize the request.u404u*The requested resource could not be found.utextutypeuconfiguactionugetN(u200u201u204(R	Rtupdatet	__utils__RRtKeyErrortsaltt
exceptionstCommandExecutionErrorRt	text_typetETt
fromstringR
txmltto_dict(tpayloadtrtconditional_payloadterrtxmldata((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pyR3s�






					 u0.0.0cC@s>dtdkr!tdd}ntS|jd�}|jd�}y�t|d�t|d�krjtSt|d�t|d�kr�tSt|d�t|d�kr�tSt|d�t|d�kr�tSt|d�t|d�kr�tSt|d�t|d�krtStSWntk
r9}tSXdS(u�
    Because different versions of Palo Alto support different command sets, this function
    will return true if the current version of Palo Alto supports the required command.
    u
sw-versionugrains_cacheu.iiiN(RRtsplittintRt	Exception(trequired_versiontcurrent_versiontrequired_version_splittcurrent_version_splitR1((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pytis_required_version�s*      cC@stjdt�S(u�
    Since grains are loaded in many different places and some of those
    places occur before the proxy can be initialized, return whether
    our init() function has been called
    uinitialized(RRR(((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pytinitialized�scC@smtjdi�settd<y0idd6dd6}t|�ddtd<Wqetk
ra}qeXntdS(u0
    Get the grains from the proxied device
    ugrains_cacheuoputypeu+<show><system><info></info></system></show>ucmduresultusystem(RRtGRAINS_CACHERR5(RR1((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pytgrains�s
cC@sdtd<t�S(u4
    Refresh the grains from the proxied device
    ugrains_cacheN(R	RR=(((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pytgrains_refresh�s
cC@sMy2idd6dd6}dt|�kr-tStSWntk
rH}tSXdS(u>
    Returns true if the device is reachable, else false.
    uoputypeu+<show><system><info></info></system></show>ucmduresultN(RRRR5(RR1((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pytping�scC@stjd�dS(u_
    Shutdown the connection to the proxy device. For this proxy,
    shutdown is a no-op.
    uPanos proxy shutdown() called.N(RR(((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pytshutdown�s(#t__doc__t
__future__RRRtloggingtsalt._compatRR*tsalt.exceptionsR&tsalt.utils.xmlutiltutilstxmlutilR,tsalt.extRt__proxyenabled__R<Rt	getLoggert__file__RRRR
RR	RR:R;R=R>R?R@(((s4/usr/lib/python2.7/site-packages/salt/proxy/panos.pyt<module>�s*	
			5Z$					

Zerion Mini Shell 1.0