%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/proxy/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/proxy/nxos.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZeje�ZdgZdZiid6Zd	�Zd
�Zdd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Z e!d�Z"d�Z#e!dddd�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,e!d �Z-d!�Z.d"�Z/d#�Z0d$�Z1d%�Z2dS(&u4	
Proxy Minion for Cisco NX OS Switches

.. versionadded: 2016.11.0

The Cisco NX OS Proxy Minion uses the built in SSHConnection module in :mod:`salt.utils.vt_helper <salt.utils.vt_helper>`

To configure the proxy minion:

.. code-block:: yaml

    proxy:
      proxytype: nxos
      host: 192.168.187.100
      username: admin
      password: admin
      prompt_name: switch
      ssh_args: '-o PubkeyAuthentication=no'
      key_accept: True

proxytype
    (REQUIRED) Use this proxy minion `nxos`

host
    (REQUIRED) ip address or hostname to connect to

username
    (REQUIRED) username to login with

password
    (REQUIRED) password to use to login with

prompt_name
    (REQUIRED, this or `prompt_regex` below, but not both)
    The name in the prompt on the switch.  Recommended to use your
    device's hostname.

prompt_regex
    (REQUIRED, this or `prompt_name` above, but not both)
    A regular expression that matches the prompt on the switch
    and any other possible prompt at which you need the proxy minion
    to continue sending input.  This feature was specifically developed
    for situations where the switch may ask for confirmation.  `prompt_name`
    above would not match these, and so the session would timeout.

    Example:

    .. code-block:: yaml

        dc01-switch-01#.*|\(y\/n\)\?.*

    This should match

    .. code-block:: shell

        dc01-switch-01#

    or

    .. code-block:: shell

        Flash complete.  Reboot this switch (y/n)? [n]


    If neither `prompt_name` nor `prompt_regex` is specified the prompt will be
    defaulted to

    .. code-block:: shell

        .+#$

    which should match any number of characters followed by a `#` at the end
    of the line.  This may be far too liberal for most installations.

ssh_args
    Any extra args to use to connect to the switch.

key_accept
    Whether or not to accept a the host key of the switch on initial login.
    Defaults to False.


The functions from the proxy minion can be run from the salt commandline using
the :mod:`salt.modules.nxos<salt.modules.nxos>` execution module.

.. note:
    If `multiprocessing: True` is set for the proxy minion config, each forked
    worker will open up a new connection to the Cisco NX OS Switch.  If you
    only want one consistent connection used for everything, use
    `multiprocessing: False`

i(tabsolute_importtprint_functiontunicode_literalsN(tgen_hashtsecure_password(t
SSHConnection(tTerminalExceptionunxosugrains_cachecC@stjd�tS(u6
    Only return if all the modules are available
    u"nxos proxy __virtual__() called...(tlogtinfot__virtualname__(((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt__virtual__qs
cC@s
tj�jS(N(tmultiprocessingtcurrent_processtname(((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt_worker_namezsc
C@s7|dkrt}ny�d}d|dkr?|dd}n=d|dkridj|dd�}ntjd�d}td|ddd	|dd
d|ddd
|djdt�d|djdd�d|�tt	�<tt	�j
d�\}}Wn!tk
r(}tj|�tSXt
td<dS(uH
    Required.
    Can be used to initialize the server connection.
    uprompt_regexuproxyuprompt_nameu{0}.*#u9nxos proxy configuration does not specify a prompt match.u.+#$thostuhosttusernameuusernametpasswordupasswordt
key_acceptu
key_accepttssh_argsussh_argsutpromptuterminal length 0uinitializedN(tNonet__opts__tformatRtwarningRtgettFalsetDETAILSRtsendlineRterrortTrue(toptstthis_prompttoutterrte((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytinit~s,	
 
cC@stjdt�S(Nuinitialized(RRR(((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytinitialized�scC@sYt�tkrt�nytt�jj�SWn!tk
rT}tj|�tSXdS(uu
    Ping the device on the other end of the connection

    .. code-block: bash

        salt '*' nxos.cmd ping
    N(	RRR$tconntisaliveRRRR(R#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytping�s

cC@stt�j�dS(u
    Disconnect
    N(RRtclose_connection(R((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytshutdown�scC@sit�tkrt�ntt�j|�\}}|jdd�\}}|jd�\}}}|S(u�
    Run command through switch's cli

    .. code-block: bash

        salt '*' nxos.cmd sendline 'show run | include "^username admin password"'
    u
i(R(RR$RRRtsplitt
rpartition(tcommandR!R"t_((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyR�s
cC@sCtds4t�}tj|�tdj|�nitdd6S(u`
    Get grains for proxy minion

    .. code-block: bash

        salt '*' nxos.cmd grains
    ugrains_cacheunxos(Rtsystem_infoRtdebugtupdate(tret((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytgrains�s

	
cC@sitd<t�S(uv
    Refresh the grains from the proxy device.

    .. code-block: bash

        salt '*' nxos.cmd grains_refresh
    ugrains_cache(RR3(((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytgrains_refresh�s
cC@stdj|��S(us
    Get username line from switch

    .. code-block: bash

        salt '*' nxos.cmd get_user username=admin
    u.show run | include "^username {0} password 5 "(RR(R((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytget_user�scC@s^tdj|��}tjd|tj�}|rT|jd�j�jd�}ng}|S(u�
    Get roles that the username is assigned from switch

    .. code-block: bash

        salt '*' nxos.cmd get_roles username=admin
    ushow user-account {0}u^\s*roles:(.*)$iu (RRtretsearcht	MULTILINEtgrouptstripR+(RRtroles((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt	get_roles�s!c
C@s�idd6dd6dd6dd6}t|�}|s8dSd	|krHtStjd
|�jd�}|tkr�tjd|�j�\}}}td
|d|d||�}	n|}	|	|kr�tStS(uE
    Check if passed password is the one assigned to user

    .. code-block: bash

        salt '*' nxos.cmd check_password username=admin password=admin
        salt '*' nxos.cmd check_password username=admin \
            password='$5$2fWwO2vK$s7.Hr3YltMNHuhywQQ3nfOd.gAPHgs3SOBYYdGT3E.A' \
            encrypted=True
    umd5u1ublowfishu2ausha256u5usha512u6u!!u(\$[0-6](?:\$[^$ ]+)+)iu^\$([0-6])\$([^$]+)\$(.*)$t
crypt_saltRt	algorithmN(	R5RRR6R7R9tgroupsRR(
RRt	encryptedthash_algorithmst
password_linetcur_hasht	hash_typetcur_saltthashed_passtnew_hash((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytcheck_passwords"

!"cC@s|t|�kS(u�
    Check if user is assigned a specific role on switch

    .. code-block:: bash

        salt '*' nxos.cmd check_role username=admin role=network-admin
    (R<(Rtrole((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt
check_role susha256c
C@s�t|�}|tkrW|d
kr9tddt�}ntd|d|d|�}n|}dj||�}|d
k	r�|dj|�7}nyAtd�t|�}td	�td
�dj||g�SWn!tk
r�}	t	j
|	�dSXd
S(u
    Set users password on switch

    .. code-block:: bash

        salt '*' nxos.cmd set_password admin TestPass
        salt '*' nxos.cmd set_password admin \
            password='$5$2fWwO2vK$s7.Hr3YltMNHuhywQQ3nfOd.gAPHgs3SOBYYdGT3E.A' \
            encrypted=True
    it
use_randomR=RR>uusername {0} password 5 {1}u	 role {0}uconfig terminaluendu"copy running-config startup-configu
uFailed to set passwordN(R5RRRRRRtjoinRRR(
RRR@RIR=R>RBRFR2R#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytset_password+s$



cC@sxyPtd�dj|�}t|�}td�td�dj||g�SWn!tk
rs}tj|�dSXdS(ur
    Remove user from switch

    .. code-block:: bash

        salt '*' nxos.cmd remove_user username=daniel
    uconfig terminaluno username {0}uendu"copy running-config startup-configu
uFailed to set passwordN(RRRLRRR(Rt	user_lineR2R#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytremove_userMs



cC@s{yStd�dj||�}t|�}td�td�dj||g�SWn!tk
rv}tj|�dSXdS(u~
    Assign role to username

    .. code-block:: bash

        salt '*' nxos.cmd set_role username=daniel role=vdc-admin
    uconfig terminaluusername {0} role {1}uendu"copy running-config startup-configu
uFailed to set passwordN(RRRLRRR(RRIt	role_lineR2R#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytset_roleas



cC@s{yStd�dj||�}t|�}td�td�dj||g�SWn!tk
rv}tj|�dSXdS(u�
    Remove role from username

    .. code-block:: bash

        salt '*' nxos.cmd unset_role username=daniel role=vdc-admin
    uconfig terminaluno username {0} role {1}uendu"copy running-config startup-configu
uFailed to set passwordN(RRRLRRR(RRIRPR2R#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt
unset_roleus



cC@s8ytd�}Wn!tk
r3}tj|�dSX|S(ul
    Shortcut to run `show run` on switch

    .. code-block:: bash

        salt '*' nxos.cmd show_run
    ushow runuFailed to "show run"(RRRR(R2R#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytshow_run�s
cC@s8ytd�}Wn!tk
r3}tj|�dSX|S(ul
    Shortcut to run `show ver` on switch

    .. code-block:: bash

        salt '*' nxos.cmd show_ver
    ushow veruFailed to "show ver"(RRRR(R2R#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytshow_ver�s
cC@s�t|t�s|g}ny=td�x|D]}t|�q/Wtd�td�Wn!tk
r{}tj|�tSXtS(u
    Add one or more config lines to the switch running config

    .. code-block:: bash

        salt '*' nxos.cmd add_config 'snmp-server community TESTSTRINGHERE group network-operator'

    .. note::
        For more than one config added per command, lines should be a list.
    uconfig terminaluendu"copy running-config startup-config(t
isinstancetlistRRRRRR(tlinestlineR#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt
add_config�s



cC@s�t|t�s|g}nyLtd�x'|D]}tdjd|g��q/Wtd�td�Wn!tk
r�}tj|�tSXtS(u$
    Delete one or more config lines to the switch running config

    .. code-block:: bash

        salt '*' nxos.cmd delete_config 'snmp-server community TESTSTRINGHERE group network-operator'

    .. note::
        For more than one config deleted per command, lines should be a list.
    uconfig terminalu unouendu"copy running-config startup-config(	RURVRRLRRRRR(RWRXR#((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt
delete_config�s



cC@s%tj|tj�}|jt��S(u
    Find all instances where the pattern is in the running command

    .. code-block:: bash

        salt '*' nxos.cmd find '^snmp-server.*$'

    .. note::
        This uses the `re.MULTILINE` regex format for python, and runs the
        regex against the whole show_run output.
    (R6tcompileR8tfindallRS(tpatterntmatcher((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytfind�scC@s|tkrNtjdjtj|��tj�}tjtj|��}n$tj|tj�}tj|�}igd6gd6}xZ|jt��D]F}|dj|j	d��|dj|j
||j	d���q�Wt|d�t|d�|S(u
    Replace string or full line matches in switch's running config

    If full_match is set to True, then the whole line will need to be matched
    as part of the old value.

    .. code-block:: bash

        salt '*' nxos.cmd replace 'TESTSTRINGHERE' 'NEWTESTSTRINGHERE'
    u	^.*{0}.*$uoldunewi(
RR6R[RtescapeR8tfinditerRStappendR9tsubRZRY(t	old_valuet	new_valuet
full_matchR^treplRWRX((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pytreplace�s'*cC@stjdjd|�tj�S(Nu^{block}
(?:^[ 
].*$
?)+tblock(R6R[RR8(Ri((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt_parser
scC@s�iid6}td�j|�jd�}tjdtj�}x7|j|�D]&}|j�\}}||d|<qPW|dS(NusoftwareuSoftwareiu^  ([^:]+): *([^
]+)(RjR7R9R6R[R8RaR?(tdataR2tsoftwareR^RXtkeytval((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt_parse_softwares
cC@s�iid6}td�j|�jd�}tjdtj�}x7|j|�D]&}|j�\}}||d|<qPW|dS(NuhardwareuHardwareiu^  ([^:
]+): *([^
]+)(RjR7R9R6R[R8RaR?(RkR2thardwareR^RXRmRn((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt_parse_hardwares
cC@syigd6}td�j|�jd�}tjdtj�}x.|j|�D]}|dj|j��qPW|dS(Nupluginsupluginiu^  (?:([^,]+), )+([^
]+)(	RjR7R9R6R[R8RatextendR?(RkR2tpluginsR^RX((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt_parse_plugins"s
cC@s:t�}it|�d6t|�d6t|�d6}|S(u�
    Return system information for grains of the NX OS proxy minion

    .. code-block:: bash

        salt '*' nxos.system_info
    usoftwareuhardwareuplugins(RTRoRqRt(RkR((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyR/+s	

(3t__doc__t
__future__RRRtloggingRR6tsalt.utils.pycryptoRRtsalt.utils.vt_helperRt
salt.utils.vtRt	getLoggert__file__Rt__proxyenabled__R	RR
RRR$R%R(R*RR3R4R5R<RRHRJRMRORQRRRSRTRYRZR_RhRjRoRqRtR/(((s3/usr/lib/python2.7/site-packages/salt/proxy/nxos.pyt<module>]sN	
			 									"										
	
		

Zerion Mini Shell 1.0