#NEWLINE# def deactivate( ns , setting , device = None ) : #NEWLINE# #INDENT# '\n    Deactivate network setting.\n\n    :param LMI_IPAssignmentSettingData setting: Setting to deactivate.\n    :param device: Device to deactivate the setting on\n    :type device: LMI_IPNetworkConnection or None\n    ' #NEWLINE# service = ns . LMI_IPConfigurationService . first_instance ( ) #NEWLINE# if _provider_check_required_device ( ns ) : #NEWLINE# #INDENT# if ( device is None ) : #NEWLINE# #INDENT# if ( setting . classname == 'LMI_BridgingMasterSettingData' ) : #NEWLINE# #INDENT# slave_class = 'LMI_BridgingSlaveSettingData' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( setting . classname == 'LMI_BondingMasterSettingData' ) : #NEWLINE# #INDENT# slave_class = 'LMI_BondingSlaveSettingData' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# slave_class = None #NEWLINE# #UNINDENT# #UNINDENT# if slave_class : #NEWLINE# #INDENT# affected_settings = setting . associators ( AssocClass = 'LMI_OrderedIPAssignmentComponent' , ResultClass = slave_class ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# affected_settings = [ setting ] #NEWLINE# #UNINDENT# for slave_setting in affected_settings : #NEWLINE# #INDENT# device = slave_setting . first_associator ( AssocClass = 'LMI_IPElementSettingData' , ResultClass = 'LMI_IPNetworkConnection' ) #NEWLINE# result = service . SyncApplySettingToIPNetworkConnection ( SettingData = slave_setting , IPNetworkConnection = device , Mode = service . ApplySettingToIPNetworkConnection . ModeValues . Mode32769 ) #NEWLINE# if result . errorstr : #NEWLINE# #INDENT# raise LmiFailed ( ( 'Unable to deactivate setting: %s' % result . errorstr ) ) #NEWLINE# #UNINDENT# isCurrent = True #NEWLINE# while isCurrent : #NEWLINE# #INDENT# for esd in slave_setting . references ( ResultClass = 'LMI_IPElementSettingData' ) : #NEWLINE# #INDENT# if ( esd . IsCurrent == ns . LMI_IPElementSettingData . IsCurrentValues . IsNotCurrent ) : #NEWLINE# #INDENT# isCurrent = False #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# time . sleep ( 1 ) #NEWLINE# #UNINDENT# #UNINDENT# LOG ( ) . info ( 'Setting %s deactivated' , setting . Caption ) #NEWLINE# return 0 #NEWLINE# #UNINDENT# #UNINDENT# if ( device is not None ) : #NEWLINE# #INDENT# LOG ( ) . debug ( 'Deactivating setting %s on device %s' , setting . Caption , device . ElementName ) #NEWLINE# result = service . SyncApplySettingToIPNetworkConnection ( SettingData = setting , IPNetworkConnection = device , Mode = service . ApplySettingToIPNetworkConnection . ModeValues . Mode32769 ) #NEWLINE# if result . errorstr : #NEWLINE# #INDENT# raise LmiFailed ( ( 'Unable to deactivate setting: %s' % result . errorstr ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# result = service . SyncApplySettingToIPNetworkConnection ( SettingData = setting , Mode = service . ApplySettingToIPNetworkConnection . ModeValues . Mode32769 ) #NEWLINE# if result . errorstr : #NEWLINE# #INDENT# raise LmiFailed ( ( 'Unable to deactivate setting: %s' % result . errorstr ) ) #NEWLINE# #UNINDENT# #UNINDENT# LOG ( ) . info ( 'Setting %s deactivated' , setting . Caption ) #NEWLINE# return 0