110110class IncomparableException (Exception ):
111111 pass
112112
113+ def trailing (template , * targets ):
114+ s = template
115+ for t in targets :
116+ n = s .find (t )
117+ if n == - 1 :
118+ raise ValueError ("Target " + t + " not found in template." )
119+ s = s [n + len (t ):]
120+ return s
121+
113122# Filter the given state content record according to the given arg list.
114123def _filter_content (content , * args ):
115124 if len (args ) > 0 :
@@ -458,7 +467,8 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query):
458467 if path_segment .startswith ('/' ):
459468 path = path_segment
460469 else :
461- path = self .path + path_segment
470+ path = self .service ._abspath (self .path + path_segment , owner = owner ,
471+ app = app , sharing = sharing )
462472 # ^-- This was "%s%s" % (self.path, path_segment).
463473 # That doesn't work, because self.path may be UrlEncoded.
464474 return self .service .get (path ,
@@ -513,7 +523,8 @@ def post(self, path_segment="", owner=None, app=None, sharing=None, **query):
513523 if path_segment .startswith ('/' ):
514524 path = path_segment
515525 else :
516- path = self .path + path_segment
526+ path = self .service ._abspath (self .path + path_segment , owner = owner ,
527+ app = app , sharing = sharing )
517528 return self .service .post (path ,
518529 owner = owner , app = app , sharing = sharing ,
519530 ** query )
@@ -986,7 +997,13 @@ def _entity_path(self, state):
986997 # This has been factored out so that it can be easily
987998 # overloaded by Configurations, which has to switch its
988999 # entities' endpoints from its own properties/ to configs/.
989- return urllib .unquote (state .links .alternate )
1000+ raw_path = urllib .unquote (state .links .alternate )
1001+ if 'servicesNS/' in raw_path :
1002+ return trailing (raw_path , 'servicesNS/' , '/' , '/' )
1003+ elif 'services/' in raw_path :
1004+ return trailing (raw_path , 'services/' )
1005+ else :
1006+ return raw_path
9901007
9911008 def _load_list (self , response ):
9921009 """Converts *response* to a list of entities.
@@ -1080,7 +1097,7 @@ def create(self, name, **params):
10801097 state = _parse_atom_entry (entry )
10811098 entity = self .item (
10821099 self .service ,
1083- urllib . unquote (state . links . alternate ),
1100+ self . _entity_path (state ),
10841101 state = state )
10851102 return entity
10861103
@@ -1278,7 +1295,7 @@ def _entity_path(self, state):
12781295 # Overridden to make all the ConfigurationFile objects
12791296 # returned refer to the configs/ path instead of the
12801297 # properties/ path used by Configrations.
1281- return self . service . _abspath ( PATH_CONF % state ['title' ])
1298+ return PATH_CONF % state ['title' ]
12821299
12831300
12841301class Stanza (Entity ):
@@ -1363,6 +1380,20 @@ def clean(self, timeout=60):
13631380 raise OperationError , "Operation timed out."
13641381 return self
13651382
1383+ def disable (self ):
1384+ """Disables this index."""
1385+ # Starting in Ace, we have to do this with specific sharing,
1386+ # unlike most other entities.
1387+ self .post ("disable" , sharing = "system" )
1388+ return self
1389+
1390+ def enable (self ):
1391+ """Enables this index."""
1392+ # Starting in Ace, we have to reenable this with a specific
1393+ # sharing unlike most other entities.
1394+ self .post ("enable" , sharing = "system" )
1395+ return self
1396+
13661397 def roll_hot_buckets (self ):
13671398 """Performs rolling hot buckets for this index."""
13681399 self .post ("roll-hot-buckets" )
@@ -1819,7 +1850,7 @@ def export(self, query, **params):
18191850 to two for create followed by preview), plus at most two more
18201851 if autologin is turned on.
18211852
1822- :raises SyntaxError : on invalid queries.
1853+ :raises ValueError : on invalid queries.
18231854
18241855 :param query: Splunk search language query to run
18251856 :type query: ``str``
@@ -1831,8 +1862,8 @@ def export(self, query, **params):
18311862 try :
18321863 return self .post (path_segment = "export" , search = query , ** params ).body
18331864 except HTTPError as he :
1834- if he .status == 400 and 'Search operation' in str ( he ) :
1835- raise SyntaxError (str (he ))
1865+ if he .status == 400 :
1866+ raise ValueError (str (he ))
18361867 else :
18371868 raise
18381869
@@ -1858,7 +1889,7 @@ def oneshot(self, query, **params):
18581889 to two for create followed by results), plus at most two more
18591890 if autologin is turned on.
18601891
1861- :raises SyntaxError : on invalid queries.
1892+ :raises ValueError : on invalid queries.
18621893
18631894 :param query: Splunk search language query to run
18641895 :type query: ``str``
@@ -1870,8 +1901,8 @@ def oneshot(self, query, **params):
18701901 try :
18711902 return self .post (search = query , exec_mode = "oneshot" , ** params ).body
18721903 except HTTPError as he :
1873- if he .status == 400 and 'Search operation' in str ( he ) :
1874- raise SyntaxError (str (he ))
1904+ if he .status == 400 :
1905+ raise ValueError (str (he ))
18751906 else :
18761907 raise
18771908
0 commit comments