Skip to content

Commit ebff1ba

Browse files
author
Jeremy Cook
committed
[DVPL-10898] Update all jobs endpoints to use v2 paths
1 parent e8c5841 commit ebff1ba

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

splunklib/client.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,9 +2661,12 @@ def oneshot(self, path, **kwargs):
26612661
class Job(Entity):
26622662

26632663
"""This class represents a search job."""
2664-
def __init__(self, service, sid, **kwargs):
2664+
def __init__(self, service, sid, defaultPath, **kwargs):
2665+
2666+
# Don't provide a path, allow it to be dynamically generated
26652667
Entity.__init__(self, service, '', skip_refresh=True, **kwargs)
26662668
self.sid = sid
2669+
self.defaultPath = defaultPath + sid + '/'
26672670

26682671
# The Job entry record is returned at the root of the response
26692672
def _load_atom_entry(self, response):
@@ -2675,7 +2678,7 @@ def cancel(self):
26752678
:return: The :class:`Job`.
26762679
"""
26772680
try:
2678-
self.post("control", action="cancel")
2681+
self.post(self.defaultPath + "control", action="cancel")
26792682
except HTTPError as he:
26802683
if he.status == 404:
26812684
# The job has already been cancelled, so
@@ -2690,7 +2693,7 @@ def disable_preview(self):
26902693
26912694
:return: The :class:`Job`.
26922695
"""
2693-
self.post("control", action="disablepreview")
2696+
self.post(self.defaultPath + "control", action="disablepreview")
26942697
return self
26952698

26962699
def enable_preview(self):
@@ -2700,7 +2703,7 @@ def enable_preview(self):
27002703
27012704
:return: The :class:`Job`.
27022705
"""
2703-
self.post("control", action="enablepreview")
2706+
self.post(self.defaultPath + "control", action="enablepreview")
27042707
return self
27052708

27062709
def events(self, **kwargs):
@@ -2727,7 +2730,7 @@ def finalize(self):
27272730
27282731
:return: The :class:`Job`.
27292732
"""
2730-
self.post("control", action="finalize")
2733+
self.post(self.defaultPath + "control", action="finalize")
27312734
return self
27322735

27332736
def is_done(self):
@@ -2748,7 +2751,7 @@ def is_ready(self):
27482751
:rtype: ``boolean``
27492752
27502753
"""
2751-
response = self.get()
2754+
response = self.get(self.defaultPath)
27522755
if response.status == 204:
27532756
return False
27542757
self._state = self.read(response)
@@ -2769,7 +2772,7 @@ def pause(self):
27692772
27702773
:return: The :class:`Job`.
27712774
"""
2772-
self.post("control", action="pause")
2775+
self.post(self.defaultPath + "control", action="pause")
27732776
return self
27742777

27752778
def results(self, **query_params):
@@ -2872,7 +2875,7 @@ def searchlog(self, **kwargs):
28722875
28732876
:return: The ``InputStream`` IO handle to this job's search log.
28742877
"""
2875-
return self.get("search.log", **kwargs).body
2878+
return self.get(self.defaultPath + "search.log", **kwargs).body
28762879

28772880
def set_priority(self, value):
28782881
"""Sets this job's search priority in the range of 0-10.
@@ -2885,7 +2888,7 @@ def set_priority(self, value):
28852888
28862889
:return: The :class:`Job`.
28872890
"""
2888-
self.post('control', action="setpriority", priority=value)
2891+
self.post(self.defaultPath + 'control', action="setpriority", priority=value)
28892892
return self
28902893

28912894
def summary(self, **kwargs):
@@ -2899,7 +2902,7 @@ def summary(self, **kwargs):
28992902
29002903
:return: The ``InputStream`` IO handle to this job's summary.
29012904
"""
2902-
return self.get("summary", **kwargs).body
2905+
return self.get(self.defaultPath + "summary", **kwargs).body
29032906

29042907
def timeline(self, **kwargs):
29052908
"""Returns a streaming handle to this job's timeline results.
@@ -2912,15 +2915,15 @@ def timeline(self, **kwargs):
29122915
29132916
:return: The ``InputStream`` IO handle to this job's timeline.
29142917
"""
2915-
return self.get("timeline", **kwargs).body
2918+
return self.get(self.defaultPath + "timeline", **kwargs).body
29162919

29172920
def touch(self):
29182921
"""Extends the expiration time of the search to the current time (now) plus
29192922
the time-to-live (ttl) value.
29202923
29212924
:return: The :class:`Job`.
29222925
"""
2923-
self.post("control", action="touch")
2926+
self.post(self.defaultPath + "control", action="touch")
29242927
return self
29252928

29262929
def set_ttl(self, value):
@@ -2932,15 +2935,15 @@ def set_ttl(self, value):
29322935
29332936
:return: The :class:`Job`.
29342937
"""
2935-
self.post("control", action="setttl", ttl=value)
2938+
self.post(self.defaultPath + "control", action="setttl", ttl=value)
29362939
return self
29372940

29382941
def unpause(self):
29392942
"""Resumes the current search, if paused.
29402943
29412944
:return: The :class:`Job`.
29422945
"""
2943-
self.post("control", action="unpause")
2946+
self.post(self.defaultPath + "control", action="unpause")
29442947
return self
29452948

29462949

@@ -2990,7 +2993,7 @@ def create(self, query, **kwargs):
29902993
raise TypeError("Cannot specify exec_mode=oneshot; use the oneshot method instead.")
29912994
response = self.post(search=query, **kwargs)
29922995
sid = _load_sid(response)
2993-
return Job(self.service, sid)
2996+
return Job(self.service, sid, self.path)
29942997

29952998
def export(self, query, **params):
29962999
"""Runs a search and immediately starts streaming preview events. This method returns a streaming handle to

0 commit comments

Comments
 (0)