HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/__pycache__/drac.cpython-310.pyc
o

�N�g5�@s�dZddlZzddlZdZWneydZYnwe�e�Zdd�Zddd	�Z	d
d�Z
ddd
�Zddd�Zddd�Z
ddd�Zddd�ZdS)z�
Manage Dell DRAC from the Master

The login credentials need to be configured in the Salt master
configuration file.

.. code-block:: yaml

    drac:
      username: admin
      password: secret

�NTFcCstrdSdS)NT)FzKThe drac runner module cannot be loaded: paramiko package is not installed.)�HAS_PARAMIKO�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/drac.py�__virtual__sr�c
Cs�t�d�}d}|s|durt�|�dS|�dd�}|s-|dur't�|�dS|�dd�}t��}|�t���z|j||||d�W|St	y^}zt�d||�WYd}~dSd}~ww)	z
    Connect to the DRAC
    Zdracz�No drac login credentials found. Please add the 'username' and 'password' fields beneath a 'drac' key in the master configuration file. Or you can pass in a username and password as kwargs at the CLI.NF�username�password)rr�timeoutzUnable to connect to %s: %s)
Z__opts__�get�log�error�paramiko�	SSHClientZset_missing_host_key_policyZ
AutoAddPolicy�connect�	Exception)�hostnamer	rrZ	drac_cred�err_msg�client�errr�	__connect%s.
�

���rcCsxddddddd�}t|tj�r:|�d�\}}}|��D]}|dd��d�r9|�t|dd��d	�d
�d�SqdS)z
    Grab DRAC version
    ZCMCZiDRAC6ZiDRAC7)�	��
���zracadm getconfig -g idRacInfo�NZ	idRacType�=�)	�
isinstancer
r�exec_command�	readlines�
startswithr
�int�split)rZversions�stdin�stdout�stderr�irrr�	__versionGs�	&�r)cCs�gd�}t||||�}t|tj�r?t|d�D]\}}t�d|�|�|�\}}	}
qd|	��vr7t�d|�dSt�	d|�dSdS)	z�
    Connect to the Dell DRAC and have the boot order set to PXE
    and power cycle the system to PXE boot

    CLI Example:

    .. code-block:: bash

        salt-run drac.pxe example.com
    )z>racadm config -g cfgServerInfo -o cfgServerFirstBootDevice pxez5racadm config -g cfgServerInfo -o cfgServerBootOnce 1�racadm serveraction powercyclerzExecuting command %s�
successfulzExecuting command: %szUnable to execute: %sFT)
rrr
r�	enumerater�infor �readliner)rr	rrZ_cmdsrr(�cmdr%r&r'rrr�pxe^s�r0cC�`t||||�}t|tj�r)|�d�\}}}d|��vr"t�d�dSt�d�dSt�d�dS)z�
    Reboot a server using the Dell DRAC

    CLI Example:

    .. code-block:: bash

        salt-run drac.reboot example.com
    r*r+zpowercycle successfulz powercycle racadm command failedF�)client was not of type paramiko.SSHClientT�	rrr
rr r.rr-r�rr	rrrr%r&r'rrr�reboot��


�
r5cCr1)zr
    Power server off

    CLI Example:

    .. code-block:: bash

        salt-run drac.poweroff example.com
    zracadm serveraction powerdownr+zpowerdown successfulzpowerdown racadm command failedFr2Tr3r4rrr�poweroff�r6r7cCr1)zp
    Power server on

    CLI Example:

    .. code-block:: bash

        salt-run drac.poweron example.com
    zracadm serveraction powerupr+zpowerup successfulzpowerup racadm command failedFr2Tr3r4rrr�poweron�r6r8cCstt||||��S)z|
    Display the version of DRAC

    CLI Example:

    .. code-block:: bash

        salt-run drac.version example.com
    )r)r)rr	rrrrr�version�s
r9)rNN)�__doc__�loggingr
r�ImportError�	getLogger�__name__rrrr)r0r5r7r8r9rrrr�<module>s"�


"

"