@@ -401,7 +401,7 @@ def messages(self):
401401 @property
402402 def modular_input_kinds (self ):
403403 """Returns a collection of the modular input kinds on this Splunk instance."""
404- if self .splunk_version [ 0 ] >= 5 :
404+ if self .splunk_version >= ( 5 ,) :
405405 return ReadOnlyCollection (self , PATH_MODULAR_INPUTS , item = ModularInputKind )
406406 else :
407407 raise IllegalOperationException ("Modular inputs are not supported before Splunk version 5." )
@@ -1481,7 +1481,7 @@ def default(self):
14811481 return index ['defaultDatabase' ]
14821482
14831483 def delete (self , name ):
1484- if self .service .splunk_version [ 0 ] >= 5 :
1484+ if self .service .splunk_version >= ( 5 ,) :
14851485 Collection .delete (self , name )
14861486 else :
14871487 raise IllegalOperationException ("Deleting indexes via the REST API is "
@@ -1548,28 +1548,42 @@ def attached_socket(self, *args, **kwargs):
15481548
15491549 def clean (self , timeout = 60 ):
15501550 """Deletes the contents of the index.
1551-
1551+
1552+ `clean` blocks until the index is empty, since it needs to restore
1553+ values at the end.
1554+
15521555 :param `timeout`: The time-out period for the operation, in seconds (the
15531556 default is 60).
15541557 """
15551558 self .refresh ()
15561559 tds = self ['maxTotalDataSizeMB' ]
15571560 ftp = self ['frozenTimePeriodInSecs' ]
1558- self . update ( maxTotalDataSizeMB = 1 , frozenTimePeriodInSecs = 1 )
1559- self . roll_hot_buckets ()
1560-
1561- # Wait until the event count goes to zero
1562- count = 0
1563- while self . content . totalEventCount != '0' and count < timeout :
1564- sleep ( 1 )
1565- count += 1
1566- self .refresh ()
1561+ was_disabled_initially = self . disabled
1562+ try :
1563+ if ( not was_disabled_initially and \
1564+ self . service . splunk_version < ( 5 ,)):
1565+ # Need to disable the index first on Splunk 4.x,
1566+ # but it doesn't work to disable it on 5.0.
1567+ self . disable ( )
1568+ self . update ( maxTotalDataSizeMB = 1 , frozenTimePeriodInSecs = 1 )
1569+ self .roll_hot_buckets ()
15671570
1568- # Restore original values
1569- self .update (maxTotalDataSizeMB = tds ,
1570- frozenTimePeriodInSecs = ftp )
1571- if self .content .totalEventCount != '0' :
1572- raise OperationError , "Operation timed out."
1571+ start = datetime .now ()
1572+ diff = timedelta (seconds = timeout )
1573+ # Wait until event count goes to 0.
1574+ while self .content .totalEventCount != '0' and datetime .now () < start + diff :
1575+ sleep (1 )
1576+ self .refresh ()
1577+ finally :
1578+ # Restore original values
1579+ self .update (maxTotalDataSizeMB = tds , frozenTimePeriodInSecs = ftp )
1580+ if self .content .totalEventCount != '0' :
1581+ raise OperationError , "Cleaning index %s took longer than %s seconds; timing out." % \
1582+ (self .name , timeout )
1583+ if (not was_disabled_initially and \
1584+ self .service .splunk_version < (5 ,)):
1585+ # Re-enable the index if it was originally enabled and we messed with it.
1586+ self .enable ()
15731587 return self
15741588
15751589 def disable (self ):
0 commit comments