@@ -421,6 +421,7 @@ def __init__(self, **kwargs):
421
421
super (Service , self ).__init__ (** kwargs )
422
422
self ._splunk_version = None
423
423
self ._kvstore_owner = None
424
+ self ._instance_type = None
424
425
425
426
@property
426
427
def apps (self ):
@@ -572,7 +573,8 @@ def parse(self, query, **kwargs):
572
573
:type kwargs: ``dict``
573
574
:return: A semantic map of the parsed search query.
574
575
"""
575
- if self .splunk_version >= (9 ,0 ,2 ):
576
+ # if self.splunk_version >= (9,0,2):
577
+ if not self .disable_v2_api :
576
578
return self .post ("search/v2/parser" , q = query , ** kwargs )
577
579
return self .get ("search/parser" , q = query , ** kwargs )
578
580
@@ -695,6 +697,22 @@ def splunk_version(self):
695
697
self ._splunk_version = tuple ([int (p ) for p in self .info ['version' ].split ('.' )])
696
698
return self ._splunk_version
697
699
700
+ @property
701
+ def splunk_instance (self ):
702
+ if self ._instance_type is None :
703
+ splunk_info = self .info ;
704
+ if hasattr (splunk_info , 'instance_type' ) :
705
+ self ._instance_type = splunk_info ['instance_type' ]
706
+ else :
707
+ self ._instance_type = ''
708
+ return self ._instance_type
709
+
710
+ @property
711
+ def disable_v2_api (self ):
712
+ if self .splunk_instance == 'cloud' :
713
+ return self .splunk_version < (9 ,0 ,2209 )
714
+ return self .splunk_version < (9 ,0 ,2 )
715
+
698
716
@property
699
717
def kvstore_owner (self ):
700
718
"""Returns the KVStore owner for this instance of Splunk.
@@ -2722,7 +2740,8 @@ def __init__(self, service, sid, **kwargs):
2722
2740
# Default to v2 in Splunk Version 9+
2723
2741
path = "{path}{sid}"
2724
2742
# Formatting path based on the Splunk Version
2725
- if service .splunk_version < (9 ,0 ,2 ):
2743
+ #if service.splunk_version < (9,0,2):
2744
+ if service .disable_v2_api :
2726
2745
path = path .format (path = PATH_JOBS , sid = sid )
2727
2746
else :
2728
2747
path = path .format (path = PATH_JOBS_V2 , sid = sid )
@@ -2782,7 +2801,8 @@ def events(self, **kwargs):
2782
2801
kwargs ['segmentation' ] = kwargs .get ('segmentation' , 'none' )
2783
2802
2784
2803
# Search API v1(GET) and v2(POST)
2785
- if self .service .splunk_version < (9 ,0 ,2 ):
2804
+ # if self.service.splunk_version < (9,0,2):
2805
+ if self .service .disable_v2_api :
2786
2806
return self .get ("events" , ** kwargs ).body
2787
2807
return self .post ("events" , ** kwargs ).body
2788
2808
@@ -2874,7 +2894,8 @@ def results(self, **query_params):
2874
2894
query_params ['segmentation' ] = query_params .get ('segmentation' , 'none' )
2875
2895
2876
2896
# Search API v1(GET) and v2(POST)
2877
- if self .service .splunk_version < (9 ,0 ,2 ):
2897
+ # if self.service.splunk_version < (9,0,2):
2898
+ if self .service .disable_v2_api :
2878
2899
return self .get ("results" , ** query_params ).body
2879
2900
return self .post ("results" , ** query_params ).body
2880
2901
@@ -2919,7 +2940,8 @@ def preview(self, **query_params):
2919
2940
query_params ['segmentation' ] = query_params .get ('segmentation' , 'none' )
2920
2941
2921
2942
# Search API v1(GET) and v2(POST)
2922
- if self .service .splunk_version < (9 ,0 ,2 ):
2943
+ # if self.service.splunk_version < (9,0,2):
2944
+ if self .service .disable_v2_api :
2923
2945
return self .get ("results_preview" , ** query_params ).body
2924
2946
return self .post ("results_preview" , ** query_params ).body
2925
2947
@@ -3011,7 +3033,8 @@ class Jobs(Collection):
3011
3033
collection using :meth:`Service.jobs`."""
3012
3034
def __init__ (self , service ):
3013
3035
# Splunk 9 introduces the v2 endpoint
3014
- if service .splunk_version >= (9 ,0 ,2 ):
3036
+ # if service.splunk_version >= (9,0,2):
3037
+ if not service .disable_v2_api :
3015
3038
path = PATH_JOBS_V2
3016
3039
else :
3017
3040
path = PATH_JOBS
0 commit comments