%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c	@@s�dZddlmZmZmZddlZddlZddlmZddl	m
Z
eje�Z
d�Zdddddddd�Zddddddddd�Zddddddd	�Zd
d
d
d�Zdd
d�ZdS(
u-
Manage chassis via Salt Proxies.

.. versionadded:: 2015.8.2

Below is an example state that sets basic parameters:

.. code-block:: yaml

    my-dell-chassis:
      dellchassis.chassis:
        - chassis_name: my-dell-chassis
        - datacenter: dc-1-us
        - location: my-location
        - mode: 2
        - idrac_launch: 1
        - slot_names:
          - server-1: my-slot-name
          - server-2: my-other-slot-name
        - blade_power_states:
          - server-1: on
          - server-2: off
          - server-3: powercycle

However, it is possible to place the entire set of chassis configuration
data in pillar. Here's an example pillar structure:

.. code-block:: yaml

    proxy:
      host: 10.27.20.18
      admin_username: root
      fallback_admin_username: root
      passwords:
        - super-secret
        - old-secret
      proxytype: fx2

      chassis:
        name: fx2-1
        username: root
        password: saltstack1
        datacenter: london
        location: rack-1-shelf-3
        management_mode: 2
        idrac_launch: 0
        slot_names:
          - 'server-1': blade1
          - 'server-2': blade2

        servers:
          server-1:
            idrac_password: saltstack1
            ipmi_over_lan: True
            ip: 172.17.17.132
            netmask: 255.255.0.0
            gateway: 172.17.17.1
          server-2:
            idrac_password: saltstack1
            ipmi_over_lan: True
            ip: 172.17.17.2
            netmask: 255.255.0.0
            gateway: 172.17.17.1
          server-3:
            idrac_password: saltstack1
            ipmi_over_lan: True
            ip: 172.17.17.20
            netmask: 255.255.0.0
            gateway: 172.17.17.1
          server-4:
            idrac_password: saltstack1
            ipmi_over_lan: True
            ip: 172.17.17.2
            netmask: 255.255.0.0
            gateway: 172.17.17.1

        switches:
          switch-1:
            ip: 192.168.1.2
            netmask: 255.255.255.0
            gateway: 192.168.1.1
            snmp: nonpublic
            password: saltstack1
          switch-2:
            ip: 192.168.1.3
            netmask: 255.255.255.0
            gateway: 192.168.1.1
            snmp: nonpublic
            password: saltstack1

And to go with it, here's an example state that pulls the data from the
pillar stated above:

.. code-block:: jinja

    {% set details = pillar.get('proxy:chassis', {}) %}
    standup-step1:
      dellchassis.chassis:
        - name: {{ details['name'] }}
        - location: {{ details['location'] }}
        - mode: {{ details['management_mode'] }}
        - idrac_launch: {{ details['idrac_launch'] }}
        - slot_names:
          {% for entry details['slot_names'] %}
            - {{ entry.keys()[0] }}: {{ entry[entry.keys()[0]]  }}
          {% endfor %}

    blade_powercycle:
      dellchassis.chassis:
        - blade_power_states:
          - server-1: powercycle
          - server-2: powercycle
          - server-3: powercycle
          - server-4: powercycle

    # Set idrac_passwords for blades.  racadm needs them to be called 'server-x'
    {% for k, v in details['servers'].iteritems() %}
    {{ k }}:
      dellchassis.blade_idrac:
        - idrac_password: {{ v['idrac_password'] }}
    {% endfor %}

    # Set management ip addresses, passwords, and snmp strings for switches
    {% for k, v in details['switches'].iteritems() %}
    {{ k }}-switch-setup:
      dellchassis.switch:
        - name: {{ k }}
        - ip: {{ v['ip'] }}
        - netmask: {{ v['netmask'] }}
        - gateway: {{ v['gateway'] }}
        - password: {{ v['password'] }}
        - snmp: {{ v['snmp'] }}
    {% endfor %}

.. note::

    This state module relies on the dracr.py execution module, which runs racadm commands on
    the chassis, blades, etc. The racadm command runs very slowly and, depending on your state,
    the proxy minion return might timeout before the racadm commands have completed. If you
    are repeatedly seeing minions timeout after state calls, please use the ``-t`` CLI argument
    to increase the timeout variable.

    For example:

    .. code-block:: bash

        salt '*' state.sls my-dell-chasis-state-name -t 60

.. note::

    The Dell CMC units perform adequately but many iDRACs are **excruciatingly**
    slow.  Some functions can take minutes to execute.

i(tabsolute_importtunicode_literalstprint_functionN(tsix(tCommandExecutionErrorcC@s
dtkS(Nuchassis.cmd(t__salt__(((s;/usr/lib/python2.7/site-packages/salt/states/dellchassis.pyt__virtual__�scC@szi|d6td6id6dd6}|s>td�\}	}
n|}
tddd	|�}|d
d}|d1k	r|tks�|dkr�d
}n|tks�|dkr�d}ntdddd|ddd|
�}
|
|kri|
d6|d6}||dd<qn|d1k	r|tdd|ddd|
�}|dd}||kr|i|d6|d6}||dd<q|n|d1k	s�|s�|s�|r:|tks�|dkr�d}nd}tj|d
d�dkr|dkri|d
dd6|d6}||dd<n|dkr:t|||g�r:tddd	|�}i}i}|d
d|kr�|d
d|d<||d<n|d
d |kr�|d
d |d!<||d!<n|d
d"|kr�|d
d"|d#<||d#<n|ikr7i|dd
<||dd
d<||dd
d<q7q:n|dikrXd$|d<|Std%r�|dikr�d1|d<d&|d<|Sd|dkr�td'dd|d|ddd|
�}|s�t|d<t|ddd(<q�nd|dkrrtd)|d|ddd|
�}|d*dkrAt|ddd(<qrt|d<t|ddd(<||ddd+<nd|dkr�tdd,d-|�}|d*r�t|ddd(<q�t|d<t|ddd(<||ddd+<nd
|dkrvtdd,d.|d/|d0|d	|�}|d*dkrEt|dd
d(<qvt|d<t|dd
d(<||dd
d+<n|S(2u(
    Set parameters for iDRAC in a blade.

    :param idrac_password: Password to use to connect to the iDRACs directly
        (idrac_ipmi and idrac_dnsname must be set directly on the iDRAC.  They
        can't be set through the CMC.  If this password is present, use it
        instead of the CMC password)
    :param idrac_ipmi: Enable/Disable IPMI over LAN
    :param idrac_ip: Set IP address for iDRAC
    :param idrac_netmask: Set netmask for iDRAC
    :param idrac_gateway: Set gateway for iDRAC
    :param idrac_dhcp: Turn on DHCP for iDRAC (True turns on, False does
        nothing becaause setting a static IP will disable DHCP).

    :return: A standard Salt changes dictionary

    NOTE: If any of the IP address settings is configured, all of ip, netmask,
    and gateway must be present
    unameuresultuchangesuucommentuchassis.chassis_credentialsuchassis.cmdunetwork_infotmoduleuNetworku
IP Addressiu1iu0udracr.get_generalu
cfgIpmiLanucfgIpmiLanEnablethosttadmin_usernameuroottadmin_passworduOlduNewuIPMIudracr.get_dns_dracnameu[Key=iDRAC.Embedded.1#NIC.1]u
DNSRacNameuDHCP Enabledu	DRAC DHCPuipuSubnet MaskunetmaskuGatewayugatewayu/iDRAC on blade is already in the desired state.utestuiDRAC on blade will change.udracr.set_generalusuccessudracr.set_dns_dracnameuretcodeureturnu
set_niccfgtdhcptiptnetmasktgatewayN(tTrueRtNonetFalseRt	text_typetallt__opts__(tnametidrac_passwordt
idrac_ipmitidrac_ipt
idrac_netmaskt
idrac_gatewayt
idrac_dnsnamet
idrac_dhcptrettusernametpasswordtmodule_networktcurrent_idrac_iptcurrent_ipmitchtdnsrettcurrent_dnsnametcurrent_networktold_ipv4tnew_ipv4tipmi_resulttdnsracname_resulttdhcp_resulttnetwork_result((s;/usr/lib/python2.7/site-packages/salt/states/dellchassis.pytblade_idrac�s�

				

	)
!
	






	

	


	
c	(
C@s�i|d6|d6td6id6dd6}	d}
d}d	}d
}
t|
d�}|ritj|�}nt|
d�}||kr�|	djii|d
6|d6d6�nt|
d�}|r�||kr�|	djii|d
6|d6d6�n|r(|	djiidd
6dd6d6�n|rvt|
d�}||krv|	djii|d
6|d6d6�qvn|r�t|
d||�}||kr�|	djii|d
6|d6d6�q�n|rt|
d||
�}||kr|	djii|d
6|d6d6�qn|r3t|
d�}x�|D]�}|j�d}||}|jd�rw|d}n|j|�jd�}||kr;i||6}i||6}|	djd�d:kr�|	djiiid
6id6d6�n|	ddd
j|�|	dddj|�q;q;Wni}i}|rx!|D]}|j�d}t|
dd |�}|jd!d"�||<||d#kr�||d"kr�||r�d#||<q�n||d$kr||d"kr||rd$||<qn||d%krL||d"kr;||r;d$||<n||d"kre||red%||<qeqLqLWx�tj	|�D]�\}} i|||6}i| |6}|	djd&�d:kr�|	djiiid
6id6d&6�n|	dd&d
j|�|	dd&dj|�qyWn|	dikr<d'|	d<|	St
d(r^d:|	d<d)|	d<|	St|
d*|�}|r�t|
d+|�}nt}!|rt}"t|
d,d-d.d/d0d1|�r
xL|d2D]7}#t|
d3d-d.d1|d |#�}"|"s�t}!q�q�Wqt}!n|r/t|
d4|�}$n|rQt|
d5|||�}n|rst|
d5||
|�}n|	djd�d:k	rg}%xa|D]Y}|j�d}||}|jd�r�|d}n|%jt|
d6||��q�Wt
|%�tkrt}qt}nt}&xEtj	|�D]4\}} t|
d7| d |�}'|'s0t}&q0q0Wt
||||||&g�tkr�t|	d<d8|	d<nd9|	d<|	S(;u(
    Manage a Dell Chassis.

    chassis_name
        The name of the chassis.

    datacenter
        The datacenter in which the chassis is located

    location
        The location of the chassis.

    password
        Password for the chassis. Note: If this password is set for the chassis,
        the current implementation of this state will set this password both on
        the chassis and the iDrac passwords on any configured blades. If the
        password for the blades should be distinct, they should be set separately
        with the blade_idrac function.

    mode
        The management mode of the chassis. Viable options are:

        - 0: None
        - 1: Monitor
        - 2: Manage and Monitor

    idrac_launch
        The iDRAC launch method of the chassis. Viable options are:

        - 0: Disabled (launch iDRAC using IP address)
        - 1: Enabled (launch iDRAC using DNS name)

    slot_names
        The names of the slots, provided as a list identified by
        their slot numbers.

    blade_power_states
        The power states of a blade server, provided as a list and
        identified by their server numbers. Viable options are:

         - on: Ensure the blade server is powered on.
         - off: Ensure the blade server is powered off.
         - powercycle: Power cycle the blade server.

    Example:

    .. code-block:: yaml

        my-dell-chassis:
          dellchassis.chassis:
            - chassis_name: my-dell-chassis
            - location: my-location
            - datacenter: london
            - mode: 2
            - idrac_launch: 1
            - slot_names:
              - 1: my-slot-name
              - 2: my-other-slot-name
            - blade_power_states:
              - server-1: on
              - server-2: off
              - server-3: powercycle
    unameuchassis_nameuresultuchangesuucommentuchassis.cmducfgRacTuningucfgRacTuneChassisMgmtAtServerucfgRacTuneIdracDNSLaunchEnableu	inventoryuget_chassis_nameuOlduNewuNameuget_chassis_datacenteru
Datacenteru******uPassworduget_chassis_locationuLocationuget_generaluManagement ModeuiDrac Launch Methodulist_slotnamesiuslot-iuslotnameu
Slot Namesuserver_powerstatusRustatusi����u	powerdownupowerupu
powercycleuBlade Power Statesu-Dell chassis is already in the desired state.utestu'Dell chassis configuration will change.uset_chassis_nameuset_chassis_locationuchange_passwordRuroottuidiRuserverudeploy_passworduset_chassis_datacenteruset_generaluset_slotnameuserver_poweru,There was an error setting the Dell chassis.uDell chassis was updated.N(RRRRtupdatetkeyst
startswithtgetRt	iteritemsRRtappendtany((Rtchassis_nameRt
datacentertlocationtmodetidrac_launcht
slot_namestblade_power_statesRtchassis_cmdt
cfg_tuningtmode_cmdt
launch_cmdt	inventorytcurrent_namet
current_dctcurrent_locationtcurrent_modetcurrent_launch_methodtcurrent_slot_nameststkeytnew_nametcurrent_slot_nametoldtnewtcurrent_power_statesttarget_power_statestbtstatustktvt	pw_resultt	pw_singletbladetdatacenter_resultt	slot_retstpowerchange_all_oktpowerchange_ok((s;/usr/lib/python2.7/site-packages/salt/states/dellchassis.pytchassis@sB




















#




 



	
		



!		



c
C@s�i|d6td6id6dd6}tddd|�}y4|jd	d
�d
krot|d<|d|d<|S|s�|s�|r�|s�|dd
}n|s�|dd}n|s�|dd}q�n|dddkr"|r"|djiii|ddd6d6i|d6d6d6�n|s4|s4|r�|r�||dd
ksw||ddksw||ddkr�|djii|dd6i|d
6|d6|d6d6d6�n|r�d|dkr�i|dd<n|ddjidd6�n|rEd|dkr&i|dd<n|ddjidd6�n|dikrkd|d|d<|SWn&tk
r�i|d<d|d<|SXtdr�d%|d<d|d|d<|St}	}
}}|r�tddd|d|�}	n|s|s|r*tdd|||d|�}
n|rOtdd d!|d|�}n|rqtdd"|d|�}nt|||
|	g�tkr�t|d<d#j	|�|d<nd$j	|�|d<|S(&uI
    Manage switches in a Dell Chassis.

    name
        The switch designation (e.g. switch-1, switch-2)

    ip
        The Static IP Address of the switch

    netmask
        The netmask for the static IP

    gateway
        The gateway for the static IP

    dhcp
        True: Enable DHCP
        False: Do not change DHCP setup
        (disabling DHCP is automatic when a static IP is set)

    password
        The access (root) password for the switch

    snmp
        The SNMP community string for the switch

    Example:

    .. code-block:: yaml

        my-dell-chassis:
          dellchassis.switch:
            - switch: switch-1
            - ip: 192.168.1.1
            - netmask: 255.255.255.0
            - gateway: 192.168.1.254
            - dhcp: True
            - password: secret
            - snmp: public

    unameuresultuchangesuucommentuchassis.cmdunetwork_infoRuretcodeiustdoutuNetworku
IP AddressuSubnet MaskuGatewayuDHCP Enabledu0uOlduNewuDHCPuIPu*****uPassworduSNMPuSwitch u is already in desired stateu2Something went wrong retrieving the switch detailsutestu configuration will changeu
set_niccfgRudeploy_passwordurootudeploy_snmpu*There was an error setting the switch {0}.u$Dell chassis switch {0} was updated.N(
RRR2RR/tAttributeErrorRRR5tformat(
RRR
RRRtsnmpRtcurrent_nictdhcp_rettnet_rettpassword_rettsnmp_ret((s;/usr/lib/python2.7/site-packages/salt/states/dellchassis.pytswitch%sx+


&-





"
ucC@sjtjj||d�}td||�tdd}tdd}td|d|d|d	|�d
S(u+
    Update firmware for a single host
    iucp.get_fileuproxyu
admin_useruadmin_passwordudracr.update_firmwareRR	R
N(tostpathtjoinRt
__pillar__(tfirmwarefileRt	directorytdestRR((s;/usr/lib/python2.7/site-packages/salt/states/dellchassis.pyt_firmware_update�s
cC@s�i}i|_t}x�|D]�\}}yCt|||�|djiidj|�d6td6d6�Wqtk
r�}t}|djiidj|�d6td6tj|�d6d6�qXqW||d<|S(	u�
        State to update the firmware on host
        using the ``racadm`` command

        firmwarefile
            filename (string) starting with ``salt://``
        host
            string representing the hostname
            supplied to the ``racadm`` command
        directory
            Directory name where firmwarefile
            will be downloaded

    .. code-block:: yaml

        dell-chassis-firmware-update:
          dellchassis.firmware_update:
            hosts:
              cmc:
                salt://firmware_cmc.exe
              server-1:
                salt://firmware.exe
            directory: /opt/firmwares
    uchangesu!Firmware update submitted for {0}ucommentusuccessuhostu!FAILED to update firmware for {0}ureasonuresult(	tchangesRRlR/R]RRRR(thostsRjRtsuccessRRiterr((s;/usr/lib/python2.7/site-packages/salt/states/dellchassis.pytfirmware_update�s&	

 
(t__doc__t
__future__RRRtloggingRetsalt.extRtsalt.exceptionsRt	getLoggert__name__tlogRRR-R[RdRlRq(((s;/usr/lib/python2.7/site-packages/salt/states/dellchassis.pyt<module>�s&		�	�u

Zerion Mini Shell 1.0