#NEWLINE# def switch( name , ip = None , netmask = None , gateway = None , dhcp = None , password = None , snmp = None ) : #NEWLINE# #INDENT# '\n    Manage switches in a Dell Chassis.\n\n    name\n        The switch designation (e.g. switch-1, switch-2)\n\n    ip\n        The Static IP Address of the switch\n\n    netmask\n        The netmask for the static IP\n\n    gateway\n        The gateway for the static IP\n\n    dhcp\n        True: Enable DHCP\n        False: Do not change DHCP setup\n        (disabling DHCP is automatic when a static IP is set)\n\n    password\n        The access (root) password for the switch\n\n    snmp\n        The SNMP community string for the switch\n\n    Example:\n\n    .. code-block:: yaml\n\n        my-dell-chassis:\n          dellchassis.switch:\n            - switch: switch-1\n            - ip: 192.168.1.1\n            - netmask: 255.255.255.0\n            - gateway: 192.168.1.254\n            - dhcp: True\n            - password: secret\n            - snmp: public\n\n    ' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : True , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'comment' : '' , #NEWLINE# #UNINDENT# } #NEWLINE# current_nic = __salt__ [ 'chassis.cmd' ] ( 'network_info' , module = name ) #NEWLINE# try : #NEWLINE# #INDENT# if ( current_nic . get ( 'retcode' , 0 ) != 0 ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = current_nic [ 'stdout' ] #NEWLINE# return ret #NEWLINE# #UNINDENT# if ( ip or netmask or gateway ) : #NEWLINE# #INDENT# if ( not ip ) : #NEWLINE# #INDENT# ip = current_nic [ 'Network' ] [ 'IP Address' ] #NEWLINE# #UNINDENT# if ( not netmask ) : #NEWLINE# #INDENT# ip = current_nic [ 'Network' ] [ 'Subnet Mask' ] #NEWLINE# #UNINDENT# if ( not gateway ) : #NEWLINE# #INDENT# ip = current_nic [ 'Network' ] [ 'Gateway' ] #NEWLINE# #UNINDENT# #UNINDENT# if ( ( current_nic [ 'Network' ] [ 'DHCP Enabled' ] == '0' ) and dhcp ) : #NEWLINE# #INDENT# ret [ 'changes' ] . update ( { #NEWLINE# #INDENT# 'DHCP' : { #NEWLINE# #INDENT# 'Old' : { #NEWLINE# #INDENT# 'DHCP Enabled' : current_nic [ 'Network' ] [ 'DHCP Enabled' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# 'New' : { #NEWLINE# #INDENT# 'DHCP Enabled' : dhcp , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( ( ip or netmask or gateway ) and ( not dhcp ) and ( ( ip != current_nic [ 'Network' ] [ 'IP Address' ] ) or ( netmask != current_nic [ 'Network' ] [ 'Subnet Mask' ] ) or ( gateway != current_nic [ 'Network' ] [ 'Gateway' ] ) ) ) : #NEWLINE# #INDENT# ret [ 'changes' ] . update ( { #NEWLINE# #INDENT# 'IP' : { #NEWLINE# #INDENT# 'Old' : current_nic [ 'Network' ] , #NEWLINE# 'New' : { #NEWLINE# #INDENT# 'IP Address' : ip , #NEWLINE# 'Subnet Mask' : netmask , #NEWLINE# 'Gateway' : gateway , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if password : #NEWLINE# #INDENT# if ( 'New' not in ret [ 'changes' ] ) : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'New' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ret [ 'changes' ] [ 'New' ] . update ( { #NEWLINE# #INDENT# 'Password' : '*****' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if snmp : #NEWLINE# #INDENT# if ( 'New' not in ret [ 'changes' ] ) : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'New' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ret [ 'changes' ] [ 'New' ] . update ( { #NEWLINE# #INDENT# 'SNMP' : '*****' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( ret [ 'changes' ] == { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# ret [ 'comment' ] = ( ( 'Switch ' + name ) + ' is already in desired state' ) #NEWLINE# return ret #NEWLINE# #UNINDENT# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# ret [ 'changes' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ret [ 'comment' ] = 'Something went wrong retrieving the switch details' #NEWLINE# return ret #NEWLINE# #UNINDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# ret [ 'comment' ] = ( ( 'Switch ' + name ) + ' configuration will change' ) #NEWLINE# return ret #NEWLINE# #UNINDENT# dhcp_ret = net_ret = password_ret = snmp_ret = True #NEWLINE# if dhcp : #NEWLINE# #INDENT# dhcp_ret = __salt__ [ 'chassis.cmd' ] ( 'set_niccfg' , module = name , dhcp = dhcp ) #NEWLINE# #UNINDENT# if ( ip or netmask or gateway ) : #NEWLINE# #INDENT# net_ret = __salt__ [ 'chassis.cmd' ] ( 'set_niccfg' , ip , netmask , gateway , module = name ) #NEWLINE# #UNINDENT# if password : #NEWLINE# #INDENT# password_ret = __salt__ [ 'chassis.cmd' ] ( 'deploy_password' , 'root' , password , module = name ) #NEWLINE# #UNINDENT# if snmp : #NEWLINE# #INDENT# snmp_ret = __salt__ [ 'chassis.cmd' ] ( 'deploy_snmp' , snmp , module = name ) #NEWLINE# #UNINDENT# if ( any ( [ password_ret , snmp_ret , net_ret , dhcp_ret ] ) is False ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'There was an error setting the switch {0}.' . format ( name ) #NEWLINE# #UNINDENT# ret [ 'comment' ] = 'Dell chassis switch {0} was updated.' . format ( name ) #NEWLINE# return ret