@@ -421,6 +421,7 @@ def __init__(self, **kwargs):
421421 super (Service , self ).__init__ (** kwargs )
422422 self ._splunk_version = None
423423 self ._kvstore_owner = None
424+ self ._instance_type = None
424425
425426 @property
426427 def apps (self ):
@@ -572,7 +573,8 @@ def parse(self, query, **kwargs):
572573 :type kwargs: ``dict``
573574 :return: A semantic map of the parsed search query.
574575 """
575- if self .splunk_version >= (9 ,0 ,2 ):
576+ # if self.splunk_version >= (9,0,2):
577+ if not self .disable_v2_api :
576578 return self .post ("search/v2/parser" , q = query , ** kwargs )
577579 return self .get ("search/parser" , q = query , ** kwargs )
578580
@@ -695,6 +697,22 @@ def splunk_version(self):
695697 self ._splunk_version = tuple ([int (p ) for p in self .info ['version' ].split ('.' )])
696698 return self ._splunk_version
697699
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+
698716 @property
699717 def kvstore_owner (self ):
700718 """Returns the KVStore owner for this instance of Splunk.
@@ -2722,7 +2740,8 @@ def __init__(self, service, sid, **kwargs):
27222740 # Default to v2 in Splunk Version 9+
27232741 path = "{path}{sid}"
27242742 # 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 :
27262745 path = path .format (path = PATH_JOBS , sid = sid )
27272746 else :
27282747 path = path .format (path = PATH_JOBS_V2 , sid = sid )
@@ -2782,7 +2801,8 @@ def events(self, **kwargs):
27822801 kwargs ['segmentation' ] = kwargs .get ('segmentation' , 'none' )
27832802
27842803 # 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 :
27862806 return self .get ("events" , ** kwargs ).body
27872807 return self .post ("events" , ** kwargs ).body
27882808
@@ -2874,7 +2894,8 @@ def results(self, **query_params):
28742894 query_params ['segmentation' ] = query_params .get ('segmentation' , 'none' )
28752895
28762896 # 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 :
28782899 return self .get ("results" , ** query_params ).body
28792900 return self .post ("results" , ** query_params ).body
28802901
@@ -2919,7 +2940,8 @@ def preview(self, **query_params):
29192940 query_params ['segmentation' ] = query_params .get ('segmentation' , 'none' )
29202941
29212942 # 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 :
29232945 return self .get ("results_preview" , ** query_params ).body
29242946 return self .post ("results_preview" , ** query_params ).body
29252947
@@ -3011,7 +3033,8 @@ class Jobs(Collection):
30113033 collection using :meth:`Service.jobs`."""
30123034 def __init__ (self , service ):
30133035 # 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 :
30153038 path = PATH_JOBS_V2
30163039 else :
30173040 path = PATH_JOBS
0 commit comments