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/modules/__pycache__/cimc.cpython-310.pyc
o

�N�g�[�@s�dZddlZddlZddlZe�e�ZdZdd�Z	dTdd�Z
dUd	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$				=		dVd>d?�Z%d@dA�Z&dWdBdC�Z'dXdDdE�Z(dYdGdH�Z)dZdIdJ�Z*d[dLdM�Z+d\dNdO�Z,dXdPdQ�Z-dXdRdS�Z.dS)]a�
Module to provide Cisco UCS compatibility to Salt

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


Configuration
=============
This module accepts connection configuration details either as
parameters, or as configuration settings in pillar as a Salt proxy.
Options passed into opts will be ignored if options are passed into pillar.

.. seealso::
    :py:mod:`Cisco UCS Proxy Module <salt.proxy.cimc>`

About
=====
This execution module was designed to handle connections to a Cisco UCS server.
This module adds support to send connections directly to the device through the
rest API.

�N�cimccCsDztjj��rtdddkrtWSWdSWdSty!YdSw)z/
    Will load for the cimc proxy minions.
    �proxyZ	proxytyper)FzDThe cimc execution module can only be loaded for cimc proxy minions.)�salt�utils�platformZis_proxyZ__opts__�__virtualname__�KeyError�r	r	�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/cimc.py�__virtual__%s����rFcCs2d}d}|dur
d}d�|�}td||d�}|S)a
    Activates the firmware backup image.

    CLI Example:

    Args:
        reset(bool): Reset the CIMC device on activate.

    .. code-block:: bash

        salt '*' cimc.activate_backup_image
        salt '*' cimc.activate_backup_image reset=True

    z2sys/rack-unit-1/mgmt/fw-boot-def/bootunit-combined�noTZyesz�<firmwareBootUnit dn='sys/rack-unit-1/mgmt/fw-boot-def/bootunit-combined'
    adminState='trigger' image='backup' resetOnActivate='{}' />�cimc.set_config_modifyF��format�	__proxy__)�reset�dn�r�inconfig�retr	r	r
�activate_backup_image2s��rcCsn|stj�d��|stj�d��|stj�d��|s tj�d��d|��}d�||||�}td||d�}|S)	a�
    Create a CIMC user with username and password.

    Args:
        uid(int): The user ID slot to create the user account in.

        username(str): The name of the user.

        password(str): The clear text password of the user.

        priv(str): The privilege level of the user.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.create_user 11 username=admin password=foobar priv=admin

    �The user ID must be specified.zThe username must be specified.zThe password must be specified.z&The privilege level must be specified.�sys/user-ext/user-zj<aaaUser id="{0}" accountStatus="active" name="{1}" priv="{2}"
    pwd="{3}"  dn="sys/user-ext/user-{0}"/>r
F�r�
exceptions�CommandExecutionErrorrr)�uid�username�password�privrrrr	r	r
�create_userSs$�
��r cC�tddd�}|S)z�
    Get the default values of BIOS tokens.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_bios_defaults

    �cimc.get_config_resolver_classZbiosPlatformDefaultsT�r�rr	r	r
�get_bios_defaults��r%cCr!)z�
    Get the C240 server BIOS token values.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_bios_settings

    r"ZbiosSettingsTr#r$r	r	r
�get_bios_settings�r&r'cCr!)z�
    Retrieves the configured boot order table.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_boot_order

    r"Z	lsbootDefTr#r$r	r	r
�get_boot_order�r&r(cCr!)z}
    Get the CPU product ID details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_cpu_details

    r"Z
pidCatalogCpuTr#r$r	r	r
�get_cpu_details�r&r)cCr!)zw
    Get the HDD product ID details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_disks

    r"Z
pidCatalogHddTr#r$r	r	r
�	get_disks�r&r*cCr!)z�
    Get the adapter Ethernet interface details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_ethernet_interfaces

    r"ZadaptorHostEthIfTr#r$r	r	r
�get_ethernet_interfaces�r&r+cCr!)z�
    Get the adapter fibre channel interface details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_fibre_channel_interfaces

    r"ZadaptorHostFcIfTr#r$r	r	r
�get_fibre_channel_interfaces�r&r,cCr!)z�
    Retrieves the current running firmware versions of server components.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_firmware

    r"ZfirmwareRunningFr#r$r	r	r
�get_firmware�r&r-c
CsLtddd�}z|ddddWSty%}zWYd}~dSd}~ww)	z�
    Retrieves the hostname from the device.

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_hostname

    r"�mgmtIfTZ
outConfigsr�hostnameNzUnable to retrieve hostname)r�	Exception)r�errr	r	r
�get_hostnames
��r2cCr!)zu
    Retrieves LDAP server details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_ldap

    r"ZaaaLdapTr#r$r	r	r
�get_ldapr&r3cCr!)z�
    Retrieve the management interface details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_management_interface

    r"r.Fr#r$r	r	r
�get_management_interface'r&r4cCr!)z}
    Get the memory RAS BIOS token.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_memory_token

    r"Z"biosVfSelectMemoryRASConfigurationFr#r$r	r	r
�get_memory_token7s�r5cCr!)z�
    Get the IMM/Memory unit product ID details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_memory_unit

    r"ZpidCatalogDimmTr#r$r	r	r
�get_memory_unitIr&r6cCr!)z�
    Get the list of network adapters and configuration details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_network_adapters

    r"ZnetworkAdapterEthIfTr#r$r	r	r
�get_network_adaptersYr&r7cCr!)z�
    Retrieves the current running NTP configuration.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_ntp

    r"ZcommNtpProviderFr#r$r	r	r
�get_ntpir&r8cCr!)z
    Get the PCI adapter product ID details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_disks

    r"ZpidCatalogPCIAdapterTr#r$r	r	r
�get_pci_adaptersyr&r9cCr!)z�
    Get the configuration of the power settings from the device. This is only available
    on some C-Series servers.

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_power_configuration

    r"ZbiosVfResumeOnACPowerLossTr#r$r	r	r
�get_power_configuration�sr:cCr!)z�
    Retrieves the power supply unit details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_power_supplies

    r"ZequipmentPsuFr#r$r	r	r
�get_power_supplies�r&r;cCr!)z�
    Get the snmp configuration details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_snmp_config

    r"ZcommSnmpFr#r$r	r	r
�get_snmp_config�r&r<cCr!)z~
    Get the Syslog client-server details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_syslog

    r"ZcommSyslogClientFr#r$r	r	r
�
get_syslog�r&r=cCr!)z�
    Get the Syslog configuration settings from the system.

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_syslog_settings

    r"Z
commSyslogFr#r$r	r	r
�get_syslog_settings�s
r>cCr!)zy
    Get the system information.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_system_info

    r"ZcomputeRackUnitFr#r$r	r	r
�get_system_info�r&r?cCr!)zk
    Get the CIMC users.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_users

    r"ZaaaUserFr#r$r	r	r
�	get_users�r&r@cCr!)z�
    Get the VIC adapter general profile details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_vic_adapters

    r"ZadaptorGenProfileTr#r$r	r	r
�get_vic_adapters�r&rAcCr!)z�
    Get the VIC adapter uplink port details.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.get_vic_uplinks

    r"ZadaptorExtEthIfTr#r$r	r	r
�get_vic_uplinksr&rB�nfsc
Csz|stj�d��|stj�d��|stj�d��|r#|r#d�||�}nd}d|��}d�|||||�}td||d	�}	|	S)
ar
    Mounts a remote file through a remote share. Currently, this feature is supported in version 1.5 or greater.
    The remote share can be either NFS, CIFS, or WWW.

    Some of the advantages of CIMC Mounted vMedia include:
      Communication between mounted media and target stays local (inside datacenter)
      Media mounts can be scripted/automated
      No vKVM requirements for media connection
      Multiple share types supported
      Connections supported through all CIMC interfaces

      Note: CIMC Mounted vMedia is enabled through BIOS configuration.

    Args:
        name(str): The name of the volume on the CIMC device.

        remote_share(str): The file share link that will be used to mount the share. This can be NFS, CIFS, or WWW. This
        must be the directory path and not the full path to the remote file.

        remote_file(str): The name of the remote file to mount. It must reside within remote_share.

        mount_type(str): The type of share to mount. Valid options are nfs, cifs, and www.

        username(str): An optional requirement to pass credentials to the remote share. If not provided, an
        unauthenticated connection attempt will be made.

        password(str): An optional requirement to pass a password to the remote share. If not provided, an
        unauthenticated connection attempt will be made.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.mount_share name=WIN7 remote_share=10.xxx.27.xxx:/nfs remote_file=sl1huu.iso

        salt '*' cimc.mount_share name=WIN7 remote_share=10.xxx.27.xxx:/nfs remote_file=sl1huu.iso username=bob password=badpassword

    z!The share name must be specified.z(The remote share path must be specified.z'The remote file name must be specified.z' mountOptions='username={},password={}'�zsys/svc-ext/vmedia-svc/vmmap-z�<commVMediaMap dn='sys/svc-ext/vmedia-svc/vmmap-{}' map='{}'{}
    remoteFile='{}' remoteShare='{}' status='created'
    volumeName='Win12' />r
Fr)
�nameZremote_shareZremote_fileZ
mount_typerrZ
mount_optionsrrrr	r	r
�mount_shares./���

��rFcCsd}d}td||d�}|S)zn
    Power cycling the server.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.reboot

    zsys/rack-unit-1zU<computeRackUnit adminPower="cycle-immediate" dn="sys/rack-unit-1"></computeRackUnit>r
Fr#)rrrr	r	r
�rebootmsrGc
Csz|stj�d��d}d�|�}td||d�}z|dddd	d
kr'WdSWdSty<}zWYd}~dSd}~ww)
z�
    Sets the hostname on the server.

    .. versionadded:: 2019.2.0

    Args:
        hostname(str): The new hostname to set.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.set_hostname foobar

    z!Hostname option must be provided.zsys/rack-unit-1/mgmt/if-1z?<mgmtIf dn="sys/rack-unit-1/mgmt/if-1" hostname="{}" ></mgmtIf>r
FZ	outConfigr.r�statusZmodifiedTN)rrrrrr0)r/rrrr1r	r	r
�set_hostname�s ����rIcCs�gd�}d}|r||vr|d|�d�7}ntj�d��|r0||vr*|d|�d�7}ntj�d��d}d	|�d
�}td||d�}|S)
a�
    Sets the logging levels of the CIMC devices. The logging levels must match
    the following options: emergency, alert, critical, error, warning, notice,
    informational, debug.

    .. versionadded:: 2019.2.0

    Args:
        remote(str): The logging level for SYSLOG logs.

        local(str): The logging level for the local device.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.set_logging_levels remote=error local=notice

    )Z	emergencyZalert�critical�error�warningZnoticeZ
informational�debugrDz remoteSeverity="�"z$Remote Severity option is not valid.z localSeverity="z#Local Severity option is not valid.zsys/svc-ext/syslogz#<commSyslog dn="sys/svc-ext/syslog"z ></commSyslog>r
F)rrrr)Zremote�localZlogging_options�queryrrrr	r	r
�set_logging_levels�s$��rQrDcCs(d}d�||||�}td||d�}|S)a"
    Sets the NTP servers configuration. This will also enable the client NTP service.

    Args:
        server1(str): The first IP address or FQDN of the NTP servers.

        server2(str): The second IP address or FQDN of the NTP servers.

        server3(str): The third IP address or FQDN of the NTP servers.

        server4(str): The fourth IP address or FQDN of the NTP servers.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.set_ntp_server 10.10.10.1

        salt '*' cimc.set_ntp_server 10.10.10.1 foo.bar.com

    zsys/svc-ext/ntp-svcz<commNtpProvider dn="sys/svc-ext/ntp-svc" ntpEnable="yes" ntpServer1="{}" ntpServer2="{}"
    ntpServer3="{}" ntpServer4="{}"/>r
Fr)Zserver1Zserver2Zserver3Zserver4rrrr	r	r
�set_ntp_server�s��rRcCs�d}|dkr-d}|r,|dkr|d7}|r|d|�d�7}n$|dkr&|d	7}ntj�d
��n|dkr4d}n
|dkr;d
}ntj�d��d}d�|�}td||d�}|S)a�
    Sets the power configuration on the device. This is only available for some
    C-Series servers.

    .. versionadded:: 2019.2.0

    Args:
        policy(str): The action to be taken when chassis power is restored after
        an unexpected power loss. This can be one of the following:

            reset: The server is allowed to boot up normally when power is
            restored. The server can restart immediately or, optionally, after a
            fixed or random delay.

            stay-off: The server remains off until it is manually restarted.

            last-state: The server restarts and the system attempts to restore
            any processes that were running before power was lost.

        delayType(str): If the selected policy is reset, the restart can be
        delayed with this option. This can be one of the following:

            fixed: The server restarts after a fixed delay.

            random: The server restarts after a random delay.

        delayValue(int): If a fixed delay is selected, once chassis power is
        restored and the Cisco IMC has finished rebooting, the system waits for
        the specified number of seconds before restarting the server. Enter an
        integer between 0 and 240.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.set_power_configuration stay-off

        salt '*' cimc.set_power_configuration reset fixed 0

    rDrz vpResumeOnACPowerLoss="reset"�fixedz delayType="fixed"z delay="rN�randomz delayType="random"zInvalid delay type entered.zstay-offz
last-statez# vpResumeOnACPowerLoss="last-state"z"The power state must be specified.z-sys/rack-unit-1/board/Resume-on-AC-power-losszu<biosVfResumeOnACPowerLoss
    dn="sys/rack-unit-1/board/Resume-on-AC-power-loss"{}>
    </biosVfResumeOnACPowerLoss>r
Fr)�policyZ	delayTypeZ
delayValuerPrrrr	r	r
�set_power_configurations<*�
�����rV�primarycCs`|stj�d��|dkrd}d�|�}n|dkr d}d�|�}ntj�d��td	||d
�}|S)a�
    Set the SYSLOG server on the host.

    Args:
        server(str): The hostname or IP address of the SYSLOG server.

        type(str): Specifies the type of SYSLOG server. This can either be primary (default) or secondary.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.set_syslog_server foo.bar.com

        salt '*' cimc.set_syslog_server foo.bar.com primary

        salt '*' cimc.set_syslog_server foo.bar.com secondary

    z$The SYSLOG server must be specified.rWz!sys/svc-ext/syslog/client-primaryz�<commSyslogClient name='primary' adminState='enabled'  hostname='{}'
        dn='sys/svc-ext/syslog/client-primary'> </commSyslogClient>Z	secondaryz#sys/svc-ext/syslog/client-secondaryz�<commSyslogClient name='secondary' adminState='enabled'  hostname='{}'
        dn='sys/svc-ext/syslog/client-secondary'> </commSyslogClient>z4The SYSLOG type must be either primary or secondary.r
Fr)�server�typerrrr	r	r
�set_syslog_serverPs.������rZc	Cs�d}|s
tj�d��|r|d|�d�7}|r|d|�d�7}|r(|d|�d�7}|r2|d|�d�7}d|��}d	�||�}td
||d�}|S)a�
    Sets a CIMC user with specified configurations.

    .. versionadded:: 2019.2.0

    Args:
        uid(int): The user ID slot to create the user account in.

        username(str): The name of the user.

        password(str): The clear text password of the user.

        priv(str): The privilege level of the user.

        status(str): The account status of the user.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.set_user 11 username=admin password=foobar priv=admin active

    rDrz accountStatus="rNz name="z priv="z pwd="rz1<aaaUser id="{0}"{1} dn="sys/user-ext/user-{0}"/>r
Fr)	rrrrrHZconfrrrr	r	r
�set_user�s
r[cC�D|stj�d��|stj�d��d}d�||�}td||d�}|S)a.
    Update the BIOS firmware through TFTP.

    Args:
        server(str): The IP address or hostname of the TFTP server.

        path(str): The TFTP path and filename for the BIOS image.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.tftp_update_bios foo.bar.com HP-SL2.cap

    �"The server name must be specified.� The TFTP path must be specified.z!sys/rack-unit-1/bios/fw-updatablez�<firmwareUpdatable adminState='trigger' dn='sys/rack-unit-1/bios/fw-updatable'
    protocol='tftp' remoteServer='{}' remotePath='{}'
    type='blade-bios' />r
Fr�rX�pathrrrr	r	r
�tftp_update_bios�����racCr\)a.
    Update the CIMC firmware through TFTP.

    Args:
        server(str): The IP address or hostname of the TFTP server.

        path(str): The TFTP path and filename for the CIMC image.

    CLI Example:

    .. code-block:: bash

        salt '*' cimc.tftp_update_cimc foo.bar.com HP-SL2.bin

    r]r^z!sys/rack-unit-1/mgmt/fw-updatablez�<firmwareUpdatable adminState='trigger' dn='sys/rack-unit-1/mgmt/fw-updatable'
    protocol='tftp' remoteServer='{}' remotePath='{}'
    type='blade-controller' />r
Frr_r	r	r
�tftp_update_cimc�rbrc)F)NNNN)NNNrCNN)N)NN)rDrDrDrD)NNN)NrW)NNNNN)/�__doc__�loggingZsalt.proxy.cimcrZsalt.utils.platform�	getLogger�__name__�logrrrr r%r'r(r)r*r+r,r-r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrFrGrIrQrRrVrZr[rarcr	r	r	r
�<module>sd


!/
�O

%
:
"
M
0
2&